Chinaunix首页 | 论坛 | 博客
  • 博客访问: 96008
  • 博文数量: 31
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 380
  • 用 户 组: 普通用户
  • 注册时间: 2014-02-24 22:04
文章分类

全部博文(31)

文章存档

2014年(31)

我的朋友

分类: C/C++

2014-07-29 11:27:38




|------tracker_load_data        
    |-----tracker_load_groups_new
        |-----tracker_load_groups_new
        |-----tracker_save_groups
        |-----iniloadFormFile
        |-----tracker_mem_add_group_ex
        |-----iniFreeContext
    
    |-----tracker_load_storage_new
        |-----tracker_load_storage_old
        |-----tracker_save_storage
        |-----iniLoadFormFile
        |-----tracker_mem_get_group_ex
        |-----tracker_mem_add_storage
            |-----tracker_mem_add_storage
            |-----tracker_mem_relloc_store_severs
        |-----iniFreeContext
        |-----tracker_locate_storage_sync_server
    
    |-----tracker_malloc_all_group_path_mbs
        |-----tracker_malloc_group_path_mbs
            |-----tracker_malloc_storage_path_mbs

    |-----tracker_load_sync_timestamps

tracker_malloc_all_group_path_mb函数:

点击(此处)折叠或打开

  1. //为所有group中的store_path分配空间
  2. static int tracker_malloc_all_group_path_mbs(FDFSGroups *pGroups)
  3. {
  4.     FDFSGroupInfo **ppGroup;
  5.     FDFSGroupInfo **ppEnd;
  6.     int result;

  7.     ppEnd = pGroups->groups + pGroups->alloc_size;
  8.     for (ppGroup=pGroups->groups; ppGroup<ppEnd; ppGroup++)
  9.     {
  10.         if ((*ppGroup)->store_path_count == 0)
  11.         {
  12.             continue;
  13.         }
  14.         //为单个group中的store_path分配空间
  15.         if ((result=tracker_malloc_group_path_mbs(*ppGroup)) != 0)
  16.         {
  17.             return result;
  18.         }
  19.     }

  20.     return 0;
  21. }
tracker_malloc_all_group_path_mb执行逻辑:
(1) 遍历groups中的每个group
(2) 调用函数tracker_malloc_group_path_mbs处理每个group


tracker_malloc_group_path_mbs函数:

点击(此处)折叠或打开

  1. //为group中的store_path分配空间
  2. static int tracker_malloc_group_path_mbs(FDFSGroupInfo *pGroup)
  3. {
  4.     FDFSStorageDetail **ppStorage;
  5.     FDFSStorageDetail **ppEnd;
  6.     int result;

  7.     ppEnd = pGroup->all_servers + pGroup->alloc_size;
  8.     for (ppStorage=pGroup->all_servers; ppStorage<ppEnd; ppStorage++)
  9.     {
  10.         //为单个store中的store_path分配空间
  11.         if ((result=tracker_malloc_storage_path_mbs(*ppStorage, \
  12.                 pGroup->store_path_count)) != 0)
  13.         {
  14.             return result;
  15.         }
  16.     }

  17.     return 0;
  18. }
tracker_malloc_group_path_mbs执行逻辑:
(1) 遍历groups中的每个storage
(2) 调用函数tracker_malloc_storage_path_mbs处理每个storage


tracker_malloc_storage_path_mbs函数:

点击(此处)折叠或打开

  1. //为每个storage中的store_path分配空间
  2. static int tracker_malloc_storage_path_mbs(FDFSStorageDetail *pStorage, \
  3.         const int store_path_count)
  4. {
  5.     int alloc_bytes; //需要分配的字节数

  6.     if (store_path_count <= 0)
  7.     {
  8.         return 0;
  9.     }

  10.     alloc_bytes = sizeof(int64_t) * store_path_count; //8 * 每个storge上的store_path的个数

  11.     pStorage->path_total_mbs = (int64_t *)malloc(alloc_bytes); //总共的mbs
  12.     if (pStorage->path_total_mbs == NULL)
  13.     {
  14.         logError("file: "__FILE__", line: %d, " \
  15.             "malloc %d bytes fail, " \
  16.             "errno: %d, error info: %s", \
  17.             __LINE__, alloc_bytes, errno, STRERROR(errno));
  18.         return errno != 0 ? errno : ENOMEM;
  19.     }

  20.     pStorage->path_free_mbs = (int64_t *)malloc(alloc_bytes); //剩余的mbs
  21.     if (pStorage->path_free_mbs == NULL)
  22.     {
  23.         free(pStorage->path_total_mbs);
  24.         pStorage->path_total_mbs = NULL;

  25.         logError("file: "__FILE__", line: %d, " \
  26.             "malloc %d bytes fail, " \
  27.             "errno: %d, error info: %s", \
  28.             __LINE__, alloc_bytes, errno, STRERROR(errno));
  29.         return errno != 0 ? errno : ENOMEM;
  30.     }

  31.     memset(pStorage->path_total_mbs, 0, alloc_bytes);
  32.     memset(pStorage->path_free_mbs, 0, alloc_bytes);

  33.     return 0;
  34. }
tracker_malloc_storage_path_mbs函数执行逻辑:
(1) 计算一共需要分配的字节数
(2) 给path_total_mbs分配空间
(3) 给path_free_mbs分配空间
(4) 初始化path_total_mbs与path_free_mbs

阅读(630) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~