specify the storage server ID for NAT network

pull/687/head
YuQing 2023-12-10 15:12:20 +08:00
parent 47759f2cf7
commit 48fb05dbb2
18 changed files with 196 additions and 92 deletions

View File

@ -1,6 +1,8 @@
Version 6.11.0 2023-12-05
Version 6.11.0 2023-12-10
* support IPv6, config item: address_family in tracker.conf and storage.conf
use libfastcommon V1.71 and libserverframe 1.2.1
* storage.conf can specify the storage server ID for NAT network
Version 6.10.0 2023-09-07
* use libfastcommon V1.70 and libserverframe 1.2.0

View File

@ -11,7 +11,7 @@ Chinese language: http://www.fastken.com/
# command lines as:
git clone https://github.com/happyfish100/libfastcommon.git
cd libfastcommon; git checkout V1.0.70
cd libfastcommon; git checkout V1.0.71
./make.sh clean && ./make.sh && ./make.sh install
@ -21,7 +21,7 @@ Chinese language: http://www.fastken.com/
# command lines as:
git clone https://github.com/happyfish100/libserverframe.git
cd libserverframe; git checkout V1.2.0
cd libserverframe; git checkout V1.2.1
./make.sh clean && ./make.sh && ./make.sh install
# step 3. download fastdfs source codes and install it,
@ -30,7 +30,7 @@ Chinese language: http://www.fastken.com/
# command lines as:
git clone https://github.com/happyfish100/fastdfs.git
cd fastdfs; git checkout V6.10.0
cd fastdfs; git checkout V6.11.0
./make.sh clean && ./make.sh && ./make.sh install

View File

@ -38,8 +38,21 @@ port = 23000
## auto: auto detect by bind_addr, IPv4 first then IPv6 when bind_addr is empty
## both: IPv4 and IPv6 dual stacks
# default value is auto
# since V6.11
address_family = auto
# specify the storage server ID for NAT network
# NOT set or commented for auto set by the local ip addresses
# since V6.11
#
# NOTE:
## * this paramter is valid only when use_storage_id and trust_storage_server_id
## in tracker.conf set to true
## * the storage server id must exist in storage_ids.conf
#server_id =
# connect timeout in seconds
# default value is 30
# Note: in the intranet network (LAN), 2 seconds is enough.

View File

@ -29,6 +29,7 @@ port = 22122
# id_type_in_filename MUST set to id when IPv6 enabled
#
# default value is auto
# since V6.11
address_family = auto
# connect timeout in seconds
@ -286,6 +287,13 @@ storage_ids_filename = storage_ids.conf
# since V4.03
id_type_in_filename = id
# if trust the storage server ID sent by the storage server
# this paramter is valid only when use_storage_id set to true
# default value is true
# since V6.11
trust_storage_server_id = true
# if store slave file use symbol link
# default value is false
# since V4.01

View File

@ -219,7 +219,32 @@ static int storage_get_group_name_from_tracker()
return result;
}
static int tracker_get_my_server_id()
static int get_my_server_id_by_local_ip()
{
FDFSStorageIdInfo *idInfo;
const char *ip_addr;
ip_addr = get_first_local_ip();
while (ip_addr != NULL) {
if ((idInfo=fdfs_get_storage_id_by_ip(g_group_name,
ip_addr)) != NULL)
{
snprintf(g_my_server_id_str, sizeof(g_my_server_id_str),
"%s", idInfo->id);
return 0;
}
ip_addr = get_next_local_ip(ip_addr);
}
logError("file: "__FILE__", line: %d, "
"can't find my server id by local ip address, "
"local ip count: %d", __LINE__, g_local_host_ip_count);
return ENOENT;
}
static int tracker_get_my_server_id(const char *conf_filename,
const char *server_id_in_conf)
{
struct in_addr ipv4_addr;
struct in6_addr ipv6_addr;
@ -241,7 +266,7 @@ static int tracker_get_my_server_id()
if (!flag)
{
logError("file: "__FILE__", line: %d, "
logWarning("file: "__FILE__", line: %d, "
"call inet_pton for ip: %s fail",
__LINE__, g_tracker_client_ip.ips[0].address);
g_server_id_in_filename = INADDR_NONE;
@ -252,20 +277,39 @@ static int tracker_get_my_server_id()
ConnectionInfo *pTrackerServer;
int result;
pTrackerServer = tracker_get_connection();
if (pTrackerServer == NULL)
{
return errno != 0 ? errno : ECONNREFUSED;
}
result = tracker_get_storage_id(pTrackerServer,
g_group_name, g_tracker_client_ip.ips[0].address,
g_my_server_id_str);
tracker_close_connection_ex(pTrackerServer, result != 0);
if (result != 0)
{
return result;
}
if (g_trust_storage_server_id) {
if (server_id_in_conf == NULL) {
if ((result=get_my_server_id_by_local_ip()) != 0) {
return result;
}
} else if (*server_id_in_conf != '\0') {
if (!fdfs_is_server_id_valid(server_id_in_conf)) {
logError("file: "__FILE__", line: %d, "
"config file: %s, server_id: %s is invalid",
__LINE__, conf_filename, server_id_in_conf);
return EINVAL;
}
snprintf(g_my_server_id_str, sizeof(g_my_server_id_str),
"%s", server_id_in_conf);
}
}
if (*g_my_server_id_str == '\0') {
pTrackerServer = tracker_get_connection();
if (pTrackerServer == NULL)
{
return errno != 0 ? errno : ECONNREFUSED;
}
result = tracker_get_storage_id(pTrackerServer,
g_group_name, g_tracker_client_ip.ips[0].address,
g_my_server_id_str);
tracker_close_connection_ex(pTrackerServer, result != 0);
if (result != 0)
{
return result;
}
}
if (g_id_type_in_filename == FDFS_ID_TYPE_SERVER_ID)
{
@ -1431,6 +1475,7 @@ int storage_func_init(const char *filename)
char *pIfAliasPrefix;
char *pHttpDomain;
char *pRotateAccessLogSize;
char *server_id_in_conf;
IniContext iniContext;
SFContextIniConfig config;
int result;
@ -1949,6 +1994,9 @@ int storage_func_init(const char *filename)
break;
}
server_id_in_conf = iniGetStrValue(NULL,
"server_id", &iniContext);
#ifdef WITH_HTTPD
{
char *pHttpTrunkSize;
@ -2097,7 +2145,16 @@ int storage_func_init(const char *filename)
return result;
}
if ((result=tracker_get_my_server_id()) != 0)
if (g_use_storage_id)
{
if ((result=fdfs_get_storage_ids_from_tracker_group(
&g_tracker_group)) != 0)
{
return result;
}
}
if ((result=tracker_get_my_server_id(filename, server_id_in_conf)) != 0)
{
logCrit("file: "__FILE__", line: %d, " \
"get my server id from tracker server fail, " \
@ -2106,15 +2163,6 @@ int storage_func_init(const char *filename)
return result;
}
if (g_use_storage_id)
{
if ((result=fdfs_get_storage_ids_from_tracker_group( \
&g_tracker_group)) != 0)
{
return result;
}
}
if ((result=storage_check_ip_changed()) != 0)
{
return result;

View File

@ -74,6 +74,7 @@ bool g_use_access_log = false; //if log to access log
bool g_rotate_access_log = false; //if rotate the access log every day
bool g_compress_old_access_log = false; //if compress the old access log
bool g_use_storage_id = false; //identify storage by ID instead of IP address
bool g_trust_storage_server_id = false;
byte g_id_type_in_filename = FDFS_ID_TYPE_IP_ADDRESS; //id type of the storage server in the filename
bool g_store_slave_file_use_link = false; //if store slave file use symbol link

View File

@ -103,6 +103,7 @@ extern LogContext g_access_log_context;
extern in_addr_64_t g_server_id_in_filename;
extern bool g_store_slave_file_use_link; //if store slave file use symbol link
extern bool g_use_storage_id; //identify storage by ID instead of IP address
extern bool g_trust_storage_server_id;
extern byte g_id_type_in_filename; //id type of the storage server in the filename
extern bool g_use_access_log; //if log to access log
extern bool g_rotate_access_log; //if rotate the access log every day

View File

@ -179,6 +179,8 @@ int storage_get_params_from_tracker()
{
g_id_type_in_filename = FDFS_ID_TYPE_IP_ADDRESS;
}
g_trust_storage_server_id = iniGetBoolValue(NULL,
"trust_storage_server_id", &iniContext, false);
iniFreeContext(&iniContext);
@ -194,6 +196,7 @@ int storage_get_params_from_tracker()
logInfo("file: "__FILE__", line: %d, "
"use_storage_id=%d, "
"id_type_in_filename=%s, "
"trust_storage_server_id=%d, "
"storage_ip_changed_auto_adjust=%d, "
"store_path=%d, "
"reserved_storage_space=%s, "
@ -217,6 +220,7 @@ int storage_get_params_from_tracker()
"store_slave_file_use_link=%d",
__LINE__, g_use_storage_id,
g_id_type_in_filename == FDFS_ID_TYPE_SERVER_ID ? "id" : "ip",
g_trust_storage_server_id,
g_storage_ip_changed_auto_adjust,
g_store_path_mode, fdfs_storage_reserved_space_to_string(
&g_storage_reserved_space, reserved_space_str),

View File

@ -2027,6 +2027,9 @@ int tracker_report_join(ConnectionInfo *pTrackerServer, \
long2buff(g_sf_global_vars.up_time, pReqBody->up_time);
pReqBody->init_flag = sync_old_done ? 0 : 1;
strcpy(pReqBody->current_tracker_ip, pTrackerServer->ip_addr);
if (g_use_storage_id) {
strcpy(pReqBody->storage_id, g_my_server_id_str);
}
memset(&targetServer, 0, sizeof(targetServer));
pTargetServer = &targetServer;

View File

@ -489,9 +489,9 @@ int fdfs_load_storage_ids(char *content, const char *pStorageIdsFilename)
if (!fdfs_is_server_id_valid(id))
{
logError("file: "__FILE__", line: %d, " \
"invalid server id: \"%s\", " \
"which must be a none zero start " \
logError("file: "__FILE__", line: %d, "
"invalid server id: \"%s\", "
"which must be a none zero start "
"integer, such as 100001", __LINE__, id);
result = EINVAL;
break;

View File

@ -99,12 +99,12 @@ static int tracker_load_store_lookup(const char *filename, \
}
static int tracker_load_storage_id_info(const char *config_filename,
IniContext *pItemContext)
IniContext *iniContext)
{
char *pIdType;
g_use_storage_id = iniGetBoolValue(NULL, "use_storage_id", \
pItemContext, false);
g_use_storage_id = iniGetBoolValue(NULL, "use_storage_id",
iniContext, false);
if (!g_use_storage_id)
{
if (SF_G_IPV6_ENABLED)
@ -118,7 +118,7 @@ static int tracker_load_storage_id_info(const char *config_filename,
return 0;
}
pIdType = iniGetStrValue(NULL, "id_type_in_filename", pItemContext);
pIdType = iniGetStrValue(NULL, "id_type_in_filename", iniContext);
if (pIdType != NULL && strcasecmp(pIdType, "id") == 0)
{
g_id_type_in_filename = FDFS_ID_TYPE_SERVER_ID;
@ -135,7 +135,9 @@ static int tracker_load_storage_id_info(const char *config_filename,
g_id_type_in_filename = FDFS_ID_TYPE_IP_ADDRESS;
}
return fdfs_load_storage_ids_from_file(config_filename, pItemContext);
g_trust_storage_server_id = iniGetBoolValue(NULL,
"trust_storage_server_id", iniContext, true);
return fdfs_load_storage_ids_from_file(config_filename, iniContext);
}
int tracker_load_from_conf_file(const char *filename)
@ -534,6 +536,7 @@ int tracker_load_from_conf_file(const char *filename)
"trunk_binlog_max_backups=%d, "
"use_storage_id=%d, "
"id_type_in_filename=%s, "
"trust_storage_server_id=%d, "
"storage_id/ip_count=%d / %d, "
"store_slave_file_use_link=%d, "
"use_connection_pool=%d, "
@ -569,6 +572,7 @@ int tracker_load_from_conf_file(const char *filename)
g_trunk_binlog_max_backups,
g_use_storage_id, g_id_type_in_filename ==
FDFS_ID_TYPE_SERVER_ID ? "id" : "ip",
g_trust_storage_server_id,
g_storage_ids_by_id.count, g_storage_ids_by_ip.count,
g_store_slave_file_use_link,
g_use_connection_pool, g_connection_pool_max_idle_time);

View File

@ -21,6 +21,7 @@ in_addr_64_t *g_allow_ip_addrs = NULL;
bool g_storage_ip_changed_auto_adjust = true;
bool g_use_storage_id = false; //if use storage ID instead of IP address
bool g_trust_storage_server_id = true;
byte g_id_type_in_filename = FDFS_ID_TYPE_IP_ADDRESS; //id type of the storage server in the filename
int g_storage_sync_file_max_delay = DEFAULT_STORAGE_SYNC_FILE_MAX_DELAY;

View File

@ -47,6 +47,7 @@ extern in_addr_64_t *g_allow_ip_addrs; /* sorted array, asc order */
extern bool g_storage_ip_changed_auto_adjust;
extern bool g_use_storage_id; //identify storage by ID instead of IP address
extern bool g_trust_storage_server_id;
extern byte g_id_type_in_filename; //id type of the storage server in the filename
extern int g_storage_sync_file_max_delay;

View File

@ -3568,8 +3568,8 @@ static int tracker_mem_add_storage(TrackerClientInfo *pClientInfo,
FDFSStorageDetail *pStorageServer;
pStorageServer = NULL;
result = _tracker_mem_add_storage(pClientInfo->pGroup, \
&pStorageServer, id, ip_addr, bNeedSleep, \
result = _tracker_mem_add_storage(pClientInfo->pGroup,
&pStorageServer, id, ip_addr, bNeedSleep,
bNeedLock, bInserted);
if (result == 0)
{
@ -4408,8 +4408,8 @@ static int tracker_mem_get_sys_files_from_others(FDFSStorageJoinBody *pJoinBody,
return tracker_open_changlog_file();
}
int tracker_mem_add_group_and_storage(TrackerClientInfo *pClientInfo, \
const char *ip_addr, FDFSStorageJoinBody *pJoinBody, \
int tracker_mem_add_group_and_storage(TrackerClientInfo *pClientInfo,
const char *ip_addr, FDFSStorageJoinBody *pJoinBody,
const bool bNeedSleep)
{
int result;
@ -4418,7 +4418,6 @@ int tracker_mem_add_group_and_storage(TrackerClientInfo *pClientInfo, \
FDFSStorageDetail *pStorageServer;
FDFSStorageDetail **ppServer;
FDFSStorageDetail **ppEnd;
FDFSStorageIdInfo *pStorageIdInfo;
FDFSStorageId storage_id;
tracker_mem_file_lock();
@ -4489,7 +4488,7 @@ int tracker_mem_add_group_and_storage(TrackerClientInfo *pClientInfo, \
tracker_mem_file_unlock();
if ((result=tracker_mem_add_group_ex(&g_groups, pClientInfo, \
if ((result=tracker_mem_add_group_ex(&g_groups, pClientInfo,
pJoinBody->group_name, bNeedSleep, &bGroupInserted)) != 0)
{
return result;
@ -4505,21 +4504,36 @@ int tracker_mem_add_group_and_storage(TrackerClientInfo *pClientInfo, \
if (g_use_storage_id)
{
pStorageIdInfo = fdfs_get_storage_id_by_ip(
pClientInfo->pGroup->group_name, ip_addr);
if (pStorageIdInfo == NULL)
{
logError("file: "__FILE__", line: %d, " \
"get storage id info fail, group_name: %s, " \
"storage ip: %s", __LINE__, \
pClientInfo->pGroup->group_name, ip_addr);
return ENOENT;
}
FDFSStorageIdInfo *pStorageIdInfo;
if (g_trust_storage_server_id && *(pJoinBody->storage_id) != '\0')
{
pStorageIdInfo = fdfs_get_storage_by_id(pJoinBody->storage_id);
if (pStorageIdInfo == NULL)
{
logError("file: "__FILE__", line: %d, "
"get storage id info fail, storage id: %s",
__LINE__, pJoinBody->storage_id);
return ENOENT;
}
}
else
{
pStorageIdInfo = fdfs_get_storage_id_by_ip(
pClientInfo->pGroup->group_name, ip_addr);
if (pStorageIdInfo == NULL)
{
logError("file: "__FILE__", line: %d, "
"get storage id info fail, group_name: %s, "
"storage ip: %s", __LINE__,
pClientInfo->pGroup->group_name, ip_addr);
return ENOENT;
}
}
storage_id.ptr = pStorageIdInfo->id;
}
else
{
pStorageIdInfo = NULL;
// 当IP地址为IPv6时其storage_id值为IP地址的short code
if (is_ipv6_addr(ip_addr))
{

View File

@ -592,47 +592,46 @@ void tracker_disconnect_server_no_pool(TrackerServerInfo *pServerInfo)
}
}
static int fdfs_do_parameter_req(ConnectionInfo *pTrackerServer, \
char *buff, const int buff_size)
static int fdfs_do_parameter_req(ConnectionInfo *pTrackerServer,
char *buff, const int buff_size)
{
char out_buff[sizeof(TrackerHeader)];
TrackerHeader *pHeader;
int64_t in_bytes;
int result;
char out_buff[sizeof(TrackerHeader)];
TrackerHeader *pHeader;
int64_t in_bytes;
int result;
memset(out_buff, 0, sizeof(out_buff));
pHeader = (TrackerHeader *)out_buff;
pHeader->cmd = TRACKER_PROTO_CMD_STORAGE_PARAMETER_REQ;
if((result=tcpsenddata_nb(pTrackerServer->sock, out_buff, \
sizeof(TrackerHeader), SF_G_NETWORK_TIMEOUT)) != 0)
{
logError("file: "__FILE__", line: %d, " \
"tracker server %s:%u, send data fail, " \
"errno: %d, error info: %s.", \
__LINE__, pTrackerServer->ip_addr, \
pTrackerServer->port, \
result, STRERROR(result));
return result;
}
memset(out_buff, 0, sizeof(out_buff));
pHeader = (TrackerHeader *)out_buff;
pHeader->cmd = TRACKER_PROTO_CMD_STORAGE_PARAMETER_REQ;
if((result=tcpsenddata_nb(pTrackerServer->sock, out_buff,
sizeof(TrackerHeader), SF_G_NETWORK_TIMEOUT)) != 0)
{
logError("file: "__FILE__", line: %d, "
"tracker server %s:%u, send data fail, "
"errno: %d, error info: %s.", __LINE__,
pTrackerServer->ip_addr, pTrackerServer->port,
result, STRERROR(result));
return result;
}
result = fdfs_recv_response(pTrackerServer, &buff, buff_size, &in_bytes);
if (result != 0)
{
return result;
}
result = fdfs_recv_response(pTrackerServer, &buff, buff_size, &in_bytes);
if (result != 0)
{
return result;
}
if (in_bytes >= buff_size)
{
logError("file: "__FILE__", line: %d, " \
"server: %s:%u, recv body bytes: " \
"%"PRId64" exceed max: %d", \
__LINE__, pTrackerServer->ip_addr, \
pTrackerServer->port, in_bytes, buff_size);
return ENOSPC;
}
if (in_bytes >= buff_size)
{
logError("file: "__FILE__", line: %d, "
"server: %s:%u, recv body bytes: "
"%"PRId64" exceed max: %d", __LINE__,
pTrackerServer->ip_addr, pTrackerServer->port,
in_bytes, buff_size);
return ENOSPC;
}
*(buff + in_bytes) = '\0';
return 0;
*(buff + in_bytes) = '\0';
return 0;
}
int fdfs_get_ini_context_from_tracker_ex(TrackerServerGroup *pTrackerGroup,

View File

@ -142,6 +142,7 @@ typedef struct
char domain_name[FDFS_DOMAIN_NAME_MAX_SIZE];
char init_flag;
signed char status;
char storage_id[FDFS_STORAGE_ID_MAX_SIZE]; //since 6.11
char current_tracker_ip[IP_ADDRESS_SIZE]; //current tracker ip address
char tracker_count[FDFS_PROTO_PKG_LEN_SIZE]; //all tracker server count
} TrackerStorageJoinBody;

View File

@ -448,6 +448,7 @@ static int tracker_deal_parameter_req(struct fast_task_info *pTask)
body_len = sprintf(pTask->send.ptr->data + sizeof(TrackerHeader),
"use_storage_id=%d\n"
"id_type_in_filename=%s\n"
"trust_storage_server_id=%d\n"
"storage_ip_changed_auto_adjust=%d\n"
"storage_sync_file_max_delay=%d\n"
"store_path=%d\n"
@ -472,6 +473,7 @@ static int tracker_deal_parameter_req(struct fast_task_info *pTask)
"store_slave_file_use_link=%d\n",
g_use_storage_id, g_id_type_in_filename ==
FDFS_ID_TYPE_SERVER_ID ? "id" : "ip",
g_trust_storage_server_id,
g_storage_ip_changed_auto_adjust,
g_storage_sync_file_max_delay, g_groups.store_path,
fdfs_storage_reserved_space_to_string(
@ -1244,7 +1246,7 @@ static int tracker_deal_storage_join(struct fast_task_info *pTask)
pClientInfo = (TrackerClientInfo *)pTask->arg;
if (pTask->recv.ptr->length - sizeof(TrackerHeader) < \
if (pTask->recv.ptr->length - sizeof(TrackerHeader) <
sizeof(TrackerStorageJoinBody))
{
logError("file: "__FILE__", line: %d, " \
@ -1377,6 +1379,7 @@ static int tracker_deal_storage_join(struct fast_task_info *pTask)
strcpy(joinBody.domain_name, pBody->domain_name);
joinBody.init_flag = pBody->init_flag;
joinBody.status = pBody->status;
memcpy(joinBody.storage_id, pBody->storage_id, FDFS_STORAGE_ID_MAX_SIZE);
pBody->current_tracker_ip[IP_ADDRESS_SIZE - 1] = '\0';

View File

@ -427,6 +427,7 @@ typedef struct
char version[FDFS_VERSION_SIZE]; //storage version
char group_name[FDFS_GROUP_NAME_MAX_LEN + 1];
char domain_name[FDFS_DOMAIN_NAME_MAX_SIZE];
char storage_id[FDFS_STORAGE_ID_MAX_SIZE];
char init_flag;
signed char status;
int tracker_count;