diff --git a/client/client_func.c b/client/client_func.c index 43b1d3d..ba8d62f 100644 --- a/client/client_func.c +++ b/client/client_func.c @@ -348,39 +348,62 @@ static int fdfs_client_do_init_ex(TrackerServerGroup *pTrackerGroup, \ return result; } - load_fdfs_parameters_from_tracker = iniGetBoolValue(NULL, \ - "load_fdfs_parameters_from_tracker", \ + load_fdfs_parameters_from_tracker = iniGetBoolValue(NULL, + "load_fdfs_parameters_from_tracker", iniContext, false); if (load_fdfs_parameters_from_tracker) { - fdfs_get_params_from_tracker(&use_storage_id); + if ((result=fdfs_get_params_from_tracker(&use_storage_id)) != 0) + { + return result; + } } else - { - use_storage_id = iniGetBoolValue(NULL, "use_storage_id", \ - iniContext, false); - if (use_storage_id) - { - result = fdfs_load_storage_ids_from_file( \ - conf_filename, iniContext); - } - } + { + use_storage_id = iniGetBoolValue(NULL, "use_storage_id", + iniContext, false); + if (use_storage_id) + { + if ((result=fdfs_load_storage_ids_from_file( + conf_filename, iniContext)) != 0) + { + return result; + } + } + } + + if (use_storage_id) + { + FDFSStorageIdInfo *idInfo; + FDFSStorageIdInfo *end; + + end = g_storage_ids_by_id.ids + g_storage_ids_by_id.count; + for (idInfo=g_storage_ids_by_id.ids; idInfoip_addrs.count > 1) + { + g_multi_storage_ips = true; + break; + } + } + } #ifdef DEBUG_FLAG - logDebug("base_path=%s, " \ - "connect_timeout=%d, "\ - "network_timeout=%d, "\ - "tracker_server_count=%d, " \ - "anti_steal_token=%d, " \ - "anti_steal_secret_key length=%d, " \ - "use_connection_pool=%d, " \ - "g_connection_pool_max_idle_time=%ds, " \ - "use_storage_id=%d, storage server id count: %d\n", \ - SF_G_BASE_PATH_STR, SF_G_CONNECT_TIMEOUT, \ - SF_G_NETWORK_TIMEOUT, pTrackerGroup->server_count, \ - g_anti_steal_token, g_anti_steal_secret_key.length, \ - g_use_connection_pool, g_connection_pool_max_idle_time, \ - use_storage_id, g_storage_ids_by_id.count); + logDebug("base_path=%s, " + "connect_timeout=%d, " + "network_timeout=%d, " + "tracker_server_count=%d, " + "anti_steal_token=%d, " + "anti_steal_secret_key length=%d, " + "use_connection_pool=%d, " + "g_connection_pool_max_idle_time=%ds, " + "use_storage_id=%d, storage server id count: %d, " + "multi storage ips: %d\n", + SF_G_BASE_PATH_STR, SF_G_CONNECT_TIMEOUT, + SF_G_NETWORK_TIMEOUT, pTrackerGroup->server_count, + g_anti_steal_token, g_anti_steal_secret_key.length, + g_use_connection_pool, g_connection_pool_max_idle_time, + use_storage_id, g_storage_ids_by_id.count, g_multi_storage_ips); #endif return 0; diff --git a/client/client_global.c b/client/client_global.c index af6c109..4db57cd 100644 --- a/client/client_global.c +++ b/client/client_global.c @@ -13,5 +13,6 @@ int g_tracker_server_http_port = 80; TrackerServerGroup g_tracker_group = {0, 0, -1, NULL}; +bool g_multi_storage_ips = false; bool g_anti_steal_token = false; BufferInfo g_anti_steal_secret_key = {0}; diff --git a/client/client_global.h b/client/client_global.h index 5c72442..45b5fea 100644 --- a/client/client_global.h +++ b/client/client_global.h @@ -22,6 +22,7 @@ extern "C" { extern int g_tracker_server_http_port; extern TrackerServerGroup g_tracker_group; +extern bool g_multi_storage_ips; extern bool g_anti_steal_token; extern BufferInfo g_anti_steal_secret_key; diff --git a/client/fdfs_monitor.c b/client/fdfs_monitor.c index 65df0fc..97e34eb 100644 --- a/client/fdfs_monitor.c +++ b/client/fdfs_monitor.c @@ -96,7 +96,7 @@ int main(int argc, char *argv[]) } log_init(); - g_log_context.log_level = LOG_DEBUG; + //g_log_context.log_level = LOG_DEBUG; ignore_signal_pipe(); if ((result=fdfs_client_init(conf_filename)) != 0) diff --git a/client/storage_client.c b/client/storage_client.c index 3977bab..92050dc 100644 --- a/client/storage_client.c +++ b/client/storage_client.c @@ -64,6 +64,44 @@ static int g_base64_context_inited = 0; ppStorageServer, TRACKER_PROTO_CMD_SERVICE_QUERY_UPDATE, \ group_name, filename, pNewStorage, new_connection) +static ConnectionInfo *storage_make_connection( + ConnectionInfo *pStorageServer, int *err_no) +{ + ConnectionInfo *conn; + FDFSStorageIdInfo *idInfo; + + if ((conn=tracker_make_connection(pStorageServer, err_no)) != NULL) + { + return conn; + } + + if (!g_multi_storage_ips) + { + return NULL; + } + + if ((idInfo=fdfs_get_storage_id_by_ip_port(pStorageServer->ip_addr, + pStorageServer->port)) == NULL) + { + return NULL; + } + + if (idInfo->ip_addrs.count < 2) + { + return NULL; + } + + if (strcmp(pStorageServer->ip_addr, idInfo->ip_addrs.ips[0].address) == 0) + { + strcpy(pStorageServer->ip_addr, idInfo->ip_addrs.ips[1].address); + } + else + { + strcpy(pStorageServer->ip_addr, idInfo->ip_addrs.ips[0].address); + } + return tracker_make_connection(pStorageServer, err_no); +} + static int storage_get_connection(ConnectionInfo *pTrackerServer, \ ConnectionInfo **ppStorageServer, const byte cmd, \ const char *group_name, const char *filename, \ @@ -97,7 +135,7 @@ static int storage_get_connection(ConnectionInfo *pTrackerServer, \ return result; } - if ((*ppStorageServer=tracker_make_connection(pNewStorage, + if ((*ppStorageServer=storage_make_connection(pNewStorage, &result)) == NULL) { return result; @@ -113,7 +151,7 @@ static int storage_get_connection(ConnectionInfo *pTrackerServer, \ } else { - if ((*ppStorageServer=tracker_make_connection( + if ((*ppStorageServer=storage_make_connection( *ppStorageServer, &result)) == NULL) { return result; @@ -162,7 +200,7 @@ static int storage_get_upload_connection(ConnectionInfo *pTrackerServer, \ return result; } - if ((*ppStorageServer=tracker_make_connection(pNewStorage, + if ((*ppStorageServer=storage_make_connection(pNewStorage, &result)) == NULL) { return result; @@ -178,7 +216,7 @@ static int storage_get_upload_connection(ConnectionInfo *pTrackerServer, \ } else { - if ((*ppStorageServer=tracker_make_connection( + if ((*ppStorageServer=storage_make_connection( *ppStorageServer, &result)) == NULL) { return result;