|------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函数:
-
//为所有group中的store_path分配空间
-
static int tracker_malloc_all_group_path_mbs(FDFSGroups *pGroups)
-
{
-
FDFSGroupInfo **ppGroup;
-
FDFSGroupInfo **ppEnd;
-
int result;
-
-
ppEnd = pGroups->groups + pGroups->alloc_size;
-
for (ppGroup=pGroups->groups; ppGroup<ppEnd; ppGroup++)
-
{
-
if ((*ppGroup)->store_path_count == 0)
-
{
-
continue;
-
}
-
//为单个group中的store_path分配空间
-
if ((result=tracker_malloc_group_path_mbs(*ppGroup)) != 0)
-
{
-
return result;
-
}
-
}
-
-
return 0;
-
}
tracker_malloc_all_group_path_mb执行逻辑:
(1) 遍历groups中的每个group
(2) 调用函数tracker_malloc_group_path_mbs处理每个group
tracker_malloc_group_path_mbs函数:
-
//为group中的store_path分配空间
-
static int tracker_malloc_group_path_mbs(FDFSGroupInfo *pGroup)
-
{
-
FDFSStorageDetail **ppStorage;
-
FDFSStorageDetail **ppEnd;
-
int result;
-
-
ppEnd = pGroup->all_servers + pGroup->alloc_size;
-
for (ppStorage=pGroup->all_servers; ppStorage<ppEnd; ppStorage++)
-
{
-
//为单个store中的store_path分配空间
-
if ((result=tracker_malloc_storage_path_mbs(*ppStorage, \
-
pGroup->store_path_count)) != 0)
-
{
-
return result;
-
}
-
}
-
-
return 0;
-
}
tracker_malloc_group_path_mbs执行逻辑:
(1) 遍历groups中的每个storage
(2) 调用函数tracker_malloc_storage_path_mbs处理每个storage
tracker_malloc_storage_path_mbs函数:
-
//为每个storage中的store_path分配空间
-
static int tracker_malloc_storage_path_mbs(FDFSStorageDetail *pStorage, \
-
const int store_path_count)
-
{
-
int alloc_bytes; //需要分配的字节数
-
-
if (store_path_count <= 0)
-
{
-
return 0;
-
}
-
-
alloc_bytes = sizeof(int64_t) * store_path_count; //8 * 每个storge上的store_path的个数
-
-
pStorage->path_total_mbs = (int64_t *)malloc(alloc_bytes); //总共的mbs
-
if (pStorage->path_total_mbs == NULL)
-
{
-
logError("file: "__FILE__", line: %d, " \
-
"malloc %d bytes fail, " \
-
"errno: %d, error info: %s", \
-
__LINE__, alloc_bytes, errno, STRERROR(errno));
-
return errno != 0 ? errno : ENOMEM;
-
}
-
-
pStorage->path_free_mbs = (int64_t *)malloc(alloc_bytes); //剩余的mbs
-
if (pStorage->path_free_mbs == NULL)
-
{
-
free(pStorage->path_total_mbs);
-
pStorage->path_total_mbs = NULL;
-
-
logError("file: "__FILE__", line: %d, " \
-
"malloc %d bytes fail, " \
-
"errno: %d, error info: %s", \
-
__LINE__, alloc_bytes, errno, STRERROR(errno));
-
return errno != 0 ? errno : ENOMEM;
-
}
-
-
memset(pStorage->path_total_mbs, 0, alloc_bytes);
-
memset(pStorage->path_free_mbs, 0, alloc_bytes);
-
-
return 0;
-
}
tracker_malloc_storage_path_mbs函数执行逻辑:
(1) 计算一共需要分配的字节数
(2) 给path_total_mbs分配空间
(3) 给path_free_mbs分配空间
(4) 初始化path_total_mbs与path_free_mbs
阅读(639) | 评论(0) | 转发(0) |