设为首页 收藏本站
查看: 1275|回复: 0

[经验分享] FastDFS HOWTO

[复制链接]
累计签到:4 天
连续签到:1 天
发表于 2015-9-10 09:00:44 | 显示全部楼层 |阅读模式
  The communication protocol of FastDFS is TCP/IP, the package composes of header and body which may be empty.
  header format:
  @ TRACKER_PROTO_PKG_LEN_SIZE bytes package length
  @ 1 byte command
  @ 1 byte status
  note:
   # TRACKER_PROTO_PKG_LEN_SIZE (8) bytes number buff is Big-Endian bytes
  
body format:
1. common command(普通命令)
* FDFS_PROTO_CMD_QUIT(终止连接)
  # function: notify server connection will be closed
  # request body: none (no body part)
  # response: none (no header and no body)
  
2. storage server to tracker server command(SS与TS 间的命令)
  * the reponse command is TRACKER_PROTO_CMD_STORAGE_RESP

* TRACKER_PROTO_CMD_STORAGE_JOIN(SS加入TS)
  # function: storage join to tracker
  # request body:
      @ FDFS_GROUP_NAME_MAX_LEN + 1 bytes: group name
      @ TRACKER_PROTO_PKG_LEN_SIZE bytes: storage port
  # response body: n * (1 + FDFS_IPADDR_SIZE) bytes, n >= 0. One storage entry format:
      @ 1 byte: storage server status
      @ FDFS_IPADDR_SIZE bytes: storage server ip address
  # memo: return all storage servers in the group only when storage servers changed or return none
  
  
* TRACKER_PROTO_CMD_STORAGE_BEAT(SS向TS发送heart beat)
  # function: heart beat
  # request body: none or storage stat info
       @ TRACKER_PROTO_PKG_LEN_SIZE bytes: total upload count
       @ TRACKER_PROTO_PKG_LEN_SIZE bytes: success upload count
       @ TRACKER_PROTO_PKG_LEN_SIZE bytes: total set metadata count
       @ TRACKER_PROTO_PKG_LEN_SIZE bytes: success set metadata count
       @ TRACKER_PROTO_PKG_LEN_SIZE bytes: total delete count
       @ TRACKER_PROTO_PKG_LEN_SIZE bytes: success delete count
       @ TRACKER_PROTO_PKG_LEN_SIZE bytes: total download count
       @ TRACKER_PROTO_PKG_LEN_SIZE bytes: success download count
       @ TRACKER_PROTO_PKG_LEN_SIZE bytes: total get metadata count
       @ TRACKER_PROTO_PKG_LEN_SIZE bytes: success get metadata count
       @ TRACKER_PROTO_PKG_LEN_SIZE bytes: last source update timestamp
       @ TRACKER_PROTO_PKG_LEN_SIZE bytes: last sync update timestamp
  # response body: same to command TRACKER_PROTO_CMD_STORAGE_JOIN
  # memo: storage server sync it's stat info to tracker server only when storage stat info changed
  
* TRACKER_PROTO_CMD_STORAGE_REPORT(报告磁盘使用情况)
  # function: report disk usage
  # request body:
      @ TRACKER_PROTO_PKG_LEN_SIZE bytes: total space in MB
      @ TRACKER_PROTO_PKG_LEN_SIZE bytes: free space in MB
  # response body: same to command TRACKER_PROTO_CMD_STORAGE_JOIN
  
* TRACKER_PROTO_CMD_STORAGE_REPLICA_CHG(复制新加入的SS)
  # function: replica new storage servers which maybe not exist in the tracker server
  # request body: n * (1 + FDFS_IPADDR_SIZE) bytes, n >= 1. One storage entry format:
      @ 1 byte: storage server status
      @ FDFS_IPADDR_SIZE bytes: storage server ip address
  # response body: none
  
* TRACKER_PROTO_CMD_STORAGE_SYNC_SRC_REQ(当加入新的SS时,同步SS)
  # function: sourcestorage require sync. when add a new storage server, the existed storage servers in the same group will ask the tracker server to tell the source storage server which will sync old data to it
  # request body:
      @ FDFS_IPADDR_SIZE bytes: dest storage server (new storage server) ip address
  # response body: none or
     @ FDFS_IPADDR_SIZE bytes: source storage server ip address
     @ TRACKER_PROTO_PKG_LEN_SIZE bytes: sync until timestamp
  # memo: if the dest storage server not do need sync from one of storage servers in the group, the response body is emtpy
  
* TRACKER_PROTO_CMD_STORAGE_SYNC_DEST_REQ(新加入的SS请求同步)
  # function: dest storage server (new storage server) require sync
  # request body: none
  # response body: none or
     @ FDFS_IPADDR_SIZE bytes: source storage server ip address
     @ TRACKER_PROTO_PKG_LEN_SIZE bytes: sync until timestamp
  # memo: if the dest storage server not do need sync from one of storage servers in the group, the response body is emtpy
  
* TRACKER_PROTO_CMD_STORAGE_SYNC_NOTIFY(新加入的SS同步通知)
  # function: new storage server sync notify
  # request body:
     @ FDFS_IPADDR_SIZE bytes: source storage server ip address
     @ TRACKER_PROTO_PKG_LEN_SIZE bytes: sync until timestamp
  # response body: same to command TRACKER_PROTO_CMD_STORAGE_JOIN
  
3. client to tracker server command(Client与TS之间的命令)
  * the reponse command of following 2 commands is TRACKER_PROTO_CMD_SERVER_RESP

* TRACKER_PROTO_CMD_SERVER_LIST_GROUP(列出所有的组)
  # function: list all groups
  # request body: none
  # response body: n group entries, n >= 0, the format of each entry:
     @ FDFS_GROUP_NAME_MAX_LEN+1 bytes: group name
     @ TRACKER_PROTO_PKG_LEN_SIZE bytes: free disk storage in MB
     @ TRACKER_PROTO_PKG_LEN_SIZE bytes: storage server count
     @ TRACKER_PROTO_PKG_LEN_SIZE bytes: storage server port
     @ TRACKER_PROTO_PKG_LEN_SIZE bytes: active server count
     @ TRACKER_PROTO_PKG_LEN_SIZE bytes: current write server index
  
* TRACKER_PROTO_CMD_SERVER_LIST_STORAGE(列出一个组的SS信息)
  # function: list storage servers of a group
  # request body:
     @ FDFS_GROUP_NAME_MAX_LEN bytes: the group name to query
  # response body: n storage entries, n >= 0, the format of each entry:
       @ 1 byte: status
       @ FDFS_IPADDR_SIZE byte: ip address
       @ TRACKER_PROTO_PKG_LEN_SIZE bytes: total space in MB
       @ TRACKER_PROTO_PKG_LEN_SIZE bytes: free space in MB
       @ TRACKER_PROTO_PKG_LEN_SIZE bytes: total upload count
       @ TRACKER_PROTO_PKG_LEN_SIZE bytes: success upload count
       @ TRACKER_PROTO_PKG_LEN_SIZE bytes: total set metadata count
       @ TRACKER_PROTO_PKG_LEN_SIZE bytes: success set metadata count
       @ TRACKER_PROTO_PKG_LEN_SIZE bytes: total delete count
       @ TRACKER_PROTO_PKG_LEN_SIZE bytes: success delete count
       @ TRACKER_PROTO_PKG_LEN_SIZE bytes: total download count
       @ TRACKER_PROTO_PKG_LEN_SIZE bytes: success download count
       @ TRACKER_PROTO_PKG_LEN_SIZE bytes: total get metadata count
       @ TRACKER_PROTO_PKG_LEN_SIZE bytes: success get metadata count
       @ TRACKER_PROTO_PKG_LEN_SIZE bytes: last source update timestamp
       @ TRACKER_PROTO_PKG_LEN_SIZE bytes: last sync update timestamp


* the reponse command of following 2 commands is TRACKER_PROTO_CMD_SERVICE_RESP

* TRACKER_PROTO_CMD_SERVICE_QUERY_STORE(询问让哪个SS存储文件)
  # function: query which storage server to store file
  # request body: none
  # response body:
     @ FDFS_GROUP_NAME_MAX_LEN bytes: group name
     @ FDFS_IPADDR_SIZE - 1 bytes: storage server ip address
     @ TRACKER_PROTO_PKG_LEN_SIZE bytes: storage server port  
  
  
* TRACKER_PROTO_CMD_SERVICE_QUERY_FETCH(询问从哪个SS下载文件)
  # function: query which storage server to download the file
  # request body:
     @ FDFS_GROUP_NAME_MAX_LEN bytes: group name
     @ filename bytes: filename
  # response body:
     @ FDFS_GROUP_NAME_MAX_LEN bytes: group name
     @ FDFS_IPADDR_SIZE - 1 bytes: storage server ip address
     @ TRACKER_PROTO_PKG_LEN_SIZE bytes: storage server port
  4. storage server to storage server command(SS之间的命令)
* the reponse command is STORAGE_PROTO_CMD_RESP

* STORAGE_PROTO_CMD_SYNC_CREATE_FILE(同步新创建的文件)
  # function: sync new created file
  # request body:
     @ TRACKER_PROTO_PKG_LEN_SIZE bytes: filename bytes
     @ TRACKER_PROTO_PKG_LEN_SIZE bytes: file size/bytes
     @ FDFS_GROUP_NAME_MAX_LEN bytes: group name
     @ filename bytes : filename
     @ file size bytes: file content
  # response body: none
  
  
* STORAGE_PROTO_CMD_SYNC_DELETE_FILE(同步被删除的文件)
  # function: sync deleted file
  # request body:
     @ FDFS_GROUP_NAME_MAX_LEN bytes: group name
     @ filename bytes: filename
  # response body: none  
  
* STORAGE_PROTO_CMD_SYNC_UPDATE_FILE(同步被更新的文件)
# function: sync updated file
# request body: same to command STORAGE_PROTO_CMD_SYNC_CREATE_FILE
# respose body: none


5. client to storage server command(Client与SS之间的命令)
* the reponse command is STORAGE_PROTO_CMD_RESP
  * STORAGE_PROTO_CMD_UPLOAD_FILE(向SS上传文件)
  # function: upload file to storage server
  # request body:
      @ TRACKER_PROTO_PKG_LEN_SIZE bytes: meta data bytes
      @ TRACKER_PROTO_PKG_LEN_SIZE bytes: file size
      @ meta data bytes: each meta data seperated by \x01,
                         name and value seperated by \x02
      @ file size bytes: file content
  # response body:
     @ FDFS_GROUP_NAME_MAX_LEN bytes: group name
     @ filename bytes: filename
  
* STORAGE_PROTO_CMD_DELETE_FILE(从SS删除文件)
  # function: delete file from storage server
  # request body:
     @ FDFS_GROUP_NAME_MAX_LEN bytes: group name
     @ filename bytes: filename
  # response body: none
  
* STORAGE_PROTO_CMD_SET_METADATA(从SS删除metadata)
  # function: delete file from storage server
  # request body:
      @ TRACKER_PROTO_PKG_LEN_SIZE bytes: filename length
      @ TRACKER_PROTO_PKG_LEN_SIZE bytes: meta data size
      @ 1 bytes: operation flag,  
           'O' for overwrite all old metadata
           'M' for merge, insert when the meta item not exist, otherwise update it
      @ FDFS_GROUP_NAME_MAX_LEN bytes: group name
      @ filename bytes: filename
      @ meta data bytes: each meta data seperated by \x01,
                         name and value seperated by \x02
  # response body: none
  
* STORAGE_PROTO_CMD_DOWNLOAD_FILE(从SS下载文件)
  # function: download/fetch file from storage server
  # request body:
      @ FDFS_GROUP_NAME_MAX_LEN bytes: group name
      @ filename bytes: filename
  # response body:
      @ file content
  

* STORAGE_PROTO_CMD_GET_METADATA(从SS获得metadata)
  # function: get metat data from storage server
  # request body:
      @ FDFS_GROUP_NAME_MAX_LEN bytes: group name
      @ filename bytes: filename
  # response body
      @ meta data buff, each meta data seperated by \x01, name and value seperated by \x02

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-111744-1-1.html 上篇帖子: FastDFS 基础知识 下篇帖子: 配置FastDFS
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表