|------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_malloc_all_group_path_mbs
|-----tracker_load_sync_timestamps
tracker_load_groups_new函数:
-
//从storage_groups_new.dat获取group数据
-
static int tracker_load_groups_new(FDFSGroups *pGroups, const char *data_path)
-
{
-
IniContext iniContext; //保存从配置文件中读取信息
-
FDFSGroupInfo *pGroup;
-
char *group_name;
-
int group_count;
-
int result;
-
int i;
-
char section_name[64];
-
TrackerClientInfo clientInfo;
-
bool bInserted;
-
-
if (!fileExists(STORAGE_GROUPS_LIST_FILENAME_NEW) && \//若_new不存在,并且_old存在
-
fileExists(STORAGE_GROUPS_LIST_FILENAME_OLD))
-
{
-
logDebug("file: "__FILE__", line: %d, " \
-
"convert old data file %s to new data file %s", \
-
__LINE__, STORAGE_GROUPS_LIST_FILENAME_OLD, \
-
STORAGE_GROUPS_LIST_FILENAME_NEW);
-
if ((result=tracker_load_groups_old(pGroups, data_path)) == 0)//从_old文件中读取配置
-
{
-
if ((result=tracker_save_groups()) == 0)//把_old文件变成_new文件
-
{
-
unlink(STORAGE_GROUPS_LIST_FILENAME_OLD); //删除_old文件
-
}
-
}
-
-
return result;
-
}
-
-
if ((result=iniLoadFromFile(STORAGE_GROUPS_LIST_FILENAME_NEW, \
-
&iniContext)) != 0)//从新的group文件中获取配置信息,并保存到inicontext结构中
-
{
-
return result;
-
}
-
-
group_count = iniGetIntValue(GROUP_SECTION_NAME_GLOBAL, \//获取集群中group的数目
-
GROUP_ITEM_GROUP_COUNT, \
-
&iniContext, -1);
-
if (group_count < 0)
-
{
-
iniFreeContext(&iniContext);
-
logError("file: "__FILE__", line: %d, " \
-
"in the file \"%s/%s\", " \
-
"item \"%s\" is not found", \
-
__LINE__, data_path, \
-
STORAGE_GROUPS_LIST_FILENAME_NEW, \
-
GROUP_ITEM_GROUP_COUNT);
-
return ENOENT;
-
}
-
-
for (i=1; i<=group_count; i++)//依次获取section name,如Group001
-
{
-
sprintf(section_name, "%s"GROUP_SECTION_NO_FORMAT, \
-
GROUP_SECTION_NAME_PREFIX, i);
-
-
group_name = iniGetStrValue(section_name, \//从section name中获取group name
-
GROUP_ITEM_GROUP_NAME, &iniContext);
-
if (group_name == NULL)
-
{
-
logError("file: "__FILE__", line: %d, " \
-
"in the file \"%s/%s\", " \
-
"item \"%s\" is not found", \
-
__LINE__, data_path, \
-
STORAGE_GROUPS_LIST_FILENAME_NEW, \
-
GROUP_ITEM_GROUP_NAME);
-
result = ENOENT;
-
break;
-
}
-
-
memset(&clientInfo, 0, sizeof(TrackerClientInfo));
-
if ((result=tracker_mem_add_group_ex(pGroups, &clientInfo, \//从pGroups中找到一个group,若没有找到,
-
group_name, false, &bInserted)) != 0) //则,创建一个group,放入到pGroups中
-
{
-
break;
-
}
-
-
if (!bInserted)
-
{
-
logError("file: "__FILE__", line: %d, " \
-
"in the file \"%s/%s\", " \
-
"group \"%s\" is duplicate", \
-
__LINE__, data_path, \
-
STORAGE_GROUPS_LIST_FILENAME_NEW, \
-
group_name);
-
result = errno != 0 ? errno : EEXIST;
-
break;
-
}
-
-
pGroup = clientInfo.pGroup;
-
pGroup->storage_port = iniGetIntValue(section_name, \
-
GROUP_ITEM_STORAGE_PORT, &iniContext, 0);
-
pGroup->storage_http_port = iniGetIntValue(section_name, \
-
GROUP_ITEM_STORAGE_HTTP_PORT, &iniContext, 0);
-
pGroup->store_path_count = iniGetIntValue(section_name, \
-
GROUP_ITEM_STORE_PATH_COUNT, &iniContext, 0);
-
pGroup->subdir_count_per_path = iniGetIntValue(section_name, \
-
GROUP_ITEM_SUBDIR_COUNT_PER_PATH, &iniContext, 0);
-
}
-
-
iniFreeContext(&iniContext); //释放iniContext空间
-
-
return result;
-
}
tracker_load_groups_new函数执行逻辑:
(1) 从配置文件中读取group配置信息并写入到group对象中。
(2) 为了兼容老的版本,先调用tracker_load_groups_old函数读取老的配置文件,并把数据写入新的配置文件。
(3) 读取新配置文件中的数据到iniContext结构中,再从iniContext中读取数据。
(4) 调用tracker_mem_add_group_ex函数把读取的数据写入到group对象中,tracker_mem_add_group_ex函数将在下一节详细分析。
阅读(1123) | 评论(0) | 转发(0) |