FastDFS源码阅读笔记.pdf
文本预览下载声明
FastDFS 源码阅读笔记(一)
FastDFS 是fishman 大牛做的分布式文件系统,并且将项目源码进行了开源,小
弟抱着学习的态度,学习了源码,并且将自己关心的比如上传文件,下载文件,文件
的数据同步在看的途中做了下学习笔记.
首先是数据服务器storage 部分.
(一).storage_nio.c
//对于超时的处理:删除文件列表,释放任务到队列里面
void task_finish_clean_up(struct fast_task_info *pTask)
{
StorageClientInfo *pClientInfo;
StorageFileContext *pFileContext;
pClientInfo = (StorageClientInfo *)pTask-arg;
pFileContext = (pClientInfo-file_context);
if (pFileContext-fd 0)
{
close(pFileContext-fd);
/* if file does not write to the end, delete it */
if (pFileContext-op == FDFS_STORAGE_FILE_OP_WRITE /
pFileContext-offset pFileContext-end)
{
if (unlink(pFileContext-filename) != 0)
{
logError(file: __FILE__, line: %d, /
client ip: %s, /
delete useless file %s fail, /
errno: %d, error info: %s, /
__LINE__, pTask-client_ip, /
pFileContext-filename, /
errno, strerror(errno));
}
}
}
close(pClientInfo-sock);
memset(pTask-arg, 0, sizeof(StorageClientInfo));
free_queue_push(pTask);
}
//数据服务器socket 事件回调,比如说在上传文件时,接收了一部分之后,调用
storage_nio_notify(pTask)
//又重新发起接收读socket 的操作,而pClientInfo-stage=FDFS_STORAGE_STAGE_NIO_RECV
//的这个赋值并没有发生改变
void storage_recv_notify_read(int sock, short event, void *arg)
{
struct fast_task_info *pTask;
StorageClientInfo *pClientInfo; //注意这个参数是不同的,一个是跟踪服务器参
数,一个是数据服务器参数
long task_addr;
int bytes;
int result;
while (1)
{
if ((bytes=read(sock, task_addr, sizeof(task_addr))) 0)
{
if (!(errno == EAGAIN || errno == EWOULDBLOCK))
{
logError(file: __FILE__, line: %d, /
显示全部