storage support multi ip for tracker server
parent
2b11a518d4
commit
16bbaf7884
|
|
@ -531,7 +531,7 @@ static int storage_do_recovery(const char *pBasePath, StorageBinLogReader *pRead
|
||||||
char local_filename[MAX_PATH_SIZE];
|
char local_filename[MAX_PATH_SIZE];
|
||||||
char src_filename[MAX_PATH_SIZE];
|
char src_filename[MAX_PATH_SIZE];
|
||||||
|
|
||||||
pTrackerServer = g_tracker_group.servers;
|
pTrackerServer = g_tracker_group.servers->connections; //TODO: fix me !!!
|
||||||
count = 0;
|
count = 0;
|
||||||
total_count = 0;
|
total_count = 0;
|
||||||
success_count = 0;
|
success_count = 0;
|
||||||
|
|
@ -549,7 +549,7 @@ static int storage_do_recovery(const char *pBasePath, StorageBinLogReader *pRead
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ((pStorageConn=tracker_connect_server(pSrcStorage, &result)) == NULL)
|
if ((pStorageConn=tracker_make_connection(pSrcStorage, &result)) == NULL)
|
||||||
{
|
{
|
||||||
sleep(5);
|
sleep(5);
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -1114,7 +1114,7 @@ int storage_disk_recovery_start(const int store_path_index)
|
||||||
return EINTR;
|
return EINTR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pStorageConn=tracker_connect_server(&srcStorage, &result)) == NULL)
|
if ((pStorageConn=tracker_make_connection(&srcStorage, &result)) == NULL)
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -174,28 +174,27 @@ static int storage_do_get_group_name(ConnectionInfo *pTrackerServer)
|
||||||
|
|
||||||
static int storage_get_group_name_from_tracker()
|
static int storage_get_group_name_from_tracker()
|
||||||
{
|
{
|
||||||
ConnectionInfo *pTrackerServer;
|
TrackerServerInfo *pTrackerServer;
|
||||||
ConnectionInfo *pServerEnd;
|
TrackerServerInfo *pServerEnd;
|
||||||
ConnectionInfo *pTrackerConn;
|
ConnectionInfo *pTrackerConn;
|
||||||
ConnectionInfo tracker_server;
|
TrackerServerInfo tracker_server;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
result = ENOENT;
|
result = ENOENT;
|
||||||
pServerEnd = g_tracker_group.servers + g_tracker_group.server_count;
|
pServerEnd = g_tracker_group.servers + g_tracker_group.server_count;
|
||||||
for (pTrackerServer=g_tracker_group.servers; \
|
for (pTrackerServer=g_tracker_group.servers;
|
||||||
pTrackerServer<pServerEnd; pTrackerServer++)
|
pTrackerServer<pServerEnd; pTrackerServer++)
|
||||||
{
|
{
|
||||||
memcpy(&tracker_server, pTrackerServer, \
|
memcpy(&tracker_server, pTrackerServer, sizeof(TrackerServerInfo));
|
||||||
sizeof(ConnectionInfo));
|
fdfs_server_sock_reset(&tracker_server);
|
||||||
tracker_server.sock = -1;
|
if ((pTrackerConn=tracker_connect_server(&tracker_server,
|
||||||
if ((pTrackerConn=tracker_connect_server(&tracker_server, \
|
|
||||||
&result)) == NULL)
|
&result)) == NULL)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = storage_do_get_group_name(pTrackerConn);
|
result = storage_do_get_group_name(pTrackerConn);
|
||||||
tracker_disconnect_server_ex(pTrackerConn, \
|
tracker_disconnect_server_ex(pTrackerConn,
|
||||||
result != 0 && result != ENOENT);
|
result != 0 && result != ENOENT);
|
||||||
if (result == 0)
|
if (result == 0)
|
||||||
{
|
{
|
||||||
|
|
@ -1049,6 +1048,34 @@ void storage_set_access_log_header(struct log_context *pContext)
|
||||||
log_header(pContext, STORAGE_ACCESS_HEADER_STR, STORAGE_ACCESS_HEADER_LEN);
|
log_header(pContext, STORAGE_ACCESS_HEADER_STR, STORAGE_ACCESS_HEADER_LEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int storage_check_tracker_ipaddr(const char *filename)
|
||||||
|
{
|
||||||
|
TrackerServerInfo *pServer;
|
||||||
|
TrackerServerInfo *pEnd;
|
||||||
|
ConnectionInfo *conn;
|
||||||
|
ConnectionInfo *conn_end;
|
||||||
|
|
||||||
|
pEnd = g_tracker_group.servers + g_tracker_group.server_count;
|
||||||
|
for (pServer=g_tracker_group.servers; pServer<pEnd; pServer++)
|
||||||
|
{
|
||||||
|
conn_end = pServer->connections + pServer->count;
|
||||||
|
for (conn=pServer->connections; conn<conn_end; conn++)
|
||||||
|
{
|
||||||
|
//logInfo("server=%s:%d\n", conn->ip_addr, conn->port);
|
||||||
|
if (strcmp(conn->ip_addr, "127.0.0.1") == 0)
|
||||||
|
{
|
||||||
|
logError("file: "__FILE__", line: %d, "
|
||||||
|
"conf file \"%s\", tracker: \"%s:%d\" is invalid, "
|
||||||
|
"tracker server ip can't be 127.0.0.1",
|
||||||
|
__LINE__, filename, conn->ip_addr, conn->port);
|
||||||
|
return EINVAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int storage_func_init(const char *filename, \
|
int storage_func_init(const char *filename, \
|
||||||
char *bind_addr, const int addr_size)
|
char *bind_addr, const int addr_size)
|
||||||
{
|
{
|
||||||
|
|
@ -1070,8 +1097,6 @@ int storage_func_init(const char *filename, \
|
||||||
int64_t buff_size;
|
int64_t buff_size;
|
||||||
int64_t rotate_access_log_size;
|
int64_t rotate_access_log_size;
|
||||||
int64_t rotate_error_log_size;
|
int64_t rotate_error_log_size;
|
||||||
ConnectionInfo *pServer;
|
|
||||||
ConnectionInfo *pEnd;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
while (nThreadCount > 0)
|
while (nThreadCount > 0)
|
||||||
|
|
@ -1181,23 +1206,7 @@ int storage_func_init(const char *filename, \
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
pEnd = g_tracker_group.servers + g_tracker_group.server_count;
|
if ((result=storage_check_tracker_ipaddr(filename)) != 0)
|
||||||
for (pServer=g_tracker_group.servers; pServer<pEnd; pServer++)
|
|
||||||
{
|
|
||||||
//printf("server=%s:%d\n", pServer->ip_addr, pServer->port);
|
|
||||||
if (strcmp(pServer->ip_addr, "127.0.0.1") == 0)
|
|
||||||
{
|
|
||||||
logError("file: "__FILE__", line: %d, " \
|
|
||||||
"conf file \"%s\", " \
|
|
||||||
"tracker: \"%s:%d\" is invalid, " \
|
|
||||||
"tracker server ip can't be 127.0.0.1",\
|
|
||||||
__LINE__, filename, pServer->ip_addr, \
|
|
||||||
pServer->port);
|
|
||||||
result = EINVAL;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (result != 0)
|
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -119,15 +119,17 @@ static int storage_report_ip_changed(ConnectionInfo *pTrackerServer)
|
||||||
|
|
||||||
int storage_get_my_tracker_client_ip()
|
int storage_get_my_tracker_client_ip()
|
||||||
{
|
{
|
||||||
ConnectionInfo *pGlobalServer;
|
TrackerServerInfo *pGlobalServer;
|
||||||
ConnectionInfo *pTServer;
|
TrackerServerInfo *pTServer;
|
||||||
ConnectionInfo *pTServerEnd;
|
TrackerServerInfo *pTServerEnd;
|
||||||
ConnectionInfo trackerServer;
|
TrackerServerInfo trackerServer;
|
||||||
|
ConnectionInfo *conn;
|
||||||
char tracker_client_ip[IP_ADDRESS_SIZE];
|
char tracker_client_ip[IP_ADDRESS_SIZE];
|
||||||
int success_count;
|
int success_count;
|
||||||
int result;
|
int result;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
conn = NULL;
|
||||||
result = 0;
|
result = 0;
|
||||||
success_count = 0;
|
success_count = 0;
|
||||||
pTServer = &trackerServer;
|
pTServer = &trackerServer;
|
||||||
|
|
@ -138,13 +140,13 @@ int storage_get_my_tracker_client_ip()
|
||||||
for (pGlobalServer=g_tracker_group.servers; pGlobalServer<pTServerEnd; \
|
for (pGlobalServer=g_tracker_group.servers; pGlobalServer<pTServerEnd; \
|
||||||
pGlobalServer++)
|
pGlobalServer++)
|
||||||
{
|
{
|
||||||
memcpy(pTServer, pGlobalServer, sizeof(ConnectionInfo));
|
memcpy(pTServer, pGlobalServer, sizeof(TrackerServerInfo));
|
||||||
|
fdfs_server_sock_reset(pTServer);
|
||||||
for (i=0; i < 3; i++)
|
for (i=0; i < 3; i++)
|
||||||
{
|
{
|
||||||
pTServer->sock = socketClientExAuto(pTServer->ip_addr,
|
conn = tracker_connect_server_no_pool_ex(pTServer,
|
||||||
pTServer->port, g_fdfs_connect_timeout, O_NONBLOCK,
|
g_client_bind_addr ? g_bind_addr : NULL, &result, false);
|
||||||
g_client_bind_addr ? g_bind_addr : NULL, &result);
|
if (conn != NULL)
|
||||||
if (pTServer->sock >= 0)
|
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -152,37 +154,40 @@ int storage_get_my_tracker_client_ip()
|
||||||
sleep(5);
|
sleep(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pTServer->sock < 0)
|
if (conn == NULL)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
logError("file: "__FILE__", line: %d, "
|
||||||
"connect to tracker server %s:%d fail, " \
|
"connect to tracker server %s:%d fail, "
|
||||||
"errno: %d, error info: %s", \
|
"errno: %d, error info: %s",
|
||||||
__LINE__, pTServer->ip_addr, pTServer->port, \
|
__LINE__, pTServer->connections[0].ip_addr,
|
||||||
|
pTServer->connections[0].port,
|
||||||
result, STRERROR(result));
|
result, STRERROR(result));
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
getSockIpaddr(pTServer->sock,tracker_client_ip,IP_ADDRESS_SIZE);
|
//TODO support multi IPs !!!
|
||||||
|
|
||||||
|
getSockIpaddr(conn->sock,tracker_client_ip,IP_ADDRESS_SIZE);
|
||||||
if (*g_tracker_client_ip == '\0')
|
if (*g_tracker_client_ip == '\0')
|
||||||
{
|
{
|
||||||
strcpy(g_tracker_client_ip, tracker_client_ip);
|
strcpy(g_tracker_client_ip, tracker_client_ip);
|
||||||
}
|
}
|
||||||
else if (strcmp(tracker_client_ip, g_tracker_client_ip) != 0)
|
else if (strcmp(tracker_client_ip, g_tracker_client_ip) != 0)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
logError("file: "__FILE__", line: %d, "
|
||||||
"as a client of tracker server %s:%d, " \
|
"as a client of tracker server %s:%d, "
|
||||||
"my ip: %s != client ip: %s of other " \
|
"my ip: %s != client ip: %s of other "
|
||||||
"tracker client", __LINE__, \
|
"tracker client", __LINE__,
|
||||||
pTServer->ip_addr, pTServer->port, \
|
conn->ip_addr, conn->port,
|
||||||
tracker_client_ip, g_tracker_client_ip);
|
tracker_client_ip, g_tracker_client_ip);
|
||||||
|
|
||||||
close(pTServer->sock);
|
close(conn->sock);
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
fdfs_quit(pTServer);
|
fdfs_quit(conn);
|
||||||
close(pTServer->sock);
|
close(conn->sock);
|
||||||
success_count++;
|
success_count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -197,10 +202,11 @@ int storage_get_my_tracker_client_ip()
|
||||||
|
|
||||||
static int storage_report_storage_ip_addr()
|
static int storage_report_storage_ip_addr()
|
||||||
{
|
{
|
||||||
ConnectionInfo *pGlobalServer;
|
TrackerServerInfo *pGlobalServer;
|
||||||
ConnectionInfo *pTServer;
|
TrackerServerInfo *pTServer;
|
||||||
ConnectionInfo *pTServerEnd;
|
TrackerServerInfo *pTServerEnd;
|
||||||
ConnectionInfo trackerServer;
|
TrackerServerInfo trackerServer;
|
||||||
|
ConnectionInfo *conn;
|
||||||
int success_count;
|
int success_count;
|
||||||
int result;
|
int result;
|
||||||
int i;
|
int i;
|
||||||
|
|
@ -229,13 +235,13 @@ static int storage_report_storage_ip_addr()
|
||||||
for (pGlobalServer=g_tracker_group.servers; pGlobalServer<pTServerEnd; \
|
for (pGlobalServer=g_tracker_group.servers; pGlobalServer<pTServerEnd; \
|
||||||
pGlobalServer++)
|
pGlobalServer++)
|
||||||
{
|
{
|
||||||
memcpy(pTServer, pGlobalServer, sizeof(ConnectionInfo));
|
memcpy(pTServer, pGlobalServer, sizeof(TrackerServerInfo));
|
||||||
|
fdfs_server_sock_reset(pTServer);
|
||||||
for (i=0; i < 3; i++)
|
for (i=0; i < 3; i++)
|
||||||
{
|
{
|
||||||
pTServer->sock = socketClientExAuto(pTServer->ip_addr,
|
conn = tracker_connect_server_no_pool_ex(pTServer,
|
||||||
pTServer->port, g_fdfs_connect_timeout, O_NONBLOCK,
|
g_client_bind_addr ? g_bind_addr : NULL, &result, false);
|
||||||
g_client_bind_addr ? g_bind_addr : NULL, &result);
|
if (conn != NULL)
|
||||||
if (pTServer->sock >= 0)
|
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -243,18 +249,19 @@ static int storage_report_storage_ip_addr()
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pTServer->sock < 0)
|
if (conn == NULL)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
logError("file: "__FILE__", line: %d, "
|
||||||
"connect to tracker server %s:%d fail, " \
|
"connect to tracker server %s:%d fail, "
|
||||||
"errno: %d, error info: %s", \
|
"errno: %d, error info: %s",
|
||||||
__LINE__, pTServer->ip_addr, pTServer->port, \
|
__LINE__, pTServer->connections[0].ip_addr,
|
||||||
|
pTServer->connections[0].port,
|
||||||
result, STRERROR(result));
|
result, STRERROR(result));
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((result=storage_report_ip_changed(pTServer)) == 0)
|
if ((result=storage_report_ip_changed(conn)) == 0)
|
||||||
{
|
{
|
||||||
success_count++;
|
success_count++;
|
||||||
}
|
}
|
||||||
|
|
@ -263,8 +270,8 @@ static int storage_report_storage_ip_addr()
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fdfs_quit(pTServer);
|
fdfs_quit(conn);
|
||||||
close(pTServer->sock);
|
close(conn->sock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -278,10 +285,11 @@ static int storage_report_storage_ip_addr()
|
||||||
|
|
||||||
int storage_changelog_req()
|
int storage_changelog_req()
|
||||||
{
|
{
|
||||||
ConnectionInfo *pGlobalServer;
|
TrackerServerInfo *pGlobalServer;
|
||||||
ConnectionInfo *pTServer;
|
TrackerServerInfo *pTServer;
|
||||||
ConnectionInfo *pTServerEnd;
|
TrackerServerInfo *pTServerEnd;
|
||||||
ConnectionInfo trackerServer;
|
TrackerServerInfo trackerServer;
|
||||||
|
ConnectionInfo *conn;
|
||||||
int success_count;
|
int success_count;
|
||||||
int result;
|
int result;
|
||||||
int i;
|
int i;
|
||||||
|
|
@ -296,13 +304,13 @@ int storage_changelog_req()
|
||||||
for (pGlobalServer=g_tracker_group.servers; pGlobalServer<pTServerEnd; \
|
for (pGlobalServer=g_tracker_group.servers; pGlobalServer<pTServerEnd; \
|
||||||
pGlobalServer++)
|
pGlobalServer++)
|
||||||
{
|
{
|
||||||
memcpy(pTServer, pGlobalServer, sizeof(ConnectionInfo));
|
memcpy(pTServer, pGlobalServer, sizeof(TrackerServerInfo));
|
||||||
|
fdfs_server_sock_reset(pTServer);
|
||||||
for (i=0; i < 3; i++)
|
for (i=0; i < 3; i++)
|
||||||
{
|
{
|
||||||
pTServer->sock = socketClientExAuto(pTServer->ip_addr,
|
conn = tracker_connect_server_no_pool_ex(pTServer,
|
||||||
pTServer->port, g_fdfs_connect_timeout, O_NONBLOCK,
|
g_client_bind_addr ? g_bind_addr : NULL, &result, false);
|
||||||
g_client_bind_addr ? g_bind_addr : NULL, &result);
|
if (conn != NULL)
|
||||||
if (pTServer->sock >= 0)
|
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -310,18 +318,19 @@ int storage_changelog_req()
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pTServer->sock < 0)
|
if (conn == NULL)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
logError("file: "__FILE__", line: %d, "
|
||||||
"connect to tracker server %s:%d fail, " \
|
"connect to tracker server %s:%d fail, "
|
||||||
"errno: %d, error info: %s", \
|
"errno: %d, error info: %s",
|
||||||
__LINE__, pTServer->ip_addr, pTServer->port, \
|
__LINE__, pTServer->connections[0].ip_addr,
|
||||||
|
pTServer->connections[0].port,
|
||||||
result, STRERROR(result));
|
result, STRERROR(result));
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = storage_do_changelog_req(pTServer);
|
result = storage_do_changelog_req(conn);
|
||||||
if (result == 0 || result == ENOENT)
|
if (result == 0 || result == ENOENT)
|
||||||
{
|
{
|
||||||
success_count++;
|
success_count++;
|
||||||
|
|
@ -331,8 +340,8 @@ int storage_changelog_req()
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fdfs_quit(pTServer);
|
fdfs_quit(conn);
|
||||||
close(pTServer->sock);
|
close(conn->sock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,29 +33,29 @@
|
||||||
|
|
||||||
static int storage_convert_src_server_id()
|
static int storage_convert_src_server_id()
|
||||||
{
|
{
|
||||||
ConnectionInfo *pTrackerServer;
|
TrackerServerInfo *pTrackerServer;
|
||||||
ConnectionInfo *pServerEnd;
|
TrackerServerInfo *pServerEnd;
|
||||||
ConnectionInfo *pTrackerConn;
|
ConnectionInfo *pTrackerConn;
|
||||||
ConnectionInfo tracker_server;
|
TrackerServerInfo tracker_server;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
result = ENOENT;
|
result = ENOENT;
|
||||||
pServerEnd = g_tracker_group.servers + g_tracker_group.server_count;
|
pServerEnd = g_tracker_group.servers + g_tracker_group.server_count;
|
||||||
for (pTrackerServer=g_tracker_group.servers; \
|
for (pTrackerServer=g_tracker_group.servers;
|
||||||
pTrackerServer<pServerEnd; pTrackerServer++)
|
pTrackerServer<pServerEnd; pTrackerServer++)
|
||||||
{
|
{
|
||||||
memcpy(&tracker_server, pTrackerServer, \
|
memcpy(&tracker_server, pTrackerServer,
|
||||||
sizeof(ConnectionInfo));
|
sizeof(TrackerServerInfo));
|
||||||
tracker_server.sock = -1;
|
fdfs_server_sock_reset(&tracker_server);
|
||||||
if ((pTrackerConn=tracker_connect_server(&tracker_server, \
|
if ((pTrackerConn=tracker_connect_server(&tracker_server,
|
||||||
&result)) == NULL)
|
&result)) == NULL)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = tracker_get_storage_id(pTrackerConn, \
|
result = tracker_get_storage_id(pTrackerConn,
|
||||||
g_group_name, g_sync_src_id, g_sync_src_id);
|
g_group_name, g_sync_src_id, g_sync_src_id);
|
||||||
tracker_disconnect_server_ex(pTrackerConn, \
|
tracker_disconnect_server_ex(pTrackerConn,
|
||||||
result != 0 && result != ENOENT);
|
result != 0 && result != ENOENT);
|
||||||
if (result == 0)
|
if (result == 0)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2301,7 +2301,7 @@ static int storage_client_create_link_wrapper(struct fast_task_info *pTask, \
|
||||||
|
|
||||||
if (!bCreateDirectly)
|
if (!bCreateDirectly)
|
||||||
{
|
{
|
||||||
if ((pStorageServer=tracker_connect_server( \
|
if ((pStorageServer=tracker_make_connection(
|
||||||
&storageServer, &result)) == NULL)
|
&storageServer, &result)) == NULL)
|
||||||
{
|
{
|
||||||
tracker_disconnect_server(pTracker);
|
tracker_disconnect_server(pTracker);
|
||||||
|
|
|
||||||
|
|
@ -1624,10 +1624,11 @@ int storage_report_storage_status(const char *storage_id, \
|
||||||
const char *ip_addr, const char status)
|
const char *ip_addr, const char status)
|
||||||
{
|
{
|
||||||
FDFSStorageBrief briefServer;
|
FDFSStorageBrief briefServer;
|
||||||
ConnectionInfo trackerServer;
|
TrackerServerInfo trackerServer;
|
||||||
ConnectionInfo *pGlobalServer;
|
TrackerServerInfo *pGlobalServer;
|
||||||
ConnectionInfo *pTServer;
|
TrackerServerInfo *pTServer;
|
||||||
ConnectionInfo *pTServerEnd;
|
TrackerServerInfo *pTServerEnd;
|
||||||
|
ConnectionInfo *conn;
|
||||||
int result;
|
int result;
|
||||||
int report_count;
|
int report_count;
|
||||||
int success_count;
|
int success_count;
|
||||||
|
|
@ -1665,6 +1666,7 @@ int storage_report_storage_status(const char *storage_id, \
|
||||||
__LINE__, ip_addr, status);
|
__LINE__, ip_addr, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
conn = NULL;
|
||||||
report_count = 0;
|
report_count = 0;
|
||||||
success_count = 0;
|
success_count = 0;
|
||||||
|
|
||||||
|
|
@ -1674,13 +1676,13 @@ int storage_report_storage_status(const char *storage_id, \
|
||||||
for (pGlobalServer=g_tracker_group.servers; pGlobalServer<pTServerEnd; \
|
for (pGlobalServer=g_tracker_group.servers; pGlobalServer<pTServerEnd; \
|
||||||
pGlobalServer++)
|
pGlobalServer++)
|
||||||
{
|
{
|
||||||
memcpy(pTServer, pGlobalServer, sizeof(ConnectionInfo));
|
memcpy(pTServer, pGlobalServer, sizeof(TrackerServerInfo));
|
||||||
|
fdfs_server_sock_reset(pTServer);
|
||||||
for (i=0; i < 3; i++)
|
for (i=0; i < 3; i++)
|
||||||
{
|
{
|
||||||
pTServer->sock = socketClientExAuto(pTServer->ip_addr,
|
conn = tracker_connect_server_no_pool_ex(pTServer,
|
||||||
pTServer->port, g_fdfs_connect_timeout, O_NONBLOCK,
|
g_client_bind_addr ? g_bind_addr : NULL, &result, false);
|
||||||
g_client_bind_addr ? g_bind_addr : NULL, &result);
|
if (conn != NULL)
|
||||||
if (pTServer->sock >= 0)
|
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -1688,20 +1690,26 @@ int storage_report_storage_status(const char *storage_id, \
|
||||||
sleep(5);
|
sleep(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pTServer->sock < 0)
|
if (conn == NULL)
|
||||||
{
|
{
|
||||||
|
logError("file: "__FILE__", line: %d, "
|
||||||
|
"connect to tracker server %s:%d fail, "
|
||||||
|
"errno: %d, error info: %s",
|
||||||
|
__LINE__, pTServer->connections[0].ip_addr,
|
||||||
|
pTServer->connections[0].port,
|
||||||
|
result, STRERROR(result));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
report_count++;
|
report_count++;
|
||||||
if ((result=tracker_report_storage_status(pTServer, \
|
if ((result=tracker_report_storage_status(conn,
|
||||||
&briefServer)) == 0)
|
&briefServer)) == 0)
|
||||||
{
|
{
|
||||||
success_count++;
|
success_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
fdfs_quit(pTServer);
|
fdfs_quit(conn);
|
||||||
close(pTServer->sock);
|
close(conn->sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
logDebug("file: "__FILE__", line: %d, " \
|
logDebug("file: "__FILE__", line: %d, " \
|
||||||
|
|
@ -1714,9 +1722,10 @@ int storage_report_storage_status(const char *storage_id, \
|
||||||
|
|
||||||
static int storage_reader_sync_init_req(StorageBinLogReader *pReader)
|
static int storage_reader_sync_init_req(StorageBinLogReader *pReader)
|
||||||
{
|
{
|
||||||
ConnectionInfo *pTrackerServers;
|
TrackerServerInfo *pTrackerServers;
|
||||||
ConnectionInfo *pTServer;
|
TrackerServerInfo *pTServer;
|
||||||
ConnectionInfo *pTServerEnd;
|
TrackerServerInfo *pTServerEnd;
|
||||||
|
ConnectionInfo *conn;
|
||||||
char tracker_client_ip[IP_ADDRESS_SIZE];
|
char tracker_client_ip[IP_ADDRESS_SIZE];
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
|
|
@ -1733,27 +1742,27 @@ static int storage_reader_sync_init_req(StorageBinLogReader *pReader)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pTrackerServers = (ConnectionInfo *)malloc( \
|
pTrackerServers = (TrackerServerInfo *)malloc(
|
||||||
sizeof(ConnectionInfo) * g_tracker_group.server_count);
|
sizeof(TrackerServerInfo) * g_tracker_group.server_count);
|
||||||
if (pTrackerServers == NULL)
|
if (pTrackerServers == NULL)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
logError("file: "__FILE__", line: %d, "
|
||||||
"malloc %d bytes fail", __LINE__, \
|
"malloc %d bytes fail", __LINE__,
|
||||||
(int)sizeof(ConnectionInfo) * \
|
(int)sizeof(TrackerServerInfo) *
|
||||||
g_tracker_group.server_count);
|
g_tracker_group.server_count);
|
||||||
return errno != 0 ? errno : ENOMEM;
|
return errno != 0 ? errno : ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(pTrackerServers, g_tracker_group.servers, \
|
memcpy(pTrackerServers, g_tracker_group.servers,
|
||||||
sizeof(ConnectionInfo) * g_tracker_group.server_count);
|
sizeof(TrackerServerInfo) * g_tracker_group.server_count);
|
||||||
pTServerEnd = pTrackerServers + g_tracker_group.server_count;
|
pTServerEnd = pTrackerServers + g_tracker_group.server_count;
|
||||||
for (pTServer=pTrackerServers; pTServer<pTServerEnd; pTServer++)
|
for (pTServer=pTrackerServers; pTServer<pTServerEnd; pTServer++)
|
||||||
{
|
{
|
||||||
pTServer->sock = -1;
|
fdfs_server_sock_reset(pTServer);
|
||||||
}
|
}
|
||||||
|
|
||||||
result = EINTR;
|
result = EINTR;
|
||||||
if (g_tracker_group.leader_index >= 0 && \
|
if (g_tracker_group.leader_index >= 0 &&
|
||||||
g_tracker_group.leader_index < g_tracker_group.server_count)
|
g_tracker_group.leader_index < g_tracker_group.server_count)
|
||||||
{
|
{
|
||||||
pTServer = pTrackerServers + g_tracker_group.leader_index;
|
pTServer = pTrackerServers + g_tracker_group.leader_index;
|
||||||
|
|
@ -1766,10 +1775,9 @@ static int storage_reader_sync_init_req(StorageBinLogReader *pReader)
|
||||||
{
|
{
|
||||||
while (g_continue_flag)
|
while (g_continue_flag)
|
||||||
{
|
{
|
||||||
pTServer->sock = socketClientExAuto(pTServer->ip_addr,
|
conn = tracker_connect_server_no_pool_ex(pTServer,
|
||||||
pTServer->port, g_fdfs_connect_timeout, O_NONBLOCK,
|
g_client_bind_addr ? g_bind_addr : NULL, &result, true);
|
||||||
g_client_bind_addr ? g_bind_addr : NULL, &result);
|
if (conn != NULL)
|
||||||
if (pTServer->sock >= 0)
|
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -1788,20 +1796,19 @@ static int storage_reader_sync_init_req(StorageBinLogReader *pReader)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
getSockIpaddr(pTServer->sock, \
|
getSockIpaddr(conn->sock, tracker_client_ip, IP_ADDRESS_SIZE);
|
||||||
tracker_client_ip, IP_ADDRESS_SIZE);
|
|
||||||
insert_into_local_host_ip(tracker_client_ip);
|
insert_into_local_host_ip(tracker_client_ip);
|
||||||
|
|
||||||
if ((result=tracker_sync_src_req(pTServer, pReader)) != 0)
|
if ((result=tracker_sync_src_req(conn, pReader)) != 0)
|
||||||
{
|
{
|
||||||
fdfs_quit(pTServer);
|
fdfs_quit(conn);
|
||||||
close(pTServer->sock);
|
close(conn->sock);
|
||||||
sleep(g_heart_beat_interval);
|
sleep(g_heart_beat_interval);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
fdfs_quit(pTServer);
|
fdfs_quit(conn);
|
||||||
close(pTServer->sock);
|
close(conn->sock);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
} while (1);
|
} while (1);
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ int kill_tracker_report_threads()
|
||||||
return kill_res;
|
return kill_res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void thracker_report_thread_exit(ConnectionInfo *pTrackerServer)
|
static void thracker_report_thread_exit(TrackerServerInfo *pTrackerServer)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
int i;
|
int i;
|
||||||
|
|
@ -165,9 +165,10 @@ static void thracker_report_thread_exit(ConnectionInfo *pTrackerServer)
|
||||||
__LINE__, result, STRERROR(result));
|
__LINE__, result, STRERROR(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
logDebug("file: "__FILE__", line: %d, " \
|
logDebug("file: "__FILE__", line: %d, "
|
||||||
"report thread to tracker server %s:%d exit", \
|
"report thread to tracker server %s:%d exit",
|
||||||
__LINE__, pTrackerServer->ip_addr, pTrackerServer->port);
|
__LINE__, pTrackerServer->connections[0].ip_addr,
|
||||||
|
pTrackerServer->connections[0].port);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tracker_unlink_mark_files(const char *storage_id)
|
static int tracker_unlink_mark_files(const char *storage_id)
|
||||||
|
|
@ -194,7 +195,8 @@ static int tracker_rename_mark_files(const char *old_ip_addr, \
|
||||||
|
|
||||||
static void *tracker_report_thread_entrance(void *arg)
|
static void *tracker_report_thread_entrance(void *arg)
|
||||||
{
|
{
|
||||||
ConnectionInfo *pTrackerServer;
|
ConnectionInfo *conn;
|
||||||
|
TrackerServerInfo *pTrackerServer;
|
||||||
char my_server_id[FDFS_STORAGE_ID_MAX_SIZE];
|
char my_server_id[FDFS_STORAGE_ID_MAX_SIZE];
|
||||||
char tracker_client_ip[IP_ADDRESS_SIZE];
|
char tracker_client_ip[IP_ADDRESS_SIZE];
|
||||||
char szFailPrompt[36];
|
char szFailPrompt[36];
|
||||||
|
|
@ -216,13 +218,14 @@ static void *tracker_report_thread_entrance(void *arg)
|
||||||
bServerPortChanged = (g_last_server_port != 0) && \
|
bServerPortChanged = (g_last_server_port != 0) && \
|
||||||
(g_server_port != g_last_server_port);
|
(g_server_port != g_last_server_port);
|
||||||
|
|
||||||
pTrackerServer = (ConnectionInfo *)arg;
|
pTrackerServer = (TrackerServerInfo *)arg;
|
||||||
pTrackerServer->sock = -1;
|
fdfs_server_sock_reset(pTrackerServer);
|
||||||
tracker_index = pTrackerServer - g_tracker_group.servers;
|
tracker_index = pTrackerServer - g_tracker_group.servers;
|
||||||
|
|
||||||
logDebug("file: "__FILE__", line: %d, " \
|
logDebug("file: "__FILE__", line: %d, "
|
||||||
"report thread to tracker server %s:%d started", \
|
"report thread to tracker server %s:%d started",
|
||||||
__LINE__, pTrackerServer->ip_addr, pTrackerServer->port);
|
__LINE__, pTrackerServer->connections[0].ip_addr,
|
||||||
|
pTrackerServer->connections[0].port);
|
||||||
|
|
||||||
sync_old_done = g_sync_old_done;
|
sync_old_done = g_sync_old_done;
|
||||||
while (g_continue_flag && \
|
while (g_continue_flag && \
|
||||||
|
|
@ -234,36 +237,25 @@ static void *tracker_report_thread_entrance(void *arg)
|
||||||
result = 0;
|
result = 0;
|
||||||
previousCode = 0;
|
previousCode = 0;
|
||||||
nContinuousFail = 0;
|
nContinuousFail = 0;
|
||||||
|
conn = NULL;
|
||||||
while (g_continue_flag)
|
while (g_continue_flag)
|
||||||
{
|
{
|
||||||
if (pTrackerServer->sock >= 0)
|
if (conn != NULL)
|
||||||
{
|
{
|
||||||
close(pTrackerServer->sock);
|
conn_pool_disconnect_server(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
pTrackerServer->sock = socketCreateExAuto(pTrackerServer->ip_addr,
|
conn = tracker_connect_server_no_pool_ex(pTrackerServer,
|
||||||
g_fdfs_connect_timeout, O_NONBLOCK,
|
g_client_bind_addr ? g_bind_addr : NULL, &result, false);
|
||||||
g_client_bind_addr ? g_bind_addr : NULL, &result);
|
if (conn == NULL)
|
||||||
if (pTrackerServer->sock < 0)
|
|
||||||
{
|
|
||||||
logCrit("file: "__FILE__", line: %d, "
|
|
||||||
"socket create fail, program exit!", __LINE__);
|
|
||||||
g_continue_flag = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
tcpsetserveropt(pTrackerServer->sock, g_fdfs_network_timeout);
|
|
||||||
|
|
||||||
if ((result=connectserverbyip_nb(pTrackerServer->sock,
|
|
||||||
pTrackerServer->ip_addr, pTrackerServer->port,
|
|
||||||
g_fdfs_connect_timeout)) != 0)
|
|
||||||
{
|
{
|
||||||
if (previousCode != result)
|
if (previousCode != result)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
logError("file: "__FILE__", line: %d, "
|
||||||
"connect to tracker server %s:%d fail" \
|
"connect to tracker server %s:%d fail, "
|
||||||
", errno: %d, error info: %s", \
|
"errno: %d, error info: %s",
|
||||||
__LINE__, pTrackerServer->ip_addr, \
|
__LINE__, pTrackerServer->connections[0].ip_addr,
|
||||||
pTrackerServer->port, \
|
pTrackerServer->connections[0].port,
|
||||||
result, STRERROR(result));
|
result, STRERROR(result));
|
||||||
previousCode = result;
|
previousCode = result;
|
||||||
}
|
}
|
||||||
|
|
@ -280,8 +272,8 @@ static void *tracker_report_thread_entrance(void *arg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getSockIpaddr(pTrackerServer->sock, \
|
tcpsetserveropt(conn->sock, g_fdfs_network_timeout);
|
||||||
tracker_client_ip, IP_ADDRESS_SIZE);
|
getSockIpaddr(conn->sock, tracker_client_ip, IP_ADDRESS_SIZE);
|
||||||
|
|
||||||
if (nContinuousFail == 0)
|
if (nContinuousFail == 0)
|
||||||
{
|
{
|
||||||
|
|
@ -289,14 +281,14 @@ static void *tracker_report_thread_entrance(void *arg)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sprintf(szFailPrompt, ", continuous fail count: %d", \
|
sprintf(szFailPrompt, ", continuous fail count: %d",
|
||||||
nContinuousFail);
|
nContinuousFail);
|
||||||
}
|
}
|
||||||
logInfo("file: "__FILE__", line: %d, " \
|
logInfo("file: "__FILE__", line: %d, "
|
||||||
"successfully connect to tracker server %s:%d%s, " \
|
"successfully connect to tracker server %s:%d%s, "
|
||||||
"as a tracker client, my ip is %s", \
|
"as a tracker client, my ip is %s",
|
||||||
__LINE__, pTrackerServer->ip_addr, \
|
__LINE__, conn->ip_addr, conn->port,
|
||||||
pTrackerServer->port, szFailPrompt, tracker_client_ip);
|
szFailPrompt, tracker_client_ip);
|
||||||
|
|
||||||
previousCode = 0;
|
previousCode = 0;
|
||||||
nContinuousFail = 0;
|
nContinuousFail = 0;
|
||||||
|
|
@ -307,15 +299,15 @@ static void *tracker_report_thread_entrance(void *arg)
|
||||||
}
|
}
|
||||||
else if (strcmp(tracker_client_ip, g_tracker_client_ip) != 0)
|
else if (strcmp(tracker_client_ip, g_tracker_client_ip) != 0)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
logError("file: "__FILE__", line: %d, "
|
||||||
"as a client of tracker server %s:%d, " \
|
"as a client of tracker server %s:%d, "
|
||||||
"my ip: %s != client ip: %s of other " \
|
"my ip: %s != client ip: %s of other "
|
||||||
"tracker client", __LINE__, \
|
"tracker client", __LINE__,
|
||||||
pTrackerServer->ip_addr, pTrackerServer->port, \
|
conn->ip_addr, conn->port,
|
||||||
tracker_client_ip, g_tracker_client_ip);
|
tracker_client_ip, g_tracker_client_ip);
|
||||||
|
|
||||||
close(pTrackerServer->sock);
|
close(conn->sock);
|
||||||
pTrackerServer->sock = -1;
|
conn->sock = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -328,7 +320,7 @@ static void *tracker_report_thread_entrance(void *arg)
|
||||||
//print_local_host_ip_addrs();
|
//print_local_host_ip_addrs();
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (tracker_report_join(pTrackerServer, tracker_index, \
|
if (tracker_report_join(conn, tracker_index,
|
||||||
sync_old_done) != 0)
|
sync_old_done) != 0)
|
||||||
{
|
{
|
||||||
sleep(g_heart_beat_interval);
|
sleep(g_heart_beat_interval);
|
||||||
|
|
@ -353,14 +345,14 @@ static void *tracker_report_thread_entrance(void *arg)
|
||||||
"errno: %d, error info: %s", \
|
"errno: %d, error info: %s", \
|
||||||
__LINE__, result, STRERROR(result));
|
__LINE__, result, STRERROR(result));
|
||||||
|
|
||||||
fdfs_quit(pTrackerServer);
|
fdfs_quit(conn);
|
||||||
sleep(g_heart_beat_interval);
|
sleep(g_heart_beat_interval);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!g_sync_old_done)
|
if (!g_sync_old_done)
|
||||||
{
|
{
|
||||||
if (tracker_sync_dest_req(pTrackerServer) == 0)
|
if (tracker_sync_dest_req(conn) == 0)
|
||||||
{
|
{
|
||||||
g_sync_old_done = true;
|
g_sync_old_done = true;
|
||||||
if (storage_write_to_sync_ini_file() \
|
if (storage_write_to_sync_ini_file() \
|
||||||
|
|
@ -382,18 +374,18 @@ static void *tracker_report_thread_entrance(void *arg)
|
||||||
pthread_mutex_unlock( \
|
pthread_mutex_unlock( \
|
||||||
&reporter_thread_lock);
|
&reporter_thread_lock);
|
||||||
|
|
||||||
fdfs_quit(pTrackerServer);
|
fdfs_quit(conn);
|
||||||
sleep(g_heart_beat_interval);
|
sleep(g_heart_beat_interval);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (tracker_sync_notify(pTrackerServer, tracker_index) != 0)
|
if (tracker_sync_notify(conn, tracker_index) != 0)
|
||||||
{
|
{
|
||||||
pthread_mutex_unlock( \
|
pthread_mutex_unlock( \
|
||||||
&reporter_thread_lock);
|
&reporter_thread_lock);
|
||||||
fdfs_quit(pTrackerServer);
|
fdfs_quit(conn);
|
||||||
sleep(g_heart_beat_interval);
|
sleep(g_heart_beat_interval);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -412,7 +404,7 @@ static void *tracker_report_thread_entrance(void *arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
src_storage_status[tracker_index] = \
|
src_storage_status[tracker_index] = \
|
||||||
tracker_sync_notify(pTrackerServer, tracker_index);
|
tracker_sync_notify(conn, tracker_index);
|
||||||
if (src_storage_status[tracker_index] != 0)
|
if (src_storage_status[tracker_index] != 0)
|
||||||
{
|
{
|
||||||
int k;
|
int k;
|
||||||
|
|
@ -432,7 +424,7 @@ static void *tracker_report_thread_entrance(void *arg)
|
||||||
g_tracker_client_ip, my_server_id, \
|
g_tracker_client_ip, my_server_id, \
|
||||||
&my_status) == 0)
|
&my_status) == 0)
|
||||||
{
|
{
|
||||||
tracker_sync_dest_query(pTrackerServer);
|
tracker_sync_dest_query(conn);
|
||||||
if(my_status<FDFS_STORAGE_STATUS_OFFLINE
|
if(my_status<FDFS_STORAGE_STATUS_OFFLINE
|
||||||
&& g_sync_old_done)
|
&& g_sync_old_done)
|
||||||
{ //need re-sync old files
|
{ //need re-sync old files
|
||||||
|
|
@ -447,7 +439,7 @@ static void *tracker_report_thread_entrance(void *arg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fdfs_quit(pTrackerServer);
|
fdfs_quit(conn);
|
||||||
sleep(g_heart_beat_interval);
|
sleep(g_heart_beat_interval);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -466,16 +458,14 @@ static void *tracker_report_thread_entrance(void *arg)
|
||||||
if (current_time - last_beat_time >= \
|
if (current_time - last_beat_time >= \
|
||||||
g_heart_beat_interval)
|
g_heart_beat_interval)
|
||||||
{
|
{
|
||||||
if (tracker_heart_beat(pTrackerServer, \
|
if (tracker_heart_beat(conn, &stat_chg_sync_count,
|
||||||
&stat_chg_sync_count, \
|
|
||||||
&bServerPortChanged) != 0)
|
&bServerPortChanged) != 0)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_storage_ip_changed_auto_adjust && \
|
if (g_storage_ip_changed_auto_adjust &&
|
||||||
tracker_storage_changelog_req( \
|
tracker_storage_changelog_req(conn) != 0)
|
||||||
pTrackerServer) != 0)
|
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -483,12 +473,12 @@ static void *tracker_report_thread_entrance(void *arg)
|
||||||
last_beat_time = current_time;
|
last_beat_time = current_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sync_time_chg_count != g_sync_change_count && \
|
if (sync_time_chg_count != g_sync_change_count &&
|
||||||
current_time - last_sync_report_time >= \
|
current_time - last_sync_report_time >=
|
||||||
g_heart_beat_interval)
|
g_heart_beat_interval)
|
||||||
{
|
{
|
||||||
if (tracker_report_sync_timestamp( \
|
if (tracker_report_sync_timestamp(
|
||||||
pTrackerServer, &bServerPortChanged)!=0)
|
conn, &bServerPortChanged)!=0)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -497,10 +487,10 @@ static void *tracker_report_thread_entrance(void *arg)
|
||||||
last_sync_report_time = current_time;
|
last_sync_report_time = current_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current_time - last_df_report_time >= \
|
if (current_time - last_df_report_time >=
|
||||||
g_stat_report_interval)
|
g_stat_report_interval)
|
||||||
{
|
{
|
||||||
if (tracker_report_df_stat(pTrackerServer, \
|
if (tracker_report_df_stat(conn,
|
||||||
&bServerPortChanged) != 0)
|
&bServerPortChanged) != 0)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
|
|
@ -513,7 +503,7 @@ static void *tracker_report_thread_entrance(void *arg)
|
||||||
{
|
{
|
||||||
if (last_trunk_file_id < g_current_trunk_file_id)
|
if (last_trunk_file_id < g_current_trunk_file_id)
|
||||||
{
|
{
|
||||||
if (tracker_report_trunk_fid(pTrackerServer)!=0)
|
if (tracker_report_trunk_fid(conn)!=0)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -522,7 +512,7 @@ static void *tracker_report_thread_entrance(void *arg)
|
||||||
|
|
||||||
if (last_trunk_total_free_space != g_trunk_total_free_space)
|
if (last_trunk_total_free_space != g_trunk_total_free_space)
|
||||||
{
|
{
|
||||||
if (tracker_report_trunk_free_space(pTrackerServer)!=0)
|
if (tracker_report_trunk_free_space(conn)!=0)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -538,12 +528,7 @@ static void *tracker_report_thread_entrance(void *arg)
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!g_continue_flag) && fdfs_quit(pTrackerServer) != 0)
|
conn_pool_disconnect_server(conn);
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
close(pTrackerServer->sock);
|
|
||||||
pTrackerServer->sock = -1;
|
|
||||||
if (g_continue_flag)
|
if (g_continue_flag)
|
||||||
{
|
{
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
|
@ -552,11 +537,11 @@ static void *tracker_report_thread_entrance(void *arg)
|
||||||
|
|
||||||
if (nContinuousFail > 0)
|
if (nContinuousFail > 0)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
logError("file: "__FILE__", line: %d, "
|
||||||
"connect to tracker server %s:%d fail, try count: %d" \
|
"connect to tracker server %s:%d fail, try count: %d"
|
||||||
", errno: %d, error info: %s", \
|
", errno: %d, error info: %s",
|
||||||
__LINE__, pTrackerServer->ip_addr, \
|
__LINE__, pTrackerServer->connections[0].ip_addr,
|
||||||
pTrackerServer->port, nContinuousFail, \
|
pTrackerServer->connections[0].port, nContinuousFail,
|
||||||
result, STRERROR(result));
|
result, STRERROR(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -998,7 +983,7 @@ static int tracker_merge_servers(ConnectionInfo *pTrackerServer, \
|
||||||
diffServers, pDiffServer - diffServers);
|
diffServers, pDiffServer - diffServers);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _notify_reselect_tleader(ConnectionInfo *pTrackerServer)
|
static int _notify_reselect_tleader(ConnectionInfo *conn)
|
||||||
{
|
{
|
||||||
char out_buff[sizeof(TrackerHeader)];
|
char out_buff[sizeof(TrackerHeader)];
|
||||||
TrackerHeader *pHeader;
|
TrackerHeader *pHeader;
|
||||||
|
|
@ -1008,19 +993,18 @@ static int _notify_reselect_tleader(ConnectionInfo *pTrackerServer)
|
||||||
pHeader = (TrackerHeader *)out_buff;
|
pHeader = (TrackerHeader *)out_buff;
|
||||||
memset(out_buff, 0, sizeof(out_buff));
|
memset(out_buff, 0, sizeof(out_buff));
|
||||||
pHeader->cmd = TRACKER_PROTO_CMD_TRACKER_NOTIFY_RESELECT_LEADER;
|
pHeader->cmd = TRACKER_PROTO_CMD_TRACKER_NOTIFY_RESELECT_LEADER;
|
||||||
if ((result=tcpsenddata_nb(pTrackerServer->sock, out_buff, \
|
if ((result=tcpsenddata_nb(conn->sock, out_buff, \
|
||||||
sizeof(out_buff), g_fdfs_network_timeout)) != 0)
|
sizeof(out_buff), g_fdfs_network_timeout)) != 0)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
logError("file: "__FILE__", line: %d, "
|
||||||
"tracker server %s:%d, send data fail, " \
|
"tracker server %s:%d, send data fail, "
|
||||||
"errno: %d, error info: %s.", \
|
"errno: %d, error info: %s.",
|
||||||
__LINE__, pTrackerServer->ip_addr, \
|
__LINE__, conn->ip_addr, conn->port,
|
||||||
pTrackerServer->port, \
|
|
||||||
result, STRERROR(result));
|
result, STRERROR(result));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((result=fdfs_recv_header(pTrackerServer, &in_bytes)) != 0)
|
if ((result=fdfs_recv_header(conn, &in_bytes)) != 0)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
"fdfs_recv_header fail, result: %d",
|
"fdfs_recv_header fail, result: %d",
|
||||||
|
|
@ -1030,28 +1014,28 @@ static int _notify_reselect_tleader(ConnectionInfo *pTrackerServer)
|
||||||
|
|
||||||
if (in_bytes != 0)
|
if (in_bytes != 0)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
logError("file: "__FILE__", line: %d, "
|
||||||
"tracker server %s:%d, recv body length: " \
|
"tracker server %s:%d, recv body length: "
|
||||||
"%"PRId64" != 0", __LINE__, pTrackerServer->ip_addr, \
|
"%"PRId64" != 0", __LINE__, conn->ip_addr,
|
||||||
pTrackerServer->port, in_bytes);
|
conn->port, in_bytes);
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int notify_reselect_tracker_leader(ConnectionInfo *pTrackerServer)
|
static int notify_reselect_tracker_leader(TrackerServerInfo *pTrackerServer)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
ConnectionInfo *conn;
|
ConnectionInfo *conn;
|
||||||
|
|
||||||
pTrackerServer->sock = -1;
|
fdfs_server_sock_reset(pTrackerServer);
|
||||||
if ((conn=tracker_connect_server(pTrackerServer, &result)) == NULL)
|
if ((conn=tracker_connect_server(pTrackerServer, &result)) == NULL)
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = _notify_reselect_tleader(pTrackerServer);
|
result = _notify_reselect_tleader(conn);
|
||||||
tracker_disconnect_server_ex(conn, result != 0);
|
tracker_disconnect_server_ex(conn, result != 0);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
@ -1063,22 +1047,24 @@ static void set_tracker_leader(const int leader_index)
|
||||||
if (old_index >= 0 && old_index != leader_index)
|
if (old_index >= 0 && old_index != leader_index)
|
||||||
{
|
{
|
||||||
TrackerRunningStatus tracker_status;
|
TrackerRunningStatus tracker_status;
|
||||||
ConnectionInfo old_leader_server;
|
TrackerServerInfo old_leader_server;
|
||||||
memcpy(&old_leader_server, g_tracker_group.servers + old_index,
|
memcpy(&old_leader_server, g_tracker_group.servers + old_index,
|
||||||
sizeof(ConnectionInfo));
|
sizeof(TrackerServerInfo));
|
||||||
if (fdfs_get_tracker_status(&old_leader_server, &tracker_status) == 0)
|
if (fdfs_get_tracker_status(&old_leader_server, &tracker_status) == 0)
|
||||||
{
|
{
|
||||||
if (tracker_status.if_leader)
|
if (tracker_status.if_leader)
|
||||||
{
|
{
|
||||||
ConnectionInfo new_leader_server;
|
TrackerServerInfo new_leader_server;
|
||||||
memcpy(&new_leader_server, g_tracker_group.servers + leader_index,
|
memcpy(&new_leader_server, g_tracker_group.servers + leader_index,
|
||||||
sizeof(ConnectionInfo));
|
sizeof(TrackerServerInfo));
|
||||||
logWarning("file: "__FILE__", line: %d, "
|
logWarning("file: "__FILE__", line: %d, "
|
||||||
"two tracker leaders occur, old leader is %s:%d, "
|
"two tracker leaders occur, old leader is %s:%d, "
|
||||||
"new leader is %s:%d, notify to re-select "
|
"new leader is %s:%d, notify to re-select "
|
||||||
"tracker leader", __LINE__,
|
"tracker leader", __LINE__,
|
||||||
old_leader_server.ip_addr, old_leader_server.port,
|
old_leader_server.connections[0].ip_addr,
|
||||||
new_leader_server.ip_addr, new_leader_server.port);
|
old_leader_server.connections[0].port,
|
||||||
|
new_leader_server.connections[0].ip_addr,
|
||||||
|
new_leader_server.connections[0].port);
|
||||||
|
|
||||||
notify_reselect_tracker_leader(&old_leader_server);
|
notify_reselect_tracker_leader(&old_leader_server);
|
||||||
notify_reselect_tracker_leader(&new_leader_server);
|
notify_reselect_tracker_leader(&new_leader_server);
|
||||||
|
|
@ -1094,12 +1080,12 @@ static void get_tracker_leader()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
TrackerRunningStatus tracker_status;
|
TrackerRunningStatus tracker_status;
|
||||||
ConnectionInfo tracker_server;
|
TrackerServerInfo tracker_server;
|
||||||
|
|
||||||
for (i=0; i<g_tracker_group.server_count; i++)
|
for (i=0; i<g_tracker_group.server_count; i++)
|
||||||
{
|
{
|
||||||
memcpy(&tracker_server, g_tracker_group.servers + i,
|
memcpy(&tracker_server, g_tracker_group.servers + i,
|
||||||
sizeof(ConnectionInfo));
|
sizeof(TrackerServerInfo));
|
||||||
if (fdfs_get_tracker_status(&tracker_server, &tracker_status) == 0)
|
if (fdfs_get_tracker_status(&tracker_server, &tracker_status) == 0)
|
||||||
{
|
{
|
||||||
if (tracker_status.if_leader)
|
if (tracker_status.if_leader)
|
||||||
|
|
@ -1107,8 +1093,8 @@ static void get_tracker_leader()
|
||||||
g_tracker_group.leader_index = i;
|
g_tracker_group.leader_index = i;
|
||||||
logInfo("file: "__FILE__", line: %d, "
|
logInfo("file: "__FILE__", line: %d, "
|
||||||
"the tracker server leader is #%d. %s:%d",
|
"the tracker server leader is #%d. %s:%d",
|
||||||
__LINE__, i, tracker_server.ip_addr,
|
__LINE__, i, tracker_server.connections[0].ip_addr,
|
||||||
tracker_server.port);
|
tracker_server.connections[0].port);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1214,16 +1200,16 @@ static int tracker_check_response(ConnectionInfo *pTrackerServer, \
|
||||||
{
|
{
|
||||||
if (g_tracker_group.leader_index >= 0)
|
if (g_tracker_group.leader_index >= 0)
|
||||||
{
|
{
|
||||||
ConnectionInfo *pTrackerLeader;
|
TrackerServerInfo *pTrackerLeader;
|
||||||
pTrackerLeader = g_tracker_group.servers + \
|
pTrackerLeader = g_tracker_group.servers +
|
||||||
g_tracker_group.leader_index;
|
g_tracker_group.leader_index;
|
||||||
logWarning("file: "__FILE__", line: %d, " \
|
logWarning("file: "__FILE__", line: %d, "
|
||||||
"tracker server %s:%d, " \
|
"tracker server %s:%d, "
|
||||||
"my tracker leader is: %s:%d, " \
|
"my tracker leader is: %s:%d, "
|
||||||
"but response tracker leader is null", \
|
"but response tracker leader is null",
|
||||||
__LINE__, pTrackerServer->ip_addr, \
|
__LINE__, pTrackerServer->ip_addr,
|
||||||
pTrackerServer->port, pTrackerLeader->ip_addr, \
|
pTrackerServer->port, pTrackerLeader->connections[0].ip_addr,
|
||||||
pTrackerLeader->port);
|
pTrackerLeader->connections[0].port);
|
||||||
|
|
||||||
g_tracker_group.leader_index = -1;
|
g_tracker_group.leader_index = -1;
|
||||||
}
|
}
|
||||||
|
|
@ -1876,19 +1862,18 @@ int tracker_report_join(ConnectionInfo *pTrackerServer, \
|
||||||
const int tracker_index, const bool sync_old_done)
|
const int tracker_index, const bool sync_old_done)
|
||||||
{
|
{
|
||||||
char out_buff[sizeof(TrackerHeader) + sizeof(TrackerStorageJoinBody) + \
|
char out_buff[sizeof(TrackerHeader) + sizeof(TrackerStorageJoinBody) + \
|
||||||
FDFS_MAX_TRACKERS * FDFS_PROTO_IP_PORT_SIZE];
|
FDFS_MAX_TRACKERS * FDFS_PROTO_MULTI_IP_PORT_SIZE];
|
||||||
TrackerHeader *pHeader;
|
TrackerHeader *pHeader;
|
||||||
TrackerStorageJoinBody *pReqBody;
|
TrackerStorageJoinBody *pReqBody;
|
||||||
TrackerStorageJoinBodyResp respBody;
|
TrackerStorageJoinBodyResp respBody;
|
||||||
char *pInBuff;
|
char *pInBuff;
|
||||||
char *p;
|
char *p;
|
||||||
ConnectionInfo *pServer;
|
TrackerServerInfo *pServer;
|
||||||
ConnectionInfo *pServerEnd;
|
TrackerServerInfo *pServerEnd;
|
||||||
FDFSStorageServer *pTargetServer;
|
FDFSStorageServer *pTargetServer;
|
||||||
FDFSStorageServer **ppFound;
|
FDFSStorageServer **ppFound;
|
||||||
FDFSStorageServer targetServer;
|
FDFSStorageServer targetServer;
|
||||||
int out_len;
|
int out_len;
|
||||||
//int tracker_count;
|
|
||||||
int result;
|
int result;
|
||||||
int i;
|
int i;
|
||||||
int64_t in_bytes;
|
int64_t in_bytes;
|
||||||
|
|
@ -1932,8 +1917,10 @@ int tracker_report_join(ConnectionInfo *pTrackerServer, \
|
||||||
{
|
{
|
||||||
logInfo("file: "__FILE__", line: %d, "
|
logInfo("file: "__FILE__", line: %d, "
|
||||||
"tracker server: #%d. %s:%d, my_report_status: %d",
|
"tracker server: #%d. %s:%d, my_report_status: %d",
|
||||||
__LINE__, i, g_tracker_group.servers[i].ip_addr,
|
__LINE__, i,
|
||||||
g_tracker_group.servers[i].port, my_report_status[i]);
|
g_tracker_group.servers[i].connections[0].ip_addr,
|
||||||
|
g_tracker_group.servers[i].connections[0].port,
|
||||||
|
my_report_status[i]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1953,22 +1940,13 @@ int tracker_report_join(ConnectionInfo *pTrackerServer, \
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//tracker_count = 0;
|
|
||||||
p = out_buff + sizeof(TrackerHeader) + sizeof(TrackerStorageJoinBody);
|
p = out_buff + sizeof(TrackerHeader) + sizeof(TrackerStorageJoinBody);
|
||||||
pServerEnd = g_tracker_group.servers + g_tracker_group.server_count;
|
pServerEnd = g_tracker_group.servers + g_tracker_group.server_count;
|
||||||
for (pServer=g_tracker_group.servers; pServer<pServerEnd; pServer++)
|
for (pServer=g_tracker_group.servers; pServer<pServerEnd; pServer++)
|
||||||
{
|
{
|
||||||
/*
|
fdfs_server_info_to_string(pServer, p,
|
||||||
if (strcmp(pServer->ip_addr, pTrackerServer->ip_addr) == 0 && \
|
FDFS_PROTO_MULTI_IP_PORT_SIZE);
|
||||||
pServer->port == pTrackerServer->port)
|
p += FDFS_PROTO_MULTI_IP_PORT_SIZE;
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
tracker_count++;
|
|
||||||
*/
|
|
||||||
|
|
||||||
sprintf(p, "%s:%d", pServer->ip_addr, pServer->port);
|
|
||||||
p += FDFS_PROTO_IP_PORT_SIZE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
out_len = p - out_buff;
|
out_len = p - out_buff;
|
||||||
|
|
@ -2463,8 +2441,8 @@ int tracker_deal_changelog_response(ConnectionInfo *pTrackerServer)
|
||||||
|
|
||||||
int tracker_report_thread_start()
|
int tracker_report_thread_start()
|
||||||
{
|
{
|
||||||
ConnectionInfo *pTrackerServer;
|
TrackerServerInfo *pTrackerServer;
|
||||||
ConnectionInfo *pServerEnd;
|
TrackerServerInfo *pServerEnd;
|
||||||
pthread_attr_t pattr;
|
pthread_attr_t pattr;
|
||||||
pthread_t tid;
|
pthread_t tid;
|
||||||
int result;
|
int result;
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ int trunk_client_trunk_alloc_space(const int file_size, \
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(&trunk_server, &g_trunk_server, sizeof(ConnectionInfo));
|
memcpy(&trunk_server, &g_trunk_server, sizeof(ConnectionInfo));
|
||||||
if ((pTrunkServer=tracker_connect_server(&trunk_server, &result)) == NULL)
|
if ((pTrunkServer=tracker_make_connection(&trunk_server, &result)) == NULL)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
logError("file: "__FILE__", line: %d, " \
|
||||||
"can't alloc trunk space because connect to trunk " \
|
"can't alloc trunk space because connect to trunk " \
|
||||||
|
|
@ -216,7 +216,7 @@ int trunk_client_trunk_alloc_confirm(const FDFSTrunkFullInfo *pTrunkInfo, \
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(&trunk_server, &g_trunk_server, sizeof(ConnectionInfo));
|
memcpy(&trunk_server, &g_trunk_server, sizeof(ConnectionInfo));
|
||||||
if ((pTrunkServer=tracker_connect_server(&trunk_server, &result)) == NULL)
|
if ((pTrunkServer=tracker_make_connection(&trunk_server, &result)) == NULL)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
logError("file: "__FILE__", line: %d, " \
|
||||||
"trunk alloc confirm fail because connect to trunk " \
|
"trunk alloc confirm fail because connect to trunk " \
|
||||||
|
|
@ -249,7 +249,7 @@ int trunk_client_trunk_free_space(const FDFSTrunkFullInfo *pTrunkInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(&trunk_server, &g_trunk_server, sizeof(ConnectionInfo));
|
memcpy(&trunk_server, &g_trunk_server, sizeof(ConnectionInfo));
|
||||||
if ((pTrunkServer=tracker_connect_server(&trunk_server, &result)) == NULL)
|
if ((pTrunkServer=tracker_make_connection(&trunk_server, &result)) == NULL)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
logError("file: "__FILE__", line: %d, " \
|
||||||
"free trunk space fail because connect to trunk " \
|
"free trunk space fail because connect to trunk " \
|
||||||
|
|
|
||||||
|
|
@ -1169,3 +1169,26 @@ int fdfs_parse_server_info(char *server_str, const int default_port,
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int fdfs_server_info_to_string_ex(TrackerServerInfo *pServer,
|
||||||
|
const int port, char *buff, const int buffSize)
|
||||||
|
{
|
||||||
|
ConnectionInfo *conn;
|
||||||
|
ConnectionInfo *end;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
if (pServer->count == 1)
|
||||||
|
{
|
||||||
|
return snprintf(buff, buffSize, "%s:%d",
|
||||||
|
pServer->connections[0].ip_addr, port);
|
||||||
|
}
|
||||||
|
|
||||||
|
len = snprintf(buff, buffSize, "%s", pServer->connections[0].ip_addr);
|
||||||
|
end = pServer->connections + pServer->count;
|
||||||
|
for (conn=pServer->connections + 1; conn<end; conn++)
|
||||||
|
{
|
||||||
|
len += snprintf(buff + len, buffSize - len, ",%s", conn->ip_addr);
|
||||||
|
}
|
||||||
|
len += snprintf(buff + len, buffSize - len, ":%d", port);
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,16 @@ void fdfs_server_sock_reset(TrackerServerInfo *pServerInfo);
|
||||||
int fdfs_parse_server_info(char *server_str, const int default_port,
|
int fdfs_parse_server_info(char *server_str, const int default_port,
|
||||||
TrackerServerInfo *pServer);
|
TrackerServerInfo *pServer);
|
||||||
|
|
||||||
|
int fdfs_server_info_to_string_ex(TrackerServerInfo *pServer,
|
||||||
|
const int port, char *buff, const int buffSize);
|
||||||
|
|
||||||
|
static inline int fdfs_server_info_to_string(TrackerServerInfo *pServer,
|
||||||
|
char *buff, const int buffSize)
|
||||||
|
{
|
||||||
|
return fdfs_server_info_to_string_ex(pServer,
|
||||||
|
pServer->connections[0].port, buff, buffSize);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -471,7 +471,7 @@ ConnectionInfo *tracker_connect_server_ex(TrackerServerInfo *pServerInfo,
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnectionInfo *tracker_connect_server_no_pool_ex(TrackerServerInfo *pServerInfo,
|
ConnectionInfo *tracker_connect_server_no_pool_ex(TrackerServerInfo *pServerInfo,
|
||||||
const char *bind_addr, int *err_no)
|
const char *bind_addr, int *err_no, const bool log_connect_error)
|
||||||
{
|
{
|
||||||
ConnectionInfo *conn;
|
ConnectionInfo *conn;
|
||||||
ConnectionInfo *end;
|
ConnectionInfo *end;
|
||||||
|
|
@ -484,7 +484,8 @@ ConnectionInfo *tracker_connect_server_no_pool_ex(TrackerServerInfo *pServerInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
*err_no = conn_pool_connect_server_ex(pServerInfo->connections
|
*err_no = conn_pool_connect_server_ex(pServerInfo->connections
|
||||||
+ pServerInfo->index, g_fdfs_connect_timeout, bind_addr);
|
+ pServerInfo->index, g_fdfs_connect_timeout,
|
||||||
|
bind_addr, log_connect_error);
|
||||||
if (*err_no == 0)
|
if (*err_no == 0)
|
||||||
{
|
{
|
||||||
return pServerInfo->connections + pServerInfo->index;
|
return pServerInfo->connections + pServerInfo->index;
|
||||||
|
|
@ -502,7 +503,8 @@ ConnectionInfo *tracker_connect_server_no_pool_ex(TrackerServerInfo *pServerInfo
|
||||||
if (current_index != pServerInfo->index)
|
if (current_index != pServerInfo->index)
|
||||||
{
|
{
|
||||||
if ((*err_no=conn_pool_connect_server_ex(conn,
|
if ((*err_no=conn_pool_connect_server_ex(conn,
|
||||||
g_fdfs_connect_timeout, bind_addr)) == 0)
|
g_fdfs_connect_timeout, bind_addr,
|
||||||
|
log_connect_error)) == 0)
|
||||||
{
|
{
|
||||||
pServerInfo->index = current_index;
|
pServerInfo->index = current_index;
|
||||||
return pServerInfo->connections + pServerInfo->index;
|
return pServerInfo->connections + pServerInfo->index;
|
||||||
|
|
@ -623,7 +625,7 @@ int fdfs_get_ini_context_from_tracker(TrackerServerGroup *pTrackerGroup, \
|
||||||
for (i=0; i < 3; i++)
|
for (i=0; i < 3; i++)
|
||||||
{
|
{
|
||||||
conn = tracker_connect_server_no_pool_ex(pTServer,
|
conn = tracker_connect_server_no_pool_ex(pTServer,
|
||||||
bind_addr, &result);
|
bind_addr, &result, false);
|
||||||
if (conn != NULL)
|
if (conn != NULL)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
|
|
@ -634,6 +636,10 @@ int fdfs_get_ini_context_from_tracker(TrackerServerGroup *pTrackerGroup, \
|
||||||
|
|
||||||
if (conn == NULL)
|
if (conn == NULL)
|
||||||
{
|
{
|
||||||
|
logError("file: "__FILE__", line: %d, "
|
||||||
|
"connect to server %s:%d fail, errno: %d, "
|
||||||
|
"error info: %s", __LINE__, conn->ip_addr,
|
||||||
|
conn->port, result, STRERROR(result));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,7 @@
|
||||||
#define FDFS_PROTO_PKG_LEN_SIZE 8
|
#define FDFS_PROTO_PKG_LEN_SIZE 8
|
||||||
#define FDFS_PROTO_CMD_SIZE 1
|
#define FDFS_PROTO_CMD_SIZE 1
|
||||||
#define FDFS_PROTO_IP_PORT_SIZE (IP_ADDRESS_SIZE + 6)
|
#define FDFS_PROTO_IP_PORT_SIZE (IP_ADDRESS_SIZE + 6)
|
||||||
|
#define FDFS_PROTO_MULTI_IP_PORT_SIZE (2 * IP_ADDRESS_SIZE + 8)
|
||||||
|
|
||||||
#define TRACKER_QUERY_STORAGE_FETCH_BODY_LEN (FDFS_GROUP_NAME_MAX_LEN \
|
#define TRACKER_QUERY_STORAGE_FETCH_BODY_LEN (FDFS_GROUP_NAME_MAX_LEN \
|
||||||
+ IP_ADDRESS_SIZE - 1 + FDFS_PROTO_PKG_LEN_SIZE)
|
+ IP_ADDRESS_SIZE - 1 + FDFS_PROTO_PKG_LEN_SIZE)
|
||||||
|
|
@ -230,22 +231,27 @@ ConnectionInfo *tracker_connect_server_ex(TrackerServerInfo *pServerInfo,
|
||||||
* connect to the tracker server directly without connection pool
|
* connect to the tracker server directly without connection pool
|
||||||
* params:
|
* params:
|
||||||
* pTrackerServer: tracker server
|
* pTrackerServer: tracker server
|
||||||
|
* bind_ipaddr: the ip address to bind, NULL or empty for any
|
||||||
|
* err_no: return the error no
|
||||||
|
* log_connect_error: if log error info when connect fail
|
||||||
* return: ConnectionInfo pointer for success, NULL for fail
|
* return: ConnectionInfo pointer for success, NULL for fail
|
||||||
**/
|
**/
|
||||||
ConnectionInfo *tracker_connect_server_no_pool_ex(TrackerServerInfo *pServerInfo,
|
ConnectionInfo *tracker_connect_server_no_pool_ex(TrackerServerInfo *pServerInfo,
|
||||||
const char *bind_addr, int *err_no);
|
const char *bind_addr, int *err_no, const bool log_connect_error);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* connect to the tracker server directly without connection pool
|
* connect to the tracker server directly without connection pool
|
||||||
* params:
|
* params:
|
||||||
* pTrackerServer: tracker server
|
* pTrackerServer: tracker server
|
||||||
* return: 0 for success, none zero for fail
|
* err_no: return the error no
|
||||||
|
* return: ConnectionInfo pointer for success, NULL for fail
|
||||||
**/
|
**/
|
||||||
static inline ConnectionInfo *tracker_connect_server_no_pool(
|
static inline ConnectionInfo *tracker_connect_server_no_pool(
|
||||||
TrackerServerInfo *pServerInfo, int *err_no)
|
TrackerServerInfo *pServerInfo, int *err_no)
|
||||||
{
|
{
|
||||||
const char *bind_addr = NULL;
|
const char *bind_addr = NULL;
|
||||||
return tracker_connect_server_no_pool_ex(pServerInfo, bind_addr, err_no);
|
return tracker_connect_server_no_pool_ex(pServerInfo,
|
||||||
|
bind_addr, err_no, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define tracker_disconnect_server(pTrackerServer) \
|
#define tracker_disconnect_server(pTrackerServer) \
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue