Skip to content

Commit

Permalink
adapt to the newest libfastcommon and libserverframe
Browse files Browse the repository at this point in the history
  • Loading branch information
happyfish100 committed Nov 29, 2023
1 parent bfb3e9f commit 7cae2bf
Show file tree
Hide file tree
Showing 14 changed files with 141 additions and 55 deletions.
2 changes: 1 addition & 1 deletion client/client_func.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ static int fdfs_get_params_from_tracker(bool *use_storage_id)

continue_flag = false;
if ((result=fdfs_get_ini_context_from_tracker(&g_tracker_group,
&iniContext, &continue_flag, false, NULL)) != 0)
&iniContext, &continue_flag)) != 0)
{
return result;
}
Expand Down
8 changes: 8 additions & 0 deletions conf/storage.conf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ client_bind = true
# the storage server port
port = 23000

# the address family of service, value list:
## IPv4: IPv4 stack
## IPv6: IPv6 stack
## auto: auto detect, IPv4 first, then IPv6
## both: IPv4 and IPv6 dual stacks
# default value is auto
address_family = auto

# connect timeout in seconds
# default value is 30
# Note: in the intranet network (LAN), 2 seconds is enough.
Expand Down
8 changes: 8 additions & 0 deletions conf/tracker.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ bind_addr =
# the tracker server port
port = 22122

# the address family of service, value list:
## IPv4: IPv4 stack
## IPv6: IPv6 stack
## auto: auto detect, IPv4 first, then IPv6
## both: IPv4 and IPv6 dual stacks
# default value is auto
address_family = auto

# connect timeout in seconds
# default value is 30
# Note: in the intranet network (LAN), 2 seconds is enough.
Expand Down
32 changes: 24 additions & 8 deletions storage/fdfs_storaged.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,30 @@ static void sigAlarmHandler(int sig)
logDebug("file: "__FILE__", line: %d, " \
"signal server to quit...", __LINE__);

if (*SF_G_INNER_BIND_ADDR != '\0')
{
strcpy(server.ip_addr, SF_G_INNER_BIND_ADDR);
}
else
{
strcpy(server.ip_addr, "127.0.0.1");
}
if (SF_G_IPV4_ENABLED)
{
server.af = AF_INET;
if (*SF_G_INNER_BIND_ADDR4 != '\0')
{
strcpy(server.ip_addr, SF_G_INNER_BIND_ADDR4);
}
else
{
strcpy(server.ip_addr, LOCAL_LOOPBACK_IPv4);
}
}
else
{
server.af = AF_INET6;
if (*SF_G_INNER_BIND_ADDR6 != '\0')
{
strcpy(server.ip_addr, SF_G_INNER_BIND_ADDR6);
}
else
{
strcpy(server.ip_addr, LOCAL_LOOPBACK_IPv6);
}
}
server.port = SF_G_INNER_PORT;
server.sock = -1;

Expand Down
6 changes: 4 additions & 2 deletions storage/storage_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ static int fdfs_dump_global_vars(char *buff, const int buffSize)
"g_check_file_duplicate=%d\n"
"g_key_namespace=%s\n"
"g_namespace_len=%d\n"
"SF_G_INNER_BIND_ADDR=%s\n"
"bind_addr_ipv4=%s\n"
"bind_addr_ipv6=%s\n"
"g_client_bind_addr=%d\n"
"g_storage_ip_changed_auto_adjust=%d\n"
"g_thread_kill_done=%d\n"
Expand Down Expand Up @@ -188,7 +189,8 @@ static int fdfs_dump_global_vars(char *buff, const int buffSize)
, g_check_file_duplicate
, g_key_namespace
, g_namespace_len
, SF_G_INNER_BIND_ADDR
, SF_G_INNER_BIND_ADDR4
, SF_G_INNER_BIND_ADDR6
, g_client_bind_addr
, g_storage_ip_changed_auto_adjust
, g_thread_kill_done
Expand Down
9 changes: 6 additions & 3 deletions storage/storage_ip_changed_dealer.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ int storage_get_my_tracker_client_ip()
for (i=0; i < 3; i++)
{
conn = tracker_connect_server_no_pool_ex(pTServer,
g_client_bind_addr ? SF_G_INNER_BIND_ADDR : NULL,
(g_client_bind_addr ? SF_G_INNER_BIND_ADDR4 : NULL),
(g_client_bind_addr ? SF_G_INNER_BIND_ADDR6 : NULL),
&result, false);
if (conn != NULL)
{
Expand Down Expand Up @@ -234,7 +235,8 @@ static int storage_report_storage_ip_addr()
for (i=0; i < 3; i++)
{
conn = tracker_connect_server_no_pool_ex(pTServer,
g_client_bind_addr ? SF_G_INNER_BIND_ADDR : NULL,
(g_client_bind_addr ? SF_G_INNER_BIND_ADDR4 : NULL),
(g_client_bind_addr ? SF_G_INNER_BIND_ADDR6 : NULL),
&result, false);
if (conn != NULL)
{
Expand Down Expand Up @@ -304,7 +306,8 @@ int storage_changelog_req()
for (i=0; i < 3; i++)
{
conn = tracker_connect_server_no_pool_ex(pTServer,
g_client_bind_addr ? SF_G_INNER_BIND_ADDR : NULL,
(g_client_bind_addr ? SF_G_INNER_BIND_ADDR4 : NULL),
(g_client_bind_addr ? SF_G_INNER_BIND_ADDR6 : NULL),
&result, false);
if (conn != NULL)
{
Expand Down
7 changes: 4 additions & 3 deletions storage/storage_param_getter.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ int storage_get_params_from_tracker()
char reserved_space_str[32];
char *pIdType;

if ((result=fdfs_get_ini_context_from_tracker(&g_tracker_group,
&iniContext, (bool * volatile)&SF_G_CONTINUE_FLAG,
g_client_bind_addr, SF_G_INNER_BIND_ADDR)) != 0)
if ((result=fdfs_get_ini_context_from_tracker_ex(&g_tracker_group,
&iniContext, (bool * volatile)&SF_G_CONTINUE_FLAG,
g_client_bind_addr, SF_G_INNER_BIND_ADDR4,
SF_G_INNER_BIND_ADDR6)) != 0)
{
return result;
}
Expand Down
8 changes: 6 additions & 2 deletions storage/storage_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -2050,7 +2050,9 @@ int storage_report_storage_status(const char *storage_id, \
for (i=0; i < 3; i++)
{
conn = tracker_connect_server_no_pool_ex(pTServer,
g_client_bind_addr ? SF_G_INNER_BIND_ADDR : NULL, &result, false);
(g_client_bind_addr ? SF_G_INNER_BIND_ADDR4 : NULL),
(g_client_bind_addr ? SF_G_INNER_BIND_ADDR6 : NULL),
&result, false);
if (conn != NULL)
{
break;
Expand Down Expand Up @@ -2146,7 +2148,9 @@ static int storage_reader_sync_init_req(StorageBinLogReader *pReader)
while (SF_G_CONTINUE_FLAG)
{
conn = tracker_connect_server_no_pool_ex(pTServer,
g_client_bind_addr ? SF_G_INNER_BIND_ADDR : NULL, &result, true);
(g_client_bind_addr ? SF_G_INNER_BIND_ADDR4 : NULL),
(g_client_bind_addr ? SF_G_INNER_BIND_ADDR6 : NULL),
&result, true);
if (conn != NULL)
{
break;
Expand Down
13 changes: 11 additions & 2 deletions storage/storage_sync_func.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ void storage_sync_connect_storage_server_ex(const FDFSStorageBrief *pStorage,
int i;
FDFSMultiIP ip_addrs;
FDFSMultiIP *multi_ip;
const char *bind_addr;

multi_ip = NULL;
if (g_use_storage_id)
Expand Down Expand Up @@ -83,9 +84,17 @@ void storage_sync_connect_storage_server_ex(const FDFSStorageBrief *pStorage,
for (i=0; i<ip_addrs.count; i++)
{
strcpy(conn->ip_addr, ip_addrs.ips[i].address);
if (g_client_bind_addr)
{
bind_addr = is_ipv6_addr(conn->ip_addr) ?
SF_G_INNER_BIND_ADDR6 : SF_G_INNER_BIND_ADDR4;
}
else
{
bind_addr = NULL;
}
conn->sock = socketCreateExAuto(conn->ip_addr,
O_NONBLOCK, g_client_bind_addr ?
SF_G_INNER_BIND_ADDR : NULL, &result);
O_NONBLOCK, bind_addr, &result);
if (conn->sock < 0)
{
logCrit("file: "__FILE__", line: %d, "
Expand Down
5 changes: 3 additions & 2 deletions storage/tracker_client_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,10 @@ static void *tracker_report_thread_entrance(void *arg)
}

conn = tracker_connect_server_no_pool_ex(pTrackerServer,
g_client_bind_addr ? SF_G_INNER_BIND_ADDR : NULL,
(g_client_bind_addr ? SF_G_INNER_BIND_ADDR4 : NULL),
(g_client_bind_addr ? SF_G_INNER_BIND_ADDR6 : NULL),
&result, false);
if (conn == NULL)
if (conn == NULL)
{
if (previousCode != result)
{
Expand Down
1 change: 0 additions & 1 deletion test/test_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#define FILENAME_FILE_ID "file_id"
#define FILENAME_FAIL "fail"

#define IP_ADDRESS_SIZE 16
#define SRAND_SEED 1225420780

#define TIME_SUB_MS(tv1, tv2) ((tv1.tv_sec - tv2.tv_sec) * 1000 + (tv1.tv_usec - tv2.tv_usec) / 1000)
Expand Down
32 changes: 24 additions & 8 deletions tracker/fdfs_trackerd.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,14 +423,30 @@ static void sigAlarmHandler(int sig)
logDebug("file: "__FILE__", line: %d, " \
"signal server to quit...", __LINE__);

if (*g_sf_context.inner_bind_addr != '\0')
{
strcpy(server.ip_addr, g_sf_context.inner_bind_addr);
}
else
{
strcpy(server.ip_addr, "127.0.0.1");
}
if (SF_G_IPV4_ENABLED)
{
server.af = AF_INET;
if (*SF_G_INNER_BIND_ADDR4 != '\0')
{
strcpy(server.ip_addr, SF_G_INNER_BIND_ADDR4);
}
else
{
strcpy(server.ip_addr, LOCAL_LOOPBACK_IPv4);
}
}
else
{
server.af = AF_INET6;
if (*SF_G_INNER_BIND_ADDR6 != '\0')
{
strcpy(server.ip_addr, SF_G_INNER_BIND_ADDR6);
}
else
{
strcpy(server.ip_addr, LOCAL_LOOPBACK_IPv6);
}
}
server.port = SF_G_INNER_PORT;
server.sock = -1;

Expand Down
36 changes: 23 additions & 13 deletions tracker/tracker_proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,8 @@ ConnectionInfo *tracker_connect_server_ex(TrackerServerInfo *pServerInfo,
}

ConnectionInfo *tracker_connect_server_no_pool_ex(TrackerServerInfo *pServerInfo,
const char *bind_addr, int *err_no, const bool log_connect_error)
const char *bind_addr4, const char *bind_addr6, int *err_no,
const bool log_connect_error)
{
ConnectionInfo *conn;
ConnectionInfo *end;
Expand All @@ -500,12 +501,12 @@ ConnectionInfo *tracker_connect_server_no_pool_ex(TrackerServerInfo *pServerInfo
return pServerInfo->connections + pServerInfo->index;
}

*err_no = conn_pool_connect_server_ex(pServerInfo->connections
+ pServerInfo->index, SF_G_CONNECT_TIMEOUT * 1000,
bind_addr, log_connect_error);
conn = pServerInfo->connections + pServerInfo->index;
*err_no = conn_pool_connect_server_ex(conn, SF_G_CONNECT_TIMEOUT * 1000,
conn->af == AF_INET ? bind_addr4 : bind_addr6, log_connect_error);
if (*err_no == 0)
{
return pServerInfo->connections + pServerInfo->index;
return conn;
}

if (pServerInfo->count == 1)
Expand All @@ -520,11 +521,12 @@ ConnectionInfo *tracker_connect_server_no_pool_ex(TrackerServerInfo *pServerInfo
if (current_index != pServerInfo->index)
{
if ((*err_no=conn_pool_connect_server_ex(conn,
SF_G_CONNECT_TIMEOUT * 1000, bind_addr,
log_connect_error)) == 0)
SF_G_CONNECT_TIMEOUT * 1000,
conn->af == AF_INET ? bind_addr4 :
bind_addr6, log_connect_error)) == 0)
{
pServerInfo->index = current_index;
return pServerInfo->connections + pServerInfo->index;
return conn;
}
}
}
Expand Down Expand Up @@ -633,9 +635,10 @@ static int fdfs_do_parameter_req(ConnectionInfo *pTrackerServer, \
return 0;
}

int fdfs_get_ini_context_from_tracker(TrackerServerGroup *pTrackerGroup, \
IniContext *iniContext, bool * volatile continue_flag, \
const bool client_bind_addr, const char *bind_addr)
int fdfs_get_ini_context_from_tracker_ex(TrackerServerGroup *pTrackerGroup,
IniContext *iniContext, bool * volatile continue_flag,
const bool client_bind_addr, const char *bind_addr4,
const char *bind_addr6)
{
ConnectionInfo *conn;
TrackerServerInfo *pGlobalServer;
Expand Down Expand Up @@ -664,7 +667,14 @@ int fdfs_get_ini_context_from_tracker(TrackerServerGroup *pTrackerGroup, \

if (!client_bind_addr)
{
bind_addr = NULL;
if (bind_addr4 != NULL)
{
bind_addr4 = NULL;
}
if (bind_addr6 != NULL)
{
bind_addr6 = NULL;
}
}

do
Expand All @@ -678,7 +688,7 @@ int fdfs_get_ini_context_from_tracker(TrackerServerGroup *pTrackerGroup, \
for (i=0; i < 3; i++)
{
conn = tracker_connect_server_no_pool_ex(pTServer,
bind_addr, &result, false);
bind_addr4, bind_addr6, &result, false);
if (conn != NULL)
{
break;
Expand Down
29 changes: 19 additions & 10 deletions tracker/tracker_proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,15 @@ ConnectionInfo *tracker_connect_server_ex(TrackerServerInfo *pServerInfo,
* connect to the tracker server directly without connection pool
* params:
* pTrackerServer: tracker server
* bind_ipaddr: the ip address to bind, NULL or empty for any
* bind_addr4: the ipv4 address to bind, NULL or empty for any
* bind_addr6: the ipv6 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
**/
ConnectionInfo *tracker_connect_server_no_pool_ex(TrackerServerInfo *pServerInfo,
const char *bind_addr, int *err_no, const bool log_connect_error);
const char *bind_addr4, const char *bind_addr6, int *err_no,
const bool log_connect_error);

/**
* connect to the tracker server directly without connection pool
Expand All @@ -258,9 +260,10 @@ ConnectionInfo *tracker_connect_server_no_pool_ex(TrackerServerInfo *pServerInfo
static inline ConnectionInfo *tracker_connect_server_no_pool(
TrackerServerInfo *pServerInfo, int *err_no)
{
const char *bind_addr = NULL;
const char *bind_addr4 = NULL;
const char *bind_addr6 = NULL;
return tracker_connect_server_no_pool_ex(pServerInfo,
bind_addr, err_no, true);
bind_addr4, bind_addr6, err_no, true);
}

#define tracker_close_connection(pTrackerServer) \
Expand Down Expand Up @@ -316,15 +319,21 @@ int fdfs_deal_no_body_cmd_ex(const char *ip_addr, const int port, const int cmd)
fdfs_split_metadata_ex(meta_buff, FDFS_RECORD_SEPERATOR, \
FDFS_FIELD_SEPERATOR, meta_count, err_no)

char *fdfs_pack_metadata(const FDFSMetaData *meta_list, const int meta_count, \
char *fdfs_pack_metadata(const FDFSMetaData *meta_list, const int meta_count,
char *meta_buff, int *buff_bytes);
FDFSMetaData *fdfs_split_metadata_ex(char *meta_buff, \
const char recordSeperator, const char filedSeperator, \
FDFSMetaData *fdfs_split_metadata_ex(char *meta_buff,
const char recordSeperator, const char filedSeperator,
int *meta_count, int *err_no);

int fdfs_get_ini_context_from_tracker(TrackerServerGroup *pTrackerGroup, \
IniContext *iniContext, bool * volatile continue_flag, \
const bool client_bind_addr, const char *bind_addr);
int fdfs_get_ini_context_from_tracker_ex(TrackerServerGroup *pTrackerGroup,
IniContext *iniContext, bool * volatile continue_flag,
const bool client_bind_addr, const char *bind_addr4,
const char *bind_addr6);

#define fdfs_get_ini_context_from_tracker(pTrackerGroup, \
iniContext, continue_flag) \
fdfs_get_ini_context_from_tracker_ex(pTrackerGroup, \
iniContext, continue_flag, false, NULL, NULL)

int fdfs_get_tracker_status(TrackerServerInfo *pTrackerServer,
TrackerRunningStatus *pStatus);
Expand Down

0 comments on commit 7cae2bf

Please sign in to comment.