support multi ip for storage server (tracker part)
parent
82e95ccee7
commit
ae8024d355
|
|
@ -188,6 +188,30 @@ static int fdfs_init_ip_array(FDFSStorageIdMapArray *mapArray,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int fdfs_check_id_duplicated()
|
||||||
|
{
|
||||||
|
FDFSStorageIdInfo *current;
|
||||||
|
FDFSStorageIdInfo *idEnd;
|
||||||
|
FDFSStorageIdInfo *previous;
|
||||||
|
|
||||||
|
current=g_storage_ids_by_id.ids + 0;
|
||||||
|
idEnd = g_storage_ids_by_id.ids + g_storage_ids_by_id.count;
|
||||||
|
for (current=g_storage_ids_by_id.ids + 1; current<idEnd; current++)
|
||||||
|
{
|
||||||
|
if (strcmp(current->id, previous->id) == 0)
|
||||||
|
{
|
||||||
|
logError("file: "__FILE__", line: %d, "
|
||||||
|
"config file: storage_ids.conf, "
|
||||||
|
"duplicate storage id: %s",
|
||||||
|
__LINE__, current->id);
|
||||||
|
return EEXIST;
|
||||||
|
}
|
||||||
|
previous = current;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int fdfs_check_ip_port()
|
static int fdfs_check_ip_port()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
@ -490,6 +514,10 @@ int fdfs_load_storage_ids(char *content, const char *pStorageIdsFilename)
|
||||||
|
|
||||||
qsort(g_storage_ids_by_id.ids, g_storage_ids_by_id.count,
|
qsort(g_storage_ids_by_id.ids, g_storage_ids_by_id.count,
|
||||||
sizeof(FDFSStorageIdInfo), fdfs_cmp_server_id);
|
sizeof(FDFSStorageIdInfo), fdfs_cmp_server_id);
|
||||||
|
if ((result=fdfs_check_id_duplicated()) != 0)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
if ((result=fdfs_init_ip_array(&g_storage_ids_by_ip,
|
if ((result=fdfs_init_ip_array(&g_storage_ids_by_ip,
|
||||||
fdfs_cmp_group_name_and_ip)) != 0)
|
fdfs_cmp_group_name_and_ip)) != 0)
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ int fdfs_load_storage_ids(char *content, const char *pStorageIdsFilename);
|
||||||
|
|
||||||
FDFSStorageIdInfo *fdfs_get_storage_by_id(const char *id);
|
FDFSStorageIdInfo *fdfs_get_storage_by_id(const char *id);
|
||||||
|
|
||||||
FDFSStorageIdInfo *fdfs_get_storage_id_by_ip(const char *group_name, \
|
FDFSStorageIdInfo *fdfs_get_storage_id_by_ip(const char *group_name,
|
||||||
const char *pIpAddr);
|
const char *pIpAddr);
|
||||||
|
|
||||||
FDFSStorageIdInfo *fdfs_get_storage_id_by_ip_port(const char *pIpAddr,
|
FDFSStorageIdInfo *fdfs_get_storage_id_by_ip_port(const char *pIpAddr,
|
||||||
|
|
@ -71,7 +71,7 @@ int fdfs_get_storage_ids_from_tracker_server(TrackerServerInfo *pTrackerServer);
|
||||||
|
|
||||||
int fdfs_get_storage_ids_from_tracker_group(TrackerServerGroup *pTrackerGroup);
|
int fdfs_get_storage_ids_from_tracker_group(TrackerServerGroup *pTrackerGroup);
|
||||||
|
|
||||||
int fdfs_load_storage_ids_from_file(const char *config_filename, \
|
int fdfs_load_storage_ids_from_file(const char *config_filename,
|
||||||
IniContext *pItemContext);
|
IniContext *pItemContext);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
||||||
|
|
@ -525,6 +525,7 @@ int fdfs_parse_multi_ips_ex(char *ip_str, FDFSMultiIP *ip_addrs,
|
||||||
char *hosts[FDFS_MULTI_IP_MAX_COUNT];
|
char *hosts[FDFS_MULTI_IP_MAX_COUNT];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
ip_addrs->index = 0;
|
||||||
ip_addrs->count = splitEx(ip_str, ',', hosts, FDFS_MULTI_IP_MAX_COUNT);
|
ip_addrs->count = splitEx(ip_str, ',', hosts, FDFS_MULTI_IP_MAX_COUNT);
|
||||||
for (i=0; i<ip_addrs->count; i++)
|
for (i=0; i<ip_addrs->count; i++)
|
||||||
{
|
{
|
||||||
|
|
@ -641,3 +642,21 @@ int fdfs_check_and_format_ips(FDFSMultiIP *ip_addrs,
|
||||||
*error_info = '\0';
|
*error_info = '\0';
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void fdfs_set_multi_ip_index(FDFSMultiIP *multi_ip, const char *target_ip)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
if (multi_ip->count == 1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i=0; i<multi_ip->count; i++)
|
||||||
|
{
|
||||||
|
if (strcmp(multi_ip->ips[i], target_ip) == 0)
|
||||||
|
{
|
||||||
|
multi_ip->index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -122,6 +122,8 @@ int fdfs_check_and_format_ips(FDFSMultiIP *ip_addrs,
|
||||||
const char *fdfs_get_ipaddr_by_client_ip(const FDFSMultiIP *ip_addrs,
|
const char *fdfs_get_ipaddr_by_client_ip(const FDFSMultiIP *ip_addrs,
|
||||||
const char *client_ip);
|
const char *client_ip);
|
||||||
|
|
||||||
|
void fdfs_set_multi_ip_index(FDFSMultiIP *multi_ip, const char *target_ip);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -72,8 +72,8 @@ static int fdfs_dump_group_stat(FDFSGroupInfo *pGroup, char *buff, const int buf
|
||||||
pGroup->store_path_count,
|
pGroup->store_path_count,
|
||||||
pGroup->subdir_count_per_path,
|
pGroup->subdir_count_per_path,
|
||||||
pGroup->current_trunk_file_id,
|
pGroup->current_trunk_file_id,
|
||||||
pGroup->pStoreServer != NULL ? pGroup->pStoreServer->ip_addr : "",
|
pGroup->pStoreServer != NULL ? FDFS_CURRENT_IP_ADDR(pGroup->pStoreServer) : "",
|
||||||
pGroup->pTrunkServer != NULL ? pGroup->pTrunkServer->ip_addr : "",
|
pGroup->pTrunkServer != NULL ? FDFS_CURRENT_IP_ADDR(pGroup->pTrunkServer) : "",
|
||||||
pGroup->last_trunk_server_id,
|
pGroup->last_trunk_server_id,
|
||||||
pGroup->chg_count,
|
pGroup->chg_count,
|
||||||
pGroup->trunk_chg_count,
|
pGroup->trunk_chg_count,
|
||||||
|
|
@ -91,7 +91,7 @@ static int fdfs_dump_group_stat(FDFSGroupInfo *pGroup, char *buff, const int buf
|
||||||
for (ppServer=pGroup->all_servers; ppServer<ppServerEnd; ppServer++)
|
for (ppServer=pGroup->all_servers; ppServer<ppServerEnd; ppServer++)
|
||||||
{
|
{
|
||||||
total_len += snprintf(buff + total_len, buffSize - total_len,
|
total_len += snprintf(buff + total_len, buffSize - total_len,
|
||||||
"\t%s\n", (*ppServer)->ip_addr);
|
"\t%s\n", FDFS_CURRENT_IP_ADDR(*ppServer));
|
||||||
}
|
}
|
||||||
|
|
||||||
total_len += snprintf(buff + total_len, buffSize - total_len,
|
total_len += snprintf(buff + total_len, buffSize - total_len,
|
||||||
|
|
@ -100,7 +100,7 @@ static int fdfs_dump_group_stat(FDFSGroupInfo *pGroup, char *buff, const int buf
|
||||||
for (ppServer=pGroup->active_servers; ppServer<ppServerEnd; ppServer++)
|
for (ppServer=pGroup->active_servers; ppServer<ppServerEnd; ppServer++)
|
||||||
{
|
{
|
||||||
total_len += snprintf(buff + total_len, buffSize - total_len,
|
total_len += snprintf(buff + total_len, buffSize - total_len,
|
||||||
"\t%s\n", (*ppServer)->ip_addr);
|
"\t%s\n", FDFS_CURRENT_IP_ADDR(*ppServer));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WITH_HTTPD
|
#ifdef WITH_HTTPD
|
||||||
|
|
@ -141,8 +141,8 @@ static int fdfs_dump_group_stat(FDFSGroupInfo *pGroup, char *buff, const int buf
|
||||||
|
|
||||||
total_len += snprintf(buff + total_len, buffSize - total_len,
|
total_len += snprintf(buff + total_len, buffSize - total_len,
|
||||||
"\t%s => %s: %s\n",
|
"\t%s => %s: %s\n",
|
||||||
pGroup->all_servers[i]->ip_addr,
|
FDFS_CURRENT_IP_ADDR(pGroup->all_servers[i]),
|
||||||
pGroup->all_servers[j]->ip_addr,
|
FDFS_CURRENT_IP_ADDR(pGroup->all_servers[j]),
|
||||||
formatDatetime(pGroup->last_sync_timestamps[i][j],
|
formatDatetime(pGroup->last_sync_timestamps[i][j],
|
||||||
"%Y-%m-%d %H:%M:%S",
|
"%Y-%m-%d %H:%M:%S",
|
||||||
szSyncedTimestamp,
|
szSyncedTimestamp,
|
||||||
|
|
@ -213,12 +213,12 @@ static int fdfs_dump_storage_stat(FDFSStorageDetail *pServer,
|
||||||
"last_sync_update=%s\n"
|
"last_sync_update=%s\n"
|
||||||
"last_synced_timestamp=%s\n"
|
"last_synced_timestamp=%s\n"
|
||||||
"last_heart_beat_time=%s\n",
|
"last_heart_beat_time=%s\n",
|
||||||
pServer->ip_addr,
|
FDFS_CURRENT_IP_ADDR(pServer),
|
||||||
pServer->version,
|
pServer->version,
|
||||||
pServer->status,
|
pServer->status,
|
||||||
pServer->domain_name,
|
pServer->domain_name,
|
||||||
pServer->psync_src_server != NULL ?
|
pServer->psync_src_server != NULL ?
|
||||||
pServer->psync_src_server->ip_addr : "",
|
FDFS_CURRENT_IP_ADDR(pServer->psync_src_server) : "",
|
||||||
formatDatetime(pServer->sync_until_timestamp,
|
formatDatetime(pServer->sync_until_timestamp,
|
||||||
"%Y-%m-%d %H:%M:%S",
|
"%Y-%m-%d %H:%M:%S",
|
||||||
szSyncUntilTimestamp, sizeof(szSyncUntilTimestamp)),
|
szSyncUntilTimestamp, sizeof(szSyncUntilTimestamp)),
|
||||||
|
|
|
||||||
|
|
@ -777,7 +777,7 @@ int tracker_load_from_conf_file(const char *filename, \
|
||||||
g_trunk_init_reload_from_binlog, \
|
g_trunk_init_reload_from_binlog, \
|
||||||
g_trunk_compress_binlog_min_interval, \
|
g_trunk_compress_binlog_min_interval, \
|
||||||
g_use_storage_id, g_id_type_in_filename == \
|
g_use_storage_id, g_id_type_in_filename == \
|
||||||
FDFS_ID_TYPE_SERVER_ID ? "id" : "ip", g_storage_id_count, \
|
FDFS_ID_TYPE_SERVER_ID ? "id" : "ip", g_storage_ids_by_id.count, \
|
||||||
g_rotate_error_log, g_error_log_rotate_time.hour, \
|
g_rotate_error_log, g_error_log_rotate_time.hour, \
|
||||||
g_error_log_rotate_time.minute, \
|
g_error_log_rotate_time.minute, \
|
||||||
g_log_context.rotate_size, g_log_file_keep_days,
|
g_log_context.rotate_size, g_log_file_keep_days,
|
||||||
|
|
|
||||||
|
|
@ -129,12 +129,16 @@ static int _tracker_mem_add_storage(FDFSGroupInfo *pGroup,
|
||||||
const char *ip_addr, const bool bNeedSleep,
|
const char *ip_addr, const bool bNeedSleep,
|
||||||
const bool bNeedLock, bool *bInserted);
|
const bool bNeedLock, bool *bInserted);
|
||||||
|
|
||||||
static int tracker_mem_add_storage(TrackerClientInfo *pClientInfo, \
|
static int tracker_mem_add_storage(TrackerClientInfo *pClientInfo,
|
||||||
const char *id, const char *ip_addr, \
|
const char *id, const char *ip_addr,
|
||||||
const bool bNeedSleep, const bool bNeedLock, bool *bInserted);
|
const bool bNeedSleep, const bool bNeedLock, bool *bInserted);
|
||||||
|
|
||||||
static int tracker_mem_add_group_ex(FDFSGroups *pGroups, \
|
static int tracker_mem_add_storage_from_file(FDFSGroups *pGroups,
|
||||||
TrackerClientInfo *pClientInfo, const char *group_name, \
|
const char *data_path, TrackerClientInfo *pClientInfo,
|
||||||
|
const char *group_name, const char *storage_id, char *ip_addr);
|
||||||
|
|
||||||
|
static int tracker_mem_add_group_ex(FDFSGroups *pGroups,
|
||||||
|
TrackerClientInfo *pClientInfo, const char *group_name,
|
||||||
const bool bNeedSleep, bool *bInserted);
|
const bool bNeedSleep, bool *bInserted);
|
||||||
|
|
||||||
static int tracker_mem_destroy_groups(FDFSGroups *pGroups, const bool saveFiles);
|
static int tracker_mem_destroy_groups(FDFSGroups *pGroups, const bool saveFiles);
|
||||||
|
|
@ -918,7 +922,7 @@ static int tracker_load_storages_old(FDFSGroups *pGroups, const char *data_path)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((result=tracker_mem_add_storage(&clientInfo, NULL, ip_addr, \
|
if ((result=tracker_mem_add_storage(&clientInfo, NULL, ip_addr,
|
||||||
false, false, &bInserted)) != 0)
|
false, false, &bInserted)) != 0)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
|
|
@ -1077,7 +1081,6 @@ static int tracker_load_storages_new(FDFSGroups *pGroups, const char *data_path)
|
||||||
int result;
|
int result;
|
||||||
char section_name[64];
|
char section_name[64];
|
||||||
TrackerClientInfo clientInfo;
|
TrackerClientInfo clientInfo;
|
||||||
bool bInserted;
|
|
||||||
|
|
||||||
if (!fileExists(STORAGE_SERVERS_LIST_FILENAME_NEW) && \
|
if (!fileExists(STORAGE_SERVERS_LIST_FILENAME_NEW) && \
|
||||||
fileExists(STORAGE_SERVERS_LIST_FILENAME_OLD))
|
fileExists(STORAGE_SERVERS_LIST_FILENAME_OLD))
|
||||||
|
|
@ -1146,58 +1149,13 @@ static int tracker_load_storages_new(FDFSGroups *pGroups, const char *data_path)
|
||||||
|
|
||||||
ip_addr = iniGetStrValue(section_name, \
|
ip_addr = iniGetStrValue(section_name, \
|
||||||
STORAGE_ITEM_IP_ADDR, &iniContext);
|
STORAGE_ITEM_IP_ADDR, &iniContext);
|
||||||
if (ip_addr == NULL)
|
|
||||||
{
|
|
||||||
logError("file: "__FILE__", line: %d, " \
|
|
||||||
"in the file \"%s/%s\", " \
|
|
||||||
"item \"%s\" is not found", \
|
|
||||||
__LINE__, data_path, \
|
|
||||||
STORAGE_SERVERS_LIST_FILENAME_NEW, \
|
|
||||||
STORAGE_ITEM_IP_ADDR);
|
|
||||||
result = ENOENT;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (*ip_addr == '\0')
|
|
||||||
{
|
|
||||||
logWarning("file: "__FILE__", line: %d, " \
|
|
||||||
"in the file \"%s/%s\", " \
|
|
||||||
"item \"%s\" is empty", \
|
|
||||||
__LINE__, data_path, \
|
|
||||||
STORAGE_SERVERS_LIST_FILENAME_NEW, \
|
|
||||||
STORAGE_ITEM_IP_ADDR);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(&clientInfo, 0, sizeof(TrackerClientInfo));
|
if ((result=tracker_mem_add_storage_from_file(pGroups,
|
||||||
if ((clientInfo.pGroup=tracker_mem_get_group_ex(pGroups, \
|
data_path, &clientInfo, group_name,
|
||||||
group_name)) == NULL)
|
storage_id, ip_addr)) != 0)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
break;
|
||||||
"in the file \"%s/%s\", " \
|
}
|
||||||
"group \"%s\" is not found", \
|
|
||||||
__LINE__, data_path, \
|
|
||||||
STORAGE_SERVERS_LIST_FILENAME_NEW, \
|
|
||||||
group_name);
|
|
||||||
result = errno != 0 ? errno : ENOENT;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((result=tracker_mem_add_storage(&clientInfo, storage_id, \
|
|
||||||
ip_addr, false, false, &bInserted)) != 0)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!bInserted)
|
|
||||||
{
|
|
||||||
logError("file: "__FILE__", line: %d, " \
|
|
||||||
"in the file \"%s/%s\", " \
|
|
||||||
"storage \"%s\" is duplicate", \
|
|
||||||
__LINE__, data_path, \
|
|
||||||
STORAGE_SERVERS_LIST_FILENAME_NEW, ip_addr);
|
|
||||||
result = errno != 0 ? errno : EEXIST;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
pStorage = clientInfo.pStorage;
|
pStorage = clientInfo.pStorage;
|
||||||
pStat = &(pStorage->stat);
|
pStat = &(pStorage->stat);
|
||||||
|
|
@ -3625,6 +3583,93 @@ static int tracker_mem_add_storage(TrackerClientInfo *pClientInfo,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int tracker_mem_add_storage_from_file(FDFSGroups *pGroups,
|
||||||
|
const char *data_path, TrackerClientInfo *pClientInfo,
|
||||||
|
const char *group_name, const char *storage_id, char *ip_addr)
|
||||||
|
{
|
||||||
|
FDFSMultiIP multi_ip;
|
||||||
|
char error_info[256];
|
||||||
|
int result;
|
||||||
|
bool bInserted;
|
||||||
|
|
||||||
|
if (g_use_storage_id)
|
||||||
|
{
|
||||||
|
if (storage_id == NULL || *storage_id == '\0')
|
||||||
|
{
|
||||||
|
logError("file: "__FILE__", line: %d, "
|
||||||
|
"in the file \"%s/%s\", "
|
||||||
|
"group: %s, item \"%s\" is not found or empty",
|
||||||
|
__LINE__, data_path,
|
||||||
|
STORAGE_SERVERS_LIST_FILENAME_NEW,
|
||||||
|
group_name, STORAGE_ITEM_SERVER_ID);
|
||||||
|
return ENOENT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ip_addr == NULL)
|
||||||
|
{
|
||||||
|
logError("file: "__FILE__", line: %d, "
|
||||||
|
"in the file \"%s/%s\", "
|
||||||
|
"group: %s, item \"%s\" is not found",
|
||||||
|
__LINE__, data_path,
|
||||||
|
STORAGE_SERVERS_LIST_FILENAME_NEW,
|
||||||
|
group_name, STORAGE_ITEM_IP_ADDR);
|
||||||
|
return ENOENT;
|
||||||
|
}
|
||||||
|
if (*ip_addr == '\0')
|
||||||
|
{
|
||||||
|
logWarning("file: "__FILE__", line: %d, "
|
||||||
|
"in the file \"%s/%s\", "
|
||||||
|
"group: %s, item \"%s\" is empty",
|
||||||
|
__LINE__, data_path,
|
||||||
|
STORAGE_SERVERS_LIST_FILENAME_NEW,
|
||||||
|
group_name, STORAGE_ITEM_IP_ADDR);
|
||||||
|
return ENOENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(pClientInfo, 0, sizeof(TrackerClientInfo));
|
||||||
|
if ((pClientInfo->pGroup=tracker_mem_get_group_ex(pGroups,
|
||||||
|
group_name)) == NULL)
|
||||||
|
{
|
||||||
|
logError("file: "__FILE__", line: %d, "
|
||||||
|
"in the file \"%s/%s\", "
|
||||||
|
"group \"%s\" is not found",
|
||||||
|
__LINE__, data_path,
|
||||||
|
STORAGE_SERVERS_LIST_FILENAME_NEW,
|
||||||
|
group_name);
|
||||||
|
return errno != 0 ? errno : ENOENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((result=fdfs_parse_multi_ips_ex(ip_addr, &multi_ip,
|
||||||
|
error_info, sizeof(error_info), false)) != 0)
|
||||||
|
{
|
||||||
|
logError("file: "__FILE__", line: %d, "
|
||||||
|
"in the file \"%s/%s\", invalid ip address, "
|
||||||
|
"group: %s, error info: %s", __LINE__, data_path,
|
||||||
|
STORAGE_SERVERS_LIST_FILENAME_NEW,
|
||||||
|
group_name, error_info);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((result=tracker_mem_add_storage(pClientInfo, storage_id,
|
||||||
|
multi_ip.ips[0], false, false, &bInserted)) != 0)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!bInserted)
|
||||||
|
{
|
||||||
|
logError("file: "__FILE__", line: %d, "
|
||||||
|
"in the file \"%s/%s\", "
|
||||||
|
"storage \"%s\" is duplicate",
|
||||||
|
__LINE__, data_path,
|
||||||
|
STORAGE_SERVERS_LIST_FILENAME_NEW, ip_addr);
|
||||||
|
return EEXIST;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int _tracker_mem_add_storage(FDFSGroupInfo *pGroup,
|
static int _tracker_mem_add_storage(FDFSGroupInfo *pGroup,
|
||||||
FDFSStorageDetail **ppStorageServer, const char *id,
|
FDFSStorageDetail **ppStorageServer, const char *id,
|
||||||
const char *ip_addr, const bool bNeedSleep,
|
const char *ip_addr, const bool bNeedSleep,
|
||||||
|
|
@ -3632,6 +3677,8 @@ static int _tracker_mem_add_storage(FDFSGroupInfo *pGroup,
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
const char *storage_id;
|
const char *storage_id;
|
||||||
|
FDFSStorageIdInfo *pStorageIdInfo;
|
||||||
|
FDFSMultiIP multi_ip;
|
||||||
|
|
||||||
if (*ip_addr == '\0')
|
if (*ip_addr == '\0')
|
||||||
{
|
{
|
||||||
|
|
@ -3640,40 +3687,59 @@ static int _tracker_mem_add_storage(FDFSGroupInfo *pGroup,
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memset(&multi_ip, 0, sizeof(multi_ip));
|
||||||
|
if (!g_use_storage_id)
|
||||||
|
{
|
||||||
|
multi_ip.count = 1;
|
||||||
|
multi_ip.index = 0;
|
||||||
|
strcpy(multi_ip.ips[0], ip_addr);
|
||||||
|
}
|
||||||
|
|
||||||
if (id != NULL)
|
if (id != NULL)
|
||||||
{
|
{
|
||||||
if (g_use_storage_id)
|
if (g_use_storage_id)
|
||||||
{
|
{
|
||||||
result = fdfs_check_storage_id( \
|
pStorageIdInfo = fdfs_get_storage_by_id(id);
|
||||||
pGroup->group_name, id);
|
if (pStorageIdInfo == NULL)
|
||||||
if (result != 0)
|
{
|
||||||
|
logError("file: "__FILE__", line: %d, "
|
||||||
|
"storage id: %s not exist in config file, "
|
||||||
|
"group_name: %s, storage ip: %s", __LINE__,
|
||||||
|
id, pGroup->group_name, ip_addr);
|
||||||
|
return ENOENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strcmp(pStorageIdInfo->group_name, pGroup->group_name) != 0)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
logError("file: "__FILE__", line: %d, "
|
||||||
"check storage id fail, " \
|
"check storage id fail, inconsistent group names, "
|
||||||
"group_name: %s, id: %s, " \
|
"id: %s, storage ip: %s, "
|
||||||
"storage ip: %s, errno: %d, " \
|
"reported group_name: %s != "
|
||||||
"error info: %s", __LINE__, \
|
"group name in config file: %s", __LINE__,
|
||||||
pGroup->group_name, id, ip_addr, \
|
pGroup->group_name, id, ip_addr,
|
||||||
result, STRERROR(result));
|
pStorageIdInfo->group_name);
|
||||||
return result;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
multi_ip = pStorageIdInfo->ip_addrs;
|
||||||
}
|
}
|
||||||
|
|
||||||
storage_id = id;
|
storage_id = id;
|
||||||
}
|
}
|
||||||
else if (g_use_storage_id)
|
else if (g_use_storage_id)
|
||||||
{
|
{
|
||||||
FDFSStorageIdInfo *pStorageIdInfo;
|
pStorageIdInfo = fdfs_get_storage_id_by_ip(
|
||||||
pStorageIdInfo = fdfs_get_storage_id_by_ip( \
|
|
||||||
pGroup->group_name, ip_addr);
|
pGroup->group_name, ip_addr);
|
||||||
if (pStorageIdInfo == NULL)
|
if (pStorageIdInfo == NULL)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
logError("file: "__FILE__", line: %d, "
|
||||||
"get storage id info fail, " \
|
"get storage id info fail, "
|
||||||
"group_name: %s, storage ip: %s", \
|
"group_name: %s, storage ip: %s not exist in config file",
|
||||||
__LINE__, pGroup->group_name, ip_addr);
|
__LINE__, pGroup->group_name, ip_addr);
|
||||||
return ENOENT;
|
return ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
multi_ip = pStorageIdInfo->ip_addrs;
|
||||||
storage_id = pStorageIdInfo->id;
|
storage_id = pStorageIdInfo->id;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -3699,8 +3765,7 @@ static int _tracker_mem_add_storage(FDFSGroupInfo *pGroup,
|
||||||
{
|
{
|
||||||
if (g_use_storage_id)
|
if (g_use_storage_id)
|
||||||
{
|
{
|
||||||
memcpy ((*ppStorageServer)->ip_addr, ip_addr, \
|
fdfs_set_multi_ip_index(&(*ppStorageServer)->ip_addrs, ip_addr);
|
||||||
IP_ADDRESS_SIZE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((*ppStorageServer)->status==FDFS_STORAGE_STATUS_DELETED \
|
if ((*ppStorageServer)->status==FDFS_STORAGE_STATUS_DELETED \
|
||||||
|
|
@ -3714,7 +3779,7 @@ static int _tracker_mem_add_storage(FDFSGroupInfo *pGroup,
|
||||||
|
|
||||||
if (pGroup->count >= pGroup->alloc_size)
|
if (pGroup->count >= pGroup->alloc_size)
|
||||||
{
|
{
|
||||||
result = tracker_mem_realloc_store_servers( \
|
result = tracker_mem_realloc_store_servers(
|
||||||
pGroup, 1, bNeedSleep);
|
pGroup, 1, bNeedSleep);
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
{
|
{
|
||||||
|
|
@ -3723,11 +3788,15 @@ static int _tracker_mem_add_storage(FDFSGroupInfo *pGroup,
|
||||||
}
|
}
|
||||||
|
|
||||||
*ppStorageServer = *(pGroup->all_servers + pGroup->count);
|
*ppStorageServer = *(pGroup->all_servers + pGroup->count);
|
||||||
snprintf((*ppStorageServer)->id, FDFS_STORAGE_ID_MAX_SIZE, \
|
snprintf((*ppStorageServer)->id, FDFS_STORAGE_ID_MAX_SIZE,
|
||||||
"%s", storage_id);
|
"%s", storage_id);
|
||||||
memcpy((*ppStorageServer)->ip_addr, ip_addr, IP_ADDRESS_SIZE);
|
(*ppStorageServer)->ip_addrs = multi_ip;
|
||||||
|
if (g_use_storage_id)
|
||||||
|
{
|
||||||
|
fdfs_set_multi_ip_index(&(*ppStorageServer)->ip_addrs, ip_addr);
|
||||||
|
}
|
||||||
|
|
||||||
tracker_mem_insert_into_sorted_servers(*ppStorageServer, \
|
tracker_mem_insert_into_sorted_servers(*ppStorageServer,
|
||||||
pGroup->sorted_servers, pGroup->count);
|
pGroup->sorted_servers, pGroup->count);
|
||||||
pGroup->count++;
|
pGroup->count++;
|
||||||
pGroup->chg_count++;
|
pGroup->chg_count++;
|
||||||
|
|
@ -4345,7 +4414,7 @@ int tracker_mem_add_group_and_storage(TrackerClientInfo *pClientInfo, \
|
||||||
|
|
||||||
if (g_use_storage_id)
|
if (g_use_storage_id)
|
||||||
{
|
{
|
||||||
pStorageIdInfo = fdfs_get_storage_id_by_ip( \
|
pStorageIdInfo = fdfs_get_storage_id_by_ip(
|
||||||
pClientInfo->pGroup->group_name, ip_addr);
|
pClientInfo->pGroup->group_name, ip_addr);
|
||||||
if (pStorageIdInfo == NULL)
|
if (pStorageIdInfo == NULL)
|
||||||
{
|
{
|
||||||
|
|
@ -4518,7 +4587,7 @@ int tracker_mem_add_group_and_storage(TrackerClientInfo *pClientInfo, \
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((result=tracker_mem_add_storage(pClientInfo, storage_id, ip_addr, \
|
if ((result=tracker_mem_add_storage(pClientInfo, storage_id, ip_addr,
|
||||||
bNeedSleep, true, &bStorageInserted)) != 0)
|
bNeedSleep, true, &bStorageInserted)) != 0)
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -4703,6 +4772,7 @@ int tracker_mem_sync_storages(FDFSGroupInfo *pGroup, \
|
||||||
FDFSStorageDetail target_storage;
|
FDFSStorageDetail target_storage;
|
||||||
FDFSStorageDetail *pTargetStorage;
|
FDFSStorageDetail *pTargetStorage;
|
||||||
FDFSStorageDetail **ppFound;
|
FDFSStorageDetail **ppFound;
|
||||||
|
char ip_str[256];
|
||||||
|
|
||||||
if ((result=pthread_mutex_lock(&mem_thread_lock)) != 0)
|
if ((result=pthread_mutex_lock(&mem_thread_lock)) != 0)
|
||||||
{
|
{
|
||||||
|
|
@ -4750,11 +4820,12 @@ int tracker_mem_sync_storages(FDFSGroupInfo *pGroup, \
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fdfs_multi_ips_to_string(&(*ppFound)->ip_addrs,
|
||||||
|
ip_str, sizeof(ip_str));
|
||||||
logWarning("file: "__FILE__", line: %d, "
|
logWarning("file: "__FILE__", line: %d, "
|
||||||
"storage server: %s:%d, dest status: %d, "
|
"storage server: %s:%d, dest status: %d, "
|
||||||
"my status: %d, should change my status!",
|
"my status: %d, should change my status!",
|
||||||
__LINE__, (*ppFound)->ip_addr,
|
__LINE__, ip_str, (*ppFound)->storage_port,
|
||||||
(*ppFound)->storage_port,
|
|
||||||
pServer->status, (*ppFound)->status);
|
pServer->status, (*ppFound)->status);
|
||||||
|
|
||||||
if (pServer->status == \
|
if (pServer->status == \
|
||||||
|
|
@ -4788,9 +4859,9 @@ int tracker_mem_sync_storages(FDFSGroupInfo *pGroup, \
|
||||||
FDFSStorageDetail *pStorageServer;
|
FDFSStorageDetail *pStorageServer;
|
||||||
bool bInserted;
|
bool bInserted;
|
||||||
|
|
||||||
result = _tracker_mem_add_storage(pGroup, \
|
result = _tracker_mem_add_storage(pGroup,
|
||||||
&pStorageServer, pServer->id, \
|
&pStorageServer, pServer->id,
|
||||||
pServer->ip_addr, true, false, \
|
pServer->ip_addr, true, false,
|
||||||
&bInserted);
|
&bInserted);
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
{
|
{
|
||||||
|
|
@ -4930,6 +5001,7 @@ static int tracker_write_to_trunk_change_log(FDFSGroupInfo *pGroup, \
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
time_t current_time;
|
time_t current_time;
|
||||||
FDFSStorageDetail *pLastTrunk;
|
FDFSStorageDetail *pLastTrunk;
|
||||||
|
char ip_str[256];
|
||||||
|
|
||||||
tracker_mem_file_lock();
|
tracker_mem_file_lock();
|
||||||
|
|
||||||
|
|
@ -4960,14 +5032,16 @@ static int tracker_write_to_trunk_change_log(FDFSGroupInfo *pGroup, \
|
||||||
{
|
{
|
||||||
if (pLastTrunk == NULL)
|
if (pLastTrunk == NULL)
|
||||||
{
|
{
|
||||||
len += sprintf(buff + len, " %s/%s => ", \
|
len += sprintf(buff + len, " %s/%s => ",
|
||||||
*(pGroup->last_trunk_server_id) == '\0' ? \
|
*(pGroup->last_trunk_server_id) == '\0' ?
|
||||||
"-" : pGroup->last_trunk_server_id, "-");
|
"-" : pGroup->last_trunk_server_id, "-");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
len += sprintf(buff + len, " %s/%s => ", \
|
fdfs_multi_ips_to_string(&pLastTrunk->ip_addrs,
|
||||||
pLastTrunk->id, pLastTrunk->ip_addr);
|
ip_str, sizeof(ip_str));
|
||||||
|
len += sprintf(buff + len, " %s/%s => ",
|
||||||
|
pLastTrunk->id, ip_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pGroup->pTrunkServer == NULL)
|
if (pGroup->pTrunkServer == NULL)
|
||||||
|
|
@ -4976,23 +5050,25 @@ static int tracker_write_to_trunk_change_log(FDFSGroupInfo *pGroup, \
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
len += sprintf(buff + len, " %s/%s\n", \
|
fdfs_multi_ips_to_string(&pGroup->pTrunkServer->ip_addrs,
|
||||||
pGroup->pTrunkServer->id, \
|
ip_str, sizeof(ip_str));
|
||||||
pGroup->pTrunkServer->ip_addr);
|
len += sprintf(buff + len, " %s/%s\n",
|
||||||
|
pGroup->pTrunkServer->id, ip_str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (pLastTrunk == NULL)
|
if (pLastTrunk == NULL)
|
||||||
{
|
{
|
||||||
len += sprintf(buff + len, " %s => ", \
|
len += sprintf(buff + len, " %s => ",
|
||||||
*(pGroup->last_trunk_server_id) == '\0' ? \
|
*(pGroup->last_trunk_server_id) == '\0' ?
|
||||||
"-" : pGroup->last_trunk_server_id);
|
"-" : pGroup->last_trunk_server_id);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
len += sprintf(buff + len, " %s => ", \
|
fdfs_multi_ips_to_string(&pLastTrunk->ip_addrs,
|
||||||
pLastTrunk->ip_addr);
|
ip_str, sizeof(ip_str));
|
||||||
|
len += sprintf(buff + len, " %s => ", ip_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pGroup->pTrunkServer == NULL)
|
if (pGroup->pTrunkServer == NULL)
|
||||||
|
|
@ -5001,8 +5077,9 @@ static int tracker_write_to_trunk_change_log(FDFSGroupInfo *pGroup, \
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
len += sprintf(buff + len, " %s\n", \
|
fdfs_multi_ips_to_string(&pGroup->pTrunkServer->ip_addrs,
|
||||||
pGroup->pTrunkServer->ip_addr);
|
ip_str, sizeof(ip_str));
|
||||||
|
len += sprintf(buff + len, " %s\n", ip_str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -5053,14 +5130,15 @@ static int tracker_mem_do_set_trunk_server(FDFSGroupInfo *pGroup,
|
||||||
FDFSStorageDetail *pTrunkServer, const bool save)
|
FDFSStorageDetail *pTrunkServer, const bool save)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
|
char ip_str[256];
|
||||||
|
|
||||||
if (*(pGroup->last_trunk_server_id) != '\0' &&
|
if (*(pGroup->last_trunk_server_id) != '\0' &&
|
||||||
strcmp(pTrunkServer->id, pGroup->last_trunk_server_id) != 0)
|
strcmp(pTrunkServer->id, pGroup->last_trunk_server_id) != 0)
|
||||||
{
|
{
|
||||||
if ((result=fdfs_deal_no_body_cmd_ex(
|
if ((result=fdfs_deal_no_body_cmd_ex(
|
||||||
pTrunkServer->ip_addr,
|
FDFS_CURRENT_IP_ADDR(pTrunkServer),
|
||||||
pGroup->storage_port,
|
pGroup->storage_port,
|
||||||
STORAGE_PROTO_CMD_TRUNK_DELETE_BINLOG_MARKS)) != 0)
|
STORAGE_PROTO_CMD_TRUNK_DELETE_BINLOG_MARKS)) != 0)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
"fdfs_deal_no_body_cmd_ex fail, result: %d",
|
"fdfs_deal_no_body_cmd_ex fail, result: %d",
|
||||||
|
|
@ -5073,10 +5151,12 @@ static int tracker_mem_do_set_trunk_server(FDFSGroupInfo *pGroup,
|
||||||
pGroup->trunk_chg_count++;
|
pGroup->trunk_chg_count++;
|
||||||
g_trunk_server_chg_count++;
|
g_trunk_server_chg_count++;
|
||||||
|
|
||||||
logInfo("file: "__FILE__", line: %d, " \
|
fdfs_multi_ips_to_string(&pGroup->pTrunkServer->ip_addrs,
|
||||||
"group: %s, trunk server set to %s(%s:%d)", __LINE__, \
|
ip_str, sizeof(ip_str));
|
||||||
pGroup->group_name, pGroup->pTrunkServer->id, \
|
logInfo("file: "__FILE__", line: %d, "
|
||||||
pGroup->pTrunkServer->ip_addr, pGroup->storage_port);
|
"group: %s, trunk server set to %s(%s:%d)", __LINE__,
|
||||||
|
pGroup->group_name, pGroup->pTrunkServer->id,
|
||||||
|
ip_str, pGroup->storage_port);
|
||||||
if (save)
|
if (save)
|
||||||
{
|
{
|
||||||
return tracker_save_groups();
|
return tracker_save_groups();
|
||||||
|
|
@ -5101,8 +5181,9 @@ static int tracker_mem_find_trunk_server(FDFSGroupInfo *pGroup,
|
||||||
return ENOENT;
|
return ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = tracker_mem_get_trunk_binlog_size(pStoreServer->ip_addr,
|
result = tracker_mem_get_trunk_binlog_size(
|
||||||
pGroup->storage_port, &max_file_size);
|
FDFS_CURRENT_IP_ADDR(pStoreServer),
|
||||||
|
pGroup->storage_port, &max_file_size);
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -5116,8 +5197,9 @@ static int tracker_mem_find_trunk_server(FDFSGroupInfo *pGroup,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = tracker_mem_get_trunk_binlog_size((*ppServer)->ip_addr,
|
result = tracker_mem_get_trunk_binlog_size(
|
||||||
pGroup->storage_port, &file_size);
|
FDFS_CURRENT_IP_ADDR(*ppServer),
|
||||||
|
pGroup->storage_port, &file_size);
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -5129,8 +5211,7 @@ static int tracker_mem_find_trunk_server(FDFSGroupInfo *pGroup,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return tracker_mem_do_set_trunk_server(pGroup, \
|
return tracker_mem_do_set_trunk_server(pGroup, pStoreServer, save);
|
||||||
pStoreServer, save);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const FDFSStorageDetail *tracker_mem_set_trunk_server( \
|
const FDFSStorageDetail *tracker_mem_set_trunk_server( \
|
||||||
|
|
@ -5322,17 +5403,17 @@ int tracker_mem_active_store_server(FDFSGroupInfo *pGroup, \
|
||||||
|
|
||||||
if (g_use_storage_id)
|
if (g_use_storage_id)
|
||||||
{
|
{
|
||||||
logDebug("file: "__FILE__", line: %d, " \
|
logDebug("file: "__FILE__", line: %d, "
|
||||||
"storage server %s::%s(%s) now active", \
|
"storage server %s::%s(%s) now active",
|
||||||
__LINE__, pGroup->group_name, \
|
__LINE__, pGroup->group_name,
|
||||||
pTargetServer->id, pTargetServer->ip_addr);
|
pTargetServer->id, FDFS_CURRENT_IP_ADDR(pTargetServer));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logDebug("file: "__FILE__", line: %d, " \
|
logDebug("file: "__FILE__", line: %d, "
|
||||||
"storage server %s::%s now active", \
|
"storage server %s::%s now active",
|
||||||
__LINE__, pGroup->group_name, \
|
__LINE__, pGroup->group_name,
|
||||||
pTargetServer->ip_addr);
|
FDFS_CURRENT_IP_ADDR(pTargetServer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -5394,17 +5475,17 @@ int tracker_mem_offline_store_server(FDFSGroupInfo *pGroup, \
|
||||||
|
|
||||||
if (g_use_storage_id)
|
if (g_use_storage_id)
|
||||||
{
|
{
|
||||||
logDebug("file: "__FILE__", line: %d, " \
|
logDebug("file: "__FILE__", line: %d, "
|
||||||
"storage server %s::%s (%s) offline", \
|
"storage server %s::%s (%s) offline",
|
||||||
__LINE__, pGroup->group_name, \
|
__LINE__, pGroup->group_name,
|
||||||
pStorage->id, pStorage->ip_addr);
|
pStorage->id, FDFS_CURRENT_IP_ADDR(pStorage));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logDebug("file: "__FILE__", line: %d, " \
|
logDebug("file: "__FILE__", line: %d, "
|
||||||
"storage server %s::%s offline", \
|
"storage server %s::%s offline",
|
||||||
__LINE__, pGroup->group_name, \
|
__LINE__, pGroup->group_name,
|
||||||
pStorage->ip_addr);
|
FDFS_CURRENT_IP_ADDR(pStorage));
|
||||||
}
|
}
|
||||||
|
|
||||||
pStorage->status = FDFS_STORAGE_STATUS_OFFLINE;
|
pStorage->status = FDFS_STORAGE_STATUS_OFFLINE;
|
||||||
|
|
@ -5679,13 +5760,13 @@ int tracker_mem_get_storage_by_filename(const byte cmd,FDFS_DOWNLOAD_TYPE_PARAM\
|
||||||
memset(&ip_addr, 0, sizeof(ip_addr));
|
memset(&ip_addr, 0, sizeof(ip_addr));
|
||||||
if (*storage_id != '\0')
|
if (*storage_id != '\0')
|
||||||
{
|
{
|
||||||
cmp_res = strcmp(storage_id, ppStoreServers[0]->id);
|
cmp_res = strcmp(storage_id, ppStoreServers[0]->id);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ip_addr.s_addr = storage_ip;
|
ip_addr.s_addr = storage_ip;
|
||||||
inet_ntop(AF_INET, &ip_addr, szIpAddr, sizeof(szIpAddr));
|
inet_ntop(AF_INET, &ip_addr, szIpAddr, sizeof(szIpAddr));
|
||||||
cmp_res = strcmp(szIpAddr, ppStoreServers[0]->ip_addr);
|
cmp_res = strcmp(szIpAddr, FDFS_CURRENT_IP_ADDR(ppStoreServers[0]));
|
||||||
}
|
}
|
||||||
if (cmp_res == 0)
|
if (cmp_res == 0)
|
||||||
{
|
{
|
||||||
|
|
@ -5866,17 +5947,17 @@ int tracker_mem_get_storage_by_filename(const byte cmd,FDFS_DOWNLOAD_TYPE_PARAM\
|
||||||
for (ppServer=(*ppGroup)->active_servers; \
|
for (ppServer=(*ppGroup)->active_servers; \
|
||||||
ppServer<ppServerEnd; ppServer++)
|
ppServer<ppServerEnd; ppServer++)
|
||||||
{
|
{
|
||||||
if ((file_timestamp < current_time - \
|
if ((file_timestamp < current_time -
|
||||||
g_storage_sync_file_max_delay) || \
|
g_storage_sync_file_max_delay) ||
|
||||||
((*ppServer)->stat.last_synced_timestamp > \
|
((*ppServer)->stat.last_synced_timestamp >
|
||||||
file_timestamp) || \
|
file_timestamp) ||
|
||||||
((*ppServer)->stat.last_synced_timestamp + 1 >= \
|
((*ppServer)->stat.last_synced_timestamp + 1 >=
|
||||||
file_timestamp && current_time - file_timestamp > \
|
file_timestamp && current_time - file_timestamp >
|
||||||
g_storage_sync_file_max_time) \
|
g_storage_sync_file_max_time)
|
||||||
|| (storage_ip == INADDR_NONE \
|
|| (storage_ip == INADDR_NONE
|
||||||
&& g_groups.store_server == \
|
&& g_groups.store_server ==
|
||||||
FDFS_STORE_SERVER_ROUND_ROBIN)
|
FDFS_STORE_SERVER_ROUND_ROBIN)
|
||||||
|| strcmp((*ppServer)->ip_addr, szIpAddr) == 0)
|
|| strcmp(FDFS_CURRENT_IP_ADDR(*ppServer), szIpAddr) == 0)
|
||||||
{
|
{
|
||||||
ppStoreServers[(*server_count)++] = *ppServer;
|
ppStoreServers[(*server_count)++] = *ppServer;
|
||||||
}
|
}
|
||||||
|
|
@ -5953,18 +6034,19 @@ int tracker_mem_check_alive(void *arg)
|
||||||
tracker_mem_deactive_store_server(*ppGroup, *ppServer);
|
tracker_mem_deactive_store_server(*ppGroup, *ppServer);
|
||||||
if (g_use_storage_id)
|
if (g_use_storage_id)
|
||||||
{
|
{
|
||||||
logInfo("file: "__FILE__", line: %d, " \
|
logInfo("file: "__FILE__", line: %d, "
|
||||||
"storage server %s(%s:%d) idle too long, " \
|
"storage server %s(%s:%d) idle too long, "
|
||||||
"status change to offline!", __LINE__, \
|
"status change to offline!", __LINE__,
|
||||||
(*ppServer)->id, (*ppServer)->ip_addr, \
|
(*ppServer)->id, FDFS_CURRENT_IP_ADDR(*ppServer),
|
||||||
(*ppGroup)->storage_port);
|
(*ppGroup)->storage_port);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logInfo("file: "__FILE__", line: %d, " \
|
logInfo("file: "__FILE__", line: %d, "
|
||||||
"storage server %s:%d idle too long, " \
|
"storage server %s:%d idle too long, "
|
||||||
"status change to offline!", __LINE__, \
|
"status change to offline!", __LINE__,
|
||||||
(*ppServer)->ip_addr, (*ppGroup)->storage_port);
|
FDFS_CURRENT_IP_ADDR(*ppServer),
|
||||||
|
(*ppGroup)->storage_port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -6010,13 +6092,13 @@ int tracker_mem_check_alive(void *arg)
|
||||||
g_check_active_interval;
|
g_check_active_interval;
|
||||||
if (last_beat_interval > check_trunk_interval)
|
if (last_beat_interval > check_trunk_interval)
|
||||||
{
|
{
|
||||||
logInfo("file: "__FILE__", line: %d, " \
|
logInfo("file: "__FILE__", line: %d, "
|
||||||
"trunk server %s(%s:%d) offline because idle " \
|
"trunk server %s(%s:%d) offline because idle "
|
||||||
"time: %d s > threshold: %d s, should " \
|
"time: %d s > threshold: %d s, should "
|
||||||
"re-select trunk server", __LINE__, \
|
"re-select trunk server", __LINE__,
|
||||||
(*ppGroup)->pTrunkServer->id, \
|
(*ppGroup)->pTrunkServer->id,
|
||||||
(*ppGroup)->pTrunkServer->ip_addr, \
|
FDFS_CURRENT_IP_ADDR((*ppGroup)->pTrunkServer),
|
||||||
(*ppGroup)->storage_port, last_beat_interval, \
|
(*ppGroup)->storage_port, last_beat_interval,
|
||||||
check_trunk_interval);
|
check_trunk_interval);
|
||||||
|
|
||||||
(*ppGroup)->pTrunkServer = NULL;
|
(*ppGroup)->pTrunkServer = NULL;
|
||||||
|
|
@ -6056,9 +6138,9 @@ int tracker_mem_get_storage_index(FDFSGroupInfo *pGroup, \
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logError("file: "__FILE__", line: %d, " \
|
logError("file: "__FILE__", line: %d, "
|
||||||
"get index of storage %s fail!!!", \
|
"get index of storage %s fail!!!",
|
||||||
__LINE__, pStorage->ip_addr);
|
__LINE__, FDFS_CURRENT_IP_ADDR(pStorage));
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -411,11 +411,11 @@ static int tracker_check_and_sync(struct fast_task_info *pTask, \
|
||||||
if (pServer != NULL)
|
if (pServer != NULL)
|
||||||
{
|
{
|
||||||
pDestServer->status = pServer->status;
|
pDestServer->status = pServer->status;
|
||||||
memcpy(pDestServer->id, pServer->id, \
|
memcpy(pDestServer->id, pServer->id,
|
||||||
FDFS_STORAGE_ID_MAX_SIZE);
|
FDFS_STORAGE_ID_MAX_SIZE);
|
||||||
memcpy(pDestServer->ip_addr, pServer->ip_addr, \
|
memcpy(pDestServer->ip_addr, FDFS_CURRENT_IP_ADDR(pServer),
|
||||||
IP_ADDRESS_SIZE);
|
IP_ADDRESS_SIZE);
|
||||||
int2buff(pClientInfo->pGroup->storage_port, \
|
int2buff(pClientInfo->pGroup->storage_port,
|
||||||
pDestServer->port);
|
pDestServer->port);
|
||||||
}
|
}
|
||||||
pDestServer++;
|
pDestServer++;
|
||||||
|
|
@ -436,11 +436,11 @@ static int tracker_check_and_sync(struct fast_task_info *pTask, \
|
||||||
ppServer<ppEnd; ppServer++)
|
ppServer<ppEnd; ppServer++)
|
||||||
{
|
{
|
||||||
pDestServer->status = (*ppServer)->status;
|
pDestServer->status = (*ppServer)->status;
|
||||||
memcpy(pDestServer->id, (*ppServer)->id, \
|
memcpy(pDestServer->id, (*ppServer)->id,
|
||||||
FDFS_STORAGE_ID_MAX_SIZE);
|
FDFS_STORAGE_ID_MAX_SIZE);
|
||||||
memcpy(pDestServer->ip_addr, (*ppServer)->ip_addr, \
|
memcpy(pDestServer->ip_addr, FDFS_CURRENT_IP_ADDR(*ppServer),
|
||||||
IP_ADDRESS_SIZE);
|
IP_ADDRESS_SIZE);
|
||||||
int2buff(pClientInfo->pGroup->storage_port, \
|
int2buff(pClientInfo->pGroup->storage_port,
|
||||||
pDestServer->port);
|
pDestServer->port);
|
||||||
pDestServer++;
|
pDestServer++;
|
||||||
}
|
}
|
||||||
|
|
@ -1054,7 +1054,7 @@ static int tracker_deal_server_get_storage_status(struct fast_task_info *pTask)
|
||||||
pDest = (FDFSStorageBrief *)(pTask->data + sizeof(TrackerHeader));
|
pDest = (FDFSStorageBrief *)(pTask->data + sizeof(TrackerHeader));
|
||||||
memset(pDest, 0, sizeof(FDFSStorageBrief));
|
memset(pDest, 0, sizeof(FDFSStorageBrief));
|
||||||
strcpy(pDest->id, pStorage->id);
|
strcpy(pDest->id, pStorage->id);
|
||||||
strcpy(pDest->ip_addr, pStorage->ip_addr);
|
strcpy(pDest->ip_addr, pStorage->ip_addrs.ips[0]);
|
||||||
pDest->status = pStorage->status;
|
pDest->status = pStorage->status;
|
||||||
int2buff(pGroup->storage_port, pDest->port);
|
int2buff(pGroup->storage_port, pDest->port);
|
||||||
|
|
||||||
|
|
@ -1213,6 +1213,7 @@ static int tracker_deal_fetch_storage_ids(struct fast_task_info *pTask)
|
||||||
int *pCurrentCount;
|
int *pCurrentCount;
|
||||||
int nPkgLen;
|
int nPkgLen;
|
||||||
int start_index;
|
int start_index;
|
||||||
|
char ip_str[256];
|
||||||
|
|
||||||
if (!g_use_storage_id)
|
if (!g_use_storage_id)
|
||||||
{
|
{
|
||||||
|
|
@ -1237,7 +1238,7 @@ static int tracker_deal_fetch_storage_ids(struct fast_task_info *pTask)
|
||||||
}
|
}
|
||||||
|
|
||||||
start_index = buff2int(pTask->data + sizeof(TrackerHeader));
|
start_index = buff2int(pTask->data + sizeof(TrackerHeader));
|
||||||
if (start_index < 0 || start_index >= g_storage_id_count)
|
if (start_index < 0 || start_index >= g_storage_ids_by_id.count)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
logError("file: "__FILE__", line: %d, " \
|
||||||
"client ip addr: %s, invalid offset: %d", \
|
"client ip addr: %s, invalid offset: %d", \
|
||||||
|
|
@ -1247,13 +1248,13 @@ static int tracker_deal_fetch_storage_ids(struct fast_task_info *pTask)
|
||||||
}
|
}
|
||||||
|
|
||||||
p = pTask->data + sizeof(TrackerHeader);
|
p = pTask->data + sizeof(TrackerHeader);
|
||||||
int2buff(g_storage_id_count, p);
|
int2buff(g_storage_ids_by_id.count, p);
|
||||||
p += sizeof(int);
|
p += sizeof(int);
|
||||||
pCurrentCount = (int *)p;
|
pCurrentCount = (int *)p;
|
||||||
p += sizeof(int);
|
p += sizeof(int);
|
||||||
|
|
||||||
pIdsStart = g_storage_ids_by_ip + start_index;
|
pIdsStart = g_storage_ids_by_id.ids + start_index;
|
||||||
pIdsEnd = g_storage_ids_by_ip + g_storage_id_count;
|
pIdsEnd = g_storage_ids_by_id.ids + g_storage_ids_by_id.count;
|
||||||
for (pIdInfo = pIdsStart; pIdInfo < pIdsEnd; pIdInfo++)
|
for (pIdInfo = pIdsStart; pIdInfo < pIdsEnd; pIdInfo++)
|
||||||
{
|
{
|
||||||
char szPortPart[16];
|
char szPortPart[16];
|
||||||
|
|
@ -1270,8 +1271,11 @@ static int tracker_deal_fetch_storage_ids(struct fast_task_info *pTask)
|
||||||
{
|
{
|
||||||
*szPortPart = '\0';
|
*szPortPart = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fdfs_multi_ips_to_string(&pIdInfo->ip_addrs,
|
||||||
|
ip_str, sizeof(ip_str));
|
||||||
p += sprintf(p, "%s %s %s%s\n", pIdInfo->id,
|
p += sprintf(p, "%s %s %s%s\n", pIdInfo->id,
|
||||||
pIdInfo->group_name, pIdInfo->ip_addr, szPortPart);
|
pIdInfo->group_name, ip_str, szPortPart);
|
||||||
}
|
}
|
||||||
|
|
||||||
int2buff((int)(pIdInfo - pIdsStart), (char *)pCurrentCount);
|
int2buff((int)(pIdInfo - pIdsStart), (char *)pCurrentCount);
|
||||||
|
|
@ -1470,8 +1474,8 @@ static int tracker_deal_storage_join(struct fast_task_info *pTask)
|
||||||
tracker_ip, IP_ADDRESS_SIZE);
|
tracker_ip, IP_ADDRESS_SIZE);
|
||||||
insert_into_local_host_ip(tracker_ip);
|
insert_into_local_host_ip(tracker_ip);
|
||||||
|
|
||||||
result = tracker_mem_add_group_and_storage(pClientInfo, \
|
result = tracker_mem_add_group_and_storage(pClientInfo,
|
||||||
pTask->client_ip, &joinBody, true);
|
pTask->client_ip, &joinBody, true);
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
{
|
{
|
||||||
pTask->length = sizeof(TrackerHeader);
|
pTask->length = sizeof(TrackerHeader);
|
||||||
|
|
@ -2281,7 +2285,7 @@ static int tracker_deal_server_list_group_storages(struct fast_task_info *pTask)
|
||||||
pStorageStat = &((*ppServer)->stat);
|
pStorageStat = &((*ppServer)->stat);
|
||||||
pDest->status = (*ppServer)->status;
|
pDest->status = (*ppServer)->status;
|
||||||
strcpy(pDest->id, (*ppServer)->id);
|
strcpy(pDest->id, (*ppServer)->id);
|
||||||
strcpy(pDest->ip_addr, (*ppServer)->ip_addr);
|
strcpy(pDest->ip_addr, FDFS_CURRENT_IP_ADDR(*ppServer));
|
||||||
if ((*ppServer)->psync_src_server != NULL)
|
if ((*ppServer)->psync_src_server != NULL)
|
||||||
{
|
{
|
||||||
strcpy(pDest->src_id, \
|
strcpy(pDest->src_id, \
|
||||||
|
|
@ -2487,7 +2491,8 @@ static int tracker_deal_service_query_fetch_update( \
|
||||||
p = pTask->data + sizeof(TrackerHeader);
|
p = pTask->data + sizeof(TrackerHeader);
|
||||||
memcpy(p, pGroup->group_name, FDFS_GROUP_NAME_MAX_LEN);
|
memcpy(p, pGroup->group_name, FDFS_GROUP_NAME_MAX_LEN);
|
||||||
p += FDFS_GROUP_NAME_MAX_LEN;
|
p += FDFS_GROUP_NAME_MAX_LEN;
|
||||||
memcpy(p, ppStoreServers[0]->ip_addr, IP_ADDRESS_SIZE-1);
|
strcpy(p, fdfs_get_ipaddr_by_client_ip(
|
||||||
|
&ppStoreServers[0]->ip_addrs, pTask->client_ip));
|
||||||
p += IP_ADDRESS_SIZE - 1;
|
p += IP_ADDRESS_SIZE - 1;
|
||||||
long2buff(pGroup->storage_port, p);
|
long2buff(pGroup->storage_port, p);
|
||||||
p += FDFS_PROTO_PKG_LEN_SIZE;
|
p += FDFS_PROTO_PKG_LEN_SIZE;
|
||||||
|
|
@ -2498,8 +2503,8 @@ static int tracker_deal_service_query_fetch_update( \
|
||||||
for (ppServer=ppStoreServers+1; ppServer<ppServerEnd; \
|
for (ppServer=ppStoreServers+1; ppServer<ppServerEnd; \
|
||||||
ppServer++)
|
ppServer++)
|
||||||
{
|
{
|
||||||
memcpy(p, (*ppServer)->ip_addr, \
|
strcpy(p, fdfs_get_ipaddr_by_client_ip(
|
||||||
IP_ADDRESS_SIZE - 1);
|
&(*ppServer)->ip_addrs, pTask->client_ip));
|
||||||
p += IP_ADDRESS_SIZE - 1;
|
p += IP_ADDRESS_SIZE - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2875,7 +2880,8 @@ static int tracker_deal_service_query_storage( \
|
||||||
for (ppServer=pStoreGroup->active_servers; ppServer<ppEnd; \
|
for (ppServer=pStoreGroup->active_servers; ppServer<ppEnd; \
|
||||||
ppServer++)
|
ppServer++)
|
||||||
{
|
{
|
||||||
memcpy(p, (*ppServer)->ip_addr, IP_ADDRESS_SIZE - 1);
|
strcpy(p, fdfs_get_ipaddr_by_client_ip(
|
||||||
|
&(*ppServer)->ip_addrs, pTask->client_ip));
|
||||||
p += IP_ADDRESS_SIZE - 1;
|
p += IP_ADDRESS_SIZE - 1;
|
||||||
|
|
||||||
long2buff(pStoreGroup->storage_port, p);
|
long2buff(pStoreGroup->storage_port, p);
|
||||||
|
|
@ -2884,7 +2890,8 @@ static int tracker_deal_service_query_storage( \
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
memcpy(p, pStorageServer->ip_addr, IP_ADDRESS_SIZE - 1);
|
strcpy(p, fdfs_get_ipaddr_by_client_ip(
|
||||||
|
&pStorageServer->ip_addrs, pTask->client_ip));
|
||||||
p += IP_ADDRESS_SIZE - 1;
|
p += IP_ADDRESS_SIZE - 1;
|
||||||
|
|
||||||
long2buff(pStoreGroup->storage_port, p);
|
long2buff(pStoreGroup->storage_port, p);
|
||||||
|
|
@ -2892,7 +2899,6 @@ static int tracker_deal_service_query_storage( \
|
||||||
}
|
}
|
||||||
|
|
||||||
*p++ = (char)write_path_index;
|
*p++ = (char)write_path_index;
|
||||||
|
|
||||||
pTask->length = p - pTask->data;
|
pTask->length = p - pTask->data;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -275,9 +275,13 @@ typedef struct
|
||||||
typedef struct StructFDFSMultiIP
|
typedef struct StructFDFSMultiIP
|
||||||
{
|
{
|
||||||
int count;
|
int count;
|
||||||
|
int index;
|
||||||
char ips[FDFS_MULTI_IP_MAX_COUNT][IP_ADDRESS_SIZE];
|
char ips[FDFS_MULTI_IP_MAX_COUNT][IP_ADDRESS_SIZE];
|
||||||
} FDFSMultiIP;
|
} FDFSMultiIP;
|
||||||
|
|
||||||
|
#define FDFS_CURRENT_IP_ADDR(pServer) \
|
||||||
|
(pServer)->ip_addrs.ips[(pServer)->ip_addrs.index]
|
||||||
|
|
||||||
typedef struct StructFDFSStorageDetail
|
typedef struct StructFDFSStorageDetail
|
||||||
{
|
{
|
||||||
char status;
|
char status;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue