client support multi ip for tracker server

multi_ipaddr
YuQing 2019-10-06 11:24:12 +08:00
parent 16bbaf7884
commit b1adb8889d
32 changed files with 309 additions and 291 deletions

View File

@ -48,24 +48,24 @@ static int storage_cmp_by_ip_and_port(const void *p1, const void *p2)
}
static void insert_into_sorted_servers(TrackerServerGroup *pTrackerGroup, \
ConnectionInfo *pInsertedServer)
TrackerServerInfo *pInsertedServer)
{
ConnectionInfo *pDestServer;
for (pDestServer=pTrackerGroup->servers+pTrackerGroup->server_count; \
TrackerServerInfo *pDestServer;
for (pDestServer=pTrackerGroup->servers+pTrackerGroup->server_count;
pDestServer>pTrackerGroup->servers; pDestServer--)
{
if (storage_cmp_by_ip_and_port(pInsertedServer, \
if (storage_cmp_by_ip_and_port(pInsertedServer,
pDestServer-1) > 0)
{
memcpy(pDestServer, pInsertedServer, \
sizeof(ConnectionInfo));
memcpy(pDestServer, pInsertedServer,
sizeof(TrackerServerInfo));
return;
}
memcpy(pDestServer, pDestServer-1, sizeof(ConnectionInfo));
memcpy(pDestServer, pDestServer-1, sizeof(TrackerServerInfo));
}
memcpy(pDestServer, pInsertedServer, sizeof(ConnectionInfo));
memcpy(pDestServer, pInsertedServer, sizeof(TrackerServerInfo));
}
static int copy_tracker_servers(TrackerServerGroup *pTrackerGroup,
@ -73,55 +73,25 @@ static int copy_tracker_servers(TrackerServerGroup *pTrackerGroup,
{
char **ppSrc;
char **ppEnd;
ConnectionInfo destServer;
char *pSeperator;
char szHost[128];
int nHostLen;
TrackerServerInfo destServer;
int result;
memset(&destServer, 0, sizeof(ConnectionInfo));
destServer.sock = -1;
memset(&destServer, 0, sizeof(TrackerServerInfo));
fdfs_server_sock_reset(&destServer);
ppEnd = ppTrackerServers + pTrackerGroup->server_count;
pTrackerGroup->server_count = 0;
for (ppSrc=ppTrackerServers; ppSrc<ppEnd; ppSrc++)
{
if ((pSeperator=strrchr(*ppSrc, ':')) == NULL)
{
logError("file: "__FILE__", line: %d, " \
"conf file \"%s\", " \
"tracker_server \"%s\" is invalid, " \
"correct format is host:port", \
__LINE__, filename, *ppSrc);
return EINVAL;
}
nHostLen = pSeperator - (*ppSrc);
if (nHostLen >= sizeof(szHost))
{
nHostLen = sizeof(szHost) - 1;
}
memcpy(szHost, *ppSrc, nHostLen);
szHost[nHostLen] = '\0';
if (getIpaddrByName(szHost, destServer.ip_addr, \
sizeof(destServer.ip_addr)) == INADDR_NONE)
{
logError("file: "__FILE__", line: %d, " \
"conf file \"%s\", " \
"host \"%s\" is invalid, error info: %s", \
__LINE__, filename, szHost, hstrerror(h_errno));
return EINVAL;
}
destServer.port = atoi(pSeperator+1);
if (destServer.port <= 0)
{
destServer.port = FDFS_TRACKER_SERVER_DEF_PORT;
}
if ((result=fdfs_parse_server_info(*ppSrc,
FDFS_TRACKER_SERVER_DEF_PORT, &destServer)) != 0)
{
return result;
}
if (bsearch(&destServer, pTrackerGroup->servers, \
pTrackerGroup->server_count, \
sizeof(ConnectionInfo), \
sizeof(TrackerServerInfo), \
storage_cmp_by_ip_and_port) == NULL)
{
insert_into_sorted_servers(pTrackerGroup, &destServer);
@ -131,7 +101,7 @@ static int copy_tracker_servers(TrackerServerGroup *pTrackerGroup,
/*
{
ConnectionInfo *pServer;
TrackerServerInfo *pServer;
for (pServer=pTrackerGroup->servers; pServer<pTrackerGroup->servers+ \
pTrackerGroup->server_count; pServer++)
{
@ -161,8 +131,8 @@ int fdfs_load_tracker_group_ex(TrackerServerGroup *pTrackerGroup, \
return ENOENT;
}
bytes = sizeof(MultiConnectionInfo) * pTrackerGroup->server_count);
pTrackerGroup->servers = (MultiConnectionInfo *)malloc(bytes);
bytes = sizeof(TrackerServerInfo) * pTrackerGroup->server_count;
pTrackerGroup->servers = (TrackerServerInfo *)malloc(bytes);
if (pTrackerGroup->servers == NULL)
{
logError("file: "__FILE__", line: %d, "
@ -412,39 +382,40 @@ int fdfs_copy_tracker_group(TrackerServerGroup *pDestTrackerGroup, \
TrackerServerGroup *pSrcTrackerGroup)
{
int bytes;
ConnectionInfo *pDestServer;
ConnectionInfo *pDestServerEnd;
TrackerServerInfo *pDestServer;
TrackerServerInfo *pDestServerEnd;
bytes = sizeof(ConnectionInfo) * pSrcTrackerGroup->server_count;
pDestTrackerGroup->servers = (ConnectionInfo *)malloc(bytes);
bytes = sizeof(TrackerServerInfo) * pSrcTrackerGroup->server_count;
pDestTrackerGroup->servers = (TrackerServerInfo *)malloc(bytes);
if (pDestTrackerGroup->servers == NULL)
{
logError("file: "__FILE__", line: %d, " \
logError("file: "__FILE__", line: %d, "
"malloc %d bytes fail", __LINE__, bytes);
return errno != 0 ? errno : ENOMEM;
}
pDestTrackerGroup->server_index = 0;
pDestTrackerGroup->leader_index = 0;
pDestTrackerGroup->server_count = pSrcTrackerGroup->server_count;
memcpy(pDestTrackerGroup->servers, pSrcTrackerGroup->servers, bytes);
pDestServerEnd = pDestTrackerGroup->servers + \
pDestServerEnd = pDestTrackerGroup->servers +
pDestTrackerGroup->server_count;
for (pDestServer=pDestTrackerGroup->servers; \
for (pDestServer=pDestTrackerGroup->servers;
pDestServer<pDestServerEnd; pDestServer++)
{
pDestServer->sock = -1;
fdfs_server_sock_reset(pDestServer);
}
return 0;
}
bool fdfs_tracker_group_equals(TrackerServerGroup *pGroup1, \
bool fdfs_tracker_group_equals(TrackerServerGroup *pGroup1,
TrackerServerGroup *pGroup2)
{
ConnectionInfo *pServer1;
ConnectionInfo *pServer2;
ConnectionInfo *pEnd1;
TrackerServerInfo *pServer1;
TrackerServerInfo *pServer2;
TrackerServerInfo *pEnd1;
if (pGroup1->server_count != pGroup2->server_count)
{
@ -456,8 +427,7 @@ bool fdfs_tracker_group_equals(TrackerServerGroup *pGroup1, \
pServer2 = pGroup2->servers;
while (pServer1 < pEnd1)
{
if (!(strcmp(pServer1->ip_addr, pServer2->ip_addr) == 0 &&
pServer1->port == pServer2->port))
if (!fdfs_server_equal(pServer1, pServer2))
{
return false;
}

View File

@ -58,7 +58,7 @@ int main(int argc, char *argv[])
return result;
}
tracker_disconnect_server_ex(pTrackerServer, true);
tracker_close_connection_ex(pTrackerServer, true);
fdfs_client_destroy();
return result;

View File

@ -147,7 +147,7 @@ int main(int argc, char *argv[])
group_name, storageServer.ip_addr, \
storageServer.port);
if ((pStorageServer=tracker_connect_server(&storageServer, \
if ((pStorageServer=tracker_make_connection(&storageServer, \
&result)) == NULL)
{
fdfs_client_destroy();
@ -233,7 +233,7 @@ int main(int argc, char *argv[])
printf("upload file fail, " \
"error no: %d, error info: %s\n", \
result, STRERROR(result));
tracker_disconnect_server_ex(pStorageServer, true);
tracker_close_connection_ex(pStorageServer, true);
fdfs_client_destroy();
return result;
}
@ -273,12 +273,12 @@ int main(int argc, char *argv[])
//sleep(90);
strcpy(appender_filename, remote_filename);
if (storage_truncate_file(pTrackerServer, pStorageServer, \
group_name, appender_filename, file_size / 2) != 0)
group_name, appender_filename, file_size * 2) != 0)
{
printf("truncate file fail, " \
"error no: %d, error info: %s\n", \
result, STRERROR(result));
tracker_disconnect_server_ex(pStorageServer, true);
tracker_close_connection_ex(pStorageServer, true);
fdfs_client_destroy();
return result;
}
@ -344,7 +344,7 @@ int main(int argc, char *argv[])
printf("append file fail, " \
"error no: %d, error info: %s\n", \
result, STRERROR(result));
tracker_disconnect_server_ex(pStorageServer, true);
tracker_close_connection_ex(pStorageServer, true);
fdfs_client_destroy();
return result;
}
@ -411,7 +411,7 @@ int main(int argc, char *argv[])
printf("modify file fail, " \
"error no: %d, error info: %s\n", \
result, STRERROR(result));
tracker_disconnect_server_ex(pStorageServer, true);
tracker_close_connection_ex(pStorageServer, true);
fdfs_client_destroy();
return result;
}
@ -429,8 +429,8 @@ int main(int argc, char *argv[])
2 * file_size + file_size /2);
}
tracker_disconnect_server_ex(pStorageServer, true);
tracker_disconnect_server_ex(pTrackerServer, true);
tracker_close_connection_ex(pStorageServer, true);
tracker_close_connection_ex(pTrackerServer, true);
fdfs_client_destroy();

View File

@ -146,7 +146,7 @@ int main(int argc, char *argv[])
group_name, storageServer.ip_addr, \
storageServer.port);
if ((pStorageServer=tracker_connect_server(&storageServer, \
if ((pStorageServer=tracker_make_connection(&storageServer, \
&result)) == NULL)
{
fdfs_client_destroy();
@ -231,7 +231,7 @@ int main(int argc, char *argv[])
printf("upload file fail, " \
"error no: %d, error info: %s\n", \
result, STRERROR(result));
tracker_disconnect_server_ex(pStorageServer, true);
tracker_close_connection_ex(pStorageServer, true);
fdfs_client_destroy();
return result;
}
@ -274,7 +274,7 @@ int main(int argc, char *argv[])
printf("truncate file fail, " \
"error no: %d, error info: %s\n", \
result, STRERROR(result));
tracker_disconnect_server_ex(pStorageServer, true);
tracker_close_connection_ex(pStorageServer, true);
fdfs_client_destroy();
return result;
}
@ -340,7 +340,7 @@ int main(int argc, char *argv[])
printf("append file fail, " \
"error no: %d, error info: %s\n", \
result, STRERROR(result));
tracker_disconnect_server_ex(pStorageServer, true);
tracker_close_connection_ex(pStorageServer, true);
fdfs_client_destroy();
return result;
}
@ -407,7 +407,7 @@ int main(int argc, char *argv[])
printf("modify file fail, " \
"error no: %d, error info: %s\n", \
result, STRERROR(result));
tracker_disconnect_server_ex(pStorageServer, true);
tracker_close_connection_ex(pStorageServer, true);
fdfs_client_destroy();
return result;
}
@ -425,8 +425,8 @@ int main(int argc, char *argv[])
2 * file_size);
}
tracker_disconnect_server_ex(pStorageServer, true);
tracker_disconnect_server_ex(pTrackerServer, true);
tracker_close_connection_ex(pStorageServer, true);
tracker_close_connection_ex(pTrackerServer, true);
fdfs_client_destroy();

View File

@ -54,7 +54,7 @@ int main(int argc, char *argv[])
result, STRERROR(result));
}
tracker_disconnect_server_ex(pTrackerServer, true);
tracker_close_connection_ex(pTrackerServer, true);
fdfs_client_destroy();
return result;

View File

@ -89,7 +89,7 @@ int main(int argc, char *argv[])
result, STRERROR(result));
}
tracker_disconnect_server_ex(pTrackerServer, true);
tracker_close_connection_ex(pTrackerServer, true);
fdfs_client_destroy();
return 0;

View File

@ -26,8 +26,11 @@ static int list_all_groups(const char *group_name);
static void usage(char *argv[])
{
printf("Usage: %s <config_file> [-h <tracker_server>] [list|delete|set_trunk_server <group_name> " \
"[storage_id]]\n", argv[0]);
printf("Usage: %s <config_file> [-h <tracker_server>] "
"[list|delete|set_trunk_server <group_name> [storage_id]]\n"
"\tthe tracker server format: host[:port], "
"the tracker default port is %d\n\n",
argv[0], FDFS_TRACKER_SERVER_DEF_PORT);
}
int main(int argc, char *argv[])
@ -116,21 +119,20 @@ int main(int argc, char *argv[])
else
{
int i;
char ip_addr[IP_ADDRESS_SIZE];
ConnectionInfo conn;
*ip_addr = '\0';
if (getIpaddrByName(tracker_server, ip_addr, sizeof(ip_addr)) \
== INADDR_NONE)
if ((result=conn_pool_parse_server_info(tracker_server, &conn,
FDFS_TRACKER_SERVER_DEF_PORT)) != 0)
{
printf("resolve ip address of tracker server: %s " \
printf("resolve ip address of tracker server: %s "
"fail!, error info: %s\n", tracker_server, hstrerror(h_errno));
return 2;
return result;
}
for (i=0; i<g_tracker_group.server_count; i++)
{
if (strcmp(g_tracker_group.servers[i].ip_addr, \
ip_addr) == 0)
if (fdfs_server_contain1(g_tracker_group.servers + i,
&conn) == 0)
{
g_tracker_group.server_index = i;
break;
@ -144,7 +146,8 @@ int main(int argc, char *argv[])
}
}
printf("server_count=%d, server_index=%d\n", g_tracker_group.server_count, g_tracker_group.server_index);
printf("server_count=%d, server_index=%d\n",
g_tracker_group.server_count, g_tracker_group.server_index);
pTrackerServer = tracker_get_connection();
if (pTrackerServer == NULL)
@ -251,7 +254,7 @@ int main(int argc, char *argv[])
usage(argv);
}
tracker_disconnect_server_ex(pTrackerServer, true);
tracker_close_connection_ex(pTrackerServer, true);
fdfs_client_destroy();
return 0;
}

View File

@ -194,7 +194,7 @@ int main(int argc, char *argv[])
group_name, storageServer.ip_addr, \
storageServer.port);
if ((pStorageServer=tracker_connect_server(&storageServer, \
if ((pStorageServer=tracker_make_connection(&storageServer, \
&result)) == NULL)
{
fdfs_client_destroy();
@ -269,7 +269,7 @@ int main(int argc, char *argv[])
printf("upload file fail, " \
"error no: %d, error info: %s\n", \
result, STRERROR(result));
tracker_disconnect_server_ex(pStorageServer, true);
tracker_close_connection_ex(pStorageServer, true);
fdfs_client_destroy();
return result;
}
@ -361,7 +361,7 @@ int main(int argc, char *argv[])
printf("upload slave file fail, " \
"error no: %d, error info: %s\n", \
result, STRERROR(result));
tracker_disconnect_server_ex(pStorageServer, true);
tracker_close_connection_ex(pStorageServer, true);
fdfs_client_destroy();
return result;
}
@ -467,7 +467,7 @@ int main(int argc, char *argv[])
printf("\n");
}
tracker_disconnect_server_ex(pTrackerServer, result != 0);
tracker_close_connection_ex(pTrackerServer, result != 0);
fdfs_client_destroy();
return result;
}
@ -491,7 +491,7 @@ int main(int argc, char *argv[])
printf("storage=%s:%d\n", storageServer.ip_addr, \
storageServer.port);
if ((pStorageServer=tracker_connect_server(&storageServer, \
if ((pStorageServer=tracker_make_connection(&storageServer, \
&result)) == NULL)
{
fdfs_client_destroy();
@ -681,8 +681,8 @@ int main(int argc, char *argv[])
pStorageServer->ip_addr, pStorageServer->port, result);
}
tracker_disconnect_server_ex(pStorageServer, true);
tracker_disconnect_server_ex(pTrackerServer, true);
tracker_close_connection_ex(pStorageServer, true);
tracker_close_connection_ex(pTrackerServer, true);
fdfs_client_destroy();

View File

@ -191,7 +191,7 @@ int main(int argc, char *argv[])
group_name, storageServer.ip_addr, \
storageServer.port);
if ((pStorageServer=tracker_connect_server(&storageServer, \
if ((pStorageServer=tracker_make_connection(&storageServer, \
&result)) == NULL)
{
fdfs_client_destroy();
@ -263,7 +263,7 @@ int main(int argc, char *argv[])
printf("upload file fail, " \
"error no: %d, error info: %s\n", \
result, STRERROR(result));
tracker_disconnect_server_ex(pStorageServer, true);
tracker_close_connection_ex(pStorageServer, true);
fdfs_client_destroy();
return result;
}
@ -349,7 +349,7 @@ int main(int argc, char *argv[])
printf("upload slave file fail, " \
"error no: %d, error info: %s\n", \
result, STRERROR(result));
tracker_disconnect_server_ex(pStorageServer, true);
tracker_close_connection_ex(pStorageServer, true);
fdfs_client_destroy();
return result;
}
@ -439,7 +439,7 @@ int main(int argc, char *argv[])
printf("\n");
}
tracker_disconnect_server_ex(pTrackerServer, true);
tracker_close_connection_ex(pTrackerServer, true);
fdfs_client_destroy();
return result;
}
@ -458,7 +458,7 @@ int main(int argc, char *argv[])
printf("storage=%s:%d\n", storageServer.ip_addr, \
storageServer.port);
if ((pStorageServer=tracker_connect_server(&storageServer, \
if ((pStorageServer=tracker_make_connection(&storageServer, \
&result)) == NULL)
{
fdfs_client_destroy();
@ -648,8 +648,8 @@ int main(int argc, char *argv[])
pStorageServer->ip_addr, pStorageServer->port, result);
}
tracker_disconnect_server_ex(pStorageServer, true);
tracker_disconnect_server_ex(pTrackerServer, true);
tracker_close_connection_ex(pStorageServer, true);
tracker_close_connection_ex(pTrackerServer, true);
fdfs_client_destroy();

View File

@ -73,14 +73,14 @@ int main(int argc, char *argv[])
"error no: %d, error info: %s\n", \
result, STRERROR(result));
tracker_disconnect_server_ex(pTrackerServer, true);
tracker_close_connection_ex(pTrackerServer, true);
fdfs_client_destroy();
return result;
}
printf("%s\n", file_id);
tracker_disconnect_server_ex(pTrackerServer, true);
tracker_close_connection_ex(pTrackerServer, true);
fdfs_client_destroy();
return 0;

View File

@ -112,7 +112,7 @@ int main(int argc, char *argv[])
result, STRERROR(result));
}
tracker_disconnect_server_ex(pTrackerServer, true);
tracker_close_connection_ex(pTrackerServer, true);
fdfs_client_destroy();
return result;

View File

@ -90,7 +90,7 @@ static int storage_get_connection(ConnectionInfo *pTrackerServer, \
if (new_tracker_connection)
{
tracker_disconnect_server_ex(pNewTracker, result != 0);
tracker_close_connection_ex(pNewTracker, result != 0);
}
if (result != 0)
@ -98,7 +98,7 @@ static int storage_get_connection(ConnectionInfo *pTrackerServer, \
return result;
}
if ((*ppStorageServer=tracker_connect_server(pNewStorage, \
if ((*ppStorageServer=tracker_make_connection(pNewStorage,
&result)) == NULL)
{
return result;
@ -114,7 +114,7 @@ static int storage_get_connection(ConnectionInfo *pTrackerServer, \
}
else
{
if ((*ppStorageServer=tracker_connect_server( \
if ((*ppStorageServer=tracker_make_connection(
*ppStorageServer, &result)) == NULL)
{
return result;
@ -155,7 +155,7 @@ static int storage_get_upload_connection(ConnectionInfo *pTrackerServer, \
if (new_tracker_connection)
{
tracker_disconnect_server_ex(pNewTracker, result != 0);
tracker_close_connection_ex(pNewTracker, result != 0);
}
if (result != 0)
@ -163,7 +163,7 @@ static int storage_get_upload_connection(ConnectionInfo *pTrackerServer, \
return result;
}
if ((*ppStorageServer=tracker_connect_server(pNewStorage, \
if ((*ppStorageServer=tracker_make_connection(pNewStorage,
&result)) == NULL)
{
return result;
@ -179,7 +179,7 @@ static int storage_get_upload_connection(ConnectionInfo *pTrackerServer, \
}
else
{
if ((*ppStorageServer=tracker_connect_server( \
if ((*ppStorageServer=tracker_make_connection(
*ppStorageServer, &result)) == NULL)
{
return result;
@ -289,7 +289,7 @@ int storage_get_metadata(ConnectionInfo *pTrackerServer, \
if (new_connection)
{
tracker_disconnect_server_ex(pStorageServer, result != 0);
tracker_close_connection_ex(pStorageServer, result != 0);
}
return result;
@ -411,7 +411,7 @@ int storage_query_file_info_ex(ConnectionInfo *pTrackerServer, \
if (new_connection)
{
tracker_disconnect_server_ex(pStorageServer, result != 0);
tracker_close_connection_ex(pStorageServer, result != 0);
}
return result;
@ -506,7 +506,7 @@ int storage_delete_file(ConnectionInfo *pTrackerServer, \
if (new_connection)
{
tracker_disconnect_server_ex(pStorageServer, result != 0);
tracker_close_connection_ex(pStorageServer, result != 0);
}
return result;
@ -684,7 +684,7 @@ int storage_do_download_file_ex(ConnectionInfo *pTrackerServer, \
if (new_connection)
{
tracker_disconnect_server_ex(pStorageServer, result != 0);
tracker_close_connection_ex(pStorageServer, result != 0);
}
return result;
@ -1035,7 +1035,7 @@ int storage_do_upload_file(ConnectionInfo *pTrackerServer, \
if (new_connection)
{
tracker_disconnect_server_ex(pStorageServer, result != 0);
tracker_close_connection_ex(pStorageServer, result != 0);
}
return result;
@ -1265,7 +1265,7 @@ int storage_set_metadata(ConnectionInfo *pTrackerServer, \
if (new_connection)
{
tracker_disconnect_server_ex(pStorageServer, result != 0);
tracker_close_connection_ex(pStorageServer, result != 0);
}
return result;
@ -1480,7 +1480,7 @@ int storage_client_create_link(ConnectionInfo *pTrackerServer, \
if (new_connection)
{
tracker_disconnect_server_ex(pStorageServer, result != 0);
tracker_close_connection_ex(pStorageServer, result != 0);
}
return result;
@ -1801,7 +1801,7 @@ int storage_do_append_file(ConnectionInfo *pTrackerServer, \
if (new_connection)
{
tracker_disconnect_server_ex(pStorageServer, result != 0);
tracker_close_connection_ex(pStorageServer, result != 0);
}
return result;
@ -1932,7 +1932,7 @@ int storage_do_modify_file(ConnectionInfo *pTrackerServer, \
if (new_connection)
{
tracker_disconnect_server_ex(pStorageServer, result != 0);
tracker_close_connection_ex(pStorageServer, result != 0);
}
return result;
@ -2210,7 +2210,7 @@ int fdfs_get_file_info_ex(const char *group_name, const char *remote_filename, \
if (get_from_server)
{
ConnectionInfo *conn;
ConnectionInfo trackerServer;
TrackerServerInfo trackerServer;
conn = tracker_get_connection_r(&trackerServer, &result);
if (result != 0)
@ -2220,7 +2220,7 @@ int fdfs_get_file_info_ex(const char *group_name, const char *remote_filename, \
result = storage_query_file_info(conn, \
NULL, group_name, remote_filename, pFileInfo);
tracker_disconnect_server_ex(conn, result != 0 && \
tracker_close_connection_ex(conn, result != 0 && \
result != ENOENT);
return result;
@ -2346,7 +2346,7 @@ int storage_truncate_file(ConnectionInfo *pTrackerServer, \
if (new_connection)
{
tracker_disconnect_server_ex(pStorageServer, result != 0);
tracker_close_connection_ex(pStorageServer, result != 0);
}
return result;

View File

@ -250,7 +250,7 @@ int main(int argc, char *argv[])
usage(argv);
}
tracker_disconnect_server_ex(pTrackerServer, true);
tracker_close_connection_ex(pTrackerServer, true);
fdfs_client_destroy();
return 0;
}

View File

@ -269,7 +269,7 @@ int main(int argc, char *argv[])
printf("upload file fail, " \
"error no: %d, error info: %s\n", \
result, STRERROR(result));
tracker_disconnect_server_ex(pStorageServer, true);
tracker_close_connection_ex(pStorageServer, true);
fdfs_client_destroy();
return result;
}
@ -361,7 +361,7 @@ int main(int argc, char *argv[])
printf("upload slave file fail, " \
"error no: %d, error info: %s\n", \
result, STRERROR(result));
tracker_disconnect_server_ex(pStorageServer, true);
tracker_close_connection_ex(pStorageServer, true);
fdfs_client_destroy();
return result;
}
@ -467,7 +467,7 @@ int main(int argc, char *argv[])
printf("\n");
}
tracker_disconnect_server_ex(pTrackerServer, result != 0);
tracker_close_connection_ex(pTrackerServer, result != 0);
fdfs_client_destroy();
return result;
}
@ -681,8 +681,8 @@ int main(int argc, char *argv[])
pStorageServer->ip_addr, pStorageServer->port, result);
}
tracker_disconnect_server_ex(pStorageServer, true);
tracker_disconnect_server_ex(pTrackerServer, true);
tracker_close_connection_ex(pStorageServer, true);
tracker_close_connection_ex(pTrackerServer, true);
fdfs_client_destroy();

View File

@ -263,7 +263,7 @@ int main(int argc, char *argv[])
printf("upload file fail, " \
"error no: %d, error info: %s\n", \
result, STRERROR(result));
tracker_disconnect_server_ex(pStorageServer, true);
tracker_close_connection_ex(pStorageServer, true);
fdfs_client_destroy();
return result;
}
@ -349,7 +349,7 @@ int main(int argc, char *argv[])
printf("upload slave file fail, " \
"error no: %d, error info: %s\n", \
result, STRERROR(result));
tracker_disconnect_server_ex(pStorageServer, true);
tracker_close_connection_ex(pStorageServer, true);
fdfs_client_destroy();
return result;
}
@ -439,7 +439,7 @@ int main(int argc, char *argv[])
printf("\n");
}
tracker_disconnect_server_ex(pTrackerServer, true);
tracker_close_connection_ex(pTrackerServer, true);
fdfs_client_destroy();
return result;
}
@ -648,8 +648,8 @@ int main(int argc, char *argv[])
pStorageServer->ip_addr, pStorageServer->port, result);
}
tracker_disconnect_server_ex(pStorageServer, true);
tracker_disconnect_server_ex(pTrackerServer, true);
tracker_close_connection_ex(pStorageServer, true);
tracker_close_connection_ex(pTrackerServer, true);
fdfs_client_destroy();

View File

@ -28,22 +28,19 @@
int tracker_get_all_connections_ex(TrackerServerGroup *pTrackerGroup)
{
ConnectionInfo *pServer;
ConnectionInfo *pEnd;
TrackerServerInfo *pServer;
TrackerServerInfo *pEnd;
ConnectionInfo *conn;
int result;
int success_count;
success_count = 0;
pEnd = pTrackerGroup->servers + pTrackerGroup->server_count;
for (pServer=pTrackerGroup->servers; pServer<pEnd; pServer++)
{
if (pServer->sock >= 0)
if ((conn=tracker_connect_server(pServer, &result)) != NULL)
{
success_count++;
}
else if (conn_pool_connect_server(pServer, \
g_fdfs_connect_timeout) == 0)
{
fdfs_active_test(pServer);
fdfs_active_test(conn);
success_count++;
}
}
@ -53,22 +50,22 @@ int tracker_get_all_connections_ex(TrackerServerGroup *pTrackerGroup)
void tracker_close_all_connections_ex(TrackerServerGroup *pTrackerGroup)
{
ConnectionInfo *pServer;
ConnectionInfo *pEnd;
TrackerServerInfo *pServer;
TrackerServerInfo *pEnd;
pEnd = pTrackerGroup->servers + pTrackerGroup->server_count;
for (pServer=pTrackerGroup->servers; pServer<pEnd; pServer++)
{
conn_pool_disconnect_server(pServer);
tracker_disconnect_server(pServer);
}
}
ConnectionInfo *tracker_get_connection_ex(TrackerServerGroup *pTrackerGroup)
{
ConnectionInfo *conn;
ConnectionInfo *pCurrentServer;
ConnectionInfo *pServer;
ConnectionInfo *pEnd;
TrackerServerInfo *pCurrentServer;
TrackerServerInfo *pServer;
TrackerServerInfo *pEnd;
int server_index;
int result;
@ -91,7 +88,7 @@ ConnectionInfo *tracker_get_connection_ex(TrackerServerGroup *pTrackerGroup)
{
if ((conn=tracker_connect_server(pServer, &result)) != NULL)
{
pTrackerGroup->server_index = pServer - \
pTrackerGroup->server_index = pServer -
pTrackerGroup->servers;
break;
}
@ -106,7 +103,7 @@ ConnectionInfo *tracker_get_connection_ex(TrackerServerGroup *pTrackerGroup)
{
if ((conn=tracker_connect_server(pServer, &result)) != NULL)
{
pTrackerGroup->server_index = pServer - \
pTrackerGroup->server_index = pServer -
pTrackerGroup->servers;
break;
}
@ -124,9 +121,9 @@ ConnectionInfo *tracker_get_connection_ex(TrackerServerGroup *pTrackerGroup)
ConnectionInfo *tracker_get_connection_no_pool(TrackerServerGroup *pTrackerGroup)
{
ConnectionInfo *pCurrentServer;
ConnectionInfo *pServer;
ConnectionInfo *pEnd;
TrackerServerInfo *pCurrentServer;
TrackerServerInfo *pServer;
TrackerServerInfo *pEnd;
ConnectionInfo *conn;
int server_index;
int result;
@ -141,20 +138,17 @@ ConnectionInfo *tracker_get_connection_no_pool(TrackerServerGroup *pTrackerGroup
do
{
pCurrentServer = pTrackerGroup->servers + server_index;
if ((result=tracker_connect_server_no_pool(pCurrentServer)) == 0)
if ((conn=tracker_connect_server_no_pool(pCurrentServer, &result)) != NULL)
{
conn = pCurrentServer;
break;
}
pEnd = pTrackerGroup->servers + pTrackerGroup->server_count;
for (pServer=pCurrentServer+1; pServer<pEnd; pServer++)
{
if ((result=tracker_connect_server_no_pool(pServer)) == 0)
if ((conn=tracker_connect_server_no_pool(pServer, &result)) != NULL)
{
conn = pServer;
pTrackerGroup->server_index = pServer - \
pTrackerGroup->servers;
pTrackerGroup->server_index = pServer - pTrackerGroup->servers;
break;
}
}
@ -166,11 +160,9 @@ ConnectionInfo *tracker_get_connection_no_pool(TrackerServerGroup *pTrackerGroup
for (pServer=pTrackerGroup->servers; pServer<pCurrentServer; pServer++)
{
if ((result=tracker_connect_server_no_pool(pServer)) == 0)
if ((conn=tracker_connect_server_no_pool(pServer, &result)) != NULL)
{
conn = pServer;
pTrackerGroup->server_index = pServer - \
pTrackerGroup->servers;
pTrackerGroup->server_index = pServer - pTrackerGroup->servers;
break;
}
}
@ -185,13 +177,13 @@ ConnectionInfo *tracker_get_connection_no_pool(TrackerServerGroup *pTrackerGroup
return conn;
}
ConnectionInfo *tracker_get_connection_r_ex(TrackerServerGroup *pTrackerGroup, \
ConnectionInfo *pTrackerServer, int *err_no)
ConnectionInfo *tracker_get_connection_r_ex(TrackerServerGroup *pTrackerGroup,
TrackerServerInfo *pTrackerServer, int *err_no)
{
ConnectionInfo *conn;
ConnectionInfo *pCurrentServer;
ConnectionInfo *pServer;
ConnectionInfo *pEnd;
TrackerServerInfo *pCurrentServer;
TrackerServerInfo *pServer;
TrackerServerInfo *pEnd;
int server_index;
server_index = pTrackerGroup->server_index;
@ -203,8 +195,8 @@ ConnectionInfo *tracker_get_connection_r_ex(TrackerServerGroup *pTrackerGroup, \
do
{
pCurrentServer = pTrackerGroup->servers + server_index;
memcpy(pTrackerServer, pCurrentServer, sizeof(ConnectionInfo));
pTrackerServer->sock = -1;
memcpy(pTrackerServer, pCurrentServer, sizeof(TrackerServerInfo));
fdfs_server_sock_reset(pTrackerServer);
if ((conn=tracker_connect_server(pTrackerServer, err_no)) != NULL)
{
break;
@ -213,11 +205,11 @@ ConnectionInfo *tracker_get_connection_r_ex(TrackerServerGroup *pTrackerGroup, \
pEnd = pTrackerGroup->servers + pTrackerGroup->server_count;
for (pServer=pCurrentServer+1; pServer<pEnd; pServer++)
{
memcpy(pTrackerServer, pServer, sizeof(ConnectionInfo));
pTrackerServer->sock = -1;
memcpy(pTrackerServer, pServer, sizeof(TrackerServerInfo));
fdfs_server_sock_reset(pTrackerServer);
if ((conn=tracker_connect_server(pTrackerServer, err_no)) != NULL)
{
pTrackerGroup->server_index = pServer - \
pTrackerGroup->server_index = pServer -
pTrackerGroup->servers;
break;
}
@ -230,11 +222,11 @@ ConnectionInfo *tracker_get_connection_r_ex(TrackerServerGroup *pTrackerGroup, \
for (pServer=pTrackerGroup->servers; pServer<pCurrentServer; pServer++)
{
memcpy(pTrackerServer, pServer, sizeof(ConnectionInfo));
pTrackerServer->sock = -1;
memcpy(pTrackerServer, pServer, sizeof(TrackerServerInfo));
fdfs_server_sock_reset(pTrackerServer);
if ((conn=tracker_connect_server(pTrackerServer, err_no)) != NULL)
{
pTrackerGroup->server_index = pServer - \
pTrackerGroup->server_index = pServer -
pTrackerGroup->servers;
break;
}
@ -327,7 +319,7 @@ int tracker_list_servers(ConnectionInfo *pTrackerServer, \
if (new_connection)
{
tracker_disconnect_server_ex(conn, result != 0);
tracker_close_connection_ex(conn, result != 0);
}
if (result != 0)
@ -530,7 +522,7 @@ int tracker_list_one_group(ConnectionInfo *pTrackerServer, \
if (new_connection)
{
tracker_disconnect_server_ex(conn, result != 0);
tracker_close_connection_ex(conn, result != 0);
}
if (result != 0)
@ -610,7 +602,7 @@ int tracker_list_groups(ConnectionInfo *pTrackerServer, \
if (new_connection)
{
tracker_disconnect_server_ex(conn, result != 0);
tracker_close_connection_ex(conn, result != 0);
}
if (result != 0)
@ -727,7 +719,7 @@ int tracker_do_query_storage(ConnectionInfo *pTrackerServer, \
if (new_connection)
{
tracker_disconnect_server_ex(conn, result != 0);
tracker_close_connection_ex(conn, result != 0);
}
if (result != 0)
@ -811,7 +803,7 @@ int tracker_query_storage_list(ConnectionInfo *pTrackerServer, \
if (new_connection)
{
tracker_disconnect_server_ex(conn, result != 0);
tracker_close_connection_ex(conn, result != 0);
}
if (result != 0)
@ -910,7 +902,7 @@ int tracker_query_storage_store_without_group(ConnectionInfo *pTrackerServer,
if (new_connection)
{
tracker_disconnect_server_ex(conn, result != 0);
tracker_close_connection_ex(conn, result != 0);
}
if (result != 0)
@ -993,7 +985,7 @@ int tracker_query_storage_store_with_group(ConnectionInfo *pTrackerServer, \
if (new_connection)
{
tracker_disconnect_server_ex(conn, result != 0);
tracker_close_connection_ex(conn, result != 0);
}
if (result != 0)
@ -1088,7 +1080,7 @@ int tracker_query_storage_store_list_with_group( \
if (new_connection)
{
tracker_disconnect_server_ex(conn, result != 0);
tracker_close_connection_ex(conn, result != 0);
}
if (result != 0)
@ -1159,9 +1151,9 @@ int tracker_delete_storage(TrackerServerGroup *pTrackerGroup, \
{
ConnectionInfo *conn;
TrackerHeader *pHeader;
ConnectionInfo tracker_server;
ConnectionInfo *pServer;
ConnectionInfo *pEnd;
TrackerServerInfo tracker_server;
TrackerServerInfo *pServer;
TrackerServerInfo *pEnd;
FDFSStorageInfo storage_infos[1];
char out_buff[sizeof(TrackerHeader) + FDFS_GROUP_NAME_MAX_LEN + \
FDFS_STORAGE_ID_MAX_SIZE];
@ -1177,8 +1169,8 @@ int tracker_delete_storage(TrackerServerGroup *pTrackerGroup, \
pEnd = pTrackerGroup->servers + pTrackerGroup->server_count;
for (pServer=pTrackerGroup->servers; pServer<pEnd; pServer++)
{
memcpy(&tracker_server, pServer, sizeof(ConnectionInfo));
tracker_server.sock = -1;
memcpy(&tracker_server, pServer, sizeof(TrackerServerInfo));
fdfs_server_sock_reset(&tracker_server);
if ((conn=tracker_connect_server(&tracker_server, &result)) == NULL)
{
return result;
@ -1186,7 +1178,7 @@ int tracker_delete_storage(TrackerServerGroup *pTrackerGroup, \
result = tracker_list_servers(conn, group_name, storage_id, \
storage_infos, 1, &storage_count);
tracker_disconnect_server_ex(conn, result != 0 && result != ENOENT);
tracker_close_connection_ex(conn, result != 0 && result != ENOENT);
if (result != 0 && result != ENOENT)
{
return result;
@ -1225,8 +1217,8 @@ int tracker_delete_storage(TrackerServerGroup *pTrackerGroup, \
result = 0;
for (pServer=pTrackerGroup->servers; pServer<pEnd; pServer++)
{
memcpy(&tracker_server, pServer, sizeof(ConnectionInfo));
tracker_server.sock = -1;
memcpy(&tracker_server, pServer, sizeof(TrackerServerInfo));
fdfs_server_sock_reset(&tracker_server);
if ((conn=tracker_connect_server(&tracker_server, &result)) == NULL)
{
return result;
@ -1236,10 +1228,10 @@ int tracker_delete_storage(TrackerServerGroup *pTrackerGroup, \
sizeof(TrackerHeader) + FDFS_GROUP_NAME_MAX_LEN +
storage_id_len, g_fdfs_network_timeout)) != 0)
{
logError("file: "__FILE__", line: %d, " \
"send data to tracker server %s:%d fail, " \
"errno: %d, error info: %s", __LINE__, \
tracker_server.ip_addr, tracker_server.port, \
logError("file: "__FILE__", line: %d, "
"send data to tracker server %s:%d fail, "
"errno: %d, error info: %s", __LINE__,
conn->ip_addr, conn->port,
result, STRERROR(result));
}
else
@ -1254,7 +1246,7 @@ int tracker_delete_storage(TrackerServerGroup *pTrackerGroup, \
}
}
tracker_disconnect_server_ex(conn, result != 0 && result != ENOENT);
tracker_close_connection_ex(conn, result != 0 && result != ENOENT);
if (result != 0)
{
if (result == ENOENT)
@ -1284,9 +1276,9 @@ int tracker_delete_group(TrackerServerGroup *pTrackerGroup, \
{
ConnectionInfo *conn;
TrackerHeader *pHeader;
ConnectionInfo tracker_server;
ConnectionInfo *pServer;
ConnectionInfo *pEnd;
TrackerServerInfo tracker_server;
TrackerServerInfo *pServer;
TrackerServerInfo *pEnd;
char out_buff[sizeof(TrackerHeader) + FDFS_GROUP_NAME_MAX_LEN];
char in_buff[1];
char *pInBuff;
@ -1305,28 +1297,28 @@ int tracker_delete_group(TrackerServerGroup *pTrackerGroup, \
pEnd = pTrackerGroup->servers + pTrackerGroup->server_count;
for (pServer=pTrackerGroup->servers; pServer<pEnd; pServer++)
{
memcpy(&tracker_server, pServer, sizeof(ConnectionInfo));
tracker_server.sock = -1;
memcpy(&tracker_server, pServer, sizeof(TrackerServerInfo));
fdfs_server_sock_reset(&tracker_server);
if ((conn=tracker_connect_server(&tracker_server, &result)) == NULL)
{
return result;
}
if ((result=tcpsenddata_nb(conn->sock, out_buff, \
if ((result=tcpsenddata_nb(conn->sock, out_buff,
sizeof(TrackerHeader) + FDFS_GROUP_NAME_MAX_LEN,
g_fdfs_network_timeout)) != 0)
{
logError("file: "__FILE__", line: %d, " \
"send data to tracker server %s:%d fail, " \
"errno: %d, error info: %s", __LINE__, \
tracker_server.ip_addr, tracker_server.port, \
logError("file: "__FILE__", line: %d, "
"send data to tracker server %s:%d fail, "
"errno: %d, error info: %s", __LINE__,
conn->ip_addr, conn->port,
result, STRERROR(result));
break;
}
pInBuff = in_buff;
result = fdfs_recv_response(conn, &pInBuff, 0, &in_bytes);
tracker_disconnect_server_ex(conn, result != 0 && result != ENOENT);
tracker_close_connection_ex(conn, result != 0 && result != ENOENT);
if (result != 0)
{
logError("file: "__FILE__", line: %d, "
@ -1345,9 +1337,9 @@ int tracker_set_trunk_server(TrackerServerGroup *pTrackerGroup, \
{
TrackerHeader *pHeader;
ConnectionInfo *conn;
ConnectionInfo *pServer;
ConnectionInfo *pEnd;
ConnectionInfo tracker_server;
TrackerServerInfo *pServer;
TrackerServerInfo *pEnd;
TrackerServerInfo tracker_server;
char out_buff[sizeof(TrackerHeader) + FDFS_GROUP_NAME_MAX_LEN + \
FDFS_STORAGE_ID_MAX_SIZE];
char in_buff[FDFS_STORAGE_ID_MAX_SIZE];
@ -1381,8 +1373,8 @@ int tracker_set_trunk_server(TrackerServerGroup *pTrackerGroup, \
pEnd = pTrackerGroup->servers + pTrackerGroup->server_count;
for (pServer=pTrackerGroup->servers; pServer<pEnd; pServer++)
{
memcpy(&tracker_server, pServer, sizeof(ConnectionInfo));
tracker_server.sock = -1;
memcpy(&tracker_server, pServer, sizeof(TrackerServerInfo));
fdfs_server_sock_reset(&tracker_server);
if ((conn=tracker_connect_server(&tracker_server, &result)) == NULL)
{
continue;
@ -1392,21 +1384,21 @@ int tracker_set_trunk_server(TrackerServerGroup *pTrackerGroup, \
sizeof(TrackerHeader) + FDFS_GROUP_NAME_MAX_LEN +
storage_id_len, g_fdfs_network_timeout)) != 0)
{
logError("file: "__FILE__", line: %d, " \
"send data to tracker server %s:%d fail, " \
"errno: %d, error info: %s", __LINE__, \
tracker_server.ip_addr, tracker_server.port, \
logError("file: "__FILE__", line: %d, "
"send data to tracker server %s:%d fail, "
"errno: %d, error info: %s", __LINE__,
conn->ip_addr, conn->port,
result, STRERROR(result));
tracker_disconnect_server_ex(conn, true);
tracker_close_connection_ex(conn, true);
continue;
}
pInBuff = in_buff;
result = fdfs_recv_response(conn, &pInBuff, \
result = fdfs_recv_response(conn, &pInBuff,
sizeof(in_buff) - 1, &in_bytes);
tracker_disconnect_server_ex(conn, result != 0);
tracker_close_connection_ex(conn, result != 0);
if (result == 0)
{
strcpy(new_trunk_server_id, in_buff);
@ -1500,7 +1492,7 @@ int tracker_get_storage_status(ConnectionInfo *pTrackerServer, \
if (new_connection)
{
tracker_disconnect_server_ex(conn, result != 0);
tracker_close_connection_ex(conn, result != 0);
}
if (result != 0)
@ -1587,7 +1579,7 @@ int tracker_get_storage_id(ConnectionInfo *pTrackerServer, \
if (new_connection)
{
tracker_disconnect_server_ex(conn, result != 0);
tracker_close_connection_ex(conn, result != 0);
}
if (result != 0)
@ -1614,9 +1606,9 @@ int tracker_get_storage_max_status(TrackerServerGroup *pTrackerGroup, \
char *storage_id, int *status)
{
ConnectionInfo *conn;
ConnectionInfo tracker_server;
ConnectionInfo *pServer;
ConnectionInfo *pEnd;
TrackerServerInfo tracker_server;
TrackerServerInfo *pServer;
TrackerServerInfo *pEnd;
FDFSStorageBrief storage_brief;
int result;
@ -1628,8 +1620,8 @@ int tracker_get_storage_max_status(TrackerServerGroup *pTrackerGroup, \
pEnd = pTrackerGroup->servers + pTrackerGroup->server_count;
for (pServer=pTrackerGroup->servers; pServer<pEnd; pServer++)
{
memcpy(&tracker_server, pServer, sizeof(ConnectionInfo));
tracker_server.sock = -1;
memcpy(&tracker_server, pServer, sizeof(TrackerServerInfo));
fdfs_server_sock_reset(&tracker_server);
if ((conn=tracker_connect_server(&tracker_server, &result)) == NULL)
{
return result;
@ -1637,7 +1629,7 @@ int tracker_get_storage_max_status(TrackerServerGroup *pTrackerGroup, \
result = tracker_get_storage_status(conn, group_name, \
ip_addr, &storage_brief);
tracker_disconnect_server_ex(conn, result != 0);
tracker_close_connection_ex(conn, result != 0);
if (result != 0)
{

View File

@ -44,7 +44,7 @@ typedef struct
do { \
if (pTrackerServer->sock < 0) \
{ \
if ((conn=tracker_connect_server( \
if ((conn=tracker_make_connection( \
pTrackerServer, &result)) != NULL) \
{ \
return result; \
@ -82,7 +82,7 @@ ConnectionInfo *tracker_get_connection_ex(TrackerServerGroup *pTrackerGroup);
* return: 0 success, !=0 fail
**/
ConnectionInfo *tracker_get_connection_r_ex(TrackerServerGroup *pTrackerGroup, \
ConnectionInfo *pTrackerServer, int *err_no);
TrackerServerInfo *pTrackerServer, int *err_no);
#define tracker_get_all_connections() \
tracker_get_all_connections_ex((&g_tracker_group))

View File

@ -119,7 +119,7 @@ static int recovery_get_src_storage_server(ConnectionInfo *pSrcStorage)
{
int result;
int storage_count;
ConnectionInfo trackerServer;
TrackerServerInfo trackerServer;
ConnectionInfo *pTrackerConn;
FDFSGroupStat groupStat;
FDFSStorageInfo storageStats[FDFS_MAX_SERVERS_EACH_GROUP];
@ -187,7 +187,7 @@ static int recovery_get_src_storage_server(ConnectionInfo *pSrcStorage)
g_group_name, &groupStat);
if (result != 0)
{
tracker_disconnect_server_ex(pTrackerConn, true);
tracker_close_connection_ex(pTrackerConn, true);
sleep(1);
continue;
}
@ -198,7 +198,7 @@ static int recovery_get_src_storage_server(ConnectionInfo *pSrcStorage)
"storage server count: %d in the group <= 0!",\
__LINE__, groupStat.count);
tracker_disconnect_server(pTrackerConn);
tracker_close_connection(pTrackerConn);
sleep(1);
continue;
}
@ -209,7 +209,7 @@ static int recovery_get_src_storage_server(ConnectionInfo *pSrcStorage)
"storage server count in the group = 1, " \
"does not need recovery", __LINE__);
tracker_disconnect_server(pTrackerConn);
tracker_close_connection(pTrackerConn);
return ENOENT;
}
@ -221,13 +221,13 @@ static int recovery_get_src_storage_server(ConnectionInfo *pSrcStorage)
"does not need recovery", __LINE__, \
g_fdfs_store_paths.count, groupStat.store_path_count);
tracker_disconnect_server(pTrackerConn);
tracker_close_connection(pTrackerConn);
return ENOENT;
}
if (groupStat.active_count <= 0)
{
tracker_disconnect_server(pTrackerConn);
tracker_close_connection(pTrackerConn);
sleep(5);
continue;
}
@ -235,7 +235,7 @@ static int recovery_get_src_storage_server(ConnectionInfo *pSrcStorage)
result = tracker_list_servers(pTrackerConn, \
g_group_name, NULL, storageStats, \
FDFS_MAX_SERVERS_EACH_GROUP, &storage_count);
tracker_disconnect_server_ex(pTrackerConn, result != 0);
tracker_close_connection_ex(pTrackerConn, result != 0);
if (result != 0)
{
sleep(5);
@ -729,7 +729,7 @@ static int storage_do_recovery(const char *pBasePath, StorageBinLogReader *pRead
}
}
tracker_disconnect_server_ex(pStorageConn, result != 0);
tracker_close_connection_ex(pStorageConn, result != 0);
recovery_write_to_mark_file(pBasePath, pReader);
if (bContinueFlag)
{
@ -1120,7 +1120,7 @@ int storage_disk_recovery_start(const int store_path_index)
}
result = storage_do_fetch_binlog(pStorageConn, store_path_index);
tracker_disconnect_server_ex(pStorageConn, true);
tracker_close_connection_ex(pStorageConn, true);
if (result != 0)
{
return result;

View File

@ -257,8 +257,8 @@ static int fdfs_dump_global_vars(char *buff, const int buffSize)
static int fdfs_dump_tracker_servers(char *buff, const int buffSize)
{
int total_len;
ConnectionInfo *pTrackerServer;
ConnectionInfo *pTrackerEnd;
TrackerServerInfo *pTrackerServer;
TrackerServerInfo *pTrackerEnd;
total_len = snprintf(buff, buffSize, \
"\ng_tracker_group.server_count=%d, " \
@ -275,9 +275,10 @@ static int fdfs_dump_tracker_servers(char *buff, const int buffSize)
pTrackerServer<pTrackerEnd; pTrackerServer++)
{
total_len += snprintf(buff + total_len, buffSize - total_len,
"\t%d. tracker server=%s:%d\n", \
(int)(pTrackerServer - g_tracker_group.servers) + 1, \
pTrackerServer->ip_addr, pTrackerServer->port);
"\t%d. tracker server=%s:%d\n",
(int)(pTrackerServer - g_tracker_group.servers) + 1,
pTrackerServer->connections[0].ip_addr,
pTrackerServer->connections[0].port);
}
return total_len;

View File

@ -194,7 +194,7 @@ static int storage_get_group_name_from_tracker()
}
result = storage_do_get_group_name(pTrackerConn);
tracker_disconnect_server_ex(pTrackerConn,
tracker_close_connection_ex(pTrackerConn,
result != 0 && result != ENOENT);
if (result == 0)
{
@ -234,7 +234,7 @@ static int tracker_get_my_server_id()
result = tracker_get_storage_id(pTrackerServer, \
g_group_name, g_tracker_client_ip, g_my_server_id_str);
tracker_disconnect_server_ex(pTrackerServer, result != 0);
tracker_close_connection_ex(pTrackerServer, result != 0);
if (result != 0)
{
return result;

View File

@ -55,7 +55,7 @@ static int storage_convert_src_server_id()
result = tracker_get_storage_id(pTrackerConn,
g_group_name, g_sync_src_id, g_sync_src_id);
tracker_disconnect_server_ex(pTrackerConn,
tracker_close_connection_ex(pTrackerConn,
result != 0 && result != ENOENT);
if (result == 0)
{

View File

@ -2258,7 +2258,7 @@ static int storage_client_create_link_wrapper(struct fast_task_info *pTask, \
{
int result;
int src_store_path_index;
ConnectionInfo trackerServer;
TrackerServerInfo trackerServer;
ConnectionInfo *pTracker;
ConnectionInfo storageServer;
ConnectionInfo *pStorageServer;
@ -2286,7 +2286,7 @@ static int storage_client_create_link_wrapper(struct fast_task_info *pTask, \
&storageServer, group_name, src_filename);
if (result != 0)
{
tracker_disconnect_server_ex(pTracker, true);
tracker_close_connection_ex(pTracker, true);
return result;
}
@ -2304,7 +2304,7 @@ static int storage_client_create_link_wrapper(struct fast_task_info *pTask, \
if ((pStorageServer=tracker_make_connection(
&storageServer, &result)) == NULL)
{
tracker_disconnect_server(pTracker);
tracker_close_connection(pTracker);
return result;
}
}
@ -2326,7 +2326,7 @@ static int storage_client_create_link_wrapper(struct fast_task_info *pTask, \
filename_len, sourceFileInfo.src_true_filename, \
&src_store_path_index)) != 0)
{
tracker_disconnect_server(pTracker);
tracker_close_connection(pTracker);
return result;
}
@ -2352,11 +2352,11 @@ static int storage_client_create_link_wrapper(struct fast_task_info *pTask, \
file_ext_name, remote_filename, filename_len);
if (pStorageServer != NULL)
{
tracker_disconnect_server_ex(pStorageServer, result != 0);
tracker_close_connection_ex(pStorageServer, result != 0);
}
}
tracker_disconnect_server(pTracker);
tracker_close_connection(pTracker);
return result;
}

View File

@ -1036,7 +1036,7 @@ static int notify_reselect_tracker_leader(TrackerServerInfo *pTrackerServer)
}
result = _notify_reselect_tleader(conn);
tracker_disconnect_server_ex(conn, result != 0);
tracker_close_connection_ex(conn, result != 0);
return result;
}

View File

@ -125,7 +125,7 @@ int trunk_client_trunk_alloc_space(const int file_size, \
result = trunk_client_trunk_do_alloc_space(pTrunkServer, \
file_size, pTrunkInfo);
tracker_disconnect_server_ex(pTrunkServer, result != 0);
tracker_close_connection_ex(pTrunkServer, result != 0);
return result;
}
@ -228,7 +228,7 @@ int trunk_client_trunk_alloc_confirm(const FDFSTrunkFullInfo *pTrunkInfo, \
result = trunk_client_trunk_do_alloc_confirm(pTrunkServer, \
pTrunkInfo, status);
tracker_disconnect_server_ex(pTrunkServer, result != 0);
tracker_close_connection_ex(pTrunkServer, result != 0);
return result;
}
@ -259,7 +259,7 @@ int trunk_client_trunk_free_space(const FDFSTrunkFullInfo *pTrunkInfo)
}
result = trunk_client_trunk_do_free_space(pTrunkServer, pTrunkInfo);
tracker_disconnect_server_ex(pTrunkServer, result != 0);
tracker_close_connection_ex(pTrunkServer, result != 0);
return result;
}

View File

@ -45,14 +45,14 @@ int upload_file(const char *file_buff, const int file_size, char *file_id, char
if ((result=tracker_query_storage_store(pTrackerServer, &storageServer,
group_name, &store_path_index)) != 0)
{
tracker_disconnect_server_ex(pTrackerServer, true);
tracker_close_connection_ex(pTrackerServer, true);
return result;
}
if ((pStorageServer=tracker_connect_server(&storageServer, &result)) \
== NULL)
{
tracker_disconnect_server(pTrackerServer);
tracker_close_connection(pTrackerServer);
return result;
}
@ -60,8 +60,8 @@ int upload_file(const char *file_buff, const int file_size, char *file_id, char
result = storage_upload_by_filebuff1(pTrackerServer, pStorageServer,
store_path_index, file_buff, file_size, NULL, NULL, 0, "", file_id);
tracker_disconnect_server(pTrackerServer);
tracker_disconnect_server(pStorageServer);
tracker_close_connection(pTrackerServer);
tracker_close_connection(pStorageServer);
return result;
}
@ -83,14 +83,14 @@ int download_file(const char *file_id, int *file_size, char *storage_ip)
if ((result=tracker_query_storage_fetch1(pTrackerServer, \
&storageServer, file_id)) != 0)
{
tracker_disconnect_server_ex(pTrackerServer, true);
tracker_close_connection_ex(pTrackerServer, true);
return result;
}
if ((pStorageServer=tracker_connect_server(&storageServer, &result)) \
== NULL)
{
tracker_disconnect_server(pTrackerServer);
tracker_close_connection(pTrackerServer);
return result;
}
@ -99,8 +99,8 @@ int download_file(const char *file_id, int *file_size, char *storage_ip)
file_id, 0, 0, downloadFileCallback, NULL, &file_bytes);
*file_size = file_bytes;
tracker_disconnect_server(pTrackerServer);
tracker_disconnect_server(pStorageServer);
tracker_close_connection(pTrackerServer);
tracker_close_connection(pStorageServer);
return result;
}
@ -121,22 +121,22 @@ int delete_file(const char *file_id, char *storage_ip)
if ((result=tracker_query_storage_update1(pTrackerServer, \
&storageServer, file_id)) != 0)
{
tracker_disconnect_server_ex(pTrackerServer, true);
tracker_close_connection_ex(pTrackerServer, true);
return result;
}
if ((pStorageServer=tracker_connect_server(&storageServer, &result)) \
== NULL)
{
tracker_disconnect_server(pTrackerServer);
tracker_close_connection(pTrackerServer);
return result;
}
strcpy(storage_ip, storageServer.ip_addr);
result = storage_delete_file1(pTrackerServer, pStorageServer, file_id);
tracker_disconnect_server(pTrackerServer);
tracker_disconnect_server(pStorageServer);
tracker_close_connection(pTrackerServer);
tracker_close_connection(pStorageServer);
return result;
}

View File

@ -80,7 +80,7 @@ void dfs_destroy()
ConnectionInfo *pEnd;
ConnectionInfo *pServer;
tracker_disconnect_server(pTrackerServer);
tracker_close_connection(pTrackerServer);
pEnd = storage_servers + storage_server_count;
for (pServer=storage_servers; pServer<pEnd; pServer++)

View File

@ -85,6 +85,35 @@ bool fdfs_server_contain_ex(TrackerServerInfo *pServer1,
return false;
}
bool fdfs_server_equal(TrackerServerInfo *pServer1,
TrackerServerInfo *pServer2)
{
ConnectionInfo *conn;
ConnectionInfo *end;
if (pServer1->count != pServer2->count)
{
return false;
}
if (pServer1->count == 1)
{
return (pServer1->connections->port == pServer2->connections->port &&
strcmp(pServer1->connections->ip_addr, pServer2->connections->ip_addr) == 0);
}
end = pServer1->connections + pServer1->count;
for (conn=pServer1->connections; conn<end; conn++)
{
if (!fdfs_server_contain1(pServer2, conn))
{
return false;
}
}
return true;
}
void fdfs_server_sock_reset(TrackerServerInfo *pServerInfo)
{
ConnectionInfo *conn;
@ -903,7 +932,7 @@ int fdfs_get_storage_ids_from_tracker_server(TrackerServerInfo *pTrackerServer)
}
}
tracker_disconnect_server_ex(conn, result != 0);
tracker_close_connection_ex(conn, result != 0);
if (result == 0)
{

View File

@ -92,6 +92,9 @@ static inline bool fdfs_server_contain1(TrackerServerInfo *pServerInfo,
bool fdfs_server_contain_ex(TrackerServerInfo *pServer1,
TrackerServerInfo *pServer2);
bool fdfs_server_equal(TrackerServerInfo *pServer1,
TrackerServerInfo *pServer2);
void fdfs_server_sock_reset(TrackerServerInfo *pServerInfo);
int fdfs_parse_server_info(char *server_str, const int default_port,

View File

@ -3915,7 +3915,7 @@ static int tracker_mem_get_sys_files(TrackerServerInfo *pTrackerServer)
if ((result=tracker_get_sys_files_start(conn)) != 0)
{
tracker_disconnect_server_ex(conn, true);
tracker_close_connection_ex(conn, true);
return result;
}
@ -3929,7 +3929,7 @@ static int tracker_mem_get_sys_files(TrackerServerInfo *pTrackerServer)
}
result = tracker_get_sys_files_end(conn);
tracker_disconnect_server_ex(conn, result != 0);
tracker_close_connection_ex(conn, result != 0);
return result;
}
@ -4905,7 +4905,7 @@ static int tracker_mem_get_trunk_binlog_size(
}
result = _storage_get_trunk_binlog_size(conn, file_size);
tracker_disconnect_server_ex(conn, result != 0);
tracker_close_connection_ex(conn, result != 0);
logDebug("file: "__FILE__", line: %d, " \

View File

@ -219,7 +219,7 @@ int fdfs_deal_no_body_cmd_ex(const char *ip_addr, const int port, const int cmd)
}
result = fdfs_deal_no_body_cmd(conn, cmd);
tracker_disconnect_server_ex(conn, result != 0);
tracker_close_connection_ex(conn, result != 0);
return result;
}
@ -421,7 +421,7 @@ char *fdfs_pack_metadata(const FDFSMetaData *meta_list, const int meta_count, \
return meta_buff;
}
void tracker_disconnect_server_ex(ConnectionInfo *conn, \
void tracker_close_connection_ex(ConnectionInfo *conn, \
const bool bForceClose)
{
if (g_use_connection_pool)
@ -537,6 +537,24 @@ ConnectionInfo *tracker_make_connection_ex(ConnectionInfo *conn,
}
}
void tracker_disconnect_server(TrackerServerInfo *pServerInfo)
{
ConnectionInfo *conn;
ConnectionInfo *end;
if (pServerInfo->count == 1)
{
conn_pool_disconnect_server(pServerInfo->connections);
return;
}
end = pServerInfo->connections + pServerInfo->count;
for (conn=pServerInfo->connections; conn<end; conn++)
{
conn_pool_disconnect_server(conn);
}
}
static int fdfs_do_parameter_req(ConnectionInfo *pTrackerServer, \
char *buff, const int buff_size)
{
@ -728,7 +746,7 @@ int fdfs_get_tracker_status(TrackerServerInfo *pTrackerServer,
} while (0);
tracker_disconnect_server_ex(conn, result != 0);
tracker_close_connection_ex(conn, result != 0);
return result;
}

View File

@ -254,8 +254,8 @@ static inline ConnectionInfo *tracker_connect_server_no_pool(
bind_addr, err_no, true);
}
#define tracker_disconnect_server(pTrackerServer) \
tracker_disconnect_server_ex(pTrackerServer, false)
#define tracker_close_connection(pTrackerServer) \
tracker_close_connection_ex(pTrackerServer, false)
/**
* close all connections to tracker servers
@ -264,10 +264,12 @@ static inline ConnectionInfo *tracker_connect_server_no_pool(
* bForceClose: if force close the connection when use connection pool
* return:
**/
void tracker_disconnect_server_ex(ConnectionInfo *conn, \
void tracker_close_connection_ex(ConnectionInfo *conn, \
const bool bForceClose);
void tracker_disconnect_server(TrackerServerInfo *pServerInfo);
ConnectionInfo *tracker_make_connection_ex(ConnectionInfo *conn,
const int connect_timeout, int *err_no);

View File

@ -310,11 +310,11 @@ static int do_notify_leader_changed(TrackerServerInfo *pTrackerServer, \
if (conn->port == g_server_port &&
is_local_host_ip(conn->ip_addr))
{
tracker_disconnect_server_ex(conn, true);
tracker_close_connection_ex(conn, true);
}
else
{
tracker_disconnect_server_ex(conn, result != 0);
tracker_close_connection_ex(conn, result != 0);
}
return result;
@ -470,7 +470,7 @@ static int relationship_ping_leader()
}
result = fdfs_ping_leader(conn);
tracker_disconnect_server_ex(conn, result != 0);
tracker_close_connection_ex(conn, result != 0);
return result;
}