client.conf add config item: connect_first_by
parent
fd77ababf5
commit
ba41d958b2
|
|
@ -376,6 +376,7 @@ static int fdfs_client_do_init_ex(TrackerServerGroup *pTrackerGroup, \
|
||||||
{
|
{
|
||||||
FDFSStorageIdInfo *idInfo;
|
FDFSStorageIdInfo *idInfo;
|
||||||
FDFSStorageIdInfo *end;
|
FDFSStorageIdInfo *end;
|
||||||
|
char *connect_first_by;
|
||||||
|
|
||||||
end = g_storage_ids_by_id.ids + g_storage_ids_by_id.count;
|
end = g_storage_ids_by_id.ids + g_storage_ids_by_id.count;
|
||||||
for (idInfo=g_storage_ids_by_id.ids; idInfo<end; idInfo++)
|
for (idInfo=g_storage_ids_by_id.ids; idInfo<end; idInfo++)
|
||||||
|
|
@ -386,6 +387,17 @@ static int fdfs_client_do_init_ex(TrackerServerGroup *pTrackerGroup, \
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (g_multi_storage_ips)
|
||||||
|
{
|
||||||
|
connect_first_by = iniGetStrValue(NULL,
|
||||||
|
"connect_first_by", iniContext);
|
||||||
|
if (connect_first_by != NULL && strncasecmp(connect_first_by,
|
||||||
|
"last", 4) == 0)
|
||||||
|
{
|
||||||
|
g_connect_first_by = fdfs_connect_first_by_last_connected;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_FLAG
|
#ifdef DEBUG_FLAG
|
||||||
|
|
@ -397,13 +409,16 @@ static int fdfs_client_do_init_ex(TrackerServerGroup *pTrackerGroup, \
|
||||||
"anti_steal_secret_key length=%d, "
|
"anti_steal_secret_key length=%d, "
|
||||||
"use_connection_pool=%d, "
|
"use_connection_pool=%d, "
|
||||||
"g_connection_pool_max_idle_time=%ds, "
|
"g_connection_pool_max_idle_time=%ds, "
|
||||||
"use_storage_id=%d, storage server id count: %d, "
|
"use_storage_id=%d, connect_first_by=%s, "
|
||||||
|
"storage server id count: %d, "
|
||||||
"multi storage ips: %d\n",
|
"multi storage ips: %d\n",
|
||||||
SF_G_BASE_PATH_STR, SF_G_CONNECT_TIMEOUT,
|
SF_G_BASE_PATH_STR, SF_G_CONNECT_TIMEOUT,
|
||||||
SF_G_NETWORK_TIMEOUT, pTrackerGroup->server_count,
|
SF_G_NETWORK_TIMEOUT, pTrackerGroup->server_count,
|
||||||
g_anti_steal_token, g_anti_steal_secret_key.length,
|
g_anti_steal_token, g_anti_steal_secret_key.length,
|
||||||
g_use_connection_pool, g_connection_pool_max_idle_time,
|
g_use_connection_pool, g_connection_pool_max_idle_time,
|
||||||
use_storage_id, g_storage_ids_by_id.count, g_multi_storage_ips);
|
use_storage_id, g_connect_first_by == fdfs_connect_first_by_tracker ?
|
||||||
|
"tracker" : "last-connected", g_storage_ids_by_id.count,
|
||||||
|
g_multi_storage_ips);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -14,5 +14,6 @@ int g_tracker_server_http_port = 80;
|
||||||
TrackerServerGroup g_tracker_group = {0, 0, -1, NULL};
|
TrackerServerGroup g_tracker_group = {0, 0, -1, NULL};
|
||||||
|
|
||||||
bool g_multi_storage_ips = false;
|
bool g_multi_storage_ips = false;
|
||||||
|
FDFSConnectFirstBy g_connect_first_by = fdfs_connect_first_by_tracker;
|
||||||
bool g_anti_steal_token = false;
|
bool g_anti_steal_token = false;
|
||||||
BufferInfo g_anti_steal_secret_key = {0};
|
BufferInfo g_anti_steal_secret_key = {0};
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,11 @@
|
||||||
#include "tracker_types.h"
|
#include "tracker_types.h"
|
||||||
#include "fdfs_shared_func.h"
|
#include "fdfs_shared_func.h"
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
fdfs_connect_first_by_tracker,
|
||||||
|
fdfs_connect_first_by_last_connected
|
||||||
|
} FDFSConnectFirstBy;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -23,6 +28,7 @@ extern int g_tracker_server_http_port;
|
||||||
extern TrackerServerGroup g_tracker_group;
|
extern TrackerServerGroup g_tracker_group;
|
||||||
|
|
||||||
extern bool g_multi_storage_ips;
|
extern bool g_multi_storage_ips;
|
||||||
|
extern FDFSConnectFirstBy g_connect_first_by;
|
||||||
extern bool g_anti_steal_token;
|
extern bool g_anti_steal_token;
|
||||||
extern BufferInfo g_anti_steal_secret_key;
|
extern BufferInfo g_anti_steal_secret_key;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ static int g_base64_context_inited = 0;
|
||||||
ppStorageServer, TRACKER_PROTO_CMD_SERVICE_QUERY_UPDATE, \
|
ppStorageServer, TRACKER_PROTO_CMD_SERVICE_QUERY_UPDATE, \
|
||||||
group_name, filename, pNewStorage, new_connection)
|
group_name, filename, pNewStorage, new_connection)
|
||||||
|
|
||||||
static ConnectionInfo *storage_make_connection(
|
static ConnectionInfo *make_connection_by_tracker(
|
||||||
ConnectionInfo *pStorageServer, int *err_no)
|
ConnectionInfo *pStorageServer, int *err_no)
|
||||||
{
|
{
|
||||||
ConnectionInfo *conn;
|
ConnectionInfo *conn;
|
||||||
|
|
@ -102,6 +102,65 @@ static ConnectionInfo *storage_make_connection(
|
||||||
return tracker_make_connection(pStorageServer, err_no);
|
return tracker_make_connection(pStorageServer, err_no);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ConnectionInfo *make_connection_by_last_connected(
|
||||||
|
ConnectionInfo *pStorageServer, int *err_no)
|
||||||
|
{
|
||||||
|
ConnectionInfo *conn;
|
||||||
|
FDFSStorageIdInfo *idInfo;
|
||||||
|
int index;
|
||||||
|
|
||||||
|
if (!g_multi_storage_ips)
|
||||||
|
{
|
||||||
|
return tracker_make_connection(pStorageServer, err_no);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((idInfo=fdfs_get_storage_id_by_ip_port(pStorageServer->ip_addr,
|
||||||
|
pStorageServer->port)) == NULL)
|
||||||
|
{
|
||||||
|
return tracker_make_connection(pStorageServer, err_no);
|
||||||
|
}
|
||||||
|
if (idInfo->ip_addrs.count < 2)
|
||||||
|
{
|
||||||
|
return tracker_make_connection(pStorageServer, err_no);
|
||||||
|
}
|
||||||
|
|
||||||
|
index = idInfo->ip_addrs.index;
|
||||||
|
if (strcmp(pStorageServer->ip_addr, idInfo->ip_addrs.
|
||||||
|
ips[index].address) != 0)
|
||||||
|
{
|
||||||
|
strcpy(pStorageServer->ip_addr, idInfo->ip_addrs.
|
||||||
|
ips[index].address);
|
||||||
|
}
|
||||||
|
if ((conn=tracker_make_connection(pStorageServer, err_no)) != NULL)
|
||||||
|
{
|
||||||
|
return conn;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (++index == idInfo->ip_addrs.count)
|
||||||
|
{
|
||||||
|
index = 0;
|
||||||
|
}
|
||||||
|
strcpy(pStorageServer->ip_addr, idInfo->ip_addrs.ips[index].address);
|
||||||
|
if ((conn=tracker_make_connection(pStorageServer, err_no)) != NULL)
|
||||||
|
{
|
||||||
|
idInfo->ip_addrs.index = index;
|
||||||
|
}
|
||||||
|
return conn;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline ConnectionInfo *storage_make_connection(
|
||||||
|
ConnectionInfo *pStorageServer, int *err_no)
|
||||||
|
{
|
||||||
|
if (g_connect_first_by == fdfs_connect_first_by_tracker)
|
||||||
|
{
|
||||||
|
return make_connection_by_tracker(pStorageServer, err_no);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return make_connection_by_last_connected(pStorageServer, err_no);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int storage_get_connection(ConnectionInfo *pTrackerServer, \
|
static int storage_get_connection(ConnectionInfo *pTrackerServer, \
|
||||||
ConnectionInfo **ppStorageServer, const byte cmd, \
|
ConnectionInfo **ppStorageServer, const byte cmd, \
|
||||||
const char *group_name, const char *filename, \
|
const char *group_name, const char *filename, \
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,13 @@ tracker_server = 192.168.0.197:22122
|
||||||
### debug
|
### debug
|
||||||
log_level = info
|
log_level = info
|
||||||
|
|
||||||
|
# connect which ip address first for multi IPs of a storage server, value list:
|
||||||
|
## tracker: connect to the ip address return by tracker server first
|
||||||
|
## last-connected: connect to the ip address last connected first
|
||||||
|
# default value is tracker
|
||||||
|
# since V6.11
|
||||||
|
connect_first_by = tracker
|
||||||
|
|
||||||
# if use connection pool
|
# if use connection pool
|
||||||
# default value is false
|
# default value is false
|
||||||
# since V4.05
|
# since V4.05
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue