Merge branch 'use_libserverframe'
commit
522bd50522
|
|
@ -104,3 +104,8 @@ php_client/run-tests.php
|
|||
# fastdfs runtime paths
|
||||
data/
|
||||
logs/
|
||||
|
||||
# others
|
||||
*.pid
|
||||
*.swp
|
||||
*.swo
|
||||
|
|
|
|||
3
HISTORY
3
HISTORY
|
|
@ -1,4 +1,7 @@
|
|||
|
||||
Version 6.09 2022-09-11
|
||||
* use libfastcommon V1.60 and libserverframe 1.1.18
|
||||
|
||||
Version 6.08 2022-06-21
|
||||
* use libfastcommon V1.56
|
||||
NOTE: you MUST upgrade libfastcommon to V1.56 or later
|
||||
|
|
|
|||
25
INSTALL
25
INSTALL
|
|
@ -11,28 +11,37 @@ Chinese language: http://www.fastken.com/
|
|||
# command lines as:
|
||||
|
||||
git clone https://github.com/happyfish100/libfastcommon.git
|
||||
cd libfastcommon; git checkout V1.0.56
|
||||
cd libfastcommon; git checkout V1.0.60
|
||||
./make.sh clean && ./make.sh && ./make.sh install
|
||||
|
||||
|
||||
# step 2. download fastdfs source codes and install it,
|
||||
# step 2. download libserverframe source codes and install it,
|
||||
# github address: https://github.com/happyfish100/libserverframe.git
|
||||
# gitee address: https://gitee.com/fastdfs100/libserverframe.git
|
||||
# command lines as:
|
||||
|
||||
git clone https://github.com/happyfish100/libserverframe.git
|
||||
cd libserverframe; git checkout V1.1.18
|
||||
./make.sh clean && ./make.sh && ./make.sh install
|
||||
|
||||
# step 3. download fastdfs source codes and install it,
|
||||
# github address: https://github.com/happyfish100/fastdfs.git
|
||||
# gitee address: https://gitee.com/fastdfs100/fastdfs.git
|
||||
# command lines as:
|
||||
|
||||
git clone https://github.com/happyfish100/fastdfs.git
|
||||
cd fastdfs; git checkout V6.08
|
||||
cd fastdfs; git checkout V6.09
|
||||
./make.sh clean && ./make.sh && ./make.sh install
|
||||
|
||||
|
||||
# step 3. setup the config files
|
||||
# step 4. setup the config files
|
||||
# the setup script does NOT overwrite existing config files,
|
||||
# please feel free to execute this script (take easy :)
|
||||
|
||||
./setup.sh /etc/fdfs
|
||||
|
||||
|
||||
# step 4. edit or modify the config files of tracker, storage and client
|
||||
# step 5. edit or modify the config files of tracker, storage and client
|
||||
such as:
|
||||
vi /etc/fdfs/tracker.conf
|
||||
vi /etc/fdfs/storage.conf
|
||||
|
|
@ -41,7 +50,7 @@ such as:
|
|||
and so on ...
|
||||
|
||||
|
||||
# step 5. run the server programs
|
||||
# step 6. run the server programs
|
||||
# start the tracker server:
|
||||
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
|
||||
|
||||
|
|
@ -53,12 +62,12 @@ such as:
|
|||
/sbin/service fdfs_storaged restart
|
||||
|
||||
|
||||
# step 6. (optional) run monitor program
|
||||
# step 7. (optional) run monitor program
|
||||
# such as:
|
||||
/usr/bin/fdfs_monitor /etc/fdfs/client.conf
|
||||
|
||||
|
||||
# step 7. (optional) run the test program
|
||||
# step 8. (optional) run the test program
|
||||
# such as:
|
||||
/usr/bin/fdfs_test <client_conf_filename> <operation>
|
||||
/usr/bin/fdfs_test1 <client_conf_filename> <operation>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ COMPILE = $(CC) $(CFLAGS)
|
|||
ENABLE_STATIC_LIB = $(ENABLE_STATIC_LIB)
|
||||
ENABLE_SHARED_LIB = $(ENABLE_SHARED_LIB)
|
||||
INC_PATH = -I../common -I../tracker -I/usr/include/fastcommon
|
||||
LIB_PATH = $(LIBS) -lfastcommon
|
||||
LIB_PATH = $(LIBS) -lfastcommon -lserverframe
|
||||
TARGET_PATH = $(TARGET_PREFIX)/bin
|
||||
TARGET_LIB = $(TARGET_PREFIX)/$(LIB_VERSION)
|
||||
TARGET_INC = $(TARGET_PREFIX)/include
|
||||
|
|
@ -49,6 +49,7 @@ CLIENT_SHARED_LIBS = libfdfsclient.so
|
|||
ALL_LIBS = $(STATIC_LIBS) $(SHARED_LIBS)
|
||||
|
||||
all: $(ALL_OBJS) $(ALL_PRGS) $(ALL_LIBS)
|
||||
|
||||
libfdfsclient.so:
|
||||
$(COMPILE) -o $@ $< -shared $(FDFS_SHARED_OBJS) $(LIB_PATH)
|
||||
libfdfsclient.a:
|
||||
|
|
|
|||
|
|
@ -270,41 +270,41 @@ static int fdfs_client_do_init_ex(TrackerServerGroup *pTrackerGroup, \
|
|||
pBasePath = iniGetStrValue(NULL, "base_path", iniContext);
|
||||
if (pBasePath == NULL)
|
||||
{
|
||||
strcpy(g_fdfs_base_path, "/tmp");
|
||||
strcpy(SF_G_BASE_PATH_STR, "/tmp");
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(g_fdfs_base_path, sizeof(g_fdfs_base_path),
|
||||
snprintf(SF_G_BASE_PATH_STR, sizeof(SF_G_BASE_PATH_STR),
|
||||
"%s", pBasePath);
|
||||
chopPath(g_fdfs_base_path);
|
||||
if (!fileExists(g_fdfs_base_path))
|
||||
chopPath(SF_G_BASE_PATH_STR);
|
||||
if (!fileExists(SF_G_BASE_PATH_STR))
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"\"%s\" can't be accessed, error info: %s", \
|
||||
__LINE__, g_fdfs_base_path, STRERROR(errno));
|
||||
__LINE__, SF_G_BASE_PATH_STR, STRERROR(errno));
|
||||
return errno != 0 ? errno : ENOENT;
|
||||
}
|
||||
if (!isDir(g_fdfs_base_path))
|
||||
if (!isDir(SF_G_BASE_PATH_STR))
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"\"%s\" is not a directory!", \
|
||||
__LINE__, g_fdfs_base_path);
|
||||
__LINE__, SF_G_BASE_PATH_STR);
|
||||
return ENOTDIR;
|
||||
}
|
||||
}
|
||||
|
||||
g_fdfs_connect_timeout = iniGetIntValue(NULL, "connect_timeout", \
|
||||
SF_G_CONNECT_TIMEOUT = iniGetIntValue(NULL, "connect_timeout", \
|
||||
iniContext, DEFAULT_CONNECT_TIMEOUT);
|
||||
if (g_fdfs_connect_timeout <= 0)
|
||||
if (SF_G_CONNECT_TIMEOUT <= 0)
|
||||
{
|
||||
g_fdfs_connect_timeout = DEFAULT_CONNECT_TIMEOUT;
|
||||
SF_G_CONNECT_TIMEOUT = DEFAULT_CONNECT_TIMEOUT;
|
||||
}
|
||||
|
||||
g_fdfs_network_timeout = iniGetIntValue(NULL, "network_timeout", \
|
||||
SF_G_NETWORK_TIMEOUT = iniGetIntValue(NULL, "network_timeout", \
|
||||
iniContext, DEFAULT_NETWORK_TIMEOUT);
|
||||
if (g_fdfs_network_timeout <= 0)
|
||||
if (SF_G_NETWORK_TIMEOUT <= 0)
|
||||
{
|
||||
g_fdfs_network_timeout = DEFAULT_NETWORK_TIMEOUT;
|
||||
SF_G_NETWORK_TIMEOUT = DEFAULT_NETWORK_TIMEOUT;
|
||||
}
|
||||
|
||||
if ((result=fdfs_load_tracker_group_ex(pTrackerGroup, \
|
||||
|
|
@ -376,8 +376,8 @@ static int fdfs_client_do_init_ex(TrackerServerGroup *pTrackerGroup, \
|
|||
"use_connection_pool=%d, " \
|
||||
"g_connection_pool_max_idle_time=%ds, " \
|
||||
"use_storage_id=%d, storage server id count: %d\n", \
|
||||
g_fdfs_base_path, g_fdfs_connect_timeout, \
|
||||
g_fdfs_network_timeout, pTrackerGroup->server_count, \
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -15,4 +15,3 @@ TrackerServerGroup g_tracker_group = {0, 0, -1, NULL};
|
|||
|
||||
bool g_anti_steal_token = false;
|
||||
BufferInfo g_anti_steal_secret_key = {0};
|
||||
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ int uploadFileCallback(void *arg, const int64_t file_size, int sock)
|
|||
|
||||
filename = (char *)arg;
|
||||
return tcpsendfile(sock, filename, file_size, \
|
||||
g_fdfs_network_timeout, &total_send_bytes);
|
||||
SF_G_NETWORK_TIMEOUT, &total_send_bytes);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ int uploadFileCallback(void *arg, const int64_t file_size, int sock)
|
|||
|
||||
filename = (char *)arg;
|
||||
return tcpsendfile(sock, filename, file_size, \
|
||||
g_fdfs_network_timeout, &total_send_bytes);
|
||||
SF_G_NETWORK_TIMEOUT, &total_send_bytes);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ int uploadFileCallback(void *arg, const int64_t file_size, int sock)
|
|||
|
||||
filename = (char *)arg;
|
||||
return tcpsendfile(sock, filename, file_size, \
|
||||
g_fdfs_network_timeout, &total_send_bytes);
|
||||
SF_G_NETWORK_TIMEOUT, &total_send_bytes);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ int uploadFileCallback(void *arg, const int64_t file_size, int sock)
|
|||
|
||||
filename = (char *)arg;
|
||||
return tcpsendfile(sock, filename, file_size, \
|
||||
g_fdfs_network_timeout, &total_send_bytes);
|
||||
SF_G_NETWORK_TIMEOUT, &total_send_bytes);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
|
|
|||
|
|
@ -252,7 +252,7 @@ int storage_get_metadata(ConnectionInfo *pTrackerServer, \
|
|||
|
||||
if ((result=tcpsenddata_nb(pStorageServer->sock, out_buff, \
|
||||
sizeof(TrackerHeader) + FDFS_GROUP_NAME_MAX_LEN + \
|
||||
filename_len, g_fdfs_network_timeout)) != 0)
|
||||
filename_len, SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"send data to storage server %s:%d fail, " \
|
||||
|
|
@ -352,7 +352,7 @@ int storage_query_file_info_ex(ConnectionInfo *pTrackerServer, \
|
|||
|
||||
if ((result=tcpsenddata_nb(pStorageServer->sock, out_buff, \
|
||||
sizeof(TrackerHeader) + FDFS_GROUP_NAME_MAX_LEN + \
|
||||
filename_len, g_fdfs_network_timeout)) != 0)
|
||||
filename_len, SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"send data to storage server %s:%d fail, " \
|
||||
|
|
@ -482,7 +482,7 @@ int storage_delete_file(ConnectionInfo *pTrackerServer, \
|
|||
|
||||
if ((result=tcpsenddata_nb(pStorageServer->sock, out_buff, \
|
||||
sizeof(TrackerHeader) + FDFS_GROUP_NAME_MAX_LEN + \
|
||||
filename_len, g_fdfs_network_timeout)) != 0)
|
||||
filename_len, SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"send data to storage server %s:%d fail, " \
|
||||
|
|
@ -578,7 +578,7 @@ int storage_do_download_file_ex(ConnectionInfo *pTrackerServer, \
|
|||
pHeader->cmd = STORAGE_PROTO_CMD_DOWNLOAD_FILE;
|
||||
|
||||
if ((result=tcpsenddata_nb(pStorageServer->sock, out_buff, \
|
||||
out_bytes, g_fdfs_network_timeout)) != 0)
|
||||
out_bytes, SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"send data to storage server %s:%d fail, " \
|
||||
|
|
@ -601,7 +601,7 @@ int storage_do_download_file_ex(ConnectionInfo *pTrackerServer, \
|
|||
|
||||
if ((result=tcprecvfile(pStorageServer->sock, \
|
||||
*file_buff, in_bytes, 0, \
|
||||
g_fdfs_network_timeout, \
|
||||
SF_G_NETWORK_TIMEOUT, \
|
||||
&total_recv_bytes)) != 0)
|
||||
{
|
||||
break;
|
||||
|
|
@ -649,7 +649,7 @@ int storage_do_download_file_ex(ConnectionInfo *pTrackerServer, \
|
|||
}
|
||||
|
||||
if ((result=tcprecvdata_nb(pStorageServer->sock, buff, \
|
||||
recv_bytes, g_fdfs_network_timeout)) != 0)
|
||||
recv_bytes, SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"recv data from storage server " \
|
||||
|
|
@ -938,7 +938,7 @@ int storage_do_upload_file(ConnectionInfo *pTrackerServer, \
|
|||
pHeader->status = 0;
|
||||
|
||||
if ((result=tcpsenddata_nb(pStorageServer->sock, out_buff, \
|
||||
p - out_buff, g_fdfs_network_timeout)) != 0)
|
||||
p - out_buff, SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"send data to storage server %s:%d fail, " \
|
||||
|
|
@ -951,7 +951,7 @@ int storage_do_upload_file(ConnectionInfo *pTrackerServer, \
|
|||
if (upload_type == FDFS_UPLOAD_BY_FILE)
|
||||
{
|
||||
if ((result=tcpsendfile(pStorageServer->sock, file_buff, \
|
||||
file_size, g_fdfs_network_timeout, \
|
||||
file_size, SF_G_NETWORK_TIMEOUT, \
|
||||
&total_send_bytes)) != 0)
|
||||
{
|
||||
break;
|
||||
|
|
@ -961,7 +961,7 @@ int storage_do_upload_file(ConnectionInfo *pTrackerServer, \
|
|||
{
|
||||
if ((result=tcpsenddata_nb(pStorageServer->sock, \
|
||||
(char *)file_buff, file_size, \
|
||||
g_fdfs_network_timeout)) != 0)
|
||||
SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"send data to storage server %s:%d fail, " \
|
||||
|
|
@ -1219,7 +1219,7 @@ int storage_set_metadata(ConnectionInfo *pTrackerServer, \
|
|||
pHeader->cmd = STORAGE_PROTO_CMD_SET_METADATA;
|
||||
|
||||
if ((result=tcpsenddata_nb(pStorageServer->sock, out_buff, \
|
||||
p - out_buff, g_fdfs_network_timeout)) != 0)
|
||||
p - out_buff, SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"send data to storage server %s:%d fail, " \
|
||||
|
|
@ -1231,7 +1231,7 @@ int storage_set_metadata(ConnectionInfo *pTrackerServer, \
|
|||
}
|
||||
|
||||
if (meta_bytes > 0 && (result=tcpsenddata_nb(pStorageServer->sock, \
|
||||
meta_buff, meta_bytes, g_fdfs_network_timeout)) != 0)
|
||||
meta_buff, meta_bytes, SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"send data to storage server %s:%d fail, " \
|
||||
|
|
@ -1433,7 +1433,7 @@ int storage_client_create_link(ConnectionInfo *pTrackerServer, \
|
|||
long2buff(p - out_buff - sizeof(TrackerHeader), pHeader->pkg_len);
|
||||
pHeader->cmd = STORAGE_PROTO_CMD_CREATE_LINK;
|
||||
if ((result=tcpsenddata_nb(pStorageServer->sock, out_buff, \
|
||||
p - out_buff, g_fdfs_network_timeout)) != 0)
|
||||
p - out_buff, SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"send data to storage server %s:%d fail, " \
|
||||
|
|
@ -1729,7 +1729,7 @@ int storage_do_append_file(ConnectionInfo *pTrackerServer, \
|
|||
pHeader->status = 0;
|
||||
|
||||
if ((result=tcpsenddata_nb(pStorageServer->sock, out_buff, \
|
||||
p - out_buff, g_fdfs_network_timeout)) != 0)
|
||||
p - out_buff, SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"send data to storage server %s:%d fail, " \
|
||||
|
|
@ -1742,7 +1742,7 @@ int storage_do_append_file(ConnectionInfo *pTrackerServer, \
|
|||
if (upload_type == FDFS_UPLOAD_BY_FILE)
|
||||
{
|
||||
if ((result=tcpsendfile(pStorageServer->sock, file_buff, \
|
||||
file_size, g_fdfs_network_timeout, \
|
||||
file_size, SF_G_NETWORK_TIMEOUT, \
|
||||
&total_send_bytes)) != 0)
|
||||
{
|
||||
break;
|
||||
|
|
@ -1752,7 +1752,7 @@ int storage_do_append_file(ConnectionInfo *pTrackerServer, \
|
|||
{
|
||||
if ((result=tcpsenddata_nb(pStorageServer->sock, \
|
||||
(char *)file_buff, file_size, \
|
||||
g_fdfs_network_timeout)) != 0)
|
||||
SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"send data to storage server %s:%d fail, " \
|
||||
|
|
@ -1860,7 +1860,7 @@ int storage_do_modify_file(ConnectionInfo *pTrackerServer, \
|
|||
pHeader->status = 0;
|
||||
|
||||
if ((result=tcpsenddata_nb(pStorageServer->sock, out_buff, \
|
||||
p - out_buff, g_fdfs_network_timeout)) != 0)
|
||||
p - out_buff, SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"send data to storage server %s:%d fail, " \
|
||||
|
|
@ -1873,7 +1873,7 @@ int storage_do_modify_file(ConnectionInfo *pTrackerServer, \
|
|||
if (upload_type == FDFS_UPLOAD_BY_FILE)
|
||||
{
|
||||
if ((result=tcpsendfile(pStorageServer->sock, file_buff, \
|
||||
file_size, g_fdfs_network_timeout, \
|
||||
file_size, SF_G_NETWORK_TIMEOUT, \
|
||||
&total_send_bytes)) != 0)
|
||||
{
|
||||
break;
|
||||
|
|
@ -1883,7 +1883,7 @@ int storage_do_modify_file(ConnectionInfo *pTrackerServer, \
|
|||
{
|
||||
if ((result=tcpsenddata_nb(pStorageServer->sock, \
|
||||
(char *)file_buff, file_size, \
|
||||
g_fdfs_network_timeout)) != 0)
|
||||
SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"send data to storage server %s:%d fail, " \
|
||||
|
|
@ -2324,7 +2324,7 @@ int storage_truncate_file(ConnectionInfo *pTrackerServer, \
|
|||
pHeader->status = 0;
|
||||
|
||||
if ((result=tcpsenddata_nb(pStorageServer->sock, out_buff, \
|
||||
p - out_buff, g_fdfs_network_timeout)) != 0)
|
||||
p - out_buff, SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"send data to storage server %s:%d fail, " \
|
||||
|
|
@ -2400,7 +2400,7 @@ int storage_regenerate_appender_filename(ConnectionInfo *pTrackerServer,
|
|||
pHeader->status = 0;
|
||||
|
||||
if ((result=tcpsenddata_nb(pStorageServer->sock, out_buff,
|
||||
p - out_buff, g_fdfs_network_timeout)) != 0)
|
||||
p - out_buff, SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"send data to storage server %s:%d fail, "
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ int uploadFileCallback(void *arg, const int64_t file_size, int sock)
|
|||
|
||||
filename = (char *)arg;
|
||||
return tcpsendfile(sock, filename, file_size, \
|
||||
g_fdfs_network_timeout, &total_send_bytes);
|
||||
SF_G_NETWORK_TIMEOUT, &total_send_bytes);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ int uploadFileCallback(void *arg, const int64_t file_size, int sock)
|
|||
|
||||
filename = (char *)arg;
|
||||
return tcpsendfile(sock, filename, file_size, \
|
||||
g_fdfs_network_timeout, &total_send_bytes);
|
||||
SF_G_NETWORK_TIMEOUT, &total_send_bytes);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
|
|
|||
|
|
@ -295,7 +295,7 @@ int tracker_list_servers(ConnectionInfo *pTrackerServer, \
|
|||
pHeader->cmd = TRACKER_PROTO_CMD_SERVER_LIST_STORAGE;
|
||||
if ((result=tcpsenddata_nb(conn->sock, out_buff, \
|
||||
sizeof(TrackerHeader) + FDFS_GROUP_NAME_MAX_LEN + id_len, \
|
||||
g_fdfs_network_timeout)) != 0)
|
||||
SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"send data to tracker server %s:%d fail, " \
|
||||
|
|
@ -498,7 +498,7 @@ int tracker_list_one_group(ConnectionInfo *pTrackerServer, \
|
|||
pHeader->cmd = TRACKER_PROTO_CMD_SERVER_LIST_ONE_GROUP;
|
||||
long2buff(FDFS_GROUP_NAME_MAX_LEN, pHeader->pkg_len);
|
||||
if ((result=tcpsenddata_nb(conn->sock, out_buff, \
|
||||
sizeof(out_buff), g_fdfs_network_timeout)) != 0)
|
||||
sizeof(out_buff), SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"send data to tracker server %s:%d fail, " \
|
||||
|
|
@ -578,7 +578,7 @@ int tracker_list_groups(ConnectionInfo *pTrackerServer, \
|
|||
header.cmd = TRACKER_PROTO_CMD_SERVER_LIST_ALL_GROUPS;
|
||||
header.status = 0;
|
||||
if ((result=tcpsenddata_nb(conn->sock, &header, \
|
||||
sizeof(header), g_fdfs_network_timeout)) != 0)
|
||||
sizeof(header), SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"send data to tracker server %s:%d fail, " \
|
||||
|
|
@ -695,7 +695,7 @@ int tracker_do_query_storage(ConnectionInfo *pTrackerServer, \
|
|||
pHeader->cmd = cmd;
|
||||
if ((result=tcpsenddata_nb(conn->sock, out_buff, \
|
||||
sizeof(TrackerHeader) + FDFS_GROUP_NAME_MAX_LEN +
|
||||
filename_len, g_fdfs_network_timeout)) != 0)
|
||||
filename_len, SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"send data to tracker server %s:%d fail, " \
|
||||
|
|
@ -779,7 +779,7 @@ int tracker_query_storage_list(ConnectionInfo *pTrackerServer, \
|
|||
pHeader->cmd = TRACKER_PROTO_CMD_SERVICE_QUERY_FETCH_ALL;
|
||||
if ((result=tcpsenddata_nb(conn->sock, out_buff, \
|
||||
sizeof(TrackerHeader) + FDFS_GROUP_NAME_MAX_LEN +
|
||||
filename_len, g_fdfs_network_timeout)) != 0)
|
||||
filename_len, SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"send data to tracker server %s:%d fail, " \
|
||||
|
|
@ -878,7 +878,7 @@ int tracker_query_storage_store_without_group(ConnectionInfo *pTrackerServer,
|
|||
memset(&header, 0, sizeof(header));
|
||||
header.cmd = TRACKER_PROTO_CMD_SERVICE_QUERY_STORE_WITHOUT_GROUP_ONE;
|
||||
if ((result=tcpsenddata_nb(conn->sock, &header, \
|
||||
sizeof(header), g_fdfs_network_timeout)) != 0)
|
||||
sizeof(header), SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"send data to tracker server %s:%d fail, " \
|
||||
|
|
@ -961,7 +961,7 @@ int tracker_query_storage_store_with_group(ConnectionInfo *pTrackerServer, \
|
|||
pHeader->cmd = TRACKER_PROTO_CMD_SERVICE_QUERY_STORE_WITH_GROUP_ONE;
|
||||
if ((result=tcpsenddata_nb(conn->sock, out_buff, \
|
||||
sizeof(TrackerHeader) + FDFS_GROUP_NAME_MAX_LEN, \
|
||||
g_fdfs_network_timeout)) != 0)
|
||||
SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"send data to tracker server %s:%d fail, " \
|
||||
|
|
@ -1056,7 +1056,7 @@ int tracker_query_storage_store_list_with_group( \
|
|||
|
||||
long2buff(out_len, pHeader->pkg_len);
|
||||
if ((result=tcpsenddata_nb(conn->sock, out_buff, \
|
||||
sizeof(TrackerHeader) + out_len, g_fdfs_network_timeout)) != 0)
|
||||
sizeof(TrackerHeader) + out_len, SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"send data to tracker server %s:%d fail, " \
|
||||
|
|
@ -1226,7 +1226,7 @@ int tracker_delete_storage(TrackerServerGroup *pTrackerGroup, \
|
|||
|
||||
if ((result=tcpsenddata_nb(conn->sock, out_buff, \
|
||||
sizeof(TrackerHeader) + FDFS_GROUP_NAME_MAX_LEN +
|
||||
storage_id_len, g_fdfs_network_timeout)) != 0)
|
||||
storage_id_len, SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"send data to tracker server %s:%d fail, "
|
||||
|
|
@ -1306,7 +1306,7 @@ int tracker_delete_group(TrackerServerGroup *pTrackerGroup, \
|
|||
|
||||
if ((result=tcpsenddata_nb(conn->sock, out_buff,
|
||||
sizeof(TrackerHeader) + FDFS_GROUP_NAME_MAX_LEN,
|
||||
g_fdfs_network_timeout)) != 0)
|
||||
SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"send data to tracker server %s:%d fail, "
|
||||
|
|
@ -1382,7 +1382,7 @@ int tracker_set_trunk_server(TrackerServerGroup *pTrackerGroup, \
|
|||
|
||||
if ((result=tcpsenddata_nb(conn->sock, out_buff, \
|
||||
sizeof(TrackerHeader) + FDFS_GROUP_NAME_MAX_LEN +
|
||||
storage_id_len, g_fdfs_network_timeout)) != 0)
|
||||
storage_id_len, SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"send data to tracker server %s:%d fail, "
|
||||
|
|
@ -1468,7 +1468,7 @@ int tracker_get_storage_status(ConnectionInfo *pTrackerServer,
|
|||
pHeader->cmd = TRACKER_PROTO_CMD_STORAGE_GET_STATUS;
|
||||
long2buff(FDFS_GROUP_NAME_MAX_LEN + ip_len, pHeader->pkg_len);
|
||||
if ((result=tcpsenddata_nb(conn->sock, out_buff, \
|
||||
p - out_buff, g_fdfs_network_timeout)) != 0)
|
||||
p - out_buff, SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"send data to tracker server %s:%d fail, " \
|
||||
|
|
@ -1556,7 +1556,7 @@ int tracker_get_storage_id(ConnectionInfo *pTrackerServer, \
|
|||
pHeader->cmd = TRACKER_PROTO_CMD_STORAGE_GET_SERVER_ID;
|
||||
long2buff(FDFS_GROUP_NAME_MAX_LEN + ip_len, pHeader->pkg_len);
|
||||
if ((result=tcpsenddata_nb(conn->sock, out_buff, \
|
||||
p - out_buff, g_fdfs_network_timeout)) != 0)
|
||||
p - out_buff, SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"send data to tracker server %s:%d fail, " \
|
||||
|
|
|
|||
|
|
@ -20,10 +20,7 @@
|
|||
#include "fastcommon/logger.h"
|
||||
#include "fdfs_global.h"
|
||||
|
||||
int g_fdfs_connect_timeout = DEFAULT_CONNECT_TIMEOUT;
|
||||
int g_fdfs_network_timeout = DEFAULT_NETWORK_TIMEOUT;
|
||||
char g_fdfs_base_path[MAX_PATH_SIZE] = {'/', 't', 'm', 'p', '\0'};
|
||||
Version g_fdfs_version = {6, 8};
|
||||
Version g_fdfs_version = {6, 9, 0};
|
||||
bool g_use_connection_pool = false;
|
||||
ConnectionPool g_connection_pool;
|
||||
int g_connection_pool_max_idle_time = 3600;
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
#define _FDFS_GLOBAL_H
|
||||
|
||||
#include "fastcommon/common_define.h"
|
||||
#include "sf/sf_global.h"
|
||||
#include "fdfs_define.h"
|
||||
#include "fastcommon/connection_pool.h"
|
||||
|
||||
|
|
@ -21,9 +22,6 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern int g_fdfs_connect_timeout;
|
||||
extern int g_fdfs_network_timeout;
|
||||
extern char g_fdfs_base_path[MAX_PATH_SIZE];
|
||||
extern Version g_fdfs_version;
|
||||
extern bool g_use_connection_pool;
|
||||
extern ConnectionPool g_connection_pool;
|
||||
|
|
|
|||
14
fastdfs.spec
14
fastdfs.spec
|
|
@ -7,7 +7,7 @@
|
|||
%define CommitVersion %(echo $COMMIT_VERSION)
|
||||
|
||||
Name: %{FastDFS}
|
||||
Version: 6.0.8
|
||||
Version: 6.0.9
|
||||
Release: 2%{?dist}
|
||||
Summary: FastDFS server and client
|
||||
License: GPL
|
||||
|
|
@ -18,24 +18,26 @@ Source: http://perso.orange.fr/sebastien.godard/%{name}-%{version}.tar.gz
|
|||
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
|
||||
|
||||
Requires: %__cp %__mv %__chmod %__grep %__mkdir %__install %__id
|
||||
BuildRequires: libfastcommon-devel >= 1.0.58
|
||||
BuildRequires: libfastcommon-devel >= 1.0.60
|
||||
BuildRequires: libserverframe-devel >= 1.1.19
|
||||
|
||||
%description
|
||||
This package provides tracker & storage of fastdfs
|
||||
commit version: %{CommitVersion}
|
||||
|
||||
%package -n %{FDFSServer}
|
||||
Requires: libfastcommon >= 1.0.58
|
||||
Requires: libfastcommon >= 1.0.60
|
||||
Requires: libserverframe >= 1.1.19
|
||||
Requires: %{FDFSConfig}
|
||||
Summary: fastdfs tracker & storage
|
||||
|
||||
%package -n %{FDFSTool}
|
||||
Requires: libfastcommon
|
||||
Requires: %{FDFSConfig}
|
||||
Requires: %{FDFSClient}
|
||||
Summary: fastdfs tools
|
||||
|
||||
%package -n %{FDFSClient}
|
||||
Requires: libfastcommon
|
||||
Requires: libfastcommon >= 1.0.60
|
||||
Requires: libserverframe >= 1.1.19
|
||||
Requires: %{FDFSConfig}
|
||||
Summary: The client dynamic library of fastdfs
|
||||
|
||||
|
|
|
|||
|
|
@ -943,7 +943,7 @@ static void php_fdfs_connect_server_impl(INTERNAL_FUNCTION_PARAMETERS, \
|
|||
server_info.sock = -1;
|
||||
|
||||
if ((pContext->err_no=conn_pool_connect_server(&server_info, \
|
||||
g_fdfs_network_timeout)) == 0)
|
||||
SF_G_NETWORK_TIMEOUT)) == 0)
|
||||
{
|
||||
array_init(return_value);
|
||||
zend_add_assoc_stringl_ex(return_value, "ip_addr", \
|
||||
|
|
@ -5034,7 +5034,7 @@ static void php_fdfs_send_data_impl(INTERNAL_FUNCTION_PARAMETERS, \
|
|||
}
|
||||
|
||||
if ((pContext->err_no=tcpsenddata_nb(sock, buff, \
|
||||
buff_len, g_fdfs_network_timeout)) != 0)
|
||||
buff_len, SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
RETURN_BOOL(false);
|
||||
}
|
||||
|
|
@ -7541,28 +7541,28 @@ static int load_config_files()
|
|||
if (zend_get_configuration_directive_wrapper(ITEM_NAME_BASE_PATH, \
|
||||
sizeof(ITEM_NAME_BASE_PATH), &base_path) != SUCCESS)
|
||||
{
|
||||
strcpy(g_fdfs_base_path, "/tmp");
|
||||
strcpy(SF_G_BASE_PATH_STR, "/tmp");
|
||||
fprintf(stderr, "file: "__FILE__", line: %d, " \
|
||||
"fastdfs_client.ini does not have item " \
|
||||
"\"%s\", set to %s!", __LINE__,
|
||||
ITEM_NAME_BASE_PATH, g_fdfs_base_path);
|
||||
ITEM_NAME_BASE_PATH, SF_G_BASE_PATH_STR);
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(g_fdfs_base_path, sizeof(g_fdfs_base_path), "%s", \
|
||||
snprintf(SF_G_BASE_PATH_STR, sizeof(SF_G_BASE_PATH_STR), "%s", \
|
||||
Z_STRVAL_P(base_path));
|
||||
chopPath(g_fdfs_base_path);
|
||||
chopPath(SF_G_BASE_PATH_STR);
|
||||
}
|
||||
|
||||
if (!fileExists(g_fdfs_base_path))
|
||||
if (!fileExists(SF_G_BASE_PATH_STR))
|
||||
{
|
||||
logError("\"%s\" can't be accessed, error info: %s", \
|
||||
g_fdfs_base_path, STRERROR(errno));
|
||||
SF_G_BASE_PATH_STR, STRERROR(errno));
|
||||
return errno != 0 ? errno : ENOENT;
|
||||
}
|
||||
if (!isDir(g_fdfs_base_path))
|
||||
if (!isDir(SF_G_BASE_PATH_STR))
|
||||
{
|
||||
logError("\"%s\" is not a directory!", g_fdfs_base_path);
|
||||
logError("\"%s\" is not a directory!", SF_G_BASE_PATH_STR);
|
||||
return ENOTDIR;
|
||||
}
|
||||
|
||||
|
|
@ -7570,30 +7570,30 @@ static int load_config_files()
|
|||
sizeof(ITEM_NAME_CONNECT_TIMEOUT), \
|
||||
&connect_timeout) == SUCCESS)
|
||||
{
|
||||
g_fdfs_connect_timeout = atoi(Z_STRVAL_P(connect_timeout));
|
||||
if (g_fdfs_connect_timeout <= 0)
|
||||
SF_G_CONNECT_TIMEOUT = atoi(Z_STRVAL_P(connect_timeout));
|
||||
if (SF_G_CONNECT_TIMEOUT <= 0)
|
||||
{
|
||||
g_fdfs_connect_timeout = DEFAULT_CONNECT_TIMEOUT;
|
||||
SF_G_CONNECT_TIMEOUT = DEFAULT_CONNECT_TIMEOUT;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g_fdfs_connect_timeout = DEFAULT_CONNECT_TIMEOUT;
|
||||
SF_G_CONNECT_TIMEOUT = DEFAULT_CONNECT_TIMEOUT;
|
||||
}
|
||||
|
||||
if (zend_get_configuration_directive_wrapper(ITEM_NAME_NETWORK_TIMEOUT, \
|
||||
sizeof(ITEM_NAME_NETWORK_TIMEOUT), \
|
||||
&network_timeout) == SUCCESS)
|
||||
{
|
||||
g_fdfs_network_timeout = atoi(Z_STRVAL_P(network_timeout));
|
||||
if (g_fdfs_network_timeout <= 0)
|
||||
SF_G_NETWORK_TIMEOUT = atoi(Z_STRVAL_P(network_timeout));
|
||||
if (SF_G_NETWORK_TIMEOUT <= 0)
|
||||
{
|
||||
g_fdfs_network_timeout = DEFAULT_NETWORK_TIMEOUT;
|
||||
SF_G_NETWORK_TIMEOUT = DEFAULT_NETWORK_TIMEOUT;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g_fdfs_network_timeout = DEFAULT_NETWORK_TIMEOUT;
|
||||
SF_G_NETWORK_TIMEOUT = DEFAULT_NETWORK_TIMEOUT;
|
||||
}
|
||||
|
||||
if (zend_get_configuration_directive_wrapper(ITEM_NAME_LOG_LEVEL, \
|
||||
|
|
@ -7724,7 +7724,7 @@ static int load_config_files()
|
|||
|
||||
g_use_connection_pool = true;
|
||||
result = conn_pool_init(&g_connection_pool, \
|
||||
g_fdfs_connect_timeout, \
|
||||
SF_G_CONNECT_TIMEOUT, \
|
||||
0, g_connection_pool_max_idle_time);
|
||||
if (result != 0)
|
||||
{
|
||||
|
|
@ -7737,8 +7737,8 @@ static int load_config_files()
|
|||
"anti_steal_secret_key length=%d, " \
|
||||
"tracker_group_count=%d, first tracker group server_count=%d, "\
|
||||
"use_connection_pool=%d, connection_pool_max_idle_time: %d", \
|
||||
g_fdfs_base_path, g_fdfs_connect_timeout, \
|
||||
g_fdfs_network_timeout, (int)strlen(pAntiStealSecretKey), \
|
||||
SF_G_BASE_PATH_STR, SF_G_CONNECT_TIMEOUT, \
|
||||
SF_G_NETWORK_TIMEOUT, (int)strlen(pAntiStealSecretKey), \
|
||||
config_count, g_tracker_group.server_count, \
|
||||
g_use_connection_pool, g_connection_pool_max_idle_time);
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
COMPILE = $(CC) $(CFLAGS)
|
||||
INC_PATH = -I. -Itrunk_mgr -I../common -I../tracker -I../client -Ifdht_client -I/usr/include/fastcommon
|
||||
LIB_PATH = $(LIBS) -lfastcommon
|
||||
LIB_PATH = $(LIBS) -lfastcommon -lserverframe
|
||||
TARGET_PATH = $(TARGET_PREFIX)/bin
|
||||
CONFIG_PATH = $(TARGET_CONF_PATH)
|
||||
|
||||
|
|
@ -10,7 +10,7 @@ SHARED_OBJS = ../common/fdfs_global.o ../tracker/fdfs_shared_func.o \
|
|||
../tracker/fdfs_server_id_func.o ../tracker/tracker_proto.o \
|
||||
tracker_client_thread.o storage_global.o storage_func.o \
|
||||
storage_sync_func.o storage_service.o storage_sync.o \
|
||||
storage_nio.o storage_dio.o storage_ip_changed_dealer.o \
|
||||
storage_dio.o storage_ip_changed_dealer.o \
|
||||
storage_param_getter.o storage_disk_recovery.o \
|
||||
trunk_mgr/trunk_mem.o trunk_mgr/trunk_shared.o \
|
||||
trunk_mgr/trunk_sync.o trunk_mgr/trunk_client.o \
|
||||
|
|
@ -26,6 +26,9 @@ ALL_OBJS = $(SHARED_OBJS)
|
|||
ALL_PRGS = fdfs_storaged
|
||||
|
||||
all: $(ALL_OBJS) $(ALL_PRGS)
|
||||
|
||||
$(ALL_PRGS): $(ALL_OBJS)
|
||||
|
||||
.o:
|
||||
$(COMPILE) -o $@ $< $(SHARED_OBJS) $(LIB_PATH) $(INC_PATH)
|
||||
.c:
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@
|
|||
#include "fdfs_global.h"
|
||||
#include "fastcommon/ini_file_reader.h"
|
||||
#include "fastcommon/sockopt.h"
|
||||
#include "sf/sf_service.h"
|
||||
#include "sf/sf_util.h"
|
||||
#include "tracker_types.h"
|
||||
#include "tracker_proto.h"
|
||||
#include "tracker_client_thread.h"
|
||||
|
|
@ -53,6 +55,7 @@
|
|||
#define ACCEPT_STAGE_DOING 1
|
||||
#define ACCEPT_STAGE_DONE 2
|
||||
|
||||
static bool daemon_mode = true;
|
||||
static bool bTerminateFlag = false;
|
||||
static char accept_stage = ACCEPT_STAGE_NONE;
|
||||
|
||||
|
|
@ -61,7 +64,7 @@ static void sigHupHandler(int sig);
|
|||
static void sigUsrHandler(int sig);
|
||||
static void sigAlarmHandler(int sig);
|
||||
|
||||
static int setupSchedules(pthread_t *schedule_tid);
|
||||
static int setup_schedule_tasks();
|
||||
static int setupSignalHandlers();
|
||||
|
||||
#if defined(DEBUG_FLAG)
|
||||
|
|
@ -75,20 +78,11 @@ static void sigSegvHandler(int signum, siginfo_t *info, void *ptr);
|
|||
static void sigDumpHandler(int sig);
|
||||
#endif
|
||||
|
||||
static void usage(const char *program)
|
||||
{
|
||||
fprintf(stderr, "FastDFS server v%d.%02d\n"
|
||||
"Usage: %s <config_file> [start | stop | restart]\n",
|
||||
g_fdfs_version.major, g_fdfs_version.minor,
|
||||
program);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char *conf_filename;
|
||||
const char *conf_filename;
|
||||
char *action;
|
||||
int result;
|
||||
int sock;
|
||||
int wait_count;
|
||||
pthread_t schedule_tid;
|
||||
char pidFilename[MAX_PATH_SIZE];
|
||||
|
|
@ -96,13 +90,18 @@ int main(int argc, char *argv[])
|
|||
|
||||
if (argc < 2)
|
||||
{
|
||||
usage(argv[0]);
|
||||
sf_usage(argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
g_current_time = time(NULL);
|
||||
g_up_time = g_current_time;
|
||||
conf_filename = sf_parse_daemon_mode_and_action(argc, argv,
|
||||
&g_fdfs_version, &daemon_mode, &action);
|
||||
if (conf_filename == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
g_current_time = time(NULL);
|
||||
log_init2();
|
||||
if ((result=trunk_shared_init()) != 0)
|
||||
{
|
||||
|
|
@ -110,17 +109,7 @@ int main(int argc, char *argv[])
|
|||
return result;
|
||||
}
|
||||
|
||||
conf_filename = argv[1];
|
||||
if (!fileExists(conf_filename))
|
||||
{
|
||||
if (starts_with(conf_filename, "-"))
|
||||
{
|
||||
usage(argv[0]);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if ((result=get_base_path_from_conf_file(conf_filename,
|
||||
g_fdfs_base_path, sizeof(g_fdfs_base_path))) != 0)
|
||||
if ((result=sf_get_base_path_from_conf_file(conf_filename)) != 0)
|
||||
{
|
||||
log_destroy();
|
||||
return result;
|
||||
|
|
@ -131,14 +120,14 @@ int main(int argc, char *argv[])
|
|||
log_destroy();
|
||||
return result;
|
||||
}
|
||||
|
||||
snprintf(pidFilename, sizeof(pidFilename),
|
||||
"%s/data/fdfs_storaged.pid", g_fdfs_base_path);
|
||||
action = argc >= 3 ? argv[2] : "start";
|
||||
"%s/data/fdfs_storaged.pid", SF_G_BASE_PATH_STR);
|
||||
if ((result=process_action(pidFilename, action, &stop)) != 0)
|
||||
{
|
||||
if (result == EINVAL)
|
||||
{
|
||||
usage(argv[0]);
|
||||
sf_usage(argv[0]);
|
||||
}
|
||||
log_destroy();
|
||||
return result;
|
||||
|
|
@ -159,14 +148,10 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
#endif
|
||||
|
||||
if (daemon_mode) {
|
||||
daemon_init(false);
|
||||
umask(0);
|
||||
|
||||
if ((result=write_to_pid_file(pidFilename)) != 0)
|
||||
{
|
||||
log_destroy();
|
||||
return result;
|
||||
}
|
||||
umask(0);
|
||||
|
||||
if ((result=setupSignalHandlers()) != 0)
|
||||
{
|
||||
|
|
@ -175,29 +160,21 @@ int main(int argc, char *argv[])
|
|||
return result;
|
||||
}
|
||||
|
||||
memset(g_bind_addr, 0, sizeof(g_bind_addr));
|
||||
if ((result=storage_func_init(conf_filename, \
|
||||
g_bind_addr, sizeof(g_bind_addr))) != 0)
|
||||
if ((result=storage_func_init(conf_filename)) != 0)
|
||||
{
|
||||
logCrit("exit abnormally!\n");
|
||||
delete_pid_file(pidFilename);
|
||||
log_destroy();
|
||||
return result;
|
||||
}
|
||||
|
||||
sock = socketServer(g_bind_addr, g_server_port, &result);
|
||||
if (sock < 0)
|
||||
if ((result=sf_socket_server()) != 0)
|
||||
{
|
||||
logCrit("exit abnormally!\n");
|
||||
delete_pid_file(pidFilename);
|
||||
log_destroy();
|
||||
return result;
|
||||
}
|
||||
|
||||
if ((result=tcpsetserveropt(sock, g_fdfs_network_timeout)) != 0)
|
||||
if ((result=write_to_pid_file(pidFilename)) != 0)
|
||||
{
|
||||
logCrit("exit abnormally!\n");
|
||||
delete_pid_file(pidFilename);
|
||||
log_destroy();
|
||||
return result;
|
||||
}
|
||||
|
|
@ -206,7 +183,7 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
logCrit("file: "__FILE__", line: %d, " \
|
||||
"storage_sync_init fail, program exit!", __LINE__);
|
||||
g_continue_flag = false;
|
||||
SF_G_CONTINUE_FLAG = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -214,7 +191,7 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
logCrit("file: "__FILE__", line: %d, " \
|
||||
"tracker_report_init fail, program exit!", __LINE__);
|
||||
g_continue_flag = false;
|
||||
SF_G_CONTINUE_FLAG = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -222,7 +199,7 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
logCrit("file: "__FILE__", line: %d, " \
|
||||
"storage_service_init fail, program exit!", __LINE__);
|
||||
g_continue_flag = false;
|
||||
SF_G_CONTINUE_FLAG = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -230,7 +207,7 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
logCrit("file: "__FILE__", line: %d, " \
|
||||
"set_rand_seed fail, program exit!", __LINE__);
|
||||
g_continue_flag = false;
|
||||
SF_G_CONTINUE_FLAG = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -238,7 +215,7 @@ int main(int argc, char *argv[])
|
|||
#ifdef WITH_HTTPD
|
||||
if (!g_http_params.disabled)
|
||||
{
|
||||
if ((result=storage_httpd_start(g_bind_addr)) != 0)
|
||||
if ((result=storage_httpd_start(SF_G_INNER_BIND_ADDR)) != 0)
|
||||
{
|
||||
logCrit("file: "__FILE__", line: %d, " \
|
||||
"storage_httpd_start fail, " \
|
||||
|
|
@ -253,20 +230,27 @@ int main(int argc, char *argv[])
|
|||
logCrit("file: "__FILE__", line: %d, " \
|
||||
"tracker_report_thread_start fail, " \
|
||||
"program exit!", __LINE__);
|
||||
g_continue_flag = false;
|
||||
SF_G_CONTINUE_FLAG = false;
|
||||
storage_func_destroy();
|
||||
log_destroy();
|
||||
return result;
|
||||
}
|
||||
|
||||
if ((result=setupSchedules(&schedule_tid)) != 0)
|
||||
if ((result=sf_startup_schedule(&schedule_tid)) != 0)
|
||||
{
|
||||
log_destroy();
|
||||
return result;
|
||||
}
|
||||
|
||||
if ((result=setup_schedule_tasks()) != 0)
|
||||
{
|
||||
logCrit("exit abnormally!\n");
|
||||
log_destroy();
|
||||
return result;
|
||||
}
|
||||
|
||||
if ((result=set_run_by(g_run_by_group, g_run_by_user)) != 0)
|
||||
if ((result=set_run_by(g_sf_global_vars.run_by_group,
|
||||
g_sf_global_vars.run_by_user)) != 0)
|
||||
{
|
||||
logCrit("exit abnormally!\n");
|
||||
log_destroy();
|
||||
|
|
@ -284,7 +268,7 @@ int main(int argc, char *argv[])
|
|||
bTerminateFlag = false;
|
||||
accept_stage = ACCEPT_STAGE_DOING;
|
||||
|
||||
storage_accept_loop(sock);
|
||||
sf_accept_loop();
|
||||
accept_stage = ACCEPT_STAGE_DONE;
|
||||
|
||||
fdfs_binlog_sync_func(NULL); //binlog fsync
|
||||
|
|
@ -294,17 +278,14 @@ int main(int argc, char *argv[])
|
|||
pthread_kill(schedule_tid, SIGINT);
|
||||
}
|
||||
|
||||
storage_terminate_threads();
|
||||
storage_dio_terminate();
|
||||
|
||||
kill_tracker_report_threads();
|
||||
kill_storage_sync_threads();
|
||||
|
||||
wait_count = 0;
|
||||
while (g_storage_thread_count != 0 || \
|
||||
g_dio_thread_count != 0 || \
|
||||
g_tracker_reporter_count > 0 || \
|
||||
g_schedule_flag)
|
||||
while (SF_G_ALIVE_THREAD_COUNT != 0 || g_dio_thread_count != 0 ||
|
||||
g_tracker_reporter_count > 0 || g_schedule_flag)
|
||||
{
|
||||
/*
|
||||
#if defined(DEBUG_FLAG) && defined(OS_LINUX)
|
||||
|
|
@ -350,7 +331,7 @@ static void sigQuitHandler(int sig)
|
|||
set_timer(1, 1, sigAlarmHandler);
|
||||
|
||||
bTerminateFlag = true;
|
||||
g_continue_flag = false;
|
||||
SF_G_CONTINUE_FLAG = false;
|
||||
|
||||
logCrit("file: "__FILE__", line: %d, " \
|
||||
"catch signal %d, program exiting...", \
|
||||
|
|
@ -370,18 +351,18 @@ static void sigAlarmHandler(int sig)
|
|||
logDebug("file: "__FILE__", line: %d, " \
|
||||
"signal server to quit...", __LINE__);
|
||||
|
||||
if (*g_bind_addr != '\0')
|
||||
if (*SF_G_INNER_BIND_ADDR != '\0')
|
||||
{
|
||||
strcpy(server.ip_addr, g_bind_addr);
|
||||
strcpy(server.ip_addr, SF_G_INNER_BIND_ADDR);
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(server.ip_addr, "127.0.0.1");
|
||||
}
|
||||
server.port = g_server_port;
|
||||
server.port = SF_G_INNER_PORT;
|
||||
server.sock = -1;
|
||||
|
||||
if (conn_pool_connect_server(&server, g_fdfs_connect_timeout) != 0)
|
||||
if (conn_pool_connect_server(&server, SF_G_CONNECT_TIMEOUT) != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -395,7 +376,7 @@ static void sigAlarmHandler(int sig)
|
|||
|
||||
static void sigHupHandler(int sig)
|
||||
{
|
||||
if (g_rotate_error_log)
|
||||
if (g_sf_global_vars.error_log.rotate_everyday)
|
||||
{
|
||||
g_log_context.rotate_immediately = true;
|
||||
}
|
||||
|
|
@ -429,44 +410,38 @@ static void sigDumpHandler(int sig)
|
|||
bDumpFlag = true;
|
||||
|
||||
snprintf(filename, sizeof(filename),
|
||||
"%s/logs/storage_dump.log", g_fdfs_base_path);
|
||||
"%s/logs/storage_dump.log", SF_G_BASE_PATH_STR);
|
||||
fdfs_dump_storage_global_vars_to_file(filename);
|
||||
|
||||
bDumpFlag = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int setupSchedules(pthread_t *schedule_tid)
|
||||
static int setup_schedule_tasks()
|
||||
{
|
||||
#define SCHEDULE_ENTRIES_MAX_COUNT 10
|
||||
#define SCHEDULE_ENTRIES_MAX_COUNT 8
|
||||
|
||||
ScheduleEntry scheduleEntries[SCHEDULE_ENTRIES_MAX_COUNT];
|
||||
ScheduleArray scheduleArray;
|
||||
int result;
|
||||
|
||||
scheduleArray.entries = scheduleEntries;
|
||||
scheduleArray.count = 0;
|
||||
memset(scheduleEntries, 0, sizeof(scheduleEntries));
|
||||
|
||||
INIT_SCHEDULE_ENTRY(scheduleEntries[scheduleArray.count],
|
||||
scheduleArray.count + 1, TIME_NONE, TIME_NONE, TIME_NONE,
|
||||
g_sync_log_buff_interval, log_sync_func, &g_log_context);
|
||||
scheduleArray.count++;
|
||||
|
||||
INIT_SCHEDULE_ENTRY(scheduleEntries[scheduleArray.count],
|
||||
scheduleArray.count + 1, TIME_NONE, TIME_NONE, TIME_NONE,
|
||||
sched_generate_next_id(), TIME_NONE, TIME_NONE, TIME_NONE,
|
||||
g_sync_binlog_buff_interval, fdfs_binlog_sync_func, NULL);
|
||||
scheduleArray.count++;
|
||||
|
||||
INIT_SCHEDULE_ENTRY(scheduleEntries[scheduleArray.count],
|
||||
scheduleArray.count + 1, TIME_NONE, TIME_NONE, TIME_NONE,
|
||||
sched_generate_next_id(), TIME_NONE, TIME_NONE, TIME_NONE,
|
||||
g_sync_stat_file_interval, fdfs_stat_file_sync_func, NULL);
|
||||
scheduleArray.count++;
|
||||
|
||||
if (g_if_use_trunk_file)
|
||||
{
|
||||
INIT_SCHEDULE_ENTRY(scheduleEntries[scheduleArray.count],
|
||||
scheduleArray.count + 1, TIME_NONE, TIME_NONE, TIME_NONE,
|
||||
sched_generate_next_id(), TIME_NONE, TIME_NONE, TIME_NONE,
|
||||
1, trunk_binlog_sync_func, NULL);
|
||||
scheduleArray.count++;
|
||||
}
|
||||
|
|
@ -474,63 +449,40 @@ static int setupSchedules(pthread_t *schedule_tid)
|
|||
if (g_use_access_log)
|
||||
{
|
||||
INIT_SCHEDULE_ENTRY(scheduleEntries[scheduleArray.count],
|
||||
scheduleArray.count + 1, TIME_NONE, TIME_NONE, TIME_NONE,
|
||||
g_sync_log_buff_interval, log_sync_func, &g_access_log_context);
|
||||
sched_generate_next_id(), TIME_NONE, TIME_NONE, TIME_NONE,
|
||||
g_sf_global_vars.error_log.sync_log_buff_interval,
|
||||
log_sync_func, &g_access_log_context);
|
||||
scheduleArray.count++;
|
||||
|
||||
if (g_rotate_access_log)
|
||||
{
|
||||
INIT_SCHEDULE_ENTRY_EX(scheduleEntries[scheduleArray.count],
|
||||
scheduleArray.count + 1, g_access_log_rotate_time,
|
||||
sched_generate_next_id(), g_access_log_rotate_time,
|
||||
24 * 3600, log_notify_rotate, &g_access_log_context);
|
||||
scheduleArray.count++;
|
||||
|
||||
if (g_log_file_keep_days > 0)
|
||||
if (g_sf_global_vars.error_log.keep_days > 0)
|
||||
{
|
||||
log_set_keep_days(&g_access_log_context,
|
||||
g_log_file_keep_days);
|
||||
g_sf_global_vars.error_log.keep_days);
|
||||
|
||||
INIT_SCHEDULE_ENTRY(scheduleEntries[scheduleArray.count],
|
||||
scheduleArray.count + 1, 1, 0, 0, 24 * 3600,
|
||||
sched_generate_next_id(), 1, 0, 0, 24 * 3600,
|
||||
log_delete_old_files, &g_access_log_context);
|
||||
scheduleArray.count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (g_rotate_error_log)
|
||||
{
|
||||
INIT_SCHEDULE_ENTRY_EX(scheduleEntries[scheduleArray.count],
|
||||
scheduleArray.count + 1, g_error_log_rotate_time,
|
||||
24 * 3600, log_notify_rotate, &g_log_context);
|
||||
scheduleArray.count++;
|
||||
|
||||
if (g_log_file_keep_days > 0)
|
||||
{
|
||||
log_set_keep_days(&g_log_context, g_log_file_keep_days);
|
||||
|
||||
INIT_SCHEDULE_ENTRY(scheduleEntries[scheduleArray.count],
|
||||
scheduleArray.count + 1, 1, 0, 0, 24 * 3600,
|
||||
log_delete_old_files, &g_log_context);
|
||||
scheduleArray.count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (g_compress_binlog)
|
||||
{
|
||||
INIT_SCHEDULE_ENTRY_EX(scheduleEntries[scheduleArray.count],
|
||||
scheduleArray.count + 1, g_compress_binlog_time,
|
||||
sched_generate_next_id(), g_compress_binlog_time,
|
||||
24 * 3600, fdfs_binlog_compress_func, NULL);
|
||||
scheduleArray.count++;
|
||||
}
|
||||
|
||||
if ((result=sched_start(&scheduleArray, schedule_tid,
|
||||
g_thread_stack_size, (bool * volatile)&g_continue_flag)) != 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return sched_add_entries(&scheduleArray);
|
||||
}
|
||||
|
||||
static int setupSignalHandlers()
|
||||
|
|
|
|||
|
|
@ -25,10 +25,11 @@
|
|||
#include "fastcommon/logger.h"
|
||||
#include "fastcommon/sockopt.h"
|
||||
#include "fastcommon/ioevent_loop.h"
|
||||
#include "storage_dio.h"
|
||||
#include "storage_nio.h"
|
||||
#include "sf/sf_service.h"
|
||||
#include "storage_global.h"
|
||||
#include "storage_service.h"
|
||||
#include "trunk_mem.h"
|
||||
#include "storage_dio.h"
|
||||
|
||||
static pthread_mutex_t g_dio_thread_lock;
|
||||
static struct storage_dio_context *g_dio_contexts = NULL;
|
||||
|
|
@ -55,7 +56,7 @@ int storage_dio_init()
|
|||
return result;
|
||||
}
|
||||
|
||||
if ((result=init_pthread_attr(&thread_attr, g_thread_stack_size)) != 0)
|
||||
if ((result=init_pthread_attr(&thread_attr, SF_G_THREAD_STACK_SIZE)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"init_pthread_attr fail, program exit!", __LINE__);
|
||||
|
|
@ -153,10 +154,10 @@ int storage_dio_queue_push(struct fast_task_info *pTask)
|
|||
pClientInfo = (StorageClientInfo *)pTask->arg;
|
||||
pFileContext = &(pClientInfo->file_context);
|
||||
pContext = g_dio_contexts + pFileContext->dio_thread_index;
|
||||
|
||||
pClientInfo->stage |= FDFS_STORAGE_STAGE_DIO_THREAD;
|
||||
sf_hold_task(pTask);
|
||||
if ((result=blocked_queue_push(&(pContext->queue), pTask)) != 0)
|
||||
{
|
||||
sf_release_task(pTask);
|
||||
ioevent_add_to_deleted_list(pTask);
|
||||
return result;
|
||||
}
|
||||
|
|
@ -246,7 +247,7 @@ int dio_discard_file(struct fast_task_info *pTask)
|
|||
else
|
||||
{
|
||||
pFileContext->buff_offset = 0;
|
||||
pFileContext->continue_callback(pTask);
|
||||
pFileContext->continue_callback(pTask, SF_NIO_STAGE_RECV);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -370,7 +371,7 @@ int dio_read_file(struct fast_task_info *pTask)
|
|||
|
||||
if (pFileContext->offset < pFileContext->end)
|
||||
{
|
||||
pFileContext->continue_callback(pTask);
|
||||
pFileContext->continue_callback(pTask, SF_NIO_STAGE_SEND);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -479,15 +480,16 @@ int dio_write_file(struct fast_task_info *pTask)
|
|||
}
|
||||
|
||||
/*
|
||||
logInfo("###dio write bytes: %d, pTask->length=%d, buff_offset=%d", \
|
||||
write_bytes, pTask->length, pFileContext->buff_offset);
|
||||
logInfo("###dio fd: %d, write bytes: %d, pTask->length=%d, "
|
||||
"buff_offset=%d", pFileContext->fd, write_bytes,
|
||||
pTask->length, pFileContext->buff_offset);
|
||||
*/
|
||||
|
||||
pFileContext->offset += write_bytes;
|
||||
if (pFileContext->offset < pFileContext->end)
|
||||
{
|
||||
pFileContext->buff_offset = 0;
|
||||
pFileContext->continue_callback(pTask);
|
||||
pFileContext->continue_callback(pTask, SF_NIO_STAGE_RECV);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -741,11 +743,12 @@ static void *dio_thread_entrance(void* arg)
|
|||
struct fast_task_info *pTask;
|
||||
|
||||
pContext = (struct storage_dio_context *)arg;
|
||||
while (g_continue_flag)
|
||||
while (SF_G_CONTINUE_FLAG)
|
||||
{
|
||||
while ((pTask=blocked_queue_pop(&(pContext->queue))) != NULL)
|
||||
{
|
||||
((StorageClientInfo *)pTask->arg)->deal_func(pTask);
|
||||
sf_release_task(pTask);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ static int storage_do_fetch_binlog(ConnectionInfo *pSrcStorage, \
|
|||
store_path_index;
|
||||
|
||||
if((result=tcpsenddata_nb(pSrcStorage->sock, out_buff,
|
||||
sizeof(out_buff), g_fdfs_network_timeout)) != 0)
|
||||
sizeof(out_buff), SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"storage server %s:%d, send data fail, "
|
||||
|
|
@ -150,9 +150,9 @@ static int storage_do_fetch_binlog(ConnectionInfo *pSrcStorage, \
|
|||
return result;
|
||||
}
|
||||
|
||||
if (g_fdfs_network_timeout >= 600)
|
||||
if (SF_G_NETWORK_TIMEOUT >= 600)
|
||||
{
|
||||
network_timeout = g_fdfs_network_timeout;
|
||||
network_timeout = SF_G_NETWORK_TIMEOUT;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -204,7 +204,7 @@ static int recovery_get_src_storage_server(ConnectionInfo *pSrcStorage)
|
|||
logDebug("file: "__FILE__", line: %d, " \
|
||||
"disk recovery: get source storage server", \
|
||||
__LINE__);
|
||||
while (g_continue_flag)
|
||||
while (SF_G_CONTINUE_FLAG)
|
||||
{
|
||||
result = tracker_get_storage_max_status(&g_tracker_group,
|
||||
g_group_name, g_tracker_client_ip.ips[0].address,
|
||||
|
|
@ -248,7 +248,7 @@ static int recovery_get_src_storage_server(ConnectionInfo *pSrcStorage)
|
|||
}
|
||||
|
||||
found = false;
|
||||
while (g_continue_flag)
|
||||
while (SF_G_CONTINUE_FLAG)
|
||||
{
|
||||
if ((pTrackerConn=tracker_get_connection_r(&trackerServer, \
|
||||
&result)) == NULL)
|
||||
|
|
@ -351,7 +351,7 @@ static int recovery_get_src_storage_server(ConnectionInfo *pSrcStorage)
|
|||
sleep(5);
|
||||
}
|
||||
|
||||
if (!g_continue_flag)
|
||||
if (!SF_G_CONTINUE_FLAG)
|
||||
{
|
||||
return EINTR;
|
||||
}
|
||||
|
|
@ -757,7 +757,7 @@ static int storage_do_recovery(RecoveryThreadData *pThreadData,
|
|||
continue;
|
||||
}
|
||||
|
||||
while (g_continue_flag)
|
||||
while (SF_G_CONTINUE_FLAG)
|
||||
{
|
||||
result = storage_binlog_read(pReader, &record, &record_length);
|
||||
if (result != 0)
|
||||
|
|
@ -893,7 +893,7 @@ static int storage_do_recovery(RecoveryThreadData *pThreadData,
|
|||
tracker_close_connection_ex(pStorageConn, result != 0);
|
||||
recovery_write_to_mark_file(pReader);
|
||||
|
||||
if (!g_continue_flag)
|
||||
if (!SF_G_CONTINUE_FLAG)
|
||||
{
|
||||
bContinueFlag = false;
|
||||
}
|
||||
|
|
@ -931,7 +931,7 @@ static int storage_do_recovery(RecoveryThreadData *pThreadData,
|
|||
pSrcStorage->port, pThreadData->base_path);
|
||||
}
|
||||
|
||||
return g_continue_flag ? result :EINTR;
|
||||
return SF_G_CONTINUE_FLAG ? result :EINTR;
|
||||
}
|
||||
|
||||
static void *storage_disk_recovery_restore_entrance(void *arg)
|
||||
|
|
@ -1111,7 +1111,7 @@ static int do_dispatch_binlog_for_threads(const char *pBasePath)
|
|||
break;
|
||||
}
|
||||
|
||||
while (g_continue_flag)
|
||||
while (SF_G_CONTINUE_FLAG)
|
||||
{
|
||||
result = storage_binlog_read(&reader, &record, &record_length);
|
||||
if (result != 0)
|
||||
|
|
@ -1326,7 +1326,7 @@ static int storage_disk_recovery_do_restore(const char *pBasePath)
|
|||
thread_count = g_disk_recovery_threads;
|
||||
if ((result=create_work_threads(&thread_count,
|
||||
storage_disk_recovery_restore_entrance,
|
||||
args, recovery_tids, g_thread_stack_size)) != 0)
|
||||
args, recovery_tids, SF_G_THREAD_STACK_SIZE)) != 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
|
@ -1334,7 +1334,7 @@ static int storage_disk_recovery_do_restore(const char *pBasePath)
|
|||
do
|
||||
{
|
||||
sleep(5);
|
||||
} while (g_continue_flag && __sync_fetch_and_add(
|
||||
} while (SF_G_CONTINUE_FLAG && __sync_fetch_and_add(
|
||||
¤t_recovery_thread_count, 0) > 0);
|
||||
|
||||
if (__sync_fetch_and_add(¤t_recovery_thread_count, 0) > 0)
|
||||
|
|
@ -1376,12 +1376,12 @@ static int storage_disk_recovery_do_restore(const char *pBasePath)
|
|||
free(args);
|
||||
free(recovery_tids);
|
||||
|
||||
if (!g_continue_flag)
|
||||
if (!SF_G_CONTINUE_FLAG)
|
||||
{
|
||||
return EINTR;
|
||||
}
|
||||
|
||||
while (g_continue_flag)
|
||||
while (SF_G_CONTINUE_FLAG)
|
||||
{
|
||||
if (storage_report_storage_status(g_my_server_id_str,
|
||||
g_tracker_client_ip.ips[0].address,
|
||||
|
|
@ -1393,7 +1393,7 @@ static int storage_disk_recovery_do_restore(const char *pBasePath)
|
|||
sleep(5);
|
||||
}
|
||||
|
||||
if (!g_continue_flag)
|
||||
if (!SF_G_CONTINUE_FLAG)
|
||||
{
|
||||
return EINTR;
|
||||
}
|
||||
|
|
@ -1562,7 +1562,7 @@ static int storage_do_split_trunk_binlog(const int store_path_index,
|
|||
memset(&trunk_info, 0, sizeof(trunk_info));
|
||||
memset(&trunkFileId, 0, sizeof(trunkFileId));
|
||||
result = 0;
|
||||
while (g_continue_flag)
|
||||
while (SF_G_CONTINUE_FLAG)
|
||||
{
|
||||
result=storage_binlog_read(pReader, &record, &record_length);
|
||||
if (result != 0)
|
||||
|
|
@ -1646,7 +1646,7 @@ static int storage_do_split_trunk_binlog(const int store_path_index,
|
|||
|
||||
avl_tree_destroy(&tree_unique_trunks);
|
||||
fclose(fp);
|
||||
if (!g_continue_flag)
|
||||
if (!SF_G_CONTINUE_FLAG)
|
||||
{
|
||||
return EINTR;
|
||||
}
|
||||
|
|
@ -1728,7 +1728,7 @@ int storage_disk_recovery_prepare(const int store_path_index)
|
|||
}
|
||||
}
|
||||
|
||||
while (g_continue_flag)
|
||||
while (SF_G_CONTINUE_FLAG)
|
||||
{
|
||||
if (storage_report_storage_status(g_my_server_id_str, \
|
||||
g_tracker_client_ip.ips[0].address,
|
||||
|
|
@ -1738,7 +1738,7 @@ int storage_disk_recovery_prepare(const int store_path_index)
|
|||
}
|
||||
}
|
||||
|
||||
if (!g_continue_flag)
|
||||
if (!SF_G_CONTINUE_FLAG)
|
||||
{
|
||||
return EINTR;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,17 +42,16 @@ static int fdfs_dump_global_vars(char *buff, const int buffSize)
|
|||
last_storage_ip_str, sizeof(last_storage_ip_str));
|
||||
|
||||
total_len = snprintf(buff, buffSize,
|
||||
"g_fdfs_connect_timeout=%ds\n"
|
||||
"g_fdfs_network_timeout=%ds\n"
|
||||
"g_fdfs_base_path=%s\n"
|
||||
"SF_G_CONNECT_TIMEOUT=%ds\n"
|
||||
"SF_G_NETWORK_TIMEOUT=%ds\n"
|
||||
"SF_G_BASE_PATH_STR=%s\n"
|
||||
"g_fdfs_version=%d.%02d\n"
|
||||
"g_continue_flag=%d\n"
|
||||
"SF_G_CONTINUE_FLAG=%d\n"
|
||||
"g_schedule_flag=%d\n"
|
||||
"g_server_port=%d\n"
|
||||
"SF_G_INNER_PORT=%d\n"
|
||||
"g_max_connections=%d\n"
|
||||
"g_storage_thread_count=%d\n"
|
||||
"g_group_name=%s\n"
|
||||
"g_sync_log_buff_interval=%d\n"
|
||||
"g_subdir_count_per_path=%d\n"
|
||||
"g_http_port=%d\n"
|
||||
"g_last_server_port=%d\n"
|
||||
|
|
@ -94,11 +93,11 @@ 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"
|
||||
"g_bind_addr=%s\n"
|
||||
"SF_G_INNER_BIND_ADDR=%s\n"
|
||||
"g_client_bind_addr=%d\n"
|
||||
"g_storage_ip_changed_auto_adjust=%d\n"
|
||||
"g_thread_kill_done=%d\n"
|
||||
"g_thread_stack_size=%d\n"
|
||||
"SF_G_THREAD_STACK_SIZE=%d\n"
|
||||
"g_upload_priority=%d\n"
|
||||
"g_up_time=%s\n"
|
||||
"g_if_alias_prefix=%s\n"
|
||||
|
|
@ -136,24 +135,23 @@ static int fdfs_dump_global_vars(char *buff, const int buffSize)
|
|||
#if defined(DEBUG_FLAG) && defined(OS_LINUX)
|
||||
"g_exe_name=%s\n"
|
||||
#endif
|
||||
, g_fdfs_connect_timeout
|
||||
, g_fdfs_network_timeout
|
||||
, g_fdfs_base_path
|
||||
, SF_G_CONNECT_TIMEOUT
|
||||
, SF_G_NETWORK_TIMEOUT
|
||||
, SF_G_BASE_PATH_STR
|
||||
, g_fdfs_version.major, g_fdfs_version.minor
|
||||
, g_continue_flag
|
||||
, SF_G_CONTINUE_FLAG
|
||||
, g_schedule_flag
|
||||
, g_server_port
|
||||
, g_max_connections
|
||||
, g_storage_thread_count
|
||||
, SF_G_INNER_PORT
|
||||
, g_sf_global_vars.max_connections
|
||||
, SF_G_ALIVE_THREAD_COUNT
|
||||
, g_group_name
|
||||
, g_sync_log_buff_interval
|
||||
, g_subdir_count_per_path
|
||||
, g_http_port
|
||||
, g_last_server_port
|
||||
, g_last_http_port
|
||||
, g_allow_ip_count
|
||||
, g_run_by_group
|
||||
, g_run_by_user
|
||||
, g_sf_global_vars.run_by_group
|
||||
, g_sf_global_vars.run_by_user
|
||||
, g_http_domain
|
||||
, g_file_distribute_path_mode
|
||||
, g_file_distribute_rotate_count
|
||||
|
|
@ -174,7 +172,7 @@ static int fdfs_dump_global_vars(char *buff, const int buffSize)
|
|||
, g_sync_start_time.hour, g_sync_start_time.minute
|
||||
, g_sync_end_time.hour, g_sync_end_time.minute
|
||||
, g_sync_part_time
|
||||
, g_sync_log_buff_interval
|
||||
, g_sf_global_vars.error_log.sync_log_buff_interval
|
||||
, g_sync_binlog_buff_interval
|
||||
, g_write_mark_file_freq
|
||||
, g_sync_stat_file_interval
|
||||
|
|
@ -190,13 +188,13 @@ static int fdfs_dump_global_vars(char *buff, const int buffSize)
|
|||
, g_check_file_duplicate
|
||||
, g_key_namespace
|
||||
, g_namespace_len
|
||||
, g_bind_addr
|
||||
, SF_G_INNER_BIND_ADDR
|
||||
, g_client_bind_addr
|
||||
, g_storage_ip_changed_auto_adjust
|
||||
, g_thread_kill_done
|
||||
, g_thread_stack_size
|
||||
, SF_G_THREAD_STACK_SIZE
|
||||
, g_upload_priority
|
||||
, formatDatetime(g_up_time, "%Y-%m-%d %H:%M:%S",
|
||||
, formatDatetime(g_sf_global_vars.up_time, "%Y-%m-%d %H:%M:%S",
|
||||
szUptime, sizeof(szUptime))
|
||||
, g_if_alias_prefix
|
||||
, g_binlog_fd
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
#include "fastcommon/sched_thread.h"
|
||||
#include "fastcommon/ini_file_reader.h"
|
||||
#include "fastcommon/connection_pool.h"
|
||||
#include "sf/sf_service.h"
|
||||
#include "tracker_types.h"
|
||||
#include "tracker_proto.h"
|
||||
#include "fdfs_shared_func.h"
|
||||
|
|
@ -148,10 +149,10 @@ static int storage_do_get_group_name(ConnectionInfo *pTrackerServer)
|
|||
pHeader = (TrackerHeader *)out_buff;
|
||||
memset(out_buff, 0, sizeof(out_buff));
|
||||
long2buff(4, pHeader->pkg_len);
|
||||
int2buff(g_server_port, out_buff + sizeof(TrackerHeader));
|
||||
int2buff(SF_G_INNER_PORT, out_buff + sizeof(TrackerHeader));
|
||||
pHeader->cmd = TRACKER_PROTO_CMD_STORAGE_GET_GROUP_NAME;
|
||||
if ((result=tcpsenddata_nb(pTrackerServer->sock, out_buff, \
|
||||
sizeof(out_buff), g_fdfs_network_timeout)) != 0)
|
||||
sizeof(out_buff), SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"tracker server %s:%d, send data fail, " \
|
||||
|
|
@ -285,7 +286,7 @@ static char *get_storage_stat_filename(const void *pArg, char *full_filename)
|
|||
}
|
||||
|
||||
snprintf(full_filename, MAX_PATH_SIZE, \
|
||||
"%s/data/%s", g_fdfs_base_path, STORAGE_STAT_FILENAME);
|
||||
"%s/data/%s", SF_G_BASE_PATH_STR, STORAGE_STAT_FILENAME);
|
||||
return full_filename;
|
||||
}
|
||||
|
||||
|
|
@ -472,7 +473,7 @@ static int storage_open_stat_file()
|
|||
return result;
|
||||
}
|
||||
|
||||
STORAGE_FCHOWN(storage_stat_fd, full_filename, geteuid(), getegid())
|
||||
SF_FCHOWN_TO_RUNBY_RETURN_ON_ERROR(storage_stat_fd, full_filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -648,7 +649,7 @@ int storage_write_to_sync_ini_file()
|
|||
int i;
|
||||
|
||||
snprintf(full_filename, sizeof(full_filename),
|
||||
"%s/data/%s", g_fdfs_base_path, DATA_DIR_INITED_FILENAME);
|
||||
"%s/data/%s", SF_G_BASE_PATH_STR, DATA_DIR_INITED_FILENAME);
|
||||
|
||||
fdfs_multi_ips_to_string(&g_tracker_client_ip,
|
||||
ip_str, sizeof(ip_str));
|
||||
|
|
@ -693,7 +694,7 @@ int storage_write_to_sync_ini_file()
|
|||
return result;
|
||||
}
|
||||
|
||||
STORAGE_CHOWN(full_filename, geteuid(), getegid())
|
||||
SF_CHOWN_TO_RUNBY_RETURN_ON_ERROR(full_filename);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -702,7 +703,7 @@ int storage_check_and_make_global_data_path()
|
|||
{
|
||||
char data_path[MAX_PATH_SIZE];
|
||||
snprintf(data_path, sizeof(data_path), "%s/data",
|
||||
g_fdfs_base_path);
|
||||
SF_G_BASE_PATH_STR);
|
||||
if (!fileExists(data_path))
|
||||
{
|
||||
if (mkdir(data_path, 0755) != 0)
|
||||
|
|
@ -715,7 +716,7 @@ int storage_check_and_make_global_data_path()
|
|||
return errno != 0 ? errno : EPERM;
|
||||
}
|
||||
|
||||
STORAGE_CHOWN(data_path, geteuid(), getegid())
|
||||
SF_CHOWN_TO_RUNBY_RETURN_ON_ERROR(data_path);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -775,7 +776,7 @@ static int storage_generate_store_path_mark(const int store_path_index)
|
|||
|
||||
memset(&mark_info, 0, sizeof(FDFSStorePathMarkInfo));
|
||||
strcpy(mark_info.ip_addr, g_tracker_client_ip.ips[0].address);
|
||||
mark_info.port = g_server_port;
|
||||
mark_info.port = SF_G_INNER_PORT;
|
||||
mark_info.store_path_index = store_path_index;
|
||||
mark_info.create_time = g_current_time;
|
||||
|
||||
|
|
@ -982,7 +983,7 @@ static int storage_check_and_make_data_dirs()
|
|||
bool pathCreated;
|
||||
|
||||
snprintf(data_path, sizeof(data_path), "%s/data",
|
||||
g_fdfs_base_path);
|
||||
SF_G_BASE_PATH_STR);
|
||||
snprintf(full_filename, sizeof(full_filename), "%s/%s",
|
||||
data_path, DATA_DIR_INITED_FILENAME);
|
||||
if (fileExists(full_filename))
|
||||
|
|
@ -1086,7 +1087,7 @@ static int storage_check_and_make_data_dirs()
|
|||
{
|
||||
if (g_last_server_port == 0)
|
||||
{
|
||||
g_last_server_port = g_server_port;
|
||||
g_last_server_port = SF_G_INNER_PORT;
|
||||
}
|
||||
|
||||
if (g_last_http_port == 0)
|
||||
|
|
@ -1121,7 +1122,7 @@ static int storage_check_and_make_data_dirs()
|
|||
{
|
||||
return result;
|
||||
}
|
||||
g_last_server_port = g_server_port;
|
||||
g_last_server_port = SF_G_INNER_PORT;
|
||||
g_last_http_port = g_http_port;
|
||||
g_storage_join_time = g_current_time;
|
||||
if ((result=storage_write_to_sync_ini_file()) != 0)
|
||||
|
|
@ -1200,7 +1201,7 @@ static int storage_make_data_dirs(const char *pBasePath, bool *pathCreated)
|
|||
return errno != 0 ? errno : EPERM;
|
||||
}
|
||||
|
||||
STORAGE_CHOWN(data_path, current_uid, current_gid)
|
||||
SF_CHOWN_RETURN_ON_ERROR(data_path, current_uid, current_gid);
|
||||
}
|
||||
|
||||
if (chdir(data_path) != 0)
|
||||
|
|
@ -1241,7 +1242,7 @@ static int storage_make_data_dirs(const char *pBasePath, bool *pathCreated)
|
|||
}
|
||||
}
|
||||
|
||||
STORAGE_CHOWN(dir_name, current_uid, current_gid)
|
||||
SF_CHOWN_RETURN_ON_ERROR(dir_name, current_uid, current_gid);
|
||||
|
||||
if (chdir(dir_name) != 0)
|
||||
{
|
||||
|
|
@ -1270,7 +1271,7 @@ static int storage_make_data_dirs(const char *pBasePath, bool *pathCreated)
|
|||
}
|
||||
}
|
||||
|
||||
STORAGE_CHOWN(sub_name, current_uid, current_gid)
|
||||
SF_CHOWN_RETURN_ON_ERROR(sub_name, current_uid, current_gid);
|
||||
}
|
||||
|
||||
if (chdir("..") != 0)
|
||||
|
|
@ -1400,27 +1401,22 @@ static int init_my_result_per_tracker()
|
|||
return 0;
|
||||
}
|
||||
|
||||
int storage_func_init(const char *filename, \
|
||||
char *bind_addr, const int addr_size)
|
||||
int storage_func_init(const char *filename)
|
||||
{
|
||||
char *pBindAddr;
|
||||
const int task_buffer_extra_size = 0;
|
||||
const bool need_set_run_by = false;
|
||||
char *pGroupName;
|
||||
char *pRunByGroup;
|
||||
char *pRunByUser;
|
||||
char *pFsyncAfterWrittenBytes;
|
||||
char *pThreadStackSize;
|
||||
char *pBuffSize;
|
||||
char *pIfAliasPrefix;
|
||||
char *pHttpDomain;
|
||||
char *pRotateAccessLogSize;
|
||||
char *pRotateErrorLogSize;
|
||||
IniContext iniContext;
|
||||
SFContextIniConfig config;
|
||||
int result;
|
||||
int64_t fsync_after_written_bytes;
|
||||
int64_t thread_stack_size;
|
||||
int64_t buff_size;
|
||||
int64_t rotate_access_log_size;
|
||||
int64_t rotate_error_log_size;
|
||||
char sz_global_config[512];
|
||||
char sz_service_config[128];
|
||||
|
||||
if ((result=iniLoadFromFile(filename, &iniContext)) != 0)
|
||||
{
|
||||
|
|
@ -1441,6 +1437,18 @@ int storage_func_init(const char *filename, \
|
|||
break;
|
||||
}
|
||||
|
||||
sf_set_current_time();
|
||||
|
||||
SF_SET_CONTEXT_INI_CONFIG_EX(config, filename, &iniContext,
|
||||
NULL, FDFS_STORAGE_SERVER_DEF_PORT,
|
||||
FDFS_STORAGE_SERVER_DEF_PORT, DEFAULT_WORK_THREADS,
|
||||
"buff_size");
|
||||
if ((result=sf_load_config_ex("storaged", &config,
|
||||
task_buffer_extra_size, need_set_run_by)) != 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
g_subdir_count_per_path=iniGetIntValue(NULL, \
|
||||
"subdir_count_per_path", &iniContext, \
|
||||
DEFAULT_DATA_DIR_COUNT_PER_PATH);
|
||||
|
|
@ -1460,31 +1468,31 @@ int storage_func_init(const char *filename, \
|
|||
}
|
||||
|
||||
load_log_level(&iniContext);
|
||||
if ((result=log_set_prefix(g_fdfs_base_path, \
|
||||
if ((result=log_set_prefix(SF_G_BASE_PATH_STR, \
|
||||
STORAGE_ERROR_LOG_FILENAME)) != 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
g_fdfs_connect_timeout = iniGetIntValue(NULL, "connect_timeout", \
|
||||
SF_G_CONNECT_TIMEOUT = iniGetIntValue(NULL, "connect_timeout", \
|
||||
&iniContext, DEFAULT_CONNECT_TIMEOUT);
|
||||
if (g_fdfs_connect_timeout <= 0)
|
||||
if (SF_G_CONNECT_TIMEOUT <= 0)
|
||||
{
|
||||
g_fdfs_connect_timeout = DEFAULT_CONNECT_TIMEOUT;
|
||||
SF_G_CONNECT_TIMEOUT = DEFAULT_CONNECT_TIMEOUT;
|
||||
}
|
||||
|
||||
g_fdfs_network_timeout = iniGetIntValue(NULL, "network_timeout", \
|
||||
SF_G_NETWORK_TIMEOUT = iniGetIntValue(NULL, "network_timeout", \
|
||||
&iniContext, DEFAULT_NETWORK_TIMEOUT);
|
||||
if (g_fdfs_network_timeout <= 0)
|
||||
if (SF_G_NETWORK_TIMEOUT <= 0)
|
||||
{
|
||||
g_fdfs_network_timeout = DEFAULT_NETWORK_TIMEOUT;
|
||||
SF_G_NETWORK_TIMEOUT = DEFAULT_NETWORK_TIMEOUT;
|
||||
}
|
||||
|
||||
g_server_port = iniGetIntValue(NULL, "port", &iniContext, \
|
||||
SF_G_INNER_PORT = iniGetIntValue(NULL, "port", &iniContext, \
|
||||
FDFS_STORAGE_SERVER_DEF_PORT);
|
||||
if (g_server_port <= 0)
|
||||
if (SF_G_INNER_PORT <= 0)
|
||||
{
|
||||
g_server_port = FDFS_STORAGE_SERVER_DEF_PORT;
|
||||
SF_G_INNER_PORT = FDFS_STORAGE_SERVER_DEF_PORT;
|
||||
}
|
||||
|
||||
g_heart_beat_interval = iniGetIntValue(NULL, \
|
||||
|
|
@ -1503,16 +1511,6 @@ int storage_func_init(const char *filename, \
|
|||
g_stat_report_interval = STORAGE_REPORT_DEF_INTERVAL;
|
||||
}
|
||||
|
||||
pBindAddr = iniGetStrValue(NULL, "bind_addr", &iniContext);
|
||||
if (pBindAddr == NULL)
|
||||
{
|
||||
*bind_addr = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(bind_addr, addr_size, "%s", pBindAddr);
|
||||
}
|
||||
|
||||
g_client_bind_addr = iniGetBoolValue(NULL, "client_bind", \
|
||||
&iniContext, true);
|
||||
|
||||
|
|
@ -1604,60 +1602,13 @@ int storage_func_init(const char *filename, \
|
|||
(g_sync_end_time.hour == 23 && \
|
||||
g_sync_end_time.minute == 59));
|
||||
|
||||
g_max_connections = iniGetIntValue(NULL, "max_connections", \
|
||||
&iniContext, DEFAULT_MAX_CONNECTONS);
|
||||
if (g_max_connections <= 0)
|
||||
{
|
||||
g_max_connections = DEFAULT_MAX_CONNECTONS;
|
||||
}
|
||||
if ((result=set_rlimit(RLIMIT_NOFILE, g_max_connections)) != 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
g_accept_threads = iniGetIntValue(NULL, "accept_threads", \
|
||||
&iniContext, 1);
|
||||
if (g_accept_threads <= 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"item \"accept_threads\" is invalid, " \
|
||||
"value: %d <= 0!", __LINE__, g_accept_threads);
|
||||
result = EINVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
g_work_threads = iniGetIntValue(NULL, "work_threads", \
|
||||
&iniContext, DEFAULT_WORK_THREADS);
|
||||
if (g_work_threads <= 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"item \"work_threads\" is invalid, " \
|
||||
"value: %d <= 0!", __LINE__, g_work_threads);
|
||||
result = EINVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
pBuffSize = iniGetStrValue(NULL, \
|
||||
"buff_size", &iniContext);
|
||||
if (pBuffSize == NULL)
|
||||
{
|
||||
buff_size = STORAGE_DEFAULT_BUFF_SIZE;
|
||||
}
|
||||
else if ((result=parse_bytes(pBuffSize, 1, &buff_size)) != 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
g_buff_size = buff_size;
|
||||
if (g_buff_size < 4 * 1024 || \
|
||||
g_buff_size < sizeof(TrackerHeader) + \
|
||||
if (g_sf_global_vars.min_buff_size < sizeof(TrackerHeader) +
|
||||
TRUNK_BINLOG_BUFFER_SIZE)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"item \"buff_size\" is too small, " \
|
||||
"value: %d < %d or < %d!", __LINE__, \
|
||||
g_buff_size, 4 * 1024, \
|
||||
(int)sizeof(TrackerHeader) + \
|
||||
TRUNK_BINLOG_BUFFER_SIZE);
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"item \"buff_size\" is too small, value: %d < %d!",
|
||||
__LINE__, g_sf_global_vars.min_buff_size,
|
||||
(int)sizeof(TrackerHeader) + TRUNK_BINLOG_BUFFER_SIZE);
|
||||
result = EINVAL;
|
||||
break;
|
||||
}
|
||||
|
|
@ -1733,75 +1684,6 @@ int storage_func_init(const char *filename, \
|
|||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
g_disk_rw_direct = iniGetBoolValue(NULL, \
|
||||
"disk_rw_direct", &iniContext, false);
|
||||
*/
|
||||
|
||||
pRunByGroup = iniGetStrValue(NULL, "run_by_group", &iniContext);
|
||||
pRunByUser = iniGetStrValue(NULL, "run_by_user", &iniContext);
|
||||
if (pRunByGroup == NULL)
|
||||
{
|
||||
*g_run_by_group = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(g_run_by_group, sizeof(g_run_by_group), \
|
||||
"%s", pRunByGroup);
|
||||
}
|
||||
if (*g_run_by_group == '\0')
|
||||
{
|
||||
g_run_by_gid = getegid();
|
||||
}
|
||||
else
|
||||
{
|
||||
struct group *pGroup;
|
||||
|
||||
pGroup = getgrnam(g_run_by_group);
|
||||
if (pGroup == NULL)
|
||||
{
|
||||
result = errno != 0 ? errno : ENOENT;
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"getgrnam fail, errno: %d, " \
|
||||
"error info: %s", __LINE__, \
|
||||
result, STRERROR(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
g_run_by_gid = pGroup->gr_gid;
|
||||
}
|
||||
|
||||
if (pRunByUser == NULL)
|
||||
{
|
||||
*g_run_by_user = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(g_run_by_user, sizeof(g_run_by_user), \
|
||||
"%s", pRunByUser);
|
||||
}
|
||||
if (*g_run_by_user == '\0')
|
||||
{
|
||||
g_run_by_uid = geteuid();
|
||||
}
|
||||
else
|
||||
{
|
||||
struct passwd *pUser;
|
||||
|
||||
pUser = getpwnam(g_run_by_user);
|
||||
if (pUser == NULL)
|
||||
{
|
||||
result = errno != 0 ? errno : ENOENT;
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"getpwnam fail, errno: %d, " \
|
||||
"error info: %s", __LINE__, \
|
||||
result, STRERROR(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
g_run_by_uid = pUser->pw_uid;
|
||||
}
|
||||
|
||||
if ((result=load_allow_hosts(&iniContext, \
|
||||
&g_allow_ip_addrs, &g_allow_ip_count)) != 0)
|
||||
{
|
||||
|
|
@ -1833,14 +1715,6 @@ int storage_func_init(const char *filename, \
|
|||
}
|
||||
g_fsync_after_written_bytes = fsync_after_written_bytes;
|
||||
|
||||
g_sync_log_buff_interval = iniGetIntValue(NULL, \
|
||||
"sync_log_buff_interval", &iniContext, \
|
||||
SYNC_LOG_BUFF_DEF_INTERVAL);
|
||||
if (g_sync_log_buff_interval <= 0)
|
||||
{
|
||||
g_sync_log_buff_interval = SYNC_LOG_BUFF_DEF_INTERVAL;
|
||||
}
|
||||
|
||||
g_sync_binlog_buff_interval = iniGetIntValue(NULL, \
|
||||
"sync_binlog_buff_interval", &iniContext,\
|
||||
SYNC_BINLOG_BUFF_DEF_INTERVAL);
|
||||
|
|
@ -1866,24 +1740,11 @@ int storage_func_init(const char *filename, \
|
|||
g_sync_stat_file_interval=DEFAULT_SYNC_STAT_FILE_INTERVAL;
|
||||
}
|
||||
|
||||
pThreadStackSize = iniGetStrValue(NULL, \
|
||||
"thread_stack_size", &iniContext);
|
||||
if (pThreadStackSize == NULL)
|
||||
{
|
||||
thread_stack_size = 512 * 1024;
|
||||
}
|
||||
else if ((result=parse_bytes(pThreadStackSize, 1, \
|
||||
&thread_stack_size)) != 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
g_thread_stack_size = (int)thread_stack_size;
|
||||
|
||||
if (g_thread_stack_size < FAST_WRITE_BUFF_SIZE + 64 * 1024)
|
||||
if (SF_G_THREAD_STACK_SIZE < FAST_WRITE_BUFF_SIZE + 64 * 1024)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"item \"thread_stack_size\" %d is invalid, " \
|
||||
"which < %d", __LINE__, g_thread_stack_size, \
|
||||
"which < %d", __LINE__, SF_G_THREAD_STACK_SIZE, \
|
||||
FAST_WRITE_BUFF_SIZE + 64 * 1024);
|
||||
result = EINVAL;
|
||||
break;
|
||||
|
|
@ -1926,9 +1787,9 @@ int storage_func_init(const char *filename, \
|
|||
STORAGE_FILE_SIGNATURE_METHOD_HASH;
|
||||
}
|
||||
|
||||
strcpy(g_fdht_base_path, g_fdfs_base_path);
|
||||
g_fdht_connect_timeout = g_fdfs_connect_timeout;
|
||||
g_fdht_network_timeout = g_fdfs_network_timeout;
|
||||
strcpy(g_fdht_base_path, SF_G_BASE_PATH_STR);
|
||||
g_fdht_connect_timeout = SF_G_CONNECT_TIMEOUT;
|
||||
g_fdht_network_timeout = SF_G_NETWORK_TIMEOUT;
|
||||
|
||||
pKeyNamespace = iniGetStrValue(NULL, \
|
||||
"key_namespace", &iniContext);
|
||||
|
|
@ -1996,7 +1857,7 @@ int storage_func_init(const char *filename, \
|
|||
LOG_TIME_PRECISION_MSECOND);
|
||||
log_set_cache_ex(&g_access_log_context, true);
|
||||
result = log_set_prefix_ex(&g_access_log_context, \
|
||||
g_fdfs_base_path, "storage_access");
|
||||
SF_G_BASE_PATH_STR, "storage_access");
|
||||
if (result != 0)
|
||||
{
|
||||
break;
|
||||
|
|
@ -2013,23 +1874,10 @@ int storage_func_init(const char *filename, \
|
|||
break;
|
||||
}
|
||||
|
||||
g_rotate_error_log = iniGetBoolValue(NULL, "rotate_error_log",\
|
||||
&iniContext, false);
|
||||
g_compress_old_access_log = iniGetBoolValue(NULL, "compress_old_access_log",
|
||||
&iniContext, false);
|
||||
g_compress_old_error_log = iniGetBoolValue(NULL, "compress_old_error_log",
|
||||
&iniContext, false);
|
||||
g_compress_error_log_days_before = iniGetIntValue(NULL,
|
||||
"compress_error_log_days_before", &iniContext, 1);
|
||||
g_compress_old_access_log = iniGetBoolValue(NULL,
|
||||
"compress_old_access_log", &iniContext, false);
|
||||
g_compress_access_log_days_before = iniGetIntValue(NULL,
|
||||
"compress_access_log_days_before", &iniContext, 1);
|
||||
|
||||
if (g_compress_old_error_log)
|
||||
{
|
||||
log_set_compress_log_flags(LOG_COMPRESS_FLAGS_ENABLED |
|
||||
LOG_COMPRESS_FLAGS_NEW_THREAD);
|
||||
log_set_compress_log_days_before(g_compress_error_log_days_before);
|
||||
}
|
||||
if (g_use_access_log && g_compress_old_access_log)
|
||||
{
|
||||
log_set_compress_log_flags_ex(&g_access_log_context,
|
||||
|
|
@ -2039,13 +1887,6 @@ int storage_func_init(const char *filename, \
|
|||
g_compress_access_log_days_before);
|
||||
}
|
||||
|
||||
if ((result=get_time_item_from_conf(&iniContext, \
|
||||
"error_log_rotate_time", &g_error_log_rotate_time, \
|
||||
0, 0)) != 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
pRotateAccessLogSize = iniGetStrValue(NULL, \
|
||||
"rotate_access_log_size", &iniContext);
|
||||
if (pRotateAccessLogSize == NULL)
|
||||
|
|
@ -2069,32 +1910,6 @@ int storage_func_init(const char *filename, \
|
|||
}
|
||||
fdfs_set_log_rotate_size(&g_access_log_context, rotate_access_log_size);
|
||||
|
||||
pRotateErrorLogSize = iniGetStrValue(NULL, \
|
||||
"rotate_error_log_size", &iniContext);
|
||||
if (pRotateErrorLogSize == NULL)
|
||||
{
|
||||
rotate_error_log_size = 0;
|
||||
}
|
||||
else if ((result=parse_bytes(pRotateErrorLogSize, 1, \
|
||||
&rotate_error_log_size)) != 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (rotate_error_log_size > 0 && \
|
||||
rotate_error_log_size < FDFS_ONE_MB)
|
||||
{
|
||||
logWarning("file: "__FILE__", line: %d, " \
|
||||
"item \"rotate_error_log_size\": " \
|
||||
"%"PRId64" is too small, " \
|
||||
"change to 1 MB", __LINE__, \
|
||||
rotate_error_log_size);
|
||||
rotate_error_log_size = FDFS_ONE_MB;
|
||||
}
|
||||
fdfs_set_log_rotate_size(&g_log_context, rotate_error_log_size);
|
||||
|
||||
g_log_file_keep_days = iniGetIntValue(NULL, \
|
||||
"log_file_keep_days", &iniContext, 0);
|
||||
|
||||
g_file_sync_skip_invalid_record = iniGetBoolValue(NULL, \
|
||||
"file_sync_skip_invalid_record", &iniContext, false);
|
||||
|
||||
|
|
@ -2140,88 +1955,70 @@ int storage_func_init(const char *filename, \
|
|||
}
|
||||
#endif
|
||||
|
||||
logInfo("FastDFS v%d.%02d, base_path=%s, store_path_count=%d, " \
|
||||
"subdir_count_per_path=%d, group_name=%s, " \
|
||||
"run_by_group=%s, run_by_user=%s, " \
|
||||
"connect_timeout=%ds, network_timeout=%ds, "\
|
||||
"port=%d, bind_addr=%s, client_bind=%d, " \
|
||||
"max_connections=%d, accept_threads=%d, " \
|
||||
"work_threads=%d, " \
|
||||
"disk_rw_separated=%d, disk_reader_threads=%d, " \
|
||||
"disk_writer_threads=%d, disk_recovery_threads=%d, " \
|
||||
"buff_size=%d KB, heart_beat_interval=%ds, " \
|
||||
"stat_report_interval=%ds, tracker_server_count=%d, " \
|
||||
"sync_wait_msec=%dms, sync_interval=%dms, " \
|
||||
"sync_start_time=%02d:%02d, sync_end_time=%02d:%02d, "\
|
||||
"write_mark_file_freq=%d, " \
|
||||
"allow_ip_count=%d, " \
|
||||
"file_distribute_path_mode=%d, " \
|
||||
"file_distribute_rotate_count=%d, " \
|
||||
"fsync_after_written_bytes=%d, " \
|
||||
"sync_log_buff_interval=%ds, " \
|
||||
"sync_binlog_buff_interval=%ds, " \
|
||||
"sync_stat_file_interval=%ds, " \
|
||||
"thread_stack_size=%d KB, upload_priority=%d, " \
|
||||
"if_alias_prefix=%s, " \
|
||||
"check_file_duplicate=%d, file_signature_method=%s, " \
|
||||
"FDHT group count=%d, FDHT server count=%d, " \
|
||||
"FDHT key_namespace=%s, FDHT keep_alive=%d, " \
|
||||
"HTTP server port=%d, domain name=%s, " \
|
||||
"use_access_log=%d, rotate_access_log=%d, " \
|
||||
"access_log_rotate_time=%02d:%02d, " \
|
||||
"compress_old_access_log=%d, " \
|
||||
"compress_access_log_days_before=%d, " \
|
||||
"rotate_error_log=%d, " \
|
||||
"error_log_rotate_time=%02d:%02d, " \
|
||||
"compress_old_error_log=%d, " \
|
||||
"compress_error_log_days_before=%d, " \
|
||||
"rotate_access_log_size=%"PRId64", " \
|
||||
"rotate_error_log_size=%"PRId64", " \
|
||||
"log_file_keep_days=%d, " \
|
||||
"file_sync_skip_invalid_record=%d, " \
|
||||
"use_connection_pool=%d, " \
|
||||
"g_connection_pool_max_idle_time=%ds, " \
|
||||
"compress_binlog=%d, " \
|
||||
"compress_binlog_time=%02d:%02d, " \
|
||||
"check_store_path_mark=%d", \
|
||||
g_fdfs_version.major, g_fdfs_version.minor, \
|
||||
g_fdfs_base_path, g_fdfs_store_paths.count, \
|
||||
g_subdir_count_per_path, \
|
||||
g_group_name, g_run_by_group, g_run_by_user, \
|
||||
g_fdfs_connect_timeout, g_fdfs_network_timeout, \
|
||||
g_server_port, bind_addr, \
|
||||
g_client_bind_addr, g_max_connections, \
|
||||
g_accept_threads, g_work_threads, g_disk_rw_separated, \
|
||||
g_disk_reader_threads, g_disk_writer_threads, \
|
||||
g_disk_recovery_threads, g_buff_size / 1024, \
|
||||
g_heart_beat_interval, g_stat_report_interval, \
|
||||
g_tracker_group.server_count, g_sync_wait_usec / 1000, \
|
||||
g_sync_interval / 1000, \
|
||||
g_sync_start_time.hour, g_sync_start_time.minute, \
|
||||
g_sync_end_time.hour, g_sync_end_time.minute, \
|
||||
g_write_mark_file_freq, \
|
||||
g_allow_ip_count, g_file_distribute_path_mode, \
|
||||
g_file_distribute_rotate_count, \
|
||||
g_fsync_after_written_bytes, g_sync_log_buff_interval, \
|
||||
g_sync_binlog_buff_interval, g_sync_stat_file_interval, \
|
||||
g_thread_stack_size/1024, g_upload_priority, \
|
||||
g_if_alias_prefix, g_check_file_duplicate, \
|
||||
g_file_signature_method == STORAGE_FILE_SIGNATURE_METHOD_HASH \
|
||||
sf_global_config_to_string_ex("buff_size", sz_global_config,
|
||||
sizeof(sz_global_config));
|
||||
sf_context_config_to_string(&g_sf_context,
|
||||
sz_service_config, sizeof(sz_service_config));
|
||||
|
||||
logInfo("FastDFS v%d.%02d, %s, %s, store_path_count=%d, "
|
||||
"subdir_count_per_path=%d, group_name=%s, client_bind=%d, "
|
||||
"disk_rw_separated=%d, disk_reader_threads=%d, "
|
||||
"disk_writer_threads=%d, disk_recovery_threads=%d, "
|
||||
"heart_beat_interval=%ds, stat_report_interval=%ds, "
|
||||
"tracker_server_count=%d, sync_wait_msec=%dms, "
|
||||
"sync_interval=%dms, sync_start_time=%02d:%02d, "
|
||||
"sync_end_time=%02d:%02d, write_mark_file_freq=%d, "
|
||||
"allow_ip_count=%d, "
|
||||
"file_distribute_path_mode=%d, "
|
||||
"file_distribute_rotate_count=%d, "
|
||||
"fsync_after_written_bytes=%d, "
|
||||
"sync_binlog_buff_interval=%ds, "
|
||||
"sync_stat_file_interval=%ds, "
|
||||
"upload_priority=%d, "
|
||||
"if_alias_prefix=%s, "
|
||||
"check_file_duplicate=%d, file_signature_method=%s, "
|
||||
"FDHT group count=%d, FDHT server count=%d, "
|
||||
"FDHT key_namespace=%s, FDHT keep_alive=%d, "
|
||||
"HTTP server port=%d, domain name=%s, "
|
||||
"use_access_log=%d, rotate_access_log=%d, "
|
||||
"access_log_rotate_time=%02d:%02d, "
|
||||
"compress_old_access_log=%d, "
|
||||
"compress_access_log_days_before=%d, "
|
||||
"rotate_access_log_size=%"PRId64", "
|
||||
"file_sync_skip_invalid_record=%d, "
|
||||
"use_connection_pool=%d, "
|
||||
"g_connection_pool_max_idle_time=%ds, "
|
||||
"compress_binlog=%d, "
|
||||
"compress_binlog_time=%02d:%02d, "
|
||||
"check_store_path_mark=%d",
|
||||
g_fdfs_version.major, g_fdfs_version.minor,
|
||||
sz_global_config, sz_service_config,
|
||||
g_fdfs_store_paths.count, g_subdir_count_per_path,
|
||||
g_group_name, g_client_bind_addr, g_disk_rw_separated,
|
||||
g_disk_reader_threads, g_disk_writer_threads,
|
||||
g_disk_recovery_threads, g_heart_beat_interval,
|
||||
g_stat_report_interval, g_tracker_group.server_count,
|
||||
g_sync_wait_usec / 1000, g_sync_interval / 1000,
|
||||
g_sync_start_time.hour, g_sync_start_time.minute,
|
||||
g_sync_end_time.hour, g_sync_end_time.minute,
|
||||
g_write_mark_file_freq, g_allow_ip_count,
|
||||
g_file_distribute_path_mode,
|
||||
g_file_distribute_rotate_count,
|
||||
g_fsync_after_written_bytes,
|
||||
g_sync_binlog_buff_interval, g_sync_stat_file_interval,
|
||||
g_upload_priority, g_if_alias_prefix, g_check_file_duplicate,
|
||||
g_file_signature_method == STORAGE_FILE_SIGNATURE_METHOD_HASH
|
||||
? "hash" : "md5",
|
||||
g_group_array.group_count, g_group_array.server_count, \
|
||||
g_key_namespace, g_keep_alive, \
|
||||
g_http_port, g_http_domain, g_use_access_log, \
|
||||
g_rotate_access_log, g_access_log_rotate_time.hour, \
|
||||
g_access_log_rotate_time.minute, g_compress_old_access_log, \
|
||||
g_compress_access_log_days_before, \
|
||||
g_rotate_error_log, g_error_log_rotate_time.hour, \
|
||||
g_error_log_rotate_time.minute, g_compress_old_error_log, \
|
||||
g_compress_error_log_days_before, \
|
||||
g_access_log_context.rotate_size, \
|
||||
g_log_context.rotate_size, g_log_file_keep_days, \
|
||||
g_file_sync_skip_invalid_record, \
|
||||
g_use_connection_pool, g_connection_pool_max_idle_time, \
|
||||
g_compress_binlog, g_compress_binlog_time.hour, \
|
||||
g_group_array.group_count, g_group_array.server_count,
|
||||
g_key_namespace, g_keep_alive,
|
||||
g_http_port, g_http_domain, g_use_access_log,
|
||||
g_rotate_access_log, g_access_log_rotate_time.hour,
|
||||
g_access_log_rotate_time.minute, g_compress_old_access_log,
|
||||
g_compress_access_log_days_before,
|
||||
g_access_log_context.rotate_size,
|
||||
g_file_sync_skip_invalid_record,
|
||||
g_use_connection_pool, g_connection_pool_max_idle_time,
|
||||
g_compress_binlog, g_compress_binlog_time.hour,
|
||||
g_compress_binlog_time.minute, g_check_store_path_mark);
|
||||
|
||||
#ifdef WITH_HTTPD
|
||||
|
|
@ -2401,7 +2198,7 @@ static int storage_get_my_ip_from_tracker(ConnectionInfo *conn,
|
|||
pHeader->cmd = TRACKER_PROTO_CMD_STORAGE_GET_MY_IP;
|
||||
strcpy(out_buff + sizeof(TrackerHeader), g_group_name);
|
||||
if((result=tcpsenddata_nb(conn->sock, out_buff,
|
||||
sizeof(out_buff), g_fdfs_network_timeout)) != 0)
|
||||
sizeof(out_buff), SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"tracker server %s:%d, send data fail, "
|
||||
|
|
@ -2716,7 +2513,7 @@ int recv_file_serialized(int sock, const char *filename, \
|
|||
}
|
||||
|
||||
if ((result=tcprecvdata_nb(sock, buff, recv_bytes, \
|
||||
g_fdfs_network_timeout)) != 0)
|
||||
SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
close(fd);
|
||||
unlink(filename);
|
||||
|
|
|
|||
|
|
@ -22,8 +22,7 @@ typedef char * (*get_filename_func)(const void *pArg, \
|
|||
|
||||
int storage_write_to_fd(int fd, get_filename_func filename_func, \
|
||||
const void *pArg, const char *buff, const int len);
|
||||
int storage_func_init(const char *filename, \
|
||||
char *bind_addr, const int addr_size);
|
||||
int storage_func_init(const char *filename);
|
||||
int storage_func_destroy();
|
||||
|
||||
int storage_write_to_stat_file();
|
||||
|
|
@ -43,36 +42,6 @@ int storage_logic_to_local_full_filename(const char *logic_filename,
|
|||
const int logic_filename_len, int *store_path_index,
|
||||
char *full_filename, const int filename_size);
|
||||
|
||||
#define STORAGE_CHOWN(path, current_uid, current_gid) \
|
||||
if (!(g_run_by_gid == current_gid && g_run_by_uid == current_uid)) \
|
||||
{ \
|
||||
if (chown(path, g_run_by_uid, g_run_by_gid) != 0) \
|
||||
{ \
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"chown \"%s\" fail, " \
|
||||
"errno: %d, error info: %s", \
|
||||
__LINE__, path, \
|
||||
errno, STRERROR(errno)); \
|
||||
return errno != 0 ? errno : EPERM; \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
#define STORAGE_FCHOWN(fd, path, current_uid, current_gid) \
|
||||
if (!(g_run_by_gid == current_gid && g_run_by_uid == current_uid)) \
|
||||
{ \
|
||||
if (fchown(fd, g_run_by_uid, g_run_by_gid) != 0) \
|
||||
{ \
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"chown \"%s\" fail, " \
|
||||
"errno: %d, error info: %s", \
|
||||
__LINE__, path, \
|
||||
errno, STRERROR(errno)); \
|
||||
return errno != 0 ? errno : EPERM; \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
int write_serialized(int fd, const char *buff, size_t count, const bool bSync);
|
||||
int fsync_serialized(int fd);
|
||||
|
|
|
|||
|
|
@ -14,18 +14,12 @@
|
|||
#include "fastcommon/shared_func.h"
|
||||
#include "storage_global.h"
|
||||
|
||||
volatile bool g_continue_flag = true;
|
||||
int g_subdir_count_per_path = DEFAULT_DATA_DIR_COUNT_PER_PATH;
|
||||
|
||||
int g_server_port = FDFS_STORAGE_SERVER_DEF_PORT;
|
||||
char g_http_domain[FDFS_DOMAIN_NAME_MAX_SIZE] = {0};
|
||||
int g_http_port = 80;
|
||||
int g_last_server_port = 0;
|
||||
int g_last_http_port = 0;
|
||||
int g_max_connections = DEFAULT_MAX_CONNECTONS;
|
||||
int g_accept_threads = 1;
|
||||
int g_work_threads = DEFAULT_WORK_THREADS;
|
||||
int g_buff_size = STORAGE_DEFAULT_BUFF_SIZE;
|
||||
|
||||
bool g_disk_rw_direct = false;
|
||||
bool g_disk_rw_separated = true;
|
||||
|
|
@ -55,7 +49,6 @@ int g_sync_interval = 0; //unit: milliseconds
|
|||
TimeInfo g_sync_start_time = {0, 0};
|
||||
TimeInfo g_sync_end_time = {23, 59};
|
||||
bool g_sync_part_time = false;
|
||||
int g_sync_log_buff_interval = SYNC_LOG_BUFF_DEF_INTERVAL;
|
||||
int g_sync_binlog_buff_interval = SYNC_BINLOG_BUFF_DEF_INTERVAL;
|
||||
int g_write_mark_file_freq = FDFS_DEFAULT_SYNC_MARK_FILE_FREQ;
|
||||
int g_sync_stat_file_interval = DEFAULT_SYNC_STAT_FILE_INTERVAL;
|
||||
|
|
@ -79,9 +72,7 @@ LogContext g_access_log_context = {LOG_INFO, STDERR_FILENO, NULL};
|
|||
in_addr_t g_server_id_in_filename = 0;
|
||||
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_rotate_error_log = false; //if rotate the error log every day
|
||||
bool g_compress_old_access_log = false; //if compress the old access log
|
||||
bool g_compress_old_error_log = false; //if compress the old error log
|
||||
bool g_use_storage_id = false; //identify storage by ID instead of IP address
|
||||
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
|
||||
|
|
@ -95,15 +86,7 @@ in_addr_t *g_allow_ip_addrs = NULL;
|
|||
StorageStatusPerTracker *g_my_report_status = NULL; //returned by tracker server
|
||||
|
||||
TimeInfo g_access_log_rotate_time = {0, 0}; //rotate access log time base
|
||||
TimeInfo g_error_log_rotate_time = {0, 0}; //rotate error log time base
|
||||
|
||||
gid_t g_run_by_gid;
|
||||
uid_t g_run_by_uid;
|
||||
|
||||
char g_run_by_group[32] = {0};
|
||||
char g_run_by_user[32] = {0};
|
||||
|
||||
char g_bind_addr[IP_ADDRESS_SIZE] = {0};
|
||||
bool g_client_bind_addr = true;
|
||||
bool g_storage_ip_changed_auto_adjust = false;
|
||||
bool g_thread_kill_done = false;
|
||||
|
|
@ -113,9 +96,7 @@ bool g_check_store_path_mark = true;
|
|||
bool g_compress_binlog = false;
|
||||
TimeInfo g_compress_binlog_time = {0, 0};
|
||||
|
||||
int g_thread_stack_size = 512 * 1024;
|
||||
int g_upload_priority = DEFAULT_UPLOAD_PRIORITY;
|
||||
time_t g_up_time = 0;
|
||||
|
||||
#ifdef WITH_HTTPD
|
||||
FDFSHTTPParams g_http_params;
|
||||
|
|
@ -126,10 +107,7 @@ int g_http_trunk_size = 64 * 1024;
|
|||
char g_exe_name[256] = {0};
|
||||
#endif
|
||||
|
||||
int g_log_file_keep_days = 0;
|
||||
int g_compress_access_log_days_before = 0;
|
||||
int g_compress_error_log_days_before = 0;
|
||||
struct storage_nio_thread_data *g_nio_thread_data = NULL;
|
||||
struct storage_dio_thread_data *g_dio_thread_data = NULL;
|
||||
|
||||
int storage_cmp_by_server_id(const void *p1, const void *p2)
|
||||
|
|
|
|||
|
|
@ -16,11 +16,12 @@
|
|||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include "fastcommon/common_define.h"
|
||||
#include "fastcommon/local_ip_func.h"
|
||||
#include "fdfs_define.h"
|
||||
#include "tracker_types.h"
|
||||
#include "client_global.h"
|
||||
#include "fdht_types.h"
|
||||
#include "fastcommon/local_ip_func.h"
|
||||
#include "storage_types.h"
|
||||
|
||||
#ifdef WITH_HTTPD
|
||||
#include "fdfs_http_shared.h"
|
||||
|
|
@ -44,35 +45,13 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
FDFSStorageBrief server;
|
||||
int last_sync_src_timestamp;
|
||||
} FDFSStorageServer;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
signed char my_status; //my status from tracker server
|
||||
signed char my_result; //my report result
|
||||
signed char src_storage_result; //src storage report result
|
||||
bool get_my_ip_done;
|
||||
bool report_my_status;
|
||||
} StorageStatusPerTracker;
|
||||
|
||||
extern volatile bool g_continue_flag;
|
||||
|
||||
/* subdirs under store path, g_subdir_count * g_subdir_count 2 level subdirs */
|
||||
extern int g_subdir_count_per_path;
|
||||
|
||||
extern int g_server_port;
|
||||
extern int g_http_port; //http server port
|
||||
extern int g_last_server_port;
|
||||
extern int g_last_http_port; //last http server port
|
||||
extern char g_http_domain[FDFS_DOMAIN_NAME_MAX_SIZE]; //http server domain name
|
||||
extern int g_max_connections;
|
||||
extern int g_accept_threads;
|
||||
extern int g_work_threads;
|
||||
extern int g_buff_size;
|
||||
|
||||
extern bool g_disk_rw_direct; //if file read / write directly
|
||||
extern bool g_disk_rw_separated; //if disk read / write separated
|
||||
|
|
@ -101,8 +80,7 @@ extern int g_sync_interval; //unit: milliseconds
|
|||
extern TimeInfo g_sync_start_time;
|
||||
extern TimeInfo g_sync_end_time;
|
||||
extern bool g_sync_part_time; //true for part time, false for all time of a day
|
||||
extern int g_sync_log_buff_interval; //sync log buff to disk every interval seconds
|
||||
extern int g_sync_binlog_buff_interval; //sync binlog buff to disk every interval seconds
|
||||
extern int g_sync_binlog_buff_interval;
|
||||
extern int g_write_mark_file_freq; //write to mark file after sync N files
|
||||
extern int g_sync_stat_file_interval; //sync storage stat info to disk interval
|
||||
|
||||
|
|
@ -128,12 +106,9 @@ extern bool g_use_storage_id; //identify storage by ID instead of IP address
|
|||
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
|
||||
extern bool g_rotate_error_log; //if rotate the error log every day
|
||||
extern bool g_compress_old_access_log; //if compress the old access log
|
||||
extern bool g_compress_old_error_log; //if compress the old error log
|
||||
|
||||
extern TimeInfo g_access_log_rotate_time; //rotate access log time base
|
||||
extern TimeInfo g_error_log_rotate_time; //rotate error log time base
|
||||
|
||||
extern bool g_check_file_duplicate; //if check file content duplicate
|
||||
extern byte g_file_signature_method; //file signature method
|
||||
|
|
@ -145,13 +120,6 @@ extern in_addr_t *g_allow_ip_addrs; /* sorted array, asc order */
|
|||
|
||||
extern StorageStatusPerTracker *g_my_report_status; //returned by tracker server
|
||||
|
||||
extern gid_t g_run_by_gid;
|
||||
extern uid_t g_run_by_uid;
|
||||
|
||||
extern char g_run_by_group[32];
|
||||
extern char g_run_by_user[32];
|
||||
|
||||
extern char g_bind_addr[IP_ADDRESS_SIZE];
|
||||
extern bool g_client_bind_addr;
|
||||
extern bool g_storage_ip_changed_auto_adjust;
|
||||
extern bool g_thread_kill_done;
|
||||
|
|
@ -162,9 +130,7 @@ extern bool g_check_store_path_mark;
|
|||
extern bool g_compress_binlog;
|
||||
extern TimeInfo g_compress_binlog_time; //compress binlog time base
|
||||
|
||||
extern int g_thread_stack_size;
|
||||
extern int g_upload_priority;
|
||||
extern time_t g_up_time;
|
||||
|
||||
#ifdef WITH_HTTPD
|
||||
extern FDFSHTTPParams g_http_params;
|
||||
|
|
@ -175,11 +141,8 @@ extern int g_http_trunk_size;
|
|||
extern char g_exe_name[256];
|
||||
#endif
|
||||
|
||||
extern int g_log_file_keep_days;
|
||||
extern int g_compress_access_log_days_before;
|
||||
extern int g_compress_error_log_days_before;
|
||||
|
||||
extern struct storage_nio_thread_data *g_nio_thread_data; //network io thread data
|
||||
extern struct storage_dio_thread_data *g_dio_thread_data; //disk io thread data
|
||||
|
||||
int storage_cmp_by_server_id(const void *p1, const void *p2);
|
||||
|
|
@ -192,4 +155,3 @@ int storage_insert_ip_addr_to_multi_ips(FDFSMultiIP *multi_ip,
|
|||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ static int storage_do_changelog_req(ConnectionInfo *pTrackerServer)
|
|||
strcpy(out_buff + sizeof(TrackerHeader) + FDFS_GROUP_NAME_MAX_LEN,
|
||||
g_my_server_id_str);
|
||||
if((result=tcpsenddata_nb(pTrackerServer->sock, out_buff, \
|
||||
sizeof(out_buff), g_fdfs_network_timeout)) != 0)
|
||||
sizeof(out_buff), SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"tracker server %s:%d, send data fail, " \
|
||||
|
|
@ -81,7 +81,7 @@ static int storage_report_ip_changed(ConnectionInfo *pTrackerServer)
|
|||
IP_ADDRESS_SIZE, g_tracker_client_ip.ips[0].address);
|
||||
|
||||
if((result=tcpsenddata_nb(pTrackerServer->sock, out_buff, \
|
||||
sizeof(out_buff), g_fdfs_network_timeout)) != 0)
|
||||
sizeof(out_buff), SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"tracker server %s:%d, send data fail, " \
|
||||
|
|
@ -136,7 +136,7 @@ int storage_get_my_tracker_client_ip()
|
|||
pTServer = &trackerServer;
|
||||
pTServerEnd = g_tracker_group.servers + g_tracker_group.server_count;
|
||||
|
||||
while (success_count == 0 && g_continue_flag)
|
||||
while (success_count == 0 && SF_G_CONTINUE_FLAG)
|
||||
{
|
||||
for (pGlobalServer=g_tracker_group.servers; pGlobalServer<pTServerEnd;
|
||||
pGlobalServer++)
|
||||
|
|
@ -146,7 +146,7 @@ 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 ? g_bind_addr : NULL, &result, false);
|
||||
g_client_bind_addr ? SF_G_INNER_BIND_ADDR : NULL, &result, false);
|
||||
if (conn != NULL)
|
||||
{
|
||||
break;
|
||||
|
|
@ -183,7 +183,7 @@ int storage_get_my_tracker_client_ip()
|
|||
}
|
||||
}
|
||||
|
||||
if (!g_continue_flag)
|
||||
if (!SF_G_CONTINUE_FLAG)
|
||||
{
|
||||
return EINTR;
|
||||
}
|
||||
|
|
@ -223,7 +223,7 @@ static int storage_report_storage_ip_addr()
|
|||
}
|
||||
|
||||
success_count = 0;
|
||||
while (success_count == 0 && g_continue_flag)
|
||||
while (success_count == 0 && SF_G_CONTINUE_FLAG)
|
||||
{
|
||||
for (pGlobalServer=g_tracker_group.servers; pGlobalServer<pTServerEnd; \
|
||||
pGlobalServer++)
|
||||
|
|
@ -233,7 +233,7 @@ 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 ? g_bind_addr : NULL, &result, false);
|
||||
g_client_bind_addr ? SF_G_INNER_BIND_ADDR : NULL, &result, false);
|
||||
if (conn != NULL)
|
||||
{
|
||||
break;
|
||||
|
|
@ -268,7 +268,7 @@ static int storage_report_storage_ip_addr()
|
|||
}
|
||||
}
|
||||
|
||||
if (!g_continue_flag)
|
||||
if (!SF_G_CONTINUE_FLAG)
|
||||
{
|
||||
return EINTR;
|
||||
}
|
||||
|
|
@ -292,7 +292,7 @@ int storage_changelog_req()
|
|||
pTServer = &trackerServer;
|
||||
pTServerEnd = g_tracker_group.servers + g_tracker_group.server_count;
|
||||
|
||||
while (success_count == 0 && g_continue_flag)
|
||||
while (success_count == 0 && SF_G_CONTINUE_FLAG)
|
||||
{
|
||||
for (pGlobalServer=g_tracker_group.servers; pGlobalServer<pTServerEnd; \
|
||||
pGlobalServer++)
|
||||
|
|
@ -302,7 +302,7 @@ int storage_changelog_req()
|
|||
for (i=0; i < 3; i++)
|
||||
{
|
||||
conn = tracker_connect_server_no_pool_ex(pTServer,
|
||||
g_client_bind_addr ? g_bind_addr : NULL, &result, false);
|
||||
g_client_bind_addr ? SF_G_INNER_BIND_ADDR : NULL, &result, false);
|
||||
if (conn != NULL)
|
||||
{
|
||||
break;
|
||||
|
|
@ -338,7 +338,7 @@ int storage_changelog_req()
|
|||
}
|
||||
}
|
||||
|
||||
if (!g_continue_flag)
|
||||
if (!SF_G_CONTINUE_FLAG)
|
||||
{
|
||||
return EINTR;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,543 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2008 Happy Fish / YuQing
|
||||
*
|
||||
* FastDFS may be copied only under the terms of the GNU General
|
||||
* Public License V3, which may be found in the FastDFS source kit.
|
||||
* Please visit the FastDFS Home Page http://www.fastken.com/ for more detail.
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <pthread.h>
|
||||
#include "fastcommon/shared_func.h"
|
||||
#include "fastcommon/sched_thread.h"
|
||||
#include "fastcommon/logger.h"
|
||||
#include "fastcommon/sockopt.h"
|
||||
#include "fastcommon/fast_task_queue.h"
|
||||
#include "tracker_types.h"
|
||||
#include "tracker_proto.h"
|
||||
#include "storage_global.h"
|
||||
#include "storage_service.h"
|
||||
#include "fastcommon/ioevent_loop.h"
|
||||
#include "storage_dio.h"
|
||||
#include "storage_nio.h"
|
||||
|
||||
static void client_sock_read(int sock, short event, void *arg);
|
||||
static void client_sock_write(int sock, short event, void *arg);
|
||||
static int storage_nio_init(struct fast_task_info *pTask);
|
||||
|
||||
void task_finish_clean_up(struct fast_task_info *pTask)
|
||||
{
|
||||
StorageClientInfo *pClientInfo;
|
||||
|
||||
pClientInfo = (StorageClientInfo *)pTask->arg;
|
||||
if (pClientInfo->clean_func != NULL)
|
||||
{
|
||||
pClientInfo->clean_func(pTask);
|
||||
}
|
||||
|
||||
ioevent_detach(&pTask->thread_data->ev_puller, pTask->event.fd);
|
||||
close(pTask->event.fd);
|
||||
pTask->event.fd = -1;
|
||||
|
||||
if (pTask->event.timer.expires > 0)
|
||||
{
|
||||
fast_timer_remove(&pTask->thread_data->timer,
|
||||
&pTask->event.timer);
|
||||
pTask->event.timer.expires = 0;
|
||||
}
|
||||
|
||||
pTask->canceled = false;
|
||||
memset(pTask->arg, 0, sizeof(StorageClientInfo));
|
||||
free_queue_push(pTask);
|
||||
|
||||
__sync_fetch_and_sub(&g_storage_stat.connection.current_count, 1);
|
||||
++g_stat_change_count;
|
||||
}
|
||||
|
||||
static int set_recv_event(struct fast_task_info *pTask)
|
||||
{
|
||||
int result;
|
||||
|
||||
if (pTask->event.callback == client_sock_read)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
pTask->event.callback = client_sock_read;
|
||||
if (ioevent_modify(&pTask->thread_data->ev_puller,
|
||||
pTask->event.fd, IOEVENT_READ, pTask) != 0)
|
||||
{
|
||||
result = errno != 0 ? errno : ENOENT;
|
||||
ioevent_add_to_deleted_list(pTask);
|
||||
|
||||
logError("file: "__FILE__", line: %d, "\
|
||||
"ioevent_modify fail, " \
|
||||
"errno: %d, error info: %s", \
|
||||
__LINE__, result, STRERROR(result));
|
||||
return result;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int set_send_event(struct fast_task_info *pTask)
|
||||
{
|
||||
int result;
|
||||
|
||||
if (pTask->event.callback == client_sock_write)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
pTask->event.callback = client_sock_write;
|
||||
if (ioevent_modify(&pTask->thread_data->ev_puller,
|
||||
pTask->event.fd, IOEVENT_WRITE, pTask) != 0)
|
||||
{
|
||||
result = errno != 0 ? errno : ENOENT;
|
||||
ioevent_add_to_deleted_list(pTask);
|
||||
|
||||
logError("file: "__FILE__", line: %d, "\
|
||||
"ioevent_modify fail, " \
|
||||
"errno: %d, error info: %s", \
|
||||
__LINE__, result, STRERROR(result));
|
||||
return result;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void storage_recv_notify_read(int sock, short event, void *arg)
|
||||
{
|
||||
struct fast_task_info *pTask;
|
||||
StorageClientInfo *pClientInfo;
|
||||
long task_addr;
|
||||
int64_t remain_bytes;
|
||||
int bytes;
|
||||
int result;
|
||||
|
||||
while (1)
|
||||
{
|
||||
if ((bytes=read(sock, &task_addr, sizeof(task_addr))) < 0)
|
||||
{
|
||||
if (!(errno == EAGAIN || errno == EWOULDBLOCK))
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"call read failed, " \
|
||||
"errno: %d, error info: %s", \
|
||||
__LINE__, errno, STRERROR(errno));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
else if (bytes == 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"call read failed, end of file", __LINE__);
|
||||
break;
|
||||
}
|
||||
|
||||
pTask = (struct fast_task_info *)task_addr;
|
||||
pClientInfo = (StorageClientInfo *)pTask->arg;
|
||||
|
||||
if (pTask->event.fd < 0) //quit flag
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* //logInfo("=====thread index: %d, pTask->event.fd=%d", \
|
||||
pClientInfo->nio_thread_index, pTask->event.fd);
|
||||
*/
|
||||
|
||||
if (pClientInfo->stage & FDFS_STORAGE_STAGE_DIO_THREAD)
|
||||
{
|
||||
pClientInfo->stage &= ~FDFS_STORAGE_STAGE_DIO_THREAD;
|
||||
}
|
||||
switch (pClientInfo->stage)
|
||||
{
|
||||
case FDFS_STORAGE_STAGE_NIO_INIT:
|
||||
result = storage_nio_init(pTask);
|
||||
break;
|
||||
case FDFS_STORAGE_STAGE_NIO_RECV:
|
||||
pTask->offset = 0;
|
||||
remain_bytes = pClientInfo->total_length - \
|
||||
pClientInfo->total_offset;
|
||||
if (remain_bytes > pTask->size)
|
||||
{
|
||||
pTask->length = pTask->size;
|
||||
}
|
||||
else
|
||||
{
|
||||
pTask->length = remain_bytes;
|
||||
}
|
||||
|
||||
if (set_recv_event(pTask) == 0)
|
||||
{
|
||||
client_sock_read(pTask->event.fd,
|
||||
IOEVENT_READ, pTask);
|
||||
}
|
||||
result = 0;
|
||||
break;
|
||||
case FDFS_STORAGE_STAGE_NIO_SEND:
|
||||
result = storage_send_add_event(pTask);
|
||||
break;
|
||||
case FDFS_STORAGE_STAGE_NIO_CLOSE:
|
||||
result = EIO; //close this socket
|
||||
break;
|
||||
default:
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"invalid stage: %d", __LINE__, \
|
||||
pClientInfo->stage);
|
||||
result = EINVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
if (result != 0)
|
||||
{
|
||||
ioevent_add_to_deleted_list(pTask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int storage_nio_init(struct fast_task_info *pTask)
|
||||
{
|
||||
StorageClientInfo *pClientInfo;
|
||||
struct storage_nio_thread_data *pThreadData;
|
||||
|
||||
pClientInfo = (StorageClientInfo *)pTask->arg;
|
||||
pThreadData = g_nio_thread_data + pClientInfo->nio_thread_index;
|
||||
|
||||
pClientInfo->stage = FDFS_STORAGE_STAGE_NIO_RECV;
|
||||
return ioevent_set(pTask, &pThreadData->thread_data,
|
||||
pTask->event.fd, IOEVENT_READ, client_sock_read,
|
||||
g_fdfs_network_timeout);
|
||||
}
|
||||
|
||||
int storage_send_add_event(struct fast_task_info *pTask)
|
||||
{
|
||||
pTask->offset = 0;
|
||||
|
||||
/* direct send */
|
||||
client_sock_write(pTask->event.fd, IOEVENT_WRITE, pTask);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void client_sock_read(int sock, short event, void *arg)
|
||||
{
|
||||
int bytes;
|
||||
int recv_bytes;
|
||||
struct fast_task_info *pTask;
|
||||
StorageClientInfo *pClientInfo;
|
||||
|
||||
pTask = (struct fast_task_info *)arg;
|
||||
pClientInfo = (StorageClientInfo *)pTask->arg;
|
||||
if (pTask->canceled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (pClientInfo->stage != FDFS_STORAGE_STAGE_NIO_RECV)
|
||||
{
|
||||
if (event & IOEVENT_TIMEOUT) {
|
||||
pTask->event.timer.expires = g_current_time +
|
||||
g_fdfs_network_timeout;
|
||||
fast_timer_add(&pTask->thread_data->timer,
|
||||
&pTask->event.timer);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (event & IOEVENT_TIMEOUT)
|
||||
{
|
||||
if (pClientInfo->total_offset == 0)
|
||||
{
|
||||
if (pTask->req_count > 0)
|
||||
{
|
||||
pTask->event.timer.expires = g_current_time +
|
||||
g_fdfs_network_timeout;
|
||||
fast_timer_add(&pTask->thread_data->timer,
|
||||
&pTask->event.timer);
|
||||
}
|
||||
else
|
||||
{
|
||||
logWarning("file: "__FILE__", line: %d, "
|
||||
"client ip: %s, recv timeout. "
|
||||
"after the connection is established, "
|
||||
"you must send a request before %ds timeout, "
|
||||
"maybe connections leak in you application.",
|
||||
__LINE__, pTask->client_ip, g_fdfs_network_timeout);
|
||||
task_finish_clean_up(pTask);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"client ip: %s, recv timeout, "
|
||||
"recv offset: %d, expect length: %d, "
|
||||
"req_count: %"PRId64, __LINE__, pTask->client_ip,
|
||||
pTask->offset, pTask->length, pTask->req_count);
|
||||
task_finish_clean_up(pTask);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (event & IOEVENT_ERROR)
|
||||
{
|
||||
logDebug("file: "__FILE__", line: %d, " \
|
||||
"client ip: %s, recv error event: %d, "
|
||||
"close connection", __LINE__, pTask->client_ip, event);
|
||||
|
||||
task_finish_clean_up(pTask);
|
||||
return;
|
||||
}
|
||||
|
||||
fast_timer_modify(&pTask->thread_data->timer,
|
||||
&pTask->event.timer, g_current_time +
|
||||
g_fdfs_network_timeout);
|
||||
while (1)
|
||||
{
|
||||
if (pClientInfo->total_length == 0) //recv header
|
||||
{
|
||||
recv_bytes = sizeof(TrackerHeader) - pTask->offset;
|
||||
}
|
||||
else
|
||||
{
|
||||
recv_bytes = pTask->length - pTask->offset;
|
||||
}
|
||||
|
||||
/*
|
||||
logInfo("total_length=%"PRId64", recv_bytes=%d, "
|
||||
"pTask->length=%d, pTask->offset=%d",
|
||||
pClientInfo->total_length, recv_bytes,
|
||||
pTask->length, pTask->offset);
|
||||
*/
|
||||
|
||||
bytes = recv(sock, pTask->data + pTask->offset, recv_bytes, 0);
|
||||
if (bytes < 0)
|
||||
{
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK)
|
||||
{
|
||||
}
|
||||
else if (errno == EINTR)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"client ip: %s, recv failed, " \
|
||||
"errno: %d, error info: %s", \
|
||||
__LINE__, pTask->client_ip, \
|
||||
errno, STRERROR(errno));
|
||||
|
||||
task_finish_clean_up(pTask);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else if (bytes == 0)
|
||||
{
|
||||
logDebug("file: "__FILE__", line: %d, " \
|
||||
"client ip: %s, recv failed, " \
|
||||
"connection disconnected.", \
|
||||
__LINE__, pTask->client_ip);
|
||||
|
||||
task_finish_clean_up(pTask);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pClientInfo->total_length == 0) //header
|
||||
{
|
||||
if (pTask->offset + bytes < sizeof(TrackerHeader))
|
||||
{
|
||||
pTask->offset += bytes;
|
||||
return;
|
||||
}
|
||||
|
||||
pClientInfo->total_length=buff2long(((TrackerHeader *) \
|
||||
pTask->data)->pkg_len);
|
||||
if (pClientInfo->total_length < 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"client ip: %s, pkg length: " \
|
||||
"%"PRId64" < 0", \
|
||||
__LINE__, pTask->client_ip, \
|
||||
pClientInfo->total_length);
|
||||
|
||||
task_finish_clean_up(pTask);
|
||||
return;
|
||||
}
|
||||
|
||||
pClientInfo->total_length += sizeof(TrackerHeader);
|
||||
if (pClientInfo->total_length > pTask->size)
|
||||
{
|
||||
pTask->length = pTask->size;
|
||||
}
|
||||
else
|
||||
{
|
||||
pTask->length = pClientInfo->total_length;
|
||||
}
|
||||
}
|
||||
|
||||
pTask->offset += bytes;
|
||||
if (pTask->offset >= pTask->length) //recv current pkg done
|
||||
{
|
||||
if (pClientInfo->total_offset + pTask->length >= \
|
||||
pClientInfo->total_length)
|
||||
{
|
||||
/* current req recv done */
|
||||
pClientInfo->stage = FDFS_STORAGE_STAGE_NIO_SEND;
|
||||
pTask->req_count++;
|
||||
}
|
||||
|
||||
if (pClientInfo->total_offset == 0)
|
||||
{
|
||||
pClientInfo->total_offset = pTask->length;
|
||||
storage_deal_task(pTask);
|
||||
}
|
||||
else
|
||||
{
|
||||
pClientInfo->total_offset += pTask->length;
|
||||
|
||||
/* continue write to file */
|
||||
storage_dio_queue_push(pTask);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void client_sock_write(int sock, short event, void *arg)
|
||||
{
|
||||
int bytes;
|
||||
struct fast_task_info *pTask;
|
||||
StorageClientInfo *pClientInfo;
|
||||
|
||||
pTask = (struct fast_task_info *)arg;
|
||||
pClientInfo = (StorageClientInfo *)pTask->arg;
|
||||
if (pTask->canceled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (event & IOEVENT_TIMEOUT)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"client ip: %s, send timeout, offset: %d, "
|
||||
"remain bytes: %d", __LINE__, pTask->client_ip,
|
||||
pTask->offset, pTask->length - pTask->offset);
|
||||
|
||||
task_finish_clean_up(pTask);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event & IOEVENT_ERROR)
|
||||
{
|
||||
logDebug("file: "__FILE__", line: %d, "
|
||||
"client ip: %s, recv error event: %d, "
|
||||
"close connection", __LINE__, pTask->client_ip, event);
|
||||
|
||||
task_finish_clean_up(pTask);
|
||||
return;
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
fast_timer_modify(&pTask->thread_data->timer,
|
||||
&pTask->event.timer, g_current_time +
|
||||
g_fdfs_network_timeout);
|
||||
bytes = send(sock, pTask->data + pTask->offset, \
|
||||
pTask->length - pTask->offset, 0);
|
||||
//printf("%08X sended %d bytes\n", (int)pTask, bytes);
|
||||
if (bytes < 0)
|
||||
{
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK)
|
||||
{
|
||||
set_send_event(pTask);
|
||||
}
|
||||
else if (errno == EINTR)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"client ip: %s, recv failed, " \
|
||||
"errno: %d, error info: %s", \
|
||||
__LINE__, pTask->client_ip, \
|
||||
errno, STRERROR(errno));
|
||||
|
||||
task_finish_clean_up(pTask);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else if (bytes == 0)
|
||||
{
|
||||
logWarning("file: "__FILE__", line: %d, " \
|
||||
"send failed, connection disconnected.", \
|
||||
__LINE__);
|
||||
|
||||
task_finish_clean_up(pTask);
|
||||
return;
|
||||
}
|
||||
|
||||
pTask->offset += bytes;
|
||||
if (pTask->offset >= pTask->length)
|
||||
{
|
||||
if (set_recv_event(pTask) != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
pClientInfo->total_offset += pTask->length;
|
||||
if (pClientInfo->total_offset>=pClientInfo->total_length)
|
||||
{
|
||||
if (pClientInfo->total_length == sizeof(TrackerHeader)
|
||||
&& ((TrackerHeader *)pTask->data)->status == EINVAL)
|
||||
{
|
||||
logDebug("file: "__FILE__", line: %d, "\
|
||||
"close conn: #%d, client ip: %s", \
|
||||
__LINE__, pTask->event.fd,
|
||||
pTask->client_ip);
|
||||
task_finish_clean_up(pTask);
|
||||
return;
|
||||
}
|
||||
|
||||
/* response done, try to recv again */
|
||||
pClientInfo->total_length = 0;
|
||||
pClientInfo->total_offset = 0;
|
||||
pTask->offset = 0;
|
||||
pTask->length = 0;
|
||||
|
||||
pClientInfo->stage = FDFS_STORAGE_STAGE_NIO_RECV;
|
||||
}
|
||||
else //continue to send file content
|
||||
{
|
||||
pTask->length = 0;
|
||||
|
||||
/* continue read from file */
|
||||
storage_dio_queue_push(pTask);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -75,8 +75,8 @@ int storage_get_params_from_tracker()
|
|||
char *pIdType;
|
||||
|
||||
if ((result=fdfs_get_ini_context_from_tracker(&g_tracker_group,
|
||||
&iniContext, (bool * volatile)&g_continue_flag,
|
||||
g_client_bind_addr, g_bind_addr)) != 0)
|
||||
&iniContext, (bool * volatile)&SF_G_CONTINUE_FLAG,
|
||||
g_client_bind_addr, SF_G_INNER_BIND_ADDR)) != 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -27,22 +27,14 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern int g_storage_thread_count;
|
||||
extern pthread_mutex_t g_storage_thread_lock;
|
||||
|
||||
int storage_service_init();
|
||||
void storage_service_destroy();
|
||||
|
||||
int fdfs_stat_file_sync_func(void *args);
|
||||
int storage_deal_task(struct fast_task_info *pTask);
|
||||
|
||||
int storage_nio_notify(struct fast_task_info *pTask);
|
||||
void storage_accept_loop(int server_sock);
|
||||
int storage_terminate_threads();
|
||||
|
||||
int storage_get_storage_path_index(int *store_path_index);
|
||||
|
||||
void storage_get_store_path(const char *filename, const int filename_len, \
|
||||
void storage_get_store_path(const char *filename, const int filename_len,
|
||||
int *sub_path_high, int *sub_path_low);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
|||
|
|
@ -227,7 +227,7 @@ static int storage_sync_copy_file(ConnectionInfo *pStorageServer, \
|
|||
p += pRecord->filename_len;
|
||||
|
||||
if((result=tcpsenddata_nb(pStorageServer->sock, out_buff, \
|
||||
p - out_buff, g_fdfs_network_timeout)) != 0)
|
||||
p - out_buff, SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"sync data to storage server %s:%d fail, " \
|
||||
|
|
@ -242,7 +242,7 @@ static int storage_sync_copy_file(ConnectionInfo *pStorageServer, \
|
|||
if (need_sync_file && (stat_buf.st_size > 0) && \
|
||||
((result=tcpsendfile_ex(pStorageServer->sock, \
|
||||
full_filename, file_offset, stat_buf.st_size, \
|
||||
g_fdfs_network_timeout, &total_send_bytes)) != 0))
|
||||
SF_G_NETWORK_TIMEOUT, &total_send_bytes)) != 0))
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"sync data to storage server %s:%d fail, " \
|
||||
|
|
@ -424,7 +424,7 @@ static int storage_sync_modify_file(ConnectionInfo *pStorageServer, \
|
|||
p += pRecord->filename_len;
|
||||
|
||||
if((result=tcpsenddata_nb(pStorageServer->sock, out_buff, \
|
||||
p - out_buff, g_fdfs_network_timeout)) != 0)
|
||||
p - out_buff, SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"sync data to storage server %s:%d fail, " \
|
||||
|
|
@ -438,7 +438,7 @@ static int storage_sync_modify_file(ConnectionInfo *pStorageServer, \
|
|||
|
||||
if ((result=tcpsendfile_ex(pStorageServer->sock, \
|
||||
full_filename, start_offset, modify_length, \
|
||||
g_fdfs_network_timeout, &total_send_bytes)) != 0)
|
||||
SF_G_NETWORK_TIMEOUT, &total_send_bytes)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"sync data to storage server %s:%d fail, " \
|
||||
|
|
@ -589,7 +589,7 @@ static int storage_sync_truncate_file(ConnectionInfo *pStorageServer, \
|
|||
p += pRecord->filename_len;
|
||||
|
||||
if((result=tcpsenddata_nb(pStorageServer->sock, out_buff, \
|
||||
p - out_buff, g_fdfs_network_timeout)) != 0)
|
||||
p - out_buff, SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"sync data to storage server %s:%d fail, " \
|
||||
|
|
@ -663,7 +663,7 @@ static int storage_sync_delete_file(ConnectionInfo *pStorageServer, \
|
|||
|
||||
if ((result=tcpsenddata_nb(pStorageServer->sock, out_buff, \
|
||||
sizeof(TrackerHeader) + 4 + FDFS_GROUP_NAME_MAX_LEN + \
|
||||
pRecord->filename_len, g_fdfs_network_timeout)) != 0)
|
||||
pRecord->filename_len, SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("FILE: "__FILE__", line: %d, " \
|
||||
"send data to storage server %s:%d fail, " \
|
||||
|
|
@ -713,7 +713,7 @@ static int storage_report_my_server_id(ConnectionInfo *pStorageServer)
|
|||
strcpy(out_buff + sizeof(TrackerHeader), g_my_server_id_str);
|
||||
if ((result=tcpsenddata_nb(pStorageServer->sock, out_buff, \
|
||||
sizeof(TrackerHeader) + FDFS_STORAGE_ID_MAX_SIZE, \
|
||||
g_fdfs_network_timeout)) != 0)
|
||||
SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("FILE: "__FILE__", line: %d, " \
|
||||
"send data to storage server %s:%d fail, " \
|
||||
|
|
@ -938,7 +938,7 @@ static int storage_sync_link_file(ConnectionInfo *pStorageServer, \
|
|||
|
||||
if ((result=tcpsenddata_nb(pStorageServer->sock, out_buff, \
|
||||
sizeof(TrackerHeader) + out_body_len, \
|
||||
g_fdfs_network_timeout)) != 0)
|
||||
SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("FILE: "__FILE__", line: %d, " \
|
||||
"send data to storage server %s:%d fail, " \
|
||||
|
|
@ -1046,7 +1046,7 @@ static int storage_sync_rename_file(ConnectionInfo *pStorageServer,
|
|||
|
||||
if ((result=tcpsenddata_nb(pStorageServer->sock, out_buff,
|
||||
sizeof(TrackerHeader) + out_body_len,
|
||||
g_fdfs_network_timeout)) != 0)
|
||||
SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("FILE: "__FILE__", line: %d, "
|
||||
"send data to storage server %s:%d fail, "
|
||||
|
|
@ -1199,7 +1199,7 @@ static int storage_sync_data(StorageBinLogReader *pReader, \
|
|||
logCrit("file: "__FILE__", line: %d, " \
|
||||
"storage_write_to_mark_file " \
|
||||
"fail, program exit!", __LINE__);
|
||||
g_continue_flag = false;
|
||||
SF_G_CONTINUE_FLAG = false;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -1216,7 +1216,7 @@ static int write_to_binlog_index(const int binlog_index)
|
|||
int len;
|
||||
|
||||
snprintf(full_filename, sizeof(full_filename),
|
||||
"%s/data/"SYNC_DIR_NAME"/%s", g_fdfs_base_path,
|
||||
"%s/data/"SYNC_DIR_NAME"/%s", SF_G_BASE_PATH_STR,
|
||||
SYNC_BINLOG_INDEX_FILENAME);
|
||||
if ((fd=open(full_filename, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0)
|
||||
{
|
||||
|
|
@ -1245,7 +1245,7 @@ static int write_to_binlog_index(const int binlog_index)
|
|||
|
||||
close(fd);
|
||||
|
||||
STORAGE_CHOWN(full_filename, geteuid(), getegid())
|
||||
SF_CHOWN_TO_RUNBY_RETURN_ON_ERROR(full_filename);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1258,7 +1258,7 @@ static int get_binlog_index_from_file_old()
|
|||
int bytes;
|
||||
|
||||
snprintf(full_filename, sizeof(full_filename),
|
||||
"%s/data/"SYNC_DIR_NAME"/%s", g_fdfs_base_path,
|
||||
"%s/data/"SYNC_DIR_NAME"/%s", SF_G_BASE_PATH_STR,
|
||||
SYNC_BINLOG_INDEX_FILENAME_OLD);
|
||||
if ((fd=open(full_filename, O_RDONLY)) >= 0)
|
||||
{
|
||||
|
|
@ -1297,7 +1297,7 @@ static int get_binlog_index_from_file()
|
|||
int result;
|
||||
|
||||
snprintf(full_filename, sizeof(full_filename),
|
||||
"%s/data/"SYNC_DIR_NAME"/%s", g_fdfs_base_path,
|
||||
"%s/data/"SYNC_DIR_NAME"/%s", SF_G_BASE_PATH_STR,
|
||||
SYNC_BINLOG_INDEX_FILENAME);
|
||||
if (access(full_filename, F_OK) != 0)
|
||||
{
|
||||
|
|
@ -1348,7 +1348,7 @@ static char *get_writable_binlog_filename(char *full_filename)
|
|||
snprintf(full_filename, MAX_PATH_SIZE, \
|
||||
"%s/data/"SYNC_DIR_NAME"/"SYNC_BINLOG_FILE_PREFIX"" \
|
||||
SYNC_BINLOG_FILE_EXT_FMT, \
|
||||
g_fdfs_base_path, g_binlog_index);
|
||||
SF_G_BASE_PATH_STR, g_binlog_index);
|
||||
return full_filename;
|
||||
}
|
||||
|
||||
|
|
@ -1358,7 +1358,7 @@ static char *get_writable_binlog_filename1(char *full_filename, \
|
|||
snprintf(full_filename, MAX_PATH_SIZE, \
|
||||
"%s/data/"SYNC_DIR_NAME"/"SYNC_BINLOG_FILE_PREFIX"" \
|
||||
SYNC_BINLOG_FILE_EXT_FMT, \
|
||||
g_fdfs_base_path, binlog_index);
|
||||
SF_G_BASE_PATH_STR, binlog_index);
|
||||
return full_filename;
|
||||
}
|
||||
|
||||
|
|
@ -1400,7 +1400,7 @@ static int open_next_writable_binlog()
|
|||
errno, STRERROR(errno));
|
||||
return errno != 0 ? errno : EACCES;
|
||||
}
|
||||
STORAGE_FCHOWN(g_binlog_fd, full_filename, geteuid(), getegid())
|
||||
SF_FCHOWN_TO_RUNBY_RETURN_ON_ERROR(g_binlog_fd, full_filename);
|
||||
|
||||
g_binlog_index++;
|
||||
return 0;
|
||||
|
|
@ -1413,7 +1413,7 @@ int storage_sync_init()
|
|||
char full_filename[MAX_PATH_SIZE];
|
||||
int result;
|
||||
|
||||
snprintf(data_path, sizeof(data_path), "%s/data", g_fdfs_base_path);
|
||||
snprintf(data_path, sizeof(data_path), "%s/data", SF_G_BASE_PATH_STR);
|
||||
if (!fileExists(data_path))
|
||||
{
|
||||
if (mkdir(data_path, 0755) != 0)
|
||||
|
|
@ -1426,7 +1426,7 @@ int storage_sync_init()
|
|||
return errno != 0 ? errno : ENOENT;
|
||||
}
|
||||
|
||||
STORAGE_CHOWN(data_path, geteuid(), getegid())
|
||||
SF_CHOWN_TO_RUNBY_RETURN_ON_ERROR(data_path);
|
||||
}
|
||||
|
||||
snprintf(sync_path, sizeof(sync_path), \
|
||||
|
|
@ -1443,7 +1443,7 @@ int storage_sync_init()
|
|||
return errno != 0 ? errno : ENOENT;
|
||||
}
|
||||
|
||||
STORAGE_CHOWN(sync_path, geteuid(), getegid())
|
||||
SF_CHOWN_TO_RUNBY_RETURN_ON_ERROR(sync_path);
|
||||
}
|
||||
|
||||
binlog_write_cache_buff = (char *)malloc(SYNC_BINLOG_WRITE_BUFF_SIZE);
|
||||
|
|
@ -1486,7 +1486,7 @@ int storage_sync_init()
|
|||
return errno != 0 ? errno : EIO;
|
||||
}
|
||||
|
||||
STORAGE_FCHOWN(g_binlog_fd, full_filename, geteuid(), getegid())
|
||||
SF_FCHOWN_TO_RUNBY_RETURN_ON_ERROR(g_binlog_fd, full_filename);
|
||||
|
||||
/*
|
||||
//printf("full_filename=%s, binlog_file_size=%d\n", \
|
||||
|
|
@ -1631,7 +1631,7 @@ static int storage_binlog_fsync(const bool bNeedLock)
|
|||
binlog_file_size = 0;
|
||||
if (write_ret != 0)
|
||||
{
|
||||
g_continue_flag = false;
|
||||
SF_G_CONTINUE_FLAG = false;
|
||||
logCrit("file: "__FILE__", line: %d, " \
|
||||
"open binlog file \"%s\" fail, " \
|
||||
"program exit!", \
|
||||
|
|
@ -1720,7 +1720,7 @@ static char *get_binlog_readable_filename_ex(
|
|||
snprintf(full_filename, MAX_PATH_SIZE,
|
||||
"%s/data/"SYNC_DIR_NAME"/"SYNC_BINLOG_FILE_PREFIX""
|
||||
SYNC_BINLOG_FILE_EXT_FMT,
|
||||
g_fdfs_base_path, binlog_index);
|
||||
SF_G_BASE_PATH_STR, binlog_index);
|
||||
return full_filename;
|
||||
}
|
||||
|
||||
|
|
@ -1952,13 +1952,13 @@ static char *get_mark_filename_by_id_and_port(const char *storage_id,
|
|||
if (g_use_storage_id)
|
||||
{
|
||||
snprintf(full_filename, filename_size,
|
||||
"%s/data/"SYNC_DIR_NAME"/%s%s", g_fdfs_base_path,
|
||||
"%s/data/"SYNC_DIR_NAME"/%s%s", SF_G_BASE_PATH_STR,
|
||||
storage_id, SYNC_MARK_FILE_EXT);
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(full_filename, filename_size,
|
||||
"%s/data/"SYNC_DIR_NAME"/%s_%d%s", g_fdfs_base_path,
|
||||
"%s/data/"SYNC_DIR_NAME"/%s_%d%s", SF_G_BASE_PATH_STR,
|
||||
storage_id, port, SYNC_MARK_FILE_EXT);
|
||||
}
|
||||
return full_filename;
|
||||
|
|
@ -1968,7 +1968,7 @@ static char *get_mark_filename_by_ip_and_port(const char *ip_addr,
|
|||
const int port, char *full_filename, const int filename_size)
|
||||
{
|
||||
snprintf(full_filename, filename_size,
|
||||
"%s/data/"SYNC_DIR_NAME"/%s_%d%s", g_fdfs_base_path,
|
||||
"%s/data/"SYNC_DIR_NAME"/%s_%d%s", SF_G_BASE_PATH_STR,
|
||||
ip_addr, port, SYNC_MARK_FILE_EXT);
|
||||
return full_filename;
|
||||
}
|
||||
|
|
@ -1976,7 +1976,7 @@ static char *get_mark_filename_by_ip_and_port(const char *ip_addr,
|
|||
char *get_mark_filename_by_reader(StorageBinLogReader *pReader)
|
||||
{
|
||||
return get_mark_filename_by_id_and_port(pReader->storage_id,
|
||||
g_server_port, pReader->mark_filename,
|
||||
SF_G_INNER_PORT, pReader->mark_filename,
|
||||
sizeof(pReader->mark_filename));
|
||||
}
|
||||
|
||||
|
|
@ -1984,7 +1984,7 @@ static char *get_mark_filename_by_id(const char *storage_id,
|
|||
char *full_filename, const int filename_size)
|
||||
{
|
||||
return get_mark_filename_by_id_and_port(storage_id,
|
||||
g_server_port, full_filename, filename_size);
|
||||
SF_G_INNER_PORT, full_filename, filename_size);
|
||||
}
|
||||
|
||||
int storage_report_storage_status(const char *storage_id, \
|
||||
|
|
@ -2017,12 +2017,12 @@ int storage_report_storage_status(const char *storage_id, \
|
|||
"waiting for g_sync_old_done turn to true...", \
|
||||
__LINE__, ip_addr, status);
|
||||
|
||||
while (g_continue_flag && !g_sync_old_done)
|
||||
while (SF_G_CONTINUE_FLAG && !g_sync_old_done)
|
||||
{
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
if (!g_continue_flag)
|
||||
if (!SF_G_CONTINUE_FLAG)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -2048,7 +2048,7 @@ 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 ? g_bind_addr : NULL, &result, false);
|
||||
g_client_bind_addr ? SF_G_INNER_BIND_ADDR : NULL, &result, false);
|
||||
if (conn != NULL)
|
||||
{
|
||||
break;
|
||||
|
|
@ -2098,12 +2098,12 @@ static int storage_reader_sync_init_req(StorageBinLogReader *pReader)
|
|||
|
||||
if (!g_sync_old_done)
|
||||
{
|
||||
while (g_continue_flag && !g_sync_old_done)
|
||||
while (SF_G_CONTINUE_FLAG && !g_sync_old_done)
|
||||
{
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
if (!g_continue_flag)
|
||||
if (!SF_G_CONTINUE_FLAG)
|
||||
{
|
||||
return EINTR;
|
||||
}
|
||||
|
|
@ -2141,10 +2141,10 @@ static int storage_reader_sync_init_req(StorageBinLogReader *pReader)
|
|||
do
|
||||
{
|
||||
conn = NULL;
|
||||
while (g_continue_flag)
|
||||
while (SF_G_CONTINUE_FLAG)
|
||||
{
|
||||
conn = tracker_connect_server_no_pool_ex(pTServer,
|
||||
g_client_bind_addr ? g_bind_addr : NULL, &result, true);
|
||||
g_client_bind_addr ? SF_G_INNER_BIND_ADDR : NULL, &result, true);
|
||||
if (conn != NULL)
|
||||
{
|
||||
break;
|
||||
|
|
@ -2159,7 +2159,7 @@ static int storage_reader_sync_init_req(StorageBinLogReader *pReader)
|
|||
sleep(g_heart_beat_interval);
|
||||
}
|
||||
|
||||
if (!g_continue_flag)
|
||||
if (!SF_G_CONTINUE_FLAG)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
|
@ -2239,7 +2239,7 @@ int storage_reader_init(FDFSStorageBrief *pStorage, StorageBinLogReader *pReader
|
|||
{
|
||||
char old_mark_filename[MAX_PATH_SIZE];
|
||||
get_mark_filename_by_ip_and_port(pStorage->ip_addr,
|
||||
g_server_port, old_mark_filename,
|
||||
SF_G_INNER_PORT, old_mark_filename,
|
||||
sizeof(old_mark_filename));
|
||||
if (fileExists(old_mark_filename))
|
||||
{
|
||||
|
|
@ -2437,7 +2437,7 @@ static int storage_write_to_mark_file(StorageBinLogReader *pReader)
|
|||
|
||||
if ((result=safeWriteToFile(pReader->mark_filename, buff, len)) == 0)
|
||||
{
|
||||
STORAGE_CHOWN(pReader->mark_filename, geteuid(), getegid())
|
||||
SF_CHOWN_TO_RUNBY_RETURN_ON_ERROR(pReader->mark_filename);
|
||||
pReader->last_scan_rows = pReader->scan_row_count;
|
||||
pReader->last_sync_rows = pReader->sync_row_count;
|
||||
}
|
||||
|
|
@ -2911,7 +2911,7 @@ static void* storage_sync_thread_entrance(void* arg)
|
|||
|
||||
pStorage = (FDFSStorageBrief *)arg;
|
||||
strcpy(storage_server.ip_addr, pStorage->ip_addr);
|
||||
storage_server.port = g_server_port;
|
||||
storage_server.port = SF_G_INNER_PORT;
|
||||
storage_server.sock = -1;
|
||||
|
||||
memset(local_ip_addr, 0, sizeof(local_ip_addr));
|
||||
|
|
@ -2922,7 +2922,7 @@ static void* storage_sync_thread_entrance(void* arg)
|
|||
"malloc %d bytes fail, "
|
||||
"fail, program exit!",
|
||||
__LINE__, (int)sizeof(StorageBinLogReader));
|
||||
g_continue_flag = false;
|
||||
SF_G_CONTINUE_FLAG = false;
|
||||
storage_sync_thread_exit(&storage_server);
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -2941,12 +2941,12 @@ static void* storage_sync_thread_entrance(void* arg)
|
|||
"sync thread to storage server %s:%d started", \
|
||||
__LINE__, storage_server.ip_addr, storage_server.port);
|
||||
|
||||
while (g_continue_flag && \
|
||||
while (SF_G_CONTINUE_FLAG && \
|
||||
pStorage->status != FDFS_STORAGE_STATUS_DELETED && \
|
||||
pStorage->status != FDFS_STORAGE_STATUS_IP_CHANGED && \
|
||||
pStorage->status != FDFS_STORAGE_STATUS_NONE)
|
||||
{
|
||||
while (g_continue_flag && \
|
||||
while (SF_G_CONTINUE_FLAG && \
|
||||
(pStorage->status == FDFS_STORAGE_STATUS_INIT ||
|
||||
pStorage->status == FDFS_STORAGE_STATUS_OFFLINE ||
|
||||
pStorage->status == FDFS_STORAGE_STATUS_ONLINE))
|
||||
|
|
@ -2954,7 +2954,7 @@ static void* storage_sync_thread_entrance(void* arg)
|
|||
sleep(1);
|
||||
}
|
||||
|
||||
if ((!g_continue_flag) ||
|
||||
if ((!SF_G_CONTINUE_FLAG) ||
|
||||
pStorage->status == FDFS_STORAGE_STATUS_DELETED || \
|
||||
pStorage->status == FDFS_STORAGE_STATUS_IP_CHANGED || \
|
||||
pStorage->status == FDFS_STORAGE_STATUS_NONE)
|
||||
|
|
@ -2970,7 +2970,7 @@ static void* storage_sync_thread_entrance(void* arg)
|
|||
&start_time, &end_time);
|
||||
start_time += 60;
|
||||
end_time -= 60;
|
||||
while (g_continue_flag && (current_time >= start_time \
|
||||
while (SF_G_CONTINUE_FLAG && (current_time >= start_time \
|
||||
&& current_time <= end_time))
|
||||
{
|
||||
current_time = g_current_time;
|
||||
|
|
@ -2980,7 +2980,7 @@ static void* storage_sync_thread_entrance(void* arg)
|
|||
|
||||
storage_sync_connect_storage_server(pStorage, &storage_server);
|
||||
|
||||
if ((!g_continue_flag) ||
|
||||
if ((!SF_G_CONTINUE_FLAG) ||
|
||||
pStorage->status == FDFS_STORAGE_STATUS_DELETED || \
|
||||
pStorage->status == FDFS_STORAGE_STATUS_IP_CHANGED || \
|
||||
pStorage->status == FDFS_STORAGE_STATUS_NONE)
|
||||
|
|
@ -3006,13 +3006,13 @@ static void* storage_sync_thread_entrance(void* arg)
|
|||
"storage_reader_init fail, errno=%d, " \
|
||||
"program exit!", \
|
||||
__LINE__, result);
|
||||
g_continue_flag = false;
|
||||
SF_G_CONTINUE_FLAG = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!pReader->need_sync_old)
|
||||
{
|
||||
while (g_continue_flag && \
|
||||
while (SF_G_CONTINUE_FLAG && \
|
||||
(pStorage->status != FDFS_STORAGE_STATUS_ACTIVE && \
|
||||
pStorage->status != FDFS_STORAGE_STATUS_DELETED && \
|
||||
pStorage->status != FDFS_STORAGE_STATUS_IP_CHANGED && \
|
||||
|
|
@ -3087,7 +3087,7 @@ static void* storage_sync_thread_entrance(void* arg)
|
|||
}
|
||||
|
||||
sync_result = 0;
|
||||
while (g_continue_flag && (!g_sync_part_time || \
|
||||
while (SF_G_CONTINUE_FLAG && (!g_sync_part_time || \
|
||||
(current_time >= start_time && \
|
||||
current_time <= end_time)) && \
|
||||
(pStorage->status == FDFS_STORAGE_STATUS_ACTIVE || \
|
||||
|
|
@ -3107,7 +3107,7 @@ static void* storage_sync_thread_entrance(void* arg)
|
|||
"storage_write_to_mark_file " \
|
||||
"fail, program exit!", \
|
||||
__LINE__);
|
||||
g_continue_flag = false;
|
||||
SF_G_CONTINUE_FLAG = false;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -3131,7 +3131,7 @@ static void* storage_sync_thread_entrance(void* arg)
|
|||
logCrit("file: "__FILE__", line: %d, " \
|
||||
"storage_write_to_mark_file fail, " \
|
||||
"program exit!", __LINE__);
|
||||
g_continue_flag = false;
|
||||
SF_G_CONTINUE_FLAG = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -3189,7 +3189,7 @@ static void* storage_sync_thread_entrance(void* arg)
|
|||
logCrit("file: "__FILE__", line: %d, " \
|
||||
"rewind_to_prev_rec_end fail, "\
|
||||
"program exit!", __LINE__);
|
||||
g_continue_flag = false;
|
||||
SF_G_CONTINUE_FLAG = false;
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
@ -3211,7 +3211,7 @@ static void* storage_sync_thread_entrance(void* arg)
|
|||
logCrit("file: "__FILE__", line: %d, " \
|
||||
"storage_write_to_mark_file fail, " \
|
||||
"program exit!", __LINE__);
|
||||
g_continue_flag = false;
|
||||
SF_G_CONTINUE_FLAG = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -3220,7 +3220,7 @@ static void* storage_sync_thread_entrance(void* arg)
|
|||
storage_server.sock = -1;
|
||||
storage_reader_destroy(pReader);
|
||||
|
||||
if (!g_continue_flag)
|
||||
if (!SF_G_CONTINUE_FLAG)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
|
@ -3276,7 +3276,7 @@ int storage_sync_thread_start(const FDFSStorageBrief *pStorage)
|
|||
return 0;
|
||||
}
|
||||
|
||||
if ((result=init_pthread_attr(&pattr, g_thread_stack_size)) != 0)
|
||||
if ((result=init_pthread_attr(&pattr, SF_G_THREAD_STACK_SIZE)) != 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ void storage_sync_connect_storage_server_ex(const FDFSStorageBrief *pStorage,
|
|||
nContinuousFail = 0;
|
||||
memset(previousCodes, 0, sizeof(previousCodes));
|
||||
memset(conn_results, 0, sizeof(conn_results));
|
||||
while (g_continue_flag && *check_flag &&
|
||||
while (SF_G_CONTINUE_FLAG && *check_flag &&
|
||||
pStorage->status != FDFS_STORAGE_STATUS_DELETED &&
|
||||
pStorage->status != FDFS_STORAGE_STATUS_IP_CHANGED &&
|
||||
pStorage->status != FDFS_STORAGE_STATUS_NONE)
|
||||
|
|
@ -85,18 +85,18 @@ void storage_sync_connect_storage_server_ex(const FDFSStorageBrief *pStorage,
|
|||
strcpy(conn->ip_addr, ip_addrs.ips[i].address);
|
||||
conn->sock = socketCreateExAuto(conn->ip_addr,
|
||||
O_NONBLOCK, g_client_bind_addr ?
|
||||
g_bind_addr : NULL, &result);
|
||||
SF_G_INNER_BIND_ADDR : NULL, &result);
|
||||
if (conn->sock < 0)
|
||||
{
|
||||
logCrit("file: "__FILE__", line: %d, "
|
||||
"socket create fail, program exit!", __LINE__);
|
||||
g_continue_flag = false;
|
||||
SF_G_CONTINUE_FLAG = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if ((conn_results[i]=connectserverbyip_nb(conn->sock,
|
||||
conn->ip_addr, g_server_port,
|
||||
g_fdfs_connect_timeout)) == 0)
|
||||
conn->ip_addr, SF_G_INNER_PORT,
|
||||
SF_G_CONNECT_TIMEOUT)) == 0)
|
||||
{
|
||||
char szFailPrompt[64];
|
||||
if (nContinuousFail == 0)
|
||||
|
|
@ -112,7 +112,7 @@ void storage_sync_connect_storage_server_ex(const FDFSStorageBrief *pStorage,
|
|||
logInfo("file: "__FILE__", line: %d, "
|
||||
"successfully connect to "
|
||||
"storage server %s:%d%s", __LINE__,
|
||||
conn->ip_addr, g_server_port, szFailPrompt);
|
||||
conn->ip_addr, SF_G_INNER_PORT, szFailPrompt);
|
||||
nContinuousFail = 0;
|
||||
break;
|
||||
}
|
||||
|
|
@ -123,7 +123,7 @@ void storage_sync_connect_storage_server_ex(const FDFSStorageBrief *pStorage,
|
|||
logError("file: "__FILE__", line: %d, "
|
||||
"connect to storage server %s:%d fail, "
|
||||
"errno: %d, error info: %s",
|
||||
__LINE__, conn->ip_addr, g_server_port,
|
||||
__LINE__, conn->ip_addr, SF_G_INNER_PORT,
|
||||
conn_results[i], STRERROR(conn_results[i]));
|
||||
previousCodes[i] = conn_results[i];
|
||||
}
|
||||
|
|
@ -132,7 +132,7 @@ void storage_sync_connect_storage_server_ex(const FDFSStorageBrief *pStorage,
|
|||
conn->sock = -1;
|
||||
}
|
||||
|
||||
if (conn->sock >= 0 || !g_continue_flag)
|
||||
if (conn->sock >= 0 || !SF_G_CONTINUE_FLAG)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
|
@ -149,7 +149,7 @@ void storage_sync_connect_storage_server_ex(const FDFSStorageBrief *pStorage,
|
|||
logError("file: "__FILE__", line: %d, "
|
||||
"connect to storage server %s:%d fail, "
|
||||
"try count: %d, errno: %d, error info: %s",
|
||||
__LINE__, ip_addrs.ips[i].address, g_server_port, avg_fails,
|
||||
__LINE__, ip_addrs.ips[i].address, SF_G_INNER_PORT, avg_fails,
|
||||
conn_results[i], STRERROR(conn_results[i]));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,29 +6,21 @@
|
|||
* Please visit the FastDFS Home Page http://www.fastken.com/ for more detail.
|
||||
**/
|
||||
|
||||
//tracker_nio.h
|
||||
//storage_types.h
|
||||
|
||||
#ifndef _TRACKER_NIO_H
|
||||
#define _TRACKER_NIO_H
|
||||
#ifndef _STORAGE_TYPES_H
|
||||
#define _STORAGE_TYPES_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include "tracker_types.h"
|
||||
#include "storage_func.h"
|
||||
#include "fastcommon/fast_task_queue.h"
|
||||
#include "storage_global.h"
|
||||
#include "tracker_types.h"
|
||||
#include "fdht_types.h"
|
||||
#include "trunk_mem.h"
|
||||
#include "fastcommon/md5.h"
|
||||
|
||||
#define FDFS_STORAGE_STAGE_NIO_INIT 0
|
||||
#define FDFS_STORAGE_STAGE_NIO_RECV 1
|
||||
#define FDFS_STORAGE_STAGE_NIO_SEND 2
|
||||
#define FDFS_STORAGE_STAGE_NIO_CLOSE 4 //close socket
|
||||
#define FDFS_STORAGE_STAGE_DIO_THREAD 8
|
||||
|
||||
#define FDFS_STORAGE_FILE_OP_READ 'R'
|
||||
#define FDFS_STORAGE_FILE_OP_WRITE 'W'
|
||||
#define FDFS_STORAGE_FILE_OP_APPEND 'A'
|
||||
|
|
@ -40,13 +32,14 @@ typedef int (*TaskDealFunc)(struct fast_task_info *pTask);
|
|||
/* this clean func will be called when connection disconnected */
|
||||
typedef void (*DisconnectCleanFunc)(struct fast_task_info *pTask);
|
||||
|
||||
typedef void (*DeleteFileLogCallback)(struct fast_task_info *pTask, \
|
||||
typedef void (*DeleteFileLogCallback)(struct fast_task_info *pTask,
|
||||
const int err_no);
|
||||
|
||||
typedef void (*FileDealDoneCallback)(struct fast_task_info *pTask, \
|
||||
typedef void (*FileDealDoneCallback)(struct fast_task_info *pTask,
|
||||
const int err_no);
|
||||
|
||||
typedef int (*FileDealContinueCallback)(struct fast_task_info *pTask);
|
||||
typedef int (*FileDealContinueCallback)(struct fast_task_info *pTask,
|
||||
const int stage);
|
||||
|
||||
typedef int (*FileBeforeOpenCallback)(struct fast_task_info *pTask);
|
||||
typedef int (*FileBeforeCloseCallback)(struct fast_task_info *pTask);
|
||||
|
|
@ -57,6 +50,21 @@ typedef int (*FileBeforeCloseCallback)(struct fast_task_info *pTask);
|
|||
#define _FILE_TYPE_REGULAR 8
|
||||
#define _FILE_TYPE_LINK 16
|
||||
|
||||
typedef struct
|
||||
{
|
||||
FDFSStorageBrief server;
|
||||
int last_sync_src_timestamp;
|
||||
} FDFSStorageServer;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
signed char my_status; //my status from tracker server
|
||||
signed char my_result; //my report result
|
||||
signed char src_storage_result; //src storage report result
|
||||
bool get_my_ip_done;
|
||||
bool report_my_status;
|
||||
} StorageStatusPerTracker;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
bool if_gen_filename; //if upload generate filename
|
||||
|
|
@ -120,8 +128,6 @@ typedef struct
|
|||
|
||||
typedef struct
|
||||
{
|
||||
int nio_thread_index; //nio thread index
|
||||
char stage; //nio stage, send or recv
|
||||
char storage_server_id[FDFS_STORAGE_ID_MAX_SIZE];
|
||||
|
||||
StorageFileContext file_context;
|
||||
|
|
@ -137,24 +143,4 @@ typedef struct
|
|||
DisconnectCleanFunc clean_func; //clean function pointer when finished
|
||||
} StorageClientInfo;
|
||||
|
||||
struct storage_nio_thread_data
|
||||
{
|
||||
struct nio_thread_data thread_data;
|
||||
GroupArray group_array; //FastDHT group array
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void storage_recv_notify_read(int sock, short event, void *arg);
|
||||
int storage_send_add_event(struct fast_task_info *pTask);
|
||||
|
||||
void task_finish_clean_up(struct fast_task_info *pTask);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -219,7 +219,7 @@ static void *tracker_report_thread_entrance(void *arg)
|
|||
bool bServerPortChanged;
|
||||
|
||||
bServerPortChanged = (g_last_server_port != 0) && \
|
||||
(g_server_port != g_last_server_port);
|
||||
(SF_G_INNER_PORT != g_last_server_port);
|
||||
|
||||
pTrackerServer = (TrackerServerInfo *)arg;
|
||||
fdfs_server_sock_reset(pTrackerServer);
|
||||
|
|
@ -231,7 +231,7 @@ static void *tracker_report_thread_entrance(void *arg)
|
|||
pTrackerServer->connections[0].port);
|
||||
|
||||
sync_old_done = g_sync_old_done;
|
||||
while (g_continue_flag && \
|
||||
while (SF_G_CONTINUE_FLAG && \
|
||||
g_tracker_reporter_count < g_tracker_group.server_count)
|
||||
{
|
||||
sleep(1); //waiting for all thread started
|
||||
|
|
@ -241,7 +241,7 @@ static void *tracker_report_thread_entrance(void *arg)
|
|||
previousCode = 0;
|
||||
nContinuousFail = 0;
|
||||
conn = NULL;
|
||||
while (g_continue_flag)
|
||||
while (SF_G_CONTINUE_FLAG)
|
||||
{
|
||||
if (conn != NULL)
|
||||
{
|
||||
|
|
@ -249,7 +249,8 @@ static void *tracker_report_thread_entrance(void *arg)
|
|||
}
|
||||
|
||||
conn = tracker_connect_server_no_pool_ex(pTrackerServer,
|
||||
g_client_bind_addr ? g_bind_addr : NULL, &result, false);
|
||||
g_client_bind_addr ? SF_G_INNER_BIND_ADDR : NULL,
|
||||
&result, false);
|
||||
if (conn == NULL)
|
||||
{
|
||||
if (previousCode != result)
|
||||
|
|
@ -264,7 +265,7 @@ static void *tracker_report_thread_entrance(void *arg)
|
|||
}
|
||||
|
||||
nContinuousFail++;
|
||||
if (g_continue_flag)
|
||||
if (SF_G_CONTINUE_FLAG)
|
||||
{
|
||||
sleep(g_heart_beat_interval);
|
||||
continue;
|
||||
|
|
@ -277,11 +278,11 @@ static void *tracker_report_thread_entrance(void *arg)
|
|||
|
||||
if ((result=storage_set_tracker_client_ips(conn, tracker_index)) != 0)
|
||||
{
|
||||
g_continue_flag = false;
|
||||
SF_G_CONTINUE_FLAG = false;
|
||||
break;
|
||||
}
|
||||
|
||||
tcpsetserveropt(conn->sock, g_fdfs_network_timeout);
|
||||
tcpsetserveropt(conn->sock, SF_G_NETWORK_TIMEOUT);
|
||||
getSockIpaddr(conn->sock, tracker_client_ip, IP_ADDRESS_SIZE);
|
||||
|
||||
if (nContinuousFail == 0)
|
||||
|
|
@ -355,7 +356,7 @@ static void *tracker_report_thread_entrance(void *arg)
|
|||
" fail, program exit!", \
|
||||
__LINE__);
|
||||
|
||||
g_continue_flag = false;
|
||||
SF_G_CONTINUE_FLAG = false;
|
||||
pthread_mutex_unlock( \
|
||||
&reporter_thread_lock);
|
||||
break;
|
||||
|
|
@ -442,7 +443,7 @@ static void *tracker_report_thread_entrance(void *arg)
|
|||
last_trunk_file_id = 0;
|
||||
last_trunk_total_free_space = -1;
|
||||
|
||||
while (g_continue_flag)
|
||||
while (SF_G_CONTINUE_FLAG)
|
||||
{
|
||||
current_time = g_current_time;
|
||||
if (current_time - last_beat_time >=
|
||||
|
|
@ -532,7 +533,7 @@ static void *tracker_report_thread_entrance(void *arg)
|
|||
}
|
||||
|
||||
conn_pool_disconnect_server(conn);
|
||||
if (g_continue_flag)
|
||||
if (SF_G_CONTINUE_FLAG)
|
||||
{
|
||||
sleep(1);
|
||||
}
|
||||
|
|
@ -610,7 +611,7 @@ int tracker_sync_diff_servers(ConnectionInfo *pTrackerServer, \
|
|||
out_len = sizeof(FDFSStorageBrief) * server_count;
|
||||
long2buff(out_len, resp.pkg_len);
|
||||
if ((result=tcpsenddata_nb(pTrackerServer->sock, &resp, sizeof(resp), \
|
||||
g_fdfs_network_timeout)) != 0)
|
||||
SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"trackert server %s:%d, send data fail, " \
|
||||
|
|
@ -621,7 +622,7 @@ int tracker_sync_diff_servers(ConnectionInfo *pTrackerServer, \
|
|||
}
|
||||
|
||||
if ((result=tcpsenddata_nb(pTrackerServer->sock, \
|
||||
briefServers, out_len, g_fdfs_network_timeout)) != 0)
|
||||
briefServers, out_len, SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"trackert server %s:%d, send data fail, " \
|
||||
|
|
@ -633,7 +634,7 @@ int tracker_sync_diff_servers(ConnectionInfo *pTrackerServer, \
|
|||
|
||||
|
||||
if ((result=tcprecvdata_nb(pTrackerServer->sock, &resp, \
|
||||
sizeof(resp), g_fdfs_network_timeout)) != 0)
|
||||
sizeof(resp), SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"tracker server %s:%d, recv data fail, " \
|
||||
|
|
@ -677,7 +678,7 @@ int tracker_report_storage_status(ConnectionInfo *pTrackerServer, \
|
|||
briefServer, sizeof(FDFSStorageBrief));
|
||||
if ((result=tcpsenddata_nb(pTrackerServer->sock, out_buff, \
|
||||
sizeof(TrackerHeader) + FDFS_GROUP_NAME_MAX_LEN + \
|
||||
sizeof(FDFSStorageBrief), g_fdfs_network_timeout)) != 0)
|
||||
sizeof(FDFSStorageBrief), SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"trackert server %s:%d, send data fail, " \
|
||||
|
|
@ -688,7 +689,7 @@ int tracker_report_storage_status(ConnectionInfo *pTrackerServer, \
|
|||
}
|
||||
|
||||
if ((result=tcprecvdata_nb(pTrackerServer->sock, &resp, \
|
||||
sizeof(resp), g_fdfs_network_timeout)) != 0)
|
||||
sizeof(resp), SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"tracker server %s:%d, recv data fail, " \
|
||||
|
|
@ -881,7 +882,7 @@ static int tracker_merge_servers(ConnectionInfo *pTrackerServer,
|
|||
*(pServer->ip_addr + IP_ADDRESS_SIZE - 1) = '\0';
|
||||
if ((strcmp(pServer->id, g_my_server_id_str) == 0) ||
|
||||
(is_local_host_ip(pServer->ip_addr) &&
|
||||
buff2int(pServer->port) == g_server_port))
|
||||
buff2int(pServer->port) == SF_G_INNER_PORT))
|
||||
{
|
||||
need_rejoin_tracker = true;
|
||||
logWarning("file: "__FILE__", line: %d, " \
|
||||
|
|
@ -1049,7 +1050,7 @@ static int _notify_reselect_tleader(ConnectionInfo *conn)
|
|||
memset(out_buff, 0, sizeof(out_buff));
|
||||
pHeader->cmd = TRACKER_PROTO_CMD_TRACKER_NOTIFY_RESELECT_LEADER;
|
||||
if ((result=tcpsenddata_nb(conn->sock, out_buff, \
|
||||
sizeof(out_buff), g_fdfs_network_timeout)) != 0)
|
||||
sizeof(out_buff), SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"tracker server %s:%d, send data fail, "
|
||||
|
|
@ -1288,7 +1289,7 @@ static int tracker_check_response(ConnectionInfo *pTrackerServer,
|
|||
char *pFlags;
|
||||
|
||||
if ((result=tcprecvdata_nb(pTrackerServer->sock, &resp, \
|
||||
sizeof(resp), g_fdfs_network_timeout)) != 0)
|
||||
sizeof(resp), SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"tracker server %s:%d, recv data fail, " \
|
||||
|
|
@ -1335,7 +1336,7 @@ static int tracker_check_response(ConnectionInfo *pTrackerServer,
|
|||
}
|
||||
|
||||
if ((result=tcprecvdata_nb(pTrackerServer->sock, in_buff, \
|
||||
nInPackLen, g_fdfs_network_timeout)) != 0)
|
||||
nInPackLen, SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"tracker server %s:%d, recv data fail, " \
|
||||
|
|
@ -1461,7 +1462,7 @@ static int tracker_check_response(ConnectionInfo *pTrackerServer,
|
|||
set_trunk_server(pBriefServers->ip_addr, port);
|
||||
if ((strcmp(pBriefServers->id, g_my_server_id_str) == 0) ||
|
||||
(is_local_host_ip(pBriefServers->ip_addr) &&
|
||||
port == g_server_port))
|
||||
port == SF_G_INNER_PORT))
|
||||
{
|
||||
if (g_if_trunker_self)
|
||||
{
|
||||
|
|
@ -1542,13 +1543,13 @@ static int tracker_check_response(ConnectionInfo *pTrackerServer,
|
|||
|
||||
tracker_rename_mark_files(pStorage->ip_addr, \
|
||||
g_last_server_port, pStorage->ip_addr, \
|
||||
g_server_port);
|
||||
SF_G_INNER_PORT);
|
||||
}
|
||||
}
|
||||
|
||||
if (g_server_port != g_last_server_port)
|
||||
if (SF_G_INNER_PORT != g_last_server_port)
|
||||
{
|
||||
g_last_server_port = g_server_port;
|
||||
g_last_server_port = SF_G_INNER_PORT;
|
||||
if ((result=storage_write_to_sync_ini_file()) != 0)
|
||||
{
|
||||
return result;
|
||||
|
|
@ -1581,7 +1582,7 @@ int tracker_sync_src_req(ConnectionInfo *pTrackerServer, \
|
|||
strcpy(out_buff + sizeof(TrackerHeader) + FDFS_GROUP_NAME_MAX_LEN, \
|
||||
pReader->storage_id);
|
||||
if ((result=tcpsenddata_nb(pTrackerServer->sock, out_buff, \
|
||||
sizeof(out_buff), g_fdfs_network_timeout)) != 0)
|
||||
sizeof(out_buff), SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"tracker server %s:%d, send data fail, " \
|
||||
|
|
@ -1643,7 +1644,7 @@ static int tracker_sync_dest_req(ConnectionInfo *pTrackerServer)
|
|||
memset(&header, 0, sizeof(header));
|
||||
header.cmd = TRACKER_PROTO_CMD_STORAGE_SYNC_DEST_REQ;
|
||||
if ((result=tcpsenddata_nb(pTrackerServer->sock, &header, \
|
||||
sizeof(header), g_fdfs_network_timeout)) != 0)
|
||||
sizeof(header), SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"tracker server %s:%d, send data fail, " \
|
||||
|
|
@ -1700,7 +1701,7 @@ static int tracker_sync_dest_query(ConnectionInfo *pTrackerServer)
|
|||
memset(&header, 0, sizeof(header));
|
||||
header.cmd = TRACKER_PROTO_CMD_STORAGE_SYNC_DEST_QUERY;
|
||||
if ((result=tcpsenddata_nb(pTrackerServer->sock, &header, \
|
||||
sizeof(header), g_fdfs_network_timeout)) != 0)
|
||||
sizeof(header), SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"tracker server %s:%d, send data fail, " \
|
||||
|
|
@ -1762,7 +1763,7 @@ static int tracker_report_trunk_fid(ConnectionInfo *pTrackerServer)
|
|||
int2buff(g_current_trunk_file_id, out_buff + sizeof(TrackerHeader));
|
||||
|
||||
if ((result=tcpsenddata_nb(pTrackerServer->sock, out_buff, \
|
||||
sizeof(out_buff), g_fdfs_network_timeout)) != 0)
|
||||
sizeof(out_buff), SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"tracker server %s:%d, send data fail, " \
|
||||
|
|
@ -1808,7 +1809,7 @@ static int tracker_report_trunk_free_space(ConnectionInfo *pTrackerServer)
|
|||
long2buff(g_trunk_total_free_space / FDFS_ONE_MB, \
|
||||
out_buff + sizeof(TrackerHeader));
|
||||
if ((result=tcpsenddata_nb(pTrackerServer->sock, out_buff, \
|
||||
sizeof(out_buff), g_fdfs_network_timeout)) != 0)
|
||||
sizeof(out_buff), SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"tracker server %s:%d, send data fail, " \
|
||||
|
|
@ -1854,7 +1855,7 @@ static int tracker_fetch_trunk_fid(ConnectionInfo *pTrackerServer)
|
|||
memset(out_buff, 0, sizeof(out_buff));
|
||||
pHeader->cmd = TRACKER_PROTO_CMD_STORAGE_FETCH_TRUNK_FID;
|
||||
if ((result=tcpsenddata_nb(pTrackerServer->sock, out_buff, \
|
||||
sizeof(out_buff), g_fdfs_network_timeout)) != 0)
|
||||
sizeof(out_buff), SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"tracker server %s:%d, send data fail, " \
|
||||
|
|
@ -1928,7 +1929,7 @@ static int tracker_sync_notify(ConnectionInfo *pTrackerServer, const int tracker
|
|||
long2buff(g_sync_until_timestamp, pReqBody->until_timestamp);
|
||||
|
||||
if ((result=tcpsenddata_nb(pTrackerServer->sock, out_buff, \
|
||||
sizeof(out_buff), g_fdfs_network_timeout)) != 0)
|
||||
sizeof(out_buff), SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"tracker server %s:%d, send data fail, " \
|
||||
|
|
@ -2009,13 +2010,13 @@ int tracker_report_join(ConnectionInfo *pTrackerServer, \
|
|||
strcpy(pReqBody->domain_name, g_http_domain);
|
||||
snprintf(pReqBody->version, sizeof(pReqBody->version), "%d.%02d", \
|
||||
g_fdfs_version.major, g_fdfs_version.minor);
|
||||
long2buff(g_server_port, pReqBody->storage_port);
|
||||
long2buff(SF_G_INNER_PORT, pReqBody->storage_port);
|
||||
long2buff(g_http_port, pReqBody->storage_http_port);
|
||||
long2buff(g_fdfs_store_paths.count, pReqBody->store_path_count);
|
||||
long2buff(g_subdir_count_per_path, pReqBody->subdir_count_per_path);
|
||||
long2buff(g_upload_priority, pReqBody->upload_priority);
|
||||
long2buff(g_storage_join_time, pReqBody->join_time);
|
||||
long2buff(g_up_time, pReqBody->up_time);
|
||||
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);
|
||||
|
||||
|
|
@ -2078,7 +2079,7 @@ int tracker_report_join(ConnectionInfo *pTrackerServer, \
|
|||
long2buff(out_len - (int)sizeof(TrackerHeader), pHeader->pkg_len);
|
||||
|
||||
if ((result=tcpsenddata_nb(pTrackerServer->sock, out_buff, \
|
||||
out_len, g_fdfs_network_timeout)) != 0)
|
||||
out_len, SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"tracker server %s:%d, send data fail, " \
|
||||
|
|
@ -2162,7 +2163,7 @@ static int tracker_report_sync_timestamp(ConnectionInfo *pTrackerServer,
|
|||
}
|
||||
|
||||
if((result=tcpsenddata_nb(pTrackerServer->sock, out_buff, \
|
||||
sizeof(TrackerHeader) + body_len, g_fdfs_network_timeout)) != 0)
|
||||
sizeof(TrackerHeader) + body_len, SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"tracker server %s:%d, send data fail, " \
|
||||
|
|
@ -2268,7 +2269,7 @@ static int tracker_report_df_stat(ConnectionInfo *pTrackerServer,
|
|||
}
|
||||
|
||||
result = tcpsenddata_nb(pTrackerServer->sock, pBuff, \
|
||||
total_len, g_fdfs_network_timeout);
|
||||
total_len, SF_G_NETWORK_TIMEOUT);
|
||||
if (pBuff != out_buff)
|
||||
{
|
||||
free(pBuff);
|
||||
|
|
@ -2405,7 +2406,7 @@ static int tracker_heart_beat(ConnectionInfo *pTrackerServer,
|
|||
pHeader->cmd = TRACKER_PROTO_CMD_STORAGE_BEAT;
|
||||
|
||||
if((result=tcpsenddata_nb(pTrackerServer->sock, out_buff, \
|
||||
sizeof(TrackerHeader) + body_len, g_fdfs_network_timeout)) != 0)
|
||||
sizeof(TrackerHeader) + body_len, SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"tracker server %s:%d, send data fail, " \
|
||||
|
|
@ -2462,7 +2463,7 @@ static int tracker_storage_change_status(ConnectionInfo *pTrackerServer,
|
|||
*(out_buff + sizeof(TrackerHeader)) = new_status;
|
||||
|
||||
if((result=tcpsenddata_nb(pTrackerServer->sock, out_buff,
|
||||
sizeof(TrackerHeader) + body_len, g_fdfs_network_timeout)) != 0)
|
||||
sizeof(TrackerHeader) + body_len, SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"tracker server %s:%d, send data fail, "
|
||||
|
|
@ -2509,7 +2510,7 @@ static int tracker_storage_changelog_req(ConnectionInfo *pTrackerServer)
|
|||
pHeader->cmd = TRACKER_PROTO_CMD_STORAGE_CHANGELOG_REQ;
|
||||
|
||||
if((result=tcpsenddata_nb(pTrackerServer->sock, out_buff, \
|
||||
sizeof(TrackerHeader), g_fdfs_network_timeout)) != 0)
|
||||
sizeof(TrackerHeader), SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"tracker server %s:%d, send data fail, " \
|
||||
|
|
@ -2614,7 +2615,7 @@ int tracker_deal_changelog_response(ConnectionInfo *pTrackerServer)
|
|||
if (!g_use_storage_id)
|
||||
{
|
||||
tracker_rename_mark_files(pOldStorageId, \
|
||||
g_server_port, pNewStorageId, g_server_port);
|
||||
SF_G_INNER_PORT, pNewStorageId, SF_G_INNER_PORT);
|
||||
if (strcmp(g_sync_src_id, pOldStorageId) == 0)
|
||||
{
|
||||
snprintf(g_sync_src_id, \
|
||||
|
|
@ -2655,7 +2656,7 @@ int tracker_report_thread_start()
|
|||
int bytes;
|
||||
int result;
|
||||
|
||||
if ((result=init_pthread_attr(&pattr, g_thread_stack_size)) != 0)
|
||||
if ((result=init_pthread_attr(&pattr, SF_G_THREAD_STACK_SIZE)) != 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ static int trunk_client_trunk_do_alloc_space(ConnectionInfo *pTrunkServer, \
|
|||
pHeader->cmd = STORAGE_PROTO_CMD_TRUNK_ALLOC_SPACE;
|
||||
|
||||
if ((result=tcpsenddata_nb(pTrunkServer->sock, out_buff, \
|
||||
sizeof(out_buff), g_fdfs_network_timeout)) != 0)
|
||||
sizeof(out_buff), SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"send data to storage server %s:%d fail, " \
|
||||
|
|
@ -186,7 +186,7 @@ static int trunk_client_trunk_confirm_or_free(ConnectionInfo *pTrunkServer,\
|
|||
int2buff(pTrunkInfo->file.size, pTrunkBuff->size);
|
||||
|
||||
if ((result=tcpsenddata_nb(pTrunkServer->sock, out_buff, \
|
||||
sizeof(out_buff), g_fdfs_network_timeout)) != 0)
|
||||
sizeof(out_buff), SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"send data to storage server %s:%d fail, " \
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ static int storage_trunk_node_compare_offset(void *p1, void *p2)
|
|||
char *storage_trunk_get_data_filename(char *full_filename)
|
||||
{
|
||||
snprintf(full_filename, MAX_PATH_SIZE, "%s/data/%s",
|
||||
g_fdfs_base_path, STORAGE_TRUNK_DATA_FILENAME);
|
||||
SF_G_BASE_PATH_STR, STORAGE_TRUNK_DATA_FILENAME);
|
||||
return full_filename;
|
||||
}
|
||||
|
||||
|
|
@ -269,7 +269,7 @@ int storage_trunk_init()
|
|||
/*
|
||||
{
|
||||
char filename[MAX_PATH_SIZE];
|
||||
sprintf(filename, "%s/logs/tttt.dat", g_fdfs_base_path);
|
||||
sprintf(filename, "%s/logs/tttt.dat", SF_G_BASE_PATH_STR);
|
||||
trunk_free_block_tree_print(filename);
|
||||
}
|
||||
*/
|
||||
|
|
@ -301,7 +301,7 @@ int storage_trunk_destroy_ex(const bool bNeedSleep,
|
|||
"storage trunk destroy", __LINE__);
|
||||
if (bSaveData)
|
||||
{
|
||||
if (g_current_time - g_up_time >= 3600 &&
|
||||
if (g_current_time - g_sf_global_vars.up_time >= 3600 &&
|
||||
g_trunk_compress_binlog_interval == 0)
|
||||
{
|
||||
result = storage_trunk_save();
|
||||
|
|
@ -727,7 +727,7 @@ static int trunk_open_file_writers(struct walk_callback_args *pCallbackArgs)
|
|||
memset(pCallbackArgs, 0, sizeof(*pCallbackArgs));
|
||||
|
||||
snprintf(temp_trunk_filename, MAX_PATH_SIZE, "%s/data/.%s.tmp",
|
||||
g_fdfs_base_path, STORAGE_TRUNK_DATA_FILENAME);
|
||||
SF_G_BASE_PATH_STR, STORAGE_TRUNK_DATA_FILENAME);
|
||||
if ((result=buffered_file_writer_open(&pCallbackArgs->data_writer,
|
||||
temp_trunk_filename)) != 0)
|
||||
{
|
||||
|
|
@ -958,12 +958,12 @@ static int storage_trunk_compress()
|
|||
return EAGAIN;
|
||||
}
|
||||
|
||||
if (g_current_time - g_up_time < 600)
|
||||
if (g_current_time - g_sf_global_vars.up_time < 600)
|
||||
{
|
||||
logWarning("file: "__FILE__", line: %d, "
|
||||
"too little time lapse: %ds afer startup, "
|
||||
"skip trunk binlog compress", __LINE__,
|
||||
(int)(g_current_time - g_up_time));
|
||||
(int)(g_current_time - g_sf_global_vars.up_time));
|
||||
return EAGAIN;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ FDFSStorePathInfo *storage_load_paths_from_conf_file_ex(
|
|||
return NULL;
|
||||
}
|
||||
|
||||
pPath = g_fdfs_base_path;
|
||||
pPath = SF_G_BASE_PATH_STR;
|
||||
}
|
||||
|
||||
store_paths[0].path_len = strlen(pPath);
|
||||
|
|
@ -185,20 +185,20 @@ int storage_load_paths_from_conf_file(IniContext *pItemContext)
|
|||
return ENOENT;
|
||||
}
|
||||
|
||||
snprintf(g_fdfs_base_path, sizeof(g_fdfs_base_path), "%s", pPath);
|
||||
chopPath(g_fdfs_base_path);
|
||||
if (!fileExists(g_fdfs_base_path))
|
||||
snprintf(SF_G_BASE_PATH_STR, sizeof(SF_G_BASE_PATH_STR), "%s", pPath);
|
||||
chopPath(SF_G_BASE_PATH_STR);
|
||||
if (!fileExists(SF_G_BASE_PATH_STR))
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"\"%s\" can't be accessed, error info: %s",
|
||||
__LINE__, STRERROR(errno), g_fdfs_base_path);
|
||||
__LINE__, STRERROR(errno), SF_G_BASE_PATH_STR);
|
||||
return errno != 0 ? errno : ENOENT;
|
||||
}
|
||||
if (!isDir(g_fdfs_base_path))
|
||||
if (!isDir(SF_G_BASE_PATH_STR))
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"\"%s\" is not a directory!",
|
||||
__LINE__, g_fdfs_base_path);
|
||||
__LINE__, SF_G_BASE_PATH_STR);
|
||||
return ENOTDIR;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ char *get_trunk_binlog_filename(char *full_filename)
|
|||
{
|
||||
snprintf(full_filename, MAX_PATH_SIZE, \
|
||||
"%s/data/"TRUNK_DIR_NAME"/"TRUNK_SYNC_BINLOG_FILENAME_STR, \
|
||||
g_fdfs_base_path);
|
||||
SF_G_BASE_PATH_STR);
|
||||
return full_filename;
|
||||
}
|
||||
|
||||
|
|
@ -171,7 +171,7 @@ int trunk_sync_init()
|
|||
char binlog_filename[MAX_PATH_SIZE];
|
||||
int result;
|
||||
|
||||
snprintf(data_path, sizeof(data_path), "%s/data", g_fdfs_base_path);
|
||||
snprintf(data_path, sizeof(data_path), "%s/data", SF_G_BASE_PATH_STR);
|
||||
if (!fileExists(data_path))
|
||||
{
|
||||
if (mkdir(data_path, 0755) != 0)
|
||||
|
|
@ -184,7 +184,7 @@ int trunk_sync_init()
|
|||
return errno != 0 ? errno : ENOENT;
|
||||
}
|
||||
|
||||
STORAGE_CHOWN(data_path, geteuid(), getegid())
|
||||
SF_CHOWN_TO_RUNBY_RETURN_ON_ERROR(data_path);
|
||||
}
|
||||
|
||||
snprintf(sync_path, sizeof(sync_path), \
|
||||
|
|
@ -201,7 +201,7 @@ int trunk_sync_init()
|
|||
return errno != 0 ? errno : ENOENT;
|
||||
}
|
||||
|
||||
STORAGE_CHOWN(sync_path, geteuid(), getegid())
|
||||
SF_CHOWN_TO_RUNBY_RETURN_ON_ERROR(sync_path);
|
||||
}
|
||||
|
||||
trunk_binlog_write_cache_buff = (char *)malloc( \
|
||||
|
|
@ -227,7 +227,7 @@ int trunk_sync_init()
|
|||
return result;
|
||||
}
|
||||
|
||||
STORAGE_FCHOWN(trunk_binlog_fd, binlog_filename, geteuid(), getegid())
|
||||
SF_FCHOWN_TO_RUNBY_RETURN_ON_ERROR(trunk_binlog_fd, binlog_filename);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -344,7 +344,7 @@ int trunk_sync_notify_thread_reset_offset()
|
|||
__LINE__, count);
|
||||
|
||||
done = false;
|
||||
for (i=0; i<300 && g_continue_flag; i++)
|
||||
for (i=0; i<300 && SF_G_CONTINUE_FLAG; i++)
|
||||
{
|
||||
info_end = sync_thread_info_array.thread_data +
|
||||
sync_thread_info_array.alloc_count;
|
||||
|
|
@ -487,7 +487,7 @@ static int trunk_binlog_delete_overflow_backups()
|
|||
TrunkBinlogBackupFileArray file_array;
|
||||
|
||||
snprintf(file_path, sizeof(file_path),
|
||||
"%s/data/%s", g_fdfs_base_path, TRUNK_DIR_NAME);
|
||||
"%s/data/%s", SF_G_BASE_PATH_STR, TRUNK_DIR_NAME);
|
||||
if ((dir=opendir(file_path)) == NULL)
|
||||
{
|
||||
result = errno != 0 ? errno : EPERM;
|
||||
|
|
@ -1435,7 +1435,7 @@ static char *get_binlog_readable_filename(const void *pArg,
|
|||
|
||||
snprintf(full_filename, MAX_PATH_SIZE,
|
||||
"%s/data/"TRUNK_DIR_NAME"/"TRUNK_SYNC_BINLOG_FILENAME_STR,
|
||||
g_fdfs_base_path);
|
||||
SF_G_BASE_PATH_STR);
|
||||
return full_filename;
|
||||
}
|
||||
|
||||
|
|
@ -1505,13 +1505,13 @@ static char *trunk_get_mark_filename_by_id_and_port(const char *storage_id, \
|
|||
if (g_use_storage_id)
|
||||
{
|
||||
snprintf(full_filename, filename_size, \
|
||||
"%s/data/"TRUNK_DIR_NAME"/%s%s", g_fdfs_base_path, \
|
||||
"%s/data/"TRUNK_DIR_NAME"/%s%s", SF_G_BASE_PATH_STR, \
|
||||
storage_id, TRUNK_SYNC_MARK_FILE_EXT_STR);
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(full_filename, filename_size, \
|
||||
"%s/data/"TRUNK_DIR_NAME"/%s_%d%s", g_fdfs_base_path, \
|
||||
"%s/data/"TRUNK_DIR_NAME"/%s_%d%s", SF_G_BASE_PATH_STR, \
|
||||
storage_id, port, TRUNK_SYNC_MARK_FILE_EXT_STR);
|
||||
}
|
||||
|
||||
|
|
@ -1522,7 +1522,7 @@ static char *trunk_get_mark_filename_by_ip_and_port(const char *ip_addr, \
|
|||
const int port, char *full_filename, const int filename_size)
|
||||
{
|
||||
snprintf(full_filename, filename_size, \
|
||||
"%s/data/"TRUNK_DIR_NAME"/%s_%d%s", g_fdfs_base_path, \
|
||||
"%s/data/"TRUNK_DIR_NAME"/%s_%d%s", SF_G_BASE_PATH_STR, \
|
||||
ip_addr, port, TRUNK_SYNC_MARK_FILE_EXT_STR);
|
||||
|
||||
return full_filename;
|
||||
|
|
@ -1540,13 +1540,13 @@ char *trunk_mark_filename_by_reader(const void *pArg, char *full_filename)
|
|||
}
|
||||
|
||||
return trunk_get_mark_filename_by_id_and_port(pReader->storage_id, \
|
||||
g_server_port, full_filename, MAX_PATH_SIZE);
|
||||
SF_G_INNER_PORT, full_filename, MAX_PATH_SIZE);
|
||||
}
|
||||
|
||||
static char *trunk_get_mark_filename_by_id(const char *storage_id,
|
||||
char *full_filename, const int filename_size)
|
||||
{
|
||||
return trunk_get_mark_filename_by_id_and_port(storage_id, g_server_port, \
|
||||
return trunk_get_mark_filename_by_id_and_port(storage_id, SF_G_INNER_PORT, \
|
||||
full_filename, filename_size);
|
||||
}
|
||||
|
||||
|
|
@ -1598,7 +1598,7 @@ int trunk_reader_init(const FDFSStorageBrief *pStorage,
|
|||
{
|
||||
char old_mark_filename[MAX_PATH_SIZE];
|
||||
trunk_get_mark_filename_by_ip_and_port(
|
||||
pStorage->ip_addr, g_server_port,
|
||||
pStorage->ip_addr, SF_G_INNER_PORT,
|
||||
old_mark_filename, sizeof(old_mark_filename));
|
||||
if (fileExists(old_mark_filename))
|
||||
{
|
||||
|
|
@ -1717,7 +1717,7 @@ static int trunk_write_to_mark_file(TrunkBinLogReader *pReader)
|
|||
|
||||
if ((result=safeWriteToFile(pReader->mark_filename, buff, len)) == 0)
|
||||
{
|
||||
STORAGE_CHOWN(pReader->mark_filename, geteuid(), getegid())
|
||||
SF_CHOWN_TO_RUNBY_RETURN_ON_ERROR(pReader->mark_filename);
|
||||
pReader->last_binlog_offset = pReader->binlog_offset;
|
||||
}
|
||||
|
||||
|
|
@ -2008,7 +2008,7 @@ static int trunk_sync_data(TrunkBinLogReader *pReader, \
|
|||
long2buff(length, header.pkg_len);
|
||||
header.cmd = STORAGE_PROTO_CMD_TRUNK_SYNC_BINLOG;
|
||||
if ((result=tcpsenddata_nb(pStorage->sock, &header, \
|
||||
sizeof(TrackerHeader), g_fdfs_network_timeout)) != 0)
|
||||
sizeof(TrackerHeader), SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("FILE: "__FILE__", line: %d, " \
|
||||
"send data to storage server %s:%d fail, " \
|
||||
|
|
@ -2019,7 +2019,7 @@ static int trunk_sync_data(TrunkBinLogReader *pReader, \
|
|||
}
|
||||
|
||||
if ((result=tcpsenddata_nb(pStorage->sock, pReader->binlog_buff.buffer,\
|
||||
length, g_fdfs_network_timeout)) != 0)
|
||||
length, SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("FILE: "__FILE__", line: %d, " \
|
||||
"send data to storage server %s:%d fail, " \
|
||||
|
|
@ -2072,14 +2072,14 @@ static void *trunk_sync_thread_entrance(void* arg)
|
|||
pStorage = thread_data->pStorage;
|
||||
|
||||
strcpy(storage_server.ip_addr, pStorage->ip_addr);
|
||||
storage_server.port = g_server_port;
|
||||
storage_server.port = SF_G_INNER_PORT;
|
||||
storage_server.sock = -1;
|
||||
|
||||
logInfo("file: "__FILE__", line: %d, " \
|
||||
"trunk sync thread to storage server %s:%d started", \
|
||||
__LINE__, storage_server.ip_addr, storage_server.port);
|
||||
|
||||
while (g_continue_flag && g_if_trunker_self && \
|
||||
while (SF_G_CONTINUE_FLAG && g_if_trunker_self && \
|
||||
pStorage->status != FDFS_STORAGE_STATUS_DELETED && \
|
||||
pStorage->status != FDFS_STORAGE_STATUS_IP_CHANGED && \
|
||||
pStorage->status != FDFS_STORAGE_STATUS_NONE)
|
||||
|
|
@ -2087,15 +2087,15 @@ static void *trunk_sync_thread_entrance(void* arg)
|
|||
storage_sync_connect_storage_server_ex(pStorage,
|
||||
&storage_server, &g_if_trunker_self);
|
||||
|
||||
if ((!g_continue_flag) || (!g_if_trunker_self) || \
|
||||
if ((!SF_G_CONTINUE_FLAG) || (!g_if_trunker_self) || \
|
||||
pStorage->status == FDFS_STORAGE_STATUS_DELETED || \
|
||||
pStorage->status == FDFS_STORAGE_STATUS_IP_CHANGED || \
|
||||
pStorage->status == FDFS_STORAGE_STATUS_NONE)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, break loop." \
|
||||
"g_continue_flag: %d, g_if_trunker_self: %d, " \
|
||||
"SF_G_CONTINUE_FLAG: %d, g_if_trunker_self: %d, " \
|
||||
"dest storage status: %d", __LINE__, \
|
||||
g_continue_flag, g_if_trunker_self, \
|
||||
SF_G_CONTINUE_FLAG, g_if_trunker_self, \
|
||||
pStorage->status);
|
||||
break;
|
||||
}
|
||||
|
|
@ -2106,7 +2106,7 @@ static void *trunk_sync_thread_entrance(void* arg)
|
|||
logCrit("file: "__FILE__", line: %d, "
|
||||
"trunk_reader_init fail, errno=%d, "
|
||||
"program exit!", __LINE__, result);
|
||||
g_continue_flag = false;
|
||||
SF_G_CONTINUE_FLAG = false;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -2160,7 +2160,7 @@ static void *trunk_sync_thread_entrance(void* arg)
|
|||
}
|
||||
|
||||
sync_result = 0;
|
||||
while (g_continue_flag && !thread_data->reset_binlog_offset &&
|
||||
while (SF_G_CONTINUE_FLAG && !thread_data->reset_binlog_offset &&
|
||||
pStorage->status != FDFS_STORAGE_STATUS_DELETED &&
|
||||
pStorage->status != FDFS_STORAGE_STATUS_IP_CHANGED &&
|
||||
pStorage->status != FDFS_STORAGE_STATUS_NONE)
|
||||
|
|
@ -2176,7 +2176,7 @@ static void *trunk_sync_thread_entrance(void* arg)
|
|||
logCrit("file: "__FILE__", line: %d, "
|
||||
"trunk_write_to_mark_file fail, "
|
||||
"program exit!", __LINE__);
|
||||
g_continue_flag = false;
|
||||
SF_G_CONTINUE_FLAG = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -2227,7 +2227,7 @@ static void *trunk_sync_thread_entrance(void* arg)
|
|||
logCrit("file: "__FILE__", line: %d, " \
|
||||
"trunk_write_to_mark_file fail, " \
|
||||
"program exit!", __LINE__);
|
||||
g_continue_flag = false;
|
||||
SF_G_CONTINUE_FLAG = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -2236,7 +2236,7 @@ static void *trunk_sync_thread_entrance(void* arg)
|
|||
storage_server.sock = -1;
|
||||
trunk_reader_destroy(&reader);
|
||||
|
||||
if (!g_continue_flag)
|
||||
if (!SF_G_CONTINUE_FLAG)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
|
@ -2384,7 +2384,7 @@ int trunk_sync_thread_start(const FDFSStorageBrief *pStorage)
|
|||
return 0;
|
||||
}
|
||||
|
||||
if ((result=init_pthread_attr(&pattr, g_thread_stack_size)) != 0)
|
||||
if ((result=init_pthread_attr(&pattr, SF_G_THREAD_STACK_SIZE)) != 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
|
@ -2486,7 +2486,7 @@ int trunk_unlink_all_mark_files()
|
|||
localtime_r(&t, &tm);
|
||||
|
||||
snprintf(file_path, sizeof(file_path),
|
||||
"%s/data/%s", g_fdfs_base_path, TRUNK_DIR_NAME);
|
||||
"%s/data/%s", SF_G_BASE_PATH_STR, TRUNK_DIR_NAME);
|
||||
|
||||
if ((dir=opendir(file_path)) == NULL)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,14 +2,14 @@
|
|||
|
||||
COMPILE = $(CC) $(CFLAGS)
|
||||
INC_PATH = -I../common -I/usr/local/include
|
||||
LIB_PATH = $(LIBS) -lfastcommon
|
||||
LIB_PATH = $(LIBS) -lfastcommon -lserverframe
|
||||
TARGET_PATH = $(TARGET_PREFIX)/bin
|
||||
CONFIG_PATH = $(TARGET_CONF_PATH)
|
||||
|
||||
SHARED_OBJS = ../common/fdfs_global.o \
|
||||
tracker_proto.o tracker_mem.o tracker_service.o tracker_status.o \
|
||||
tracker_global.o tracker_func.o fdfs_server_id_func.o \
|
||||
fdfs_shared_func.o tracker_nio.o tracker_relationship.o \
|
||||
fdfs_shared_func.o tracker_relationship.o \
|
||||
$(TRACKER_EXTRA_OBJS)
|
||||
|
||||
ALL_OBJS = $(SHARED_OBJS)
|
||||
|
|
@ -17,6 +17,9 @@ ALL_OBJS = $(SHARED_OBJS)
|
|||
ALL_PRGS = fdfs_trackerd
|
||||
|
||||
all: $(ALL_OBJS) $(ALL_PRGS)
|
||||
|
||||
$(ALL_PRGS): $(ALL_OBJS)
|
||||
|
||||
.o:
|
||||
$(COMPILE) -o $@ $< $(SHARED_OBJS) $(LIB_PATH) $(INC_PATH)
|
||||
.c:
|
||||
|
|
|
|||
|
|
@ -573,7 +573,7 @@ int fdfs_get_storage_ids_from_tracker_server(TrackerServerInfo *pTrackerServer)
|
|||
{
|
||||
int2buff(start_index, p);
|
||||
if ((result=tcpsenddata_nb(conn->sock, out_buff,
|
||||
sizeof(out_buff), g_fdfs_network_timeout)) != 0)
|
||||
sizeof(out_buff), SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"send data to tracker server %s:%d fail, "
|
||||
|
|
|
|||
|
|
@ -413,7 +413,7 @@ int fdfs_connection_pool_init(const char *config_filename, \
|
|||
return EINVAL;
|
||||
}
|
||||
|
||||
return conn_pool_init(&g_connection_pool, g_fdfs_connect_timeout, \
|
||||
return conn_pool_init(&g_connection_pool, SF_G_CONNECT_TIMEOUT, \
|
||||
0, g_connection_pool_max_idle_time);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@
|
|||
#include "fastcommon/base64.h"
|
||||
#include "fastcommon/sockopt.h"
|
||||
#include "fastcommon/sched_thread.h"
|
||||
#include "sf/sf_service.h"
|
||||
#include "sf/sf_util.h"
|
||||
#include "tracker_types.h"
|
||||
#include "tracker_mem.h"
|
||||
#include "tracker_service.h"
|
||||
|
|
@ -46,86 +48,144 @@
|
|||
#include "tracker_dump.h"
|
||||
#endif
|
||||
|
||||
static bool daemon_mode = true;
|
||||
static bool bTerminateFlag = false;
|
||||
static bool bAcceptEndFlag = false;
|
||||
|
||||
static char bind_addr[IP_ADDRESS_SIZE];
|
||||
|
||||
static void sigQuitHandler(int sig);
|
||||
static void sigHupHandler(int sig);
|
||||
static void sigUsrHandler(int sig);
|
||||
static void sigAlarmHandler(int sig);
|
||||
|
||||
#if defined(DEBUG_FLAG)
|
||||
/*
|
||||
#if defined(OS_LINUX)
|
||||
static void sigSegvHandler(int signum, siginfo_t *info, void *ptr);
|
||||
#endif
|
||||
*/
|
||||
|
||||
static void sigDumpHandler(int sig);
|
||||
#endif
|
||||
|
||||
#define SCHEDULE_ENTRIES_COUNT 5
|
||||
|
||||
static void usage(const char *program)
|
||||
static int setup_signal_handlers()
|
||||
{
|
||||
fprintf(stderr, "FastDFS server v%d.%02d\n"
|
||||
"Usage: %s <config_file> [start | stop | restart]\n",
|
||||
g_fdfs_version.major, g_fdfs_version.minor,
|
||||
program);
|
||||
struct sigaction act;
|
||||
|
||||
memset(&act, 0, sizeof(act));
|
||||
sigemptyset(&act.sa_mask);
|
||||
act.sa_handler = sigUsrHandler;
|
||||
if(sigaction(SIGUSR1, &act, NULL) < 0 || \
|
||||
sigaction(SIGUSR2, &act, NULL) < 0)
|
||||
{
|
||||
logCrit("file: "__FILE__", line: %d, " \
|
||||
"call sigaction fail, errno: %d, error info: %s", \
|
||||
__LINE__, errno, STRERROR(errno));
|
||||
return errno;
|
||||
}
|
||||
|
||||
act.sa_handler = sigHupHandler;
|
||||
if(sigaction(SIGHUP, &act, NULL) < 0)
|
||||
{
|
||||
logCrit("file: "__FILE__", line: %d, " \
|
||||
"call sigaction fail, errno: %d, error info: %s", \
|
||||
__LINE__, errno, STRERROR(errno));
|
||||
return errno;
|
||||
}
|
||||
|
||||
act.sa_handler = SIG_IGN;
|
||||
if(sigaction(SIGPIPE, &act, NULL) < 0)
|
||||
{
|
||||
logCrit("file: "__FILE__", line: %d, " \
|
||||
"call sigaction fail, errno: %d, error info: %s", \
|
||||
__LINE__, errno, STRERROR(errno));
|
||||
return errno;
|
||||
}
|
||||
|
||||
act.sa_handler = sigQuitHandler;
|
||||
if(sigaction(SIGINT, &act, NULL) < 0 || \
|
||||
sigaction(SIGTERM, &act, NULL) < 0 || \
|
||||
sigaction(SIGQUIT, &act, NULL) < 0)
|
||||
{
|
||||
logCrit("file: "__FILE__", line: %d, " \
|
||||
"call sigaction fail, errno: %d, error info: %s", \
|
||||
__LINE__, errno, STRERROR(errno));
|
||||
return errno;
|
||||
}
|
||||
|
||||
#if defined(DEBUG_FLAG)
|
||||
memset(&act, 0, sizeof(act));
|
||||
sigemptyset(&act.sa_mask);
|
||||
act.sa_handler = sigDumpHandler;
|
||||
if(sigaction(SIGUSR1, &act, NULL) < 0 || \
|
||||
sigaction(SIGUSR2, &act, NULL) < 0)
|
||||
{
|
||||
logCrit("file: "__FILE__", line: %d, " \
|
||||
"call sigaction fail, errno: %d, error info: %s", \
|
||||
__LINE__, errno, STRERROR(errno));
|
||||
return errno;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int setup_schedule_tasks()
|
||||
{
|
||||
#define SCHEDULE_ENTRIES_COUNT 4
|
||||
ScheduleEntry scheduleEntries[SCHEDULE_ENTRIES_COUNT];
|
||||
ScheduleArray scheduleArray;
|
||||
|
||||
scheduleArray.entries = scheduleEntries;
|
||||
scheduleArray.count = 0;
|
||||
memset(scheduleEntries, 0, sizeof(scheduleEntries));
|
||||
|
||||
INIT_SCHEDULE_ENTRY(scheduleEntries[scheduleArray.count],
|
||||
sched_generate_next_id(), TIME_NONE, TIME_NONE, TIME_NONE,
|
||||
g_check_active_interval, tracker_mem_check_alive, NULL);
|
||||
scheduleArray.count++;
|
||||
|
||||
INIT_SCHEDULE_ENTRY(scheduleEntries[scheduleArray.count],
|
||||
sched_generate_next_id(), 0, 0, 0,
|
||||
TRACKER_SYNC_STATUS_FILE_INTERVAL,
|
||||
tracker_write_status_to_file, NULL);
|
||||
scheduleArray.count++;
|
||||
|
||||
return sched_add_entries(&scheduleArray);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char *conf_filename;
|
||||
const char *conf_filename;
|
||||
char *action;
|
||||
int result;
|
||||
int wait_count;
|
||||
int sock;
|
||||
pthread_t schedule_tid;
|
||||
struct sigaction act;
|
||||
ScheduleEntry scheduleEntries[SCHEDULE_ENTRIES_COUNT];
|
||||
ScheduleArray scheduleArray;
|
||||
char pidFilename[MAX_PATH_SIZE];
|
||||
bool stop;
|
||||
|
||||
if (argc < 2)
|
||||
{
|
||||
usage(argv[0]);
|
||||
sf_usage(argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
g_current_time = time(NULL);
|
||||
g_up_time = g_current_time;
|
||||
srand(g_up_time);
|
||||
|
||||
log_init2();
|
||||
|
||||
conf_filename = argv[1];
|
||||
if (!fileExists(conf_filename))
|
||||
conf_filename = sf_parse_daemon_mode_and_action(argc, argv,
|
||||
&g_fdfs_version, &daemon_mode, &action);
|
||||
if (conf_filename == NULL)
|
||||
{
|
||||
if (starts_with(conf_filename, "-"))
|
||||
{
|
||||
usage(argv[0]);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if ((result=get_base_path_from_conf_file(conf_filename,
|
||||
g_fdfs_base_path, sizeof(g_fdfs_base_path))) != 0)
|
||||
|
||||
g_current_time = time(NULL);
|
||||
log_init2();
|
||||
|
||||
if ((result=sf_get_base_path_from_conf_file(conf_filename)) != 0)
|
||||
{
|
||||
log_destroy();
|
||||
return result;
|
||||
}
|
||||
|
||||
snprintf(pidFilename, sizeof(pidFilename),
|
||||
"%s/data/fdfs_trackerd.pid", g_fdfs_base_path);
|
||||
action = argc >= 3 ? argv[2] : "start";
|
||||
"%s/data/fdfs_trackerd.pid", SF_G_BASE_PATH_STR);
|
||||
if ((result=process_action(pidFilename, action, &stop)) != 0)
|
||||
{
|
||||
if (result == EINVAL)
|
||||
{
|
||||
usage(argv[0]);
|
||||
sf_usage(argv[0]);
|
||||
}
|
||||
log_destroy();
|
||||
return result;
|
||||
|
|
@ -146,9 +206,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
#endif
|
||||
|
||||
memset(bind_addr, 0, sizeof(bind_addr));
|
||||
if ((result=tracker_load_from_conf_file(conf_filename, \
|
||||
bind_addr, sizeof(bind_addr))) != 0)
|
||||
if ((result=tracker_load_from_conf_file(conf_filename)) != 0)
|
||||
{
|
||||
logCrit("exit abnormally!\n");
|
||||
log_destroy();
|
||||
|
|
@ -177,22 +235,16 @@ int main(int argc, char *argv[])
|
|||
return result;
|
||||
}
|
||||
|
||||
sock = socketServer(bind_addr, g_server_port, &result);
|
||||
if (sock < 0)
|
||||
if ((result=sf_socket_server()) != 0)
|
||||
{
|
||||
logCrit("exit abnormally!\n");
|
||||
log_destroy();
|
||||
return result;
|
||||
}
|
||||
|
||||
if ((result=tcpsetserveropt(sock, g_fdfs_network_timeout)) != 0)
|
||||
if (daemon_mode)
|
||||
{
|
||||
logCrit("exit abnormally!\n");
|
||||
log_destroy();
|
||||
return result;
|
||||
}
|
||||
|
||||
daemon_init(false);
|
||||
}
|
||||
umask(0);
|
||||
|
||||
if ((result=write_to_pid_file(pidFilename)) != 0)
|
||||
|
|
@ -208,89 +260,17 @@ int main(int argc, char *argv[])
|
|||
return result;
|
||||
}
|
||||
|
||||
memset(&act, 0, sizeof(act));
|
||||
sigemptyset(&act.sa_mask);
|
||||
|
||||
act.sa_handler = sigUsrHandler;
|
||||
if(sigaction(SIGUSR1, &act, NULL) < 0 || \
|
||||
sigaction(SIGUSR2, &act, NULL) < 0)
|
||||
if ((result=setup_signal_handlers()) != 0)
|
||||
{
|
||||
logCrit("file: "__FILE__", line: %d, " \
|
||||
"call sigaction fail, errno: %d, error info: %s", \
|
||||
__LINE__, errno, STRERROR(errno));
|
||||
logCrit("exit abnormally!\n");
|
||||
return errno;
|
||||
log_destroy();
|
||||
return result;
|
||||
}
|
||||
|
||||
act.sa_handler = sigHupHandler;
|
||||
if(sigaction(SIGHUP, &act, NULL) < 0)
|
||||
{
|
||||
logCrit("file: "__FILE__", line: %d, " \
|
||||
"call sigaction fail, errno: %d, error info: %s", \
|
||||
__LINE__, errno, STRERROR(errno));
|
||||
logCrit("exit abnormally!\n");
|
||||
return errno;
|
||||
}
|
||||
|
||||
act.sa_handler = SIG_IGN;
|
||||
if(sigaction(SIGPIPE, &act, NULL) < 0)
|
||||
{
|
||||
logCrit("file: "__FILE__", line: %d, " \
|
||||
"call sigaction fail, errno: %d, error info: %s", \
|
||||
__LINE__, errno, STRERROR(errno));
|
||||
logCrit("exit abnormally!\n");
|
||||
return errno;
|
||||
}
|
||||
|
||||
act.sa_handler = sigQuitHandler;
|
||||
if(sigaction(SIGINT, &act, NULL) < 0 || \
|
||||
sigaction(SIGTERM, &act, NULL) < 0 || \
|
||||
sigaction(SIGQUIT, &act, NULL) < 0)
|
||||
{
|
||||
logCrit("file: "__FILE__", line: %d, " \
|
||||
"call sigaction fail, errno: %d, error info: %s", \
|
||||
__LINE__, errno, STRERROR(errno));
|
||||
logCrit("exit abnormally!\n");
|
||||
return errno;
|
||||
}
|
||||
|
||||
#if defined(DEBUG_FLAG)
|
||||
/*
|
||||
#if defined(OS_LINUX)
|
||||
memset(&act, 0, sizeof(act));
|
||||
sigemptyset(&act.sa_mask);
|
||||
act.sa_sigaction = sigSegvHandler;
|
||||
act.sa_flags = SA_SIGINFO;
|
||||
if (sigaction(SIGSEGV, &act, NULL) < 0 || \
|
||||
sigaction(SIGABRT, &act, NULL) < 0)
|
||||
{
|
||||
logCrit("file: "__FILE__", line: %d, " \
|
||||
"call sigaction fail, errno: %d, error info: %s", \
|
||||
__LINE__, errno, STRERROR(errno));
|
||||
logCrit("exit abnormally!\n");
|
||||
return errno;
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
|
||||
memset(&act, 0, sizeof(act));
|
||||
sigemptyset(&act.sa_mask);
|
||||
act.sa_handler = sigDumpHandler;
|
||||
if(sigaction(SIGUSR1, &act, NULL) < 0 || \
|
||||
sigaction(SIGUSR2, &act, NULL) < 0)
|
||||
{
|
||||
logCrit("file: "__FILE__", line: %d, " \
|
||||
"call sigaction fail, errno: %d, error info: %s", \
|
||||
__LINE__, errno, STRERROR(errno));
|
||||
logCrit("exit abnormally!\n");
|
||||
return errno;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef WITH_HTTPD
|
||||
if (!g_http_params.disabled)
|
||||
{
|
||||
if ((result=tracker_httpd_start(bind_addr)) != 0)
|
||||
if ((result=tracker_httpd_start(g_sf_context.inner_bind_addr)) != 0)
|
||||
{
|
||||
logCrit("file: "__FILE__", line: %d, " \
|
||||
"tracker_httpd_start fail, program exit!", \
|
||||
|
|
@ -309,55 +289,22 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
#endif
|
||||
|
||||
if ((result=set_run_by(g_run_by_group, g_run_by_user)) != 0)
|
||||
if ((result=set_run_by(g_sf_global_vars.run_by_group,
|
||||
g_sf_global_vars.run_by_user)) != 0)
|
||||
{
|
||||
logCrit("exit abnormally!\n");
|
||||
log_destroy();
|
||||
return result;
|
||||
}
|
||||
|
||||
scheduleArray.entries = scheduleEntries;
|
||||
scheduleArray.count = 0;
|
||||
memset(scheduleEntries, 0, sizeof(scheduleEntries));
|
||||
|
||||
INIT_SCHEDULE_ENTRY(scheduleEntries[scheduleArray.count],
|
||||
scheduleArray.count + 1, TIME_NONE, TIME_NONE, TIME_NONE,
|
||||
g_sync_log_buff_interval, log_sync_func, &g_log_context);
|
||||
scheduleArray.count++;
|
||||
|
||||
INIT_SCHEDULE_ENTRY(scheduleEntries[scheduleArray.count],
|
||||
scheduleArray.count + 1, TIME_NONE, TIME_NONE, TIME_NONE,
|
||||
g_check_active_interval, tracker_mem_check_alive, NULL);
|
||||
scheduleArray.count++;
|
||||
|
||||
INIT_SCHEDULE_ENTRY(scheduleEntries[scheduleArray.count],
|
||||
scheduleArray.count + 1, 0, 0, 0,
|
||||
TRACKER_SYNC_STATUS_FILE_INTERVAL,
|
||||
tracker_write_status_to_file, NULL);
|
||||
scheduleArray.count++;
|
||||
|
||||
if (g_rotate_error_log)
|
||||
if ((result=sf_startup_schedule(&schedule_tid)) != 0)
|
||||
{
|
||||
INIT_SCHEDULE_ENTRY_EX(scheduleEntries[scheduleArray.count],
|
||||
scheduleArray.count + 1, g_error_log_rotate_time,
|
||||
24 * 3600, log_notify_rotate, &g_log_context);
|
||||
scheduleArray.count++;
|
||||
|
||||
if (g_log_file_keep_days > 0)
|
||||
{
|
||||
log_set_keep_days(&g_log_context, g_log_file_keep_days);
|
||||
|
||||
INIT_SCHEDULE_ENTRY(scheduleEntries[scheduleArray.count],
|
||||
scheduleArray.count + 1, 1, 0, 0, 24 * 3600,
|
||||
log_delete_old_files, &g_log_context);
|
||||
scheduleArray.count++;
|
||||
}
|
||||
log_destroy();
|
||||
return result;
|
||||
}
|
||||
|
||||
if ((result=sched_start(&scheduleArray, &schedule_tid, \
|
||||
g_thread_stack_size, (bool * volatile)&g_continue_flag)) != 0)
|
||||
if ((result=setup_schedule_tasks()) != 0)
|
||||
{
|
||||
logCrit("exit abnormally!\n");
|
||||
log_destroy();
|
||||
return result;
|
||||
}
|
||||
|
|
@ -374,13 +321,13 @@ int main(int argc, char *argv[])
|
|||
bTerminateFlag = false;
|
||||
bAcceptEndFlag = false;
|
||||
|
||||
tracker_accept_loop(sock);
|
||||
sf_accept_loop();
|
||||
|
||||
bAcceptEndFlag = true;
|
||||
if (g_schedule_flag)
|
||||
{
|
||||
pthread_kill(schedule_tid, SIGINT);
|
||||
}
|
||||
tracker_terminate_threads();
|
||||
|
||||
#ifdef WITH_HTTPD
|
||||
if (g_http_check_flag)
|
||||
|
|
@ -395,20 +342,9 @@ int main(int argc, char *argv[])
|
|||
#endif
|
||||
|
||||
wait_count = 0;
|
||||
while ((g_tracker_thread_count != 0) || g_schedule_flag)
|
||||
while ((SF_G_ALIVE_THREAD_COUNT != 0) || g_schedule_flag)
|
||||
{
|
||||
|
||||
/*
|
||||
#if defined(DEBUG_FLAG) && defined(OS_LINUX)
|
||||
if (bSegmentFault)
|
||||
{
|
||||
sleep(5);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
|
||||
usleep(10000);
|
||||
fc_sleep_ms(10);
|
||||
if (++wait_count > 3000)
|
||||
{
|
||||
logWarning("waiting timeout, exit!");
|
||||
|
|
@ -441,7 +377,7 @@ static void sigDumpHandler(int sig)
|
|||
bDumpFlag = true;
|
||||
|
||||
snprintf(filename, sizeof(filename),
|
||||
"%s/logs/tracker_dump.log", g_fdfs_base_path);
|
||||
"%s/logs/tracker_dump.log", SF_G_BASE_PATH_STR);
|
||||
fdfs_dump_tracker_global_vars_to_file(filename);
|
||||
|
||||
bDumpFlag = false;
|
||||
|
|
@ -457,7 +393,7 @@ static void sigQuitHandler(int sig)
|
|||
set_timer(1, 1, sigAlarmHandler);
|
||||
|
||||
bTerminateFlag = true;
|
||||
g_continue_flag = false;
|
||||
SF_G_CONTINUE_FLAG = false;
|
||||
logCrit("file: "__FILE__", line: %d, " \
|
||||
"catch signal %d, program exiting...", \
|
||||
__LINE__, sig);
|
||||
|
|
@ -466,12 +402,12 @@ static void sigQuitHandler(int sig)
|
|||
|
||||
static void sigHupHandler(int sig)
|
||||
{
|
||||
if (g_rotate_error_log)
|
||||
if (g_sf_global_vars.error_log.rotate_everyday)
|
||||
{
|
||||
g_log_context.rotate_immediately = true;
|
||||
}
|
||||
|
||||
logInfo("file: "__FILE__", line: %d, " \
|
||||
logInfo("file: "__FILE__", line: %d, "
|
||||
"catch signal %d, rotate log", __LINE__, sig);
|
||||
}
|
||||
|
||||
|
|
@ -487,18 +423,18 @@ static void sigAlarmHandler(int sig)
|
|||
logDebug("file: "__FILE__", line: %d, " \
|
||||
"signal server to quit...", __LINE__);
|
||||
|
||||
if (*bind_addr != '\0')
|
||||
if (*g_sf_context.inner_bind_addr != '\0')
|
||||
{
|
||||
strcpy(server.ip_addr, bind_addr);
|
||||
strcpy(server.ip_addr, g_sf_context.inner_bind_addr);
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(server.ip_addr, "127.0.0.1");
|
||||
}
|
||||
server.port = g_server_port;
|
||||
server.port = SF_G_INNER_PORT;
|
||||
server.sock = -1;
|
||||
|
||||
if (conn_pool_connect_server(&server, g_fdfs_connect_timeout) != 0)
|
||||
if (conn_pool_connect_server(&server, SF_G_CONNECT_TIMEOUT) != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -291,13 +291,13 @@ static int fdfs_dump_global_vars(char *buff, const int buffSize)
|
|||
char *p;
|
||||
|
||||
total_len = snprintf(buff, buffSize,
|
||||
"g_fdfs_connect_timeout=%ds\n"
|
||||
"g_fdfs_network_timeout=%ds\n"
|
||||
"g_fdfs_base_path=%s\n"
|
||||
"SF_G_CONNECT_TIMEOUT=%ds\n"
|
||||
"SF_G_NETWORK_TIMEOUT=%ds\n"
|
||||
"SF_G_BASE_PATH_STR=%s\n"
|
||||
"g_fdfs_version=%d.%02d\n"
|
||||
"g_continue_flag=%d\n"
|
||||
"SF_G_CONTINUE_FLAG=%d\n"
|
||||
"g_schedule_flag=%d\n"
|
||||
"g_server_port=%d\n"
|
||||
"SF_G_INNER_PORT=%d\n"
|
||||
"g_max_connections=%d\n"
|
||||
"g_tracker_thread_count=%d\n"
|
||||
"g_sync_log_buff_interval=%ds\n"
|
||||
|
|
@ -309,7 +309,7 @@ static int fdfs_dump_global_vars(char *buff, const int buffSize)
|
|||
"g_run_by_group=%s\n"
|
||||
"g_run_by_user=%s\n"
|
||||
"g_storage_ip_changed_auto_adjust=%d\n"
|
||||
"g_thread_stack_size=%d\n"
|
||||
"SF_G_THREAD_STACK_SIZE=%d\n"
|
||||
"if_use_trunk_file=%d\n"
|
||||
"slot_min_size=%d\n"
|
||||
"slot_max_size=%d MB\n"
|
||||
|
|
@ -345,26 +345,26 @@ static int fdfs_dump_global_vars(char *buff, const int buffSize)
|
|||
#if defined(DEBUG_FLAG) && defined(OS_LINUX)
|
||||
"g_exe_name=%s\n"
|
||||
#endif
|
||||
, g_fdfs_connect_timeout
|
||||
, g_fdfs_network_timeout
|
||||
, g_fdfs_base_path
|
||||
, SF_G_CONNECT_TIMEOUT
|
||||
, SF_G_NETWORK_TIMEOUT
|
||||
, SF_G_BASE_PATH_STR
|
||||
, g_fdfs_version.major, g_fdfs_version.minor
|
||||
, g_continue_flag
|
||||
, SF_G_CONTINUE_FLAG
|
||||
, g_schedule_flag
|
||||
, g_server_port
|
||||
, g_max_connections
|
||||
, g_tracker_thread_count
|
||||
, g_sync_log_buff_interval
|
||||
, SF_G_INNER_PORT
|
||||
, g_sf_global_vars.max_connections
|
||||
, g_sf_context.thread_count
|
||||
, g_sf_global_vars.error_log.sync_log_buff_interval
|
||||
, g_check_active_interval
|
||||
, g_storage_stat_chg_count
|
||||
, g_storage_sync_time_chg_count
|
||||
, fdfs_storage_reserved_space_to_string( \
|
||||
&g_storage_reserved_space, reserved_space_str) \
|
||||
, g_allow_ip_count
|
||||
, g_run_by_group
|
||||
, g_run_by_user
|
||||
, g_sf_global_vars.run_by_group
|
||||
, g_sf_global_vars.run_by_user
|
||||
, g_storage_ip_changed_auto_adjust
|
||||
, g_thread_stack_size
|
||||
, SF_G_THREAD_STACK_SIZE
|
||||
, g_if_use_trunk_file
|
||||
, g_slot_min_size
|
||||
, g_slot_max_size / FDFS_ONE_MB
|
||||
|
|
@ -372,7 +372,7 @@ static int fdfs_dump_global_vars(char *buff, const int buffSize)
|
|||
, g_changelog_fsize
|
||||
, g_storage_sync_file_max_delay
|
||||
, g_storage_sync_file_max_time
|
||||
, (int)g_up_time
|
||||
, (int)g_sf_global_vars.up_time
|
||||
, (int)g_tracker_last_status.up_time
|
||||
, (int)g_tracker_last_status.last_check_time
|
||||
, g_if_leader_self
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
#include "fastcommon/shared_func.h"
|
||||
#include "fastcommon/ini_file_reader.h"
|
||||
#include "fastcommon/connection_pool.h"
|
||||
#include "sf/sf_service.h"
|
||||
#include "tracker_types.h"
|
||||
#include "tracker_proto.h"
|
||||
#include "tracker_global.h"
|
||||
|
|
@ -123,37 +124,27 @@ static int tracker_load_storage_id_info(const char *config_filename, \
|
|||
return fdfs_load_storage_ids_from_file(config_filename, pItemContext);
|
||||
}
|
||||
|
||||
int tracker_load_from_conf_file(const char *filename, \
|
||||
char *bind_addr, const int addr_size)
|
||||
int tracker_load_from_conf_file(const char *filename)
|
||||
{
|
||||
char *pBasePath;
|
||||
char *pBindAddr;
|
||||
char *pRunByGroup;
|
||||
char *pRunByUser;
|
||||
char *pThreadStackSize;
|
||||
const int task_buffer_extra_size = 0;
|
||||
const bool need_set_run_by = false;
|
||||
char *pSlotMinSize;
|
||||
char *pSlotMaxSize;
|
||||
char *pSpaceThreshold;
|
||||
char *pTrunkFileSize;
|
||||
char *pRotateErrorLogSize;
|
||||
char *pMinBuffSize;
|
||||
char *pMaxBuffSize;
|
||||
#ifdef WITH_HTTPD
|
||||
char *pHttpCheckUri;
|
||||
char *pHttpCheckType;
|
||||
#endif
|
||||
IniContext iniContext;
|
||||
SFContextIniConfig config;
|
||||
int result;
|
||||
int64_t thread_stack_size;
|
||||
int64_t trunk_file_size;
|
||||
int64_t slot_min_size;
|
||||
int64_t slot_max_size;
|
||||
int64_t rotate_error_log_size;
|
||||
int64_t min_buff_size;
|
||||
int64_t max_buff_size;
|
||||
char sz_min_buff_size[32];
|
||||
char sz_max_buff_size[32];
|
||||
char reserved_space_str[32];
|
||||
char sz_global_config[512];
|
||||
char sz_service_config[128];
|
||||
|
||||
memset(&g_groups, 0, sizeof(FDFSGroups));
|
||||
memset(&iniContext, 0, sizeof(IniContext));
|
||||
|
|
@ -178,75 +169,19 @@ int tracker_load_from_conf_file(const char *filename, \
|
|||
break;
|
||||
}
|
||||
|
||||
pBasePath = iniGetStrValue(NULL, "base_path", &iniContext);
|
||||
if (pBasePath == NULL)
|
||||
sf_set_current_time();
|
||||
|
||||
SF_SET_CONTEXT_INI_CONFIG_EX(config, filename, &iniContext,
|
||||
NULL, FDFS_TRACKER_SERVER_DEF_PORT,
|
||||
FDFS_TRACKER_SERVER_DEF_PORT, DEFAULT_WORK_THREADS,
|
||||
"buff_size");
|
||||
if ((result=sf_load_config_ex("trackerd", &config,
|
||||
task_buffer_extra_size, need_set_run_by)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"conf file \"%s\" must have item " \
|
||||
"\"base_path\"!", __LINE__, filename);
|
||||
result = ENOENT;
|
||||
break;
|
||||
return result;
|
||||
}
|
||||
|
||||
snprintf(g_fdfs_base_path, sizeof(g_fdfs_base_path), "%s", pBasePath);
|
||||
chopPath(g_fdfs_base_path);
|
||||
if (!fileExists(g_fdfs_base_path))
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"\"%s\" can't be accessed, error info: %s", \
|
||||
__LINE__, g_fdfs_base_path, STRERROR(errno));
|
||||
result = errno != 0 ? errno : ENOENT;
|
||||
break;
|
||||
}
|
||||
if (!isDir(g_fdfs_base_path))
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"\"%s\" is not a directory!", \
|
||||
__LINE__, g_fdfs_base_path);
|
||||
result = ENOTDIR;
|
||||
break;
|
||||
}
|
||||
|
||||
load_log_level(&iniContext);
|
||||
if ((result=log_set_prefix(g_fdfs_base_path, \
|
||||
TRACKER_ERROR_LOG_FILENAME)) != 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
g_fdfs_connect_timeout = iniGetIntValue(NULL, "connect_timeout", \
|
||||
&iniContext, DEFAULT_CONNECT_TIMEOUT);
|
||||
if (g_fdfs_connect_timeout <= 0)
|
||||
{
|
||||
g_fdfs_connect_timeout = DEFAULT_CONNECT_TIMEOUT;
|
||||
}
|
||||
|
||||
g_fdfs_network_timeout = iniGetIntValue(NULL, "network_timeout", \
|
||||
&iniContext, DEFAULT_NETWORK_TIMEOUT);
|
||||
if (g_fdfs_network_timeout <= 0)
|
||||
{
|
||||
g_fdfs_network_timeout = DEFAULT_NETWORK_TIMEOUT;
|
||||
}
|
||||
|
||||
g_server_port = iniGetIntValue(NULL, "port", &iniContext, \
|
||||
FDFS_TRACKER_SERVER_DEF_PORT);
|
||||
if (g_server_port <= 0)
|
||||
{
|
||||
g_server_port = FDFS_TRACKER_SERVER_DEF_PORT;
|
||||
}
|
||||
|
||||
pBindAddr = iniGetStrValue(NULL, "bind_addr", &iniContext);
|
||||
if (pBindAddr == NULL)
|
||||
{
|
||||
bind_addr[0] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(bind_addr, addr_size, "%s", pBindAddr);
|
||||
}
|
||||
|
||||
if ((result=tracker_load_store_lookup(filename, \
|
||||
&iniContext)) != 0)
|
||||
if ((result=tracker_load_store_lookup(filename, &iniContext)) != 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
|
@ -303,119 +238,12 @@ int tracker_load_from_conf_file(const char *filename, \
|
|||
break;
|
||||
}
|
||||
|
||||
g_max_connections = iniGetIntValue(NULL, "max_connections", \
|
||||
&iniContext, DEFAULT_MAX_CONNECTONS);
|
||||
if (g_max_connections <= 0)
|
||||
{
|
||||
g_max_connections = DEFAULT_MAX_CONNECTONS;
|
||||
}
|
||||
|
||||
g_accept_threads = iniGetIntValue(NULL, "accept_threads", \
|
||||
&iniContext, 1);
|
||||
if (g_accept_threads <= 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"item \"accept_threads\" is invalid, " \
|
||||
"value: %d <= 0!", __LINE__, g_accept_threads);
|
||||
result = EINVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
g_work_threads = iniGetIntValue(NULL, "work_threads", \
|
||||
&iniContext, DEFAULT_WORK_THREADS);
|
||||
if (g_work_threads <= 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"item \"work_threads\" is invalid, " \
|
||||
"value: %d <= 0!", __LINE__, g_work_threads);
|
||||
result = EINVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
if ((result=set_rlimit(RLIMIT_NOFILE, g_max_connections)) != 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
pRunByGroup = iniGetStrValue(NULL, "run_by_group", &iniContext);
|
||||
pRunByUser = iniGetStrValue(NULL, "run_by_user", &iniContext);
|
||||
if (pRunByGroup == NULL)
|
||||
{
|
||||
*g_run_by_group = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(g_run_by_group, sizeof(g_run_by_group), \
|
||||
"%s", pRunByGroup);
|
||||
}
|
||||
if (*g_run_by_group == '\0')
|
||||
{
|
||||
g_run_by_gid = getegid();
|
||||
}
|
||||
else
|
||||
{
|
||||
struct group *pGroup;
|
||||
|
||||
pGroup = getgrnam(g_run_by_group);
|
||||
if (pGroup == NULL)
|
||||
{
|
||||
result = errno != 0 ? errno : ENOENT;
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"getgrnam fail, errno: %d, " \
|
||||
"error info: %s", __LINE__, \
|
||||
result, STRERROR(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
g_run_by_gid = pGroup->gr_gid;
|
||||
}
|
||||
|
||||
|
||||
if (pRunByUser == NULL)
|
||||
{
|
||||
*g_run_by_user = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(g_run_by_user, sizeof(g_run_by_user), \
|
||||
"%s", pRunByUser);
|
||||
}
|
||||
if (*g_run_by_user == '\0')
|
||||
{
|
||||
g_run_by_uid = geteuid();
|
||||
}
|
||||
else
|
||||
{
|
||||
struct passwd *pUser;
|
||||
|
||||
pUser = getpwnam(g_run_by_user);
|
||||
if (pUser == NULL)
|
||||
{
|
||||
result = errno != 0 ? errno : ENOENT;
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"getpwnam fail, errno: %d, " \
|
||||
"error info: %s", __LINE__, \
|
||||
result, STRERROR(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
g_run_by_uid = pUser->pw_uid;
|
||||
}
|
||||
|
||||
if ((result=load_allow_hosts(&iniContext, \
|
||||
&g_allow_ip_addrs, &g_allow_ip_count)) != 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
g_sync_log_buff_interval = iniGetIntValue(NULL, \
|
||||
"sync_log_buff_interval", &iniContext, \
|
||||
SYNC_LOG_BUFF_DEF_INTERVAL);
|
||||
if (g_sync_log_buff_interval <= 0)
|
||||
{
|
||||
g_sync_log_buff_interval = SYNC_LOG_BUFF_DEF_INTERVAL;
|
||||
}
|
||||
|
||||
g_check_active_interval = iniGetIntValue(NULL, \
|
||||
"check_active_interval", &iniContext, \
|
||||
CHECK_ACTIVE_DEF_INTERVAL);
|
||||
|
|
@ -424,19 +252,6 @@ int tracker_load_from_conf_file(const char *filename, \
|
|||
g_check_active_interval = CHECK_ACTIVE_DEF_INTERVAL;
|
||||
}
|
||||
|
||||
pThreadStackSize = iniGetStrValue(NULL, \
|
||||
"thread_stack_size", &iniContext);
|
||||
if (pThreadStackSize == NULL)
|
||||
{
|
||||
thread_stack_size = 64 * 1024;
|
||||
}
|
||||
else if ((result=parse_bytes(pThreadStackSize, 1, \
|
||||
&thread_stack_size)) != 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
g_thread_stack_size = (int)thread_stack_size;
|
||||
|
||||
g_storage_ip_changed_auto_adjust = iniGetBoolValue(NULL, \
|
||||
"storage_ip_changed_auto_adjust", \
|
||||
&iniContext, true);
|
||||
|
|
@ -610,52 +425,6 @@ int tracker_load_from_conf_file(const char *filename, \
|
|||
return result;
|
||||
}
|
||||
|
||||
g_rotate_error_log = iniGetBoolValue(NULL, "rotate_error_log",
|
||||
&iniContext, false);
|
||||
g_compress_old_error_log = iniGetBoolValue(NULL, "compress_old_error_log",
|
||||
&iniContext, false);
|
||||
g_compress_error_log_days_before = iniGetIntValue(NULL,
|
||||
"compress_error_log_days_before", &iniContext, 1);
|
||||
if (g_compress_old_error_log)
|
||||
{
|
||||
log_set_compress_log_flags(LOG_COMPRESS_FLAGS_ENABLED |
|
||||
LOG_COMPRESS_FLAGS_NEW_THREAD);
|
||||
log_set_compress_log_days_before(g_compress_error_log_days_before);
|
||||
}
|
||||
|
||||
if ((result=get_time_item_from_conf(&iniContext,
|
||||
"error_log_rotate_time", &g_error_log_rotate_time,
|
||||
0, 0)) != 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
pRotateErrorLogSize = iniGetStrValue(NULL,
|
||||
"rotate_error_log_size", &iniContext);
|
||||
if (pRotateErrorLogSize == NULL)
|
||||
{
|
||||
rotate_error_log_size = 0;
|
||||
}
|
||||
else if ((result=parse_bytes(pRotateErrorLogSize, 1,
|
||||
&rotate_error_log_size)) != 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (rotate_error_log_size > 0 &&
|
||||
rotate_error_log_size < FDFS_ONE_MB)
|
||||
{
|
||||
logWarning("file: "__FILE__", line: %d, "
|
||||
"item \"rotate_error_log_size\": "
|
||||
"%"PRId64" is too small, "
|
||||
"change to 1 MB", __LINE__,
|
||||
rotate_error_log_size);
|
||||
rotate_error_log_size = FDFS_ONE_MB;
|
||||
}
|
||||
fdfs_set_log_rotate_size(&g_log_context, rotate_error_log_size);
|
||||
|
||||
g_log_file_keep_days = iniGetIntValue(NULL,
|
||||
"log_file_keep_days", &iniContext, 0);
|
||||
|
||||
g_store_slave_file_use_link = iniGetBoolValue(NULL,
|
||||
"store_slave_file_use_link", &iniContext, false);
|
||||
|
||||
|
|
@ -664,38 +433,6 @@ int tracker_load_from_conf_file(const char *filename, \
|
|||
break;
|
||||
}
|
||||
|
||||
|
||||
pMinBuffSize = iniGetStrValue(NULL,
|
||||
"min_buff_size", &iniContext);
|
||||
if (pMinBuffSize == NULL) {
|
||||
min_buff_size = TRACKER_MAX_PACKAGE_SIZE;
|
||||
}
|
||||
else if ((result=parse_bytes(pMinBuffSize, 1,
|
||||
&min_buff_size)) != 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
g_min_buff_size = (int)min_buff_size;
|
||||
|
||||
pMaxBuffSize = iniGetStrValue(NULL,
|
||||
"max_buff_size", &iniContext);
|
||||
if (pMaxBuffSize == NULL) {
|
||||
max_buff_size = 16 * TRACKER_MAX_PACKAGE_SIZE;
|
||||
}
|
||||
else if ((result=parse_bytes(pMaxBuffSize, 1,
|
||||
&max_buff_size)) != 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
g_max_buff_size = (int)max_buff_size;
|
||||
|
||||
if (g_min_buff_size < TRACKER_MAX_PACKAGE_SIZE) {
|
||||
g_min_buff_size = TRACKER_MAX_PACKAGE_SIZE;
|
||||
}
|
||||
if (g_max_buff_size < g_min_buff_size) {
|
||||
g_max_buff_size = g_min_buff_size;
|
||||
}
|
||||
|
||||
#ifdef WITH_HTTPD
|
||||
if ((result=fdfs_http_params_load(&iniContext, \
|
||||
filename, &g_http_params)) != 0)
|
||||
|
|
@ -739,7 +476,8 @@ int tracker_load_from_conf_file(const char *filename, \
|
|||
|
||||
#endif
|
||||
|
||||
if (g_if_use_trunk_file && g_groups.store_server == FDFS_STORE_SERVER_ROUND_ROBIN)
|
||||
if (g_if_use_trunk_file && g_groups.store_server ==
|
||||
FDFS_STORE_SERVER_ROUND_ROBIN)
|
||||
{
|
||||
logInfo("file: "__FILE__", line: %d, "
|
||||
"set store_server to %d because use_trunk_file is true",
|
||||
|
|
@ -747,26 +485,18 @@ int tracker_load_from_conf_file(const char *filename, \
|
|||
g_groups.store_server = FDFS_STORE_SERVER_FIRST_BY_IP;
|
||||
}
|
||||
|
||||
int_to_comma_str(g_min_buff_size, sz_min_buff_size);
|
||||
int_to_comma_str(g_max_buff_size, sz_max_buff_size);
|
||||
sf_global_config_to_string(sz_global_config,
|
||||
sizeof(sz_global_config));
|
||||
sf_context_config_to_string(&g_sf_context,
|
||||
sz_service_config, sizeof(sz_service_config));
|
||||
|
||||
logInfo("FastDFS v%d.%02d, base_path=%s, "
|
||||
"run_by_group=%s, run_by_user=%s, "
|
||||
"connect_timeout=%ds, "
|
||||
"network_timeout=%ds, "
|
||||
"port=%d, bind_addr=%s, "
|
||||
"max_connections=%d, "
|
||||
"accept_threads=%d, "
|
||||
"work_threads=%d, "
|
||||
"min_buff_size=%s, "
|
||||
"max_buff_size=%s, "
|
||||
logInfo("FastDFS v%d.%02d, %s, %s, "
|
||||
"store_lookup=%d, store_group=%s, "
|
||||
"store_server=%d, store_path=%d, "
|
||||
"reserved_storage_space=%s, "
|
||||
"download_server=%d, "
|
||||
"allow_ip_count=%d, sync_log_buff_interval=%ds, "
|
||||
"allow_ip_count=%d, "
|
||||
"check_active_interval=%ds, "
|
||||
"thread_stack_size=%d KB, "
|
||||
"storage_ip_changed_auto_adjust=%d, "
|
||||
"storage_sync_file_max_delay=%ds, "
|
||||
"storage_sync_file_max_time=%ds, "
|
||||
|
|
@ -790,28 +520,17 @@ int tracker_load_from_conf_file(const char *filename, \
|
|||
"use_storage_id=%d, "
|
||||
"id_type_in_filename=%s, "
|
||||
"storage_id/ip_count=%d / %d, "
|
||||
"rotate_error_log=%d, "
|
||||
"error_log_rotate_time=%02d:%02d, "
|
||||
"compress_old_error_log=%d, "
|
||||
"compress_error_log_days_before=%d, "
|
||||
"rotate_error_log_size=%"PRId64", "
|
||||
"log_file_keep_days=%d, "
|
||||
"store_slave_file_use_link=%d, "
|
||||
"use_connection_pool=%d, "
|
||||
"g_connection_pool_max_idle_time=%ds",
|
||||
g_fdfs_version.major, g_fdfs_version.minor,
|
||||
g_fdfs_base_path, g_run_by_group, g_run_by_user,
|
||||
g_fdfs_connect_timeout,
|
||||
g_fdfs_network_timeout, g_server_port, bind_addr,
|
||||
g_max_connections, g_accept_threads, g_work_threads,
|
||||
sz_min_buff_size, sz_max_buff_size,
|
||||
sz_global_config, sz_service_config,
|
||||
g_groups.store_lookup, g_groups.store_group,
|
||||
g_groups.store_server, g_groups.store_path,
|
||||
fdfs_storage_reserved_space_to_string(
|
||||
&g_storage_reserved_space, reserved_space_str),
|
||||
g_groups.download_server,
|
||||
g_allow_ip_count, g_sync_log_buff_interval,
|
||||
g_check_active_interval, g_thread_stack_size / 1024,
|
||||
g_groups.download_server, g_allow_ip_count,
|
||||
g_check_active_interval,
|
||||
g_storage_ip_changed_auto_adjust,
|
||||
g_storage_sync_file_max_delay,
|
||||
g_storage_sync_file_max_time,
|
||||
|
|
@ -836,10 +555,6 @@ int tracker_load_from_conf_file(const char *filename, \
|
|||
g_use_storage_id, g_id_type_in_filename ==
|
||||
FDFS_ID_TYPE_SERVER_ID ? "id" : "ip",
|
||||
g_storage_ids_by_id.count, g_storage_ids_by_ip.count,
|
||||
g_rotate_error_log, g_error_log_rotate_time.hour,
|
||||
g_error_log_rotate_time.minute, g_compress_old_error_log,
|
||||
g_compress_error_log_days_before,
|
||||
g_log_context.rotate_size, g_log_file_keep_days,
|
||||
g_store_slave_file_use_link,
|
||||
g_use_connection_pool, g_connection_pool_max_idle_time);
|
||||
|
||||
|
|
@ -878,4 +593,3 @@ int tracker_load_from_conf_file(const char *filename, \
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,8 +17,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
int tracker_load_from_conf_file(const char *filename, \
|
||||
char *bind_addr, const int addr_size);
|
||||
int tracker_load_from_conf_file(const char *filename);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,15 +8,7 @@
|
|||
|
||||
#include "tracker_global.h"
|
||||
|
||||
volatile bool g_continue_flag = true;
|
||||
int g_server_port = FDFS_TRACKER_SERVER_DEF_PORT;
|
||||
int g_max_connections = DEFAULT_MAX_CONNECTONS;
|
||||
int g_accept_threads = 1;
|
||||
int g_work_threads = DEFAULT_WORK_THREADS;
|
||||
int g_sync_log_buff_interval = SYNC_LOG_BUFF_DEF_INTERVAL;
|
||||
int g_check_active_interval = CHECK_ACTIVE_DEF_INTERVAL;
|
||||
int g_min_buff_size = TRACKER_MAX_PACKAGE_SIZE;
|
||||
int g_max_buff_size = 16 * TRACKER_MAX_PACKAGE_SIZE;
|
||||
|
||||
FDFSGroups g_groups;
|
||||
int g_storage_stat_chg_count = 0;
|
||||
|
|
@ -29,20 +21,10 @@ in_addr_t *g_allow_ip_addrs = NULL;
|
|||
|
||||
struct base64_context g_base64_context;
|
||||
|
||||
gid_t g_run_by_gid;
|
||||
uid_t g_run_by_uid;
|
||||
|
||||
char g_run_by_group[32] = {0};
|
||||
char g_run_by_user[32] = {0};
|
||||
|
||||
bool g_storage_ip_changed_auto_adjust = true;
|
||||
bool g_use_storage_id = false; //if use storage ID instead of IP address
|
||||
byte g_id_type_in_filename = FDFS_ID_TYPE_IP_ADDRESS; //id type of the storage server in the filename
|
||||
bool g_rotate_error_log = false; //if rotate the error log every day
|
||||
bool g_compress_old_error_log = false; //if compress the old error log
|
||||
TimeInfo g_error_log_rotate_time = {0, 0, 0}; //rotate error log time base
|
||||
|
||||
int g_thread_stack_size = 64 * 1024;
|
||||
int g_storage_sync_file_max_delay = DEFAULT_STORAGE_SYNC_FILE_MAX_DELAY;
|
||||
int g_storage_sync_file_max_time = DEFAULT_STORAGE_SYNC_FILE_MAX_TIME;
|
||||
|
||||
|
|
@ -65,7 +47,6 @@ int g_trunk_binlog_max_backups = 0;
|
|||
int g_trunk_alloc_alignment_size = 0;
|
||||
int64_t g_trunk_create_file_space_threshold = 0;
|
||||
|
||||
time_t g_up_time = 0;
|
||||
TrackerStatus g_tracker_last_status = {0, 0};
|
||||
|
||||
#ifdef WITH_HTTPD
|
||||
|
|
@ -79,8 +60,3 @@ bool g_http_servers_dirty = false;
|
|||
#if defined(DEBUG_FLAG) && defined(OS_LINUX)
|
||||
char g_exe_name[256] = {0};
|
||||
#endif
|
||||
|
||||
int g_log_file_keep_days = 0;
|
||||
int g_compress_error_log_days_before = 0;
|
||||
FDFSConnectionStat g_connection_stat = {0, 0};
|
||||
|
||||
|
|
|
|||
|
|
@ -35,38 +35,21 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern volatile bool g_continue_flag;
|
||||
extern int g_server_port;
|
||||
extern FDFSGroups g_groups;
|
||||
extern int g_storage_stat_chg_count;
|
||||
extern int g_storage_sync_time_chg_count; //sync timestamp
|
||||
extern int g_max_connections;
|
||||
extern int g_min_buff_size;
|
||||
extern int g_max_buff_size;
|
||||
extern int g_accept_threads;
|
||||
extern int g_work_threads;
|
||||
|
||||
extern FDFSStorageReservedSpace g_storage_reserved_space;
|
||||
extern int g_sync_log_buff_interval; //sync log buff to disk every interval seconds
|
||||
extern int g_check_active_interval; //check storage server alive every interval seconds
|
||||
|
||||
extern int g_allow_ip_count; /* -1 means match any ip address */
|
||||
extern in_addr_t *g_allow_ip_addrs; /* sorted array, asc order */
|
||||
extern struct base64_context g_base64_context;
|
||||
|
||||
extern gid_t g_run_by_gid;
|
||||
extern uid_t g_run_by_uid;
|
||||
|
||||
extern char g_run_by_group[32];
|
||||
extern char g_run_by_user[32];
|
||||
|
||||
extern bool g_storage_ip_changed_auto_adjust;
|
||||
extern bool g_use_storage_id; //identify storage by ID instead of IP address
|
||||
extern byte g_id_type_in_filename; //id type of the storage server in the filename
|
||||
extern bool g_rotate_error_log; //if rotate the error log every day
|
||||
extern bool g_compress_old_error_log; //if compress the old error log
|
||||
extern TimeInfo g_error_log_rotate_time; //rotate error log time base
|
||||
|
||||
extern int g_thread_stack_size;
|
||||
extern int g_storage_sync_file_max_delay;
|
||||
extern int g_storage_sync_file_max_time;
|
||||
|
||||
|
|
@ -89,7 +72,6 @@ extern int g_trunk_binlog_max_backups;
|
|||
extern int g_trunk_alloc_alignment_size;
|
||||
extern int64_t g_trunk_create_file_space_threshold;
|
||||
|
||||
extern time_t g_up_time;
|
||||
extern TrackerStatus g_tracker_last_status; //the status of last running
|
||||
|
||||
#ifdef WITH_HTTPD
|
||||
|
|
@ -104,10 +86,6 @@ extern bool g_http_servers_dirty;
|
|||
extern char g_exe_name[256];
|
||||
#endif
|
||||
|
||||
extern int g_log_file_keep_days;
|
||||
extern int g_compress_error_log_days_before;
|
||||
extern FDFSConnectionStat g_connection_stat;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ static void *http_check_entrance(void *arg)
|
|||
|
||||
g_http_check_flag = true;
|
||||
g_http_servers_dirty = false;
|
||||
while (g_continue_flag)
|
||||
while (SF_G_CONTINUE_FLAG)
|
||||
{
|
||||
if (g_http_servers_dirty)
|
||||
{
|
||||
|
|
@ -48,7 +48,7 @@ static void *http_check_entrance(void *arg)
|
|||
}
|
||||
|
||||
ppGroupEnd = g_groups.groups + g_groups.count;
|
||||
for (ppGroup=g_groups.groups; g_continue_flag && (!g_http_servers_dirty)\
|
||||
for (ppGroup=g_groups.groups; SF_G_CONTINUE_FLAG && (!g_http_servers_dirty)\
|
||||
&& ppGroup<ppGroupEnd; ppGroup++)
|
||||
{
|
||||
|
||||
|
|
@ -59,14 +59,14 @@ static void *http_check_entrance(void *arg)
|
|||
|
||||
server_count = 0;
|
||||
ppServerEnd = (*ppGroup)->active_servers + (*ppGroup)->active_count;
|
||||
for (ppServer=(*ppGroup)->active_servers; g_continue_flag && \
|
||||
for (ppServer=(*ppGroup)->active_servers; SF_G_CONTINUE_FLAG && \
|
||||
(!g_http_servers_dirty) && ppServer<ppServerEnd; ppServer++)
|
||||
{
|
||||
if (g_http_check_type == FDFS_HTTP_CHECK_ALIVE_TYPE_TCP)
|
||||
{
|
||||
sock = socketClientAuto((*ppServer)->ip_addr,
|
||||
(*ppGroup)->storage_http_port,
|
||||
g_fdfs_connect_timeout, O_NONBLOCK, &result);
|
||||
SF_G_CONNECT_TIMEOUT, O_NONBLOCK, &result);
|
||||
if (sock >= 0)
|
||||
{
|
||||
close(sock);
|
||||
|
|
@ -135,8 +135,8 @@ static void *http_check_entrance(void *arg)
|
|||
sprintf(url, "http://%s:%d%s", (*ppServer)->ip_addr, \
|
||||
(*ppGroup)->storage_http_port, g_http_check_uri);
|
||||
|
||||
result = get_url_content(url, g_fdfs_connect_timeout, \
|
||||
g_fdfs_network_timeout, &http_status, \
|
||||
result = get_url_content(url, SF_G_CONNECT_TIMEOUT, \
|
||||
SF_G_NETWORK_TIMEOUT, &http_status, \
|
||||
&content, &content_len, error_info);
|
||||
|
||||
if (g_http_servers_dirty)
|
||||
|
|
|
|||
|
|
@ -150,35 +150,6 @@ char *g_tracker_sys_filenames[TRACKER_SYS_FILE_COUNT] = {
|
|||
STORAGE_SERVERS_CHANGELOG_FILENAME
|
||||
};
|
||||
|
||||
#define TRACKER_CHOWN(path, current_uid, current_gid) \
|
||||
if (!(g_run_by_gid == current_gid && g_run_by_uid == current_uid)) \
|
||||
{ \
|
||||
if (chown(path, g_run_by_uid, g_run_by_gid) != 0) \
|
||||
{ \
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"chown \"%s\" fail, " \
|
||||
"errno: %d, error info: %s", \
|
||||
__LINE__, path, \
|
||||
errno, STRERROR(errno)); \
|
||||
return errno != 0 ? errno : EPERM; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define TRACKER_FCHOWN(fd, path, current_uid, current_gid) \
|
||||
if (!(g_run_by_gid == current_gid && g_run_by_uid == current_uid)) \
|
||||
{ \
|
||||
if (fchown(fd, g_run_by_uid, g_run_by_gid) != 0) \
|
||||
{ \
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"chown \"%s\" fail, " \
|
||||
"errno: %d, error info: %s", \
|
||||
__LINE__, path, \
|
||||
errno, STRERROR(errno)); \
|
||||
return errno != 0 ? errno : EPERM; \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
int tracker_mem_pthread_lock()
|
||||
{
|
||||
int result;
|
||||
|
|
@ -758,7 +729,7 @@ static int tracker_locate_group_trunk_servers(FDFSGroups *pGroups, \
|
|||
{
|
||||
snprintf(buff, sizeof(buff), \
|
||||
"in the file \"%s/data/%s\", ", \
|
||||
g_fdfs_base_path, \
|
||||
SF_G_BASE_PATH_STR, \
|
||||
STORAGE_GROUPS_LIST_FILENAME_NEW);
|
||||
}
|
||||
else
|
||||
|
|
@ -824,7 +795,7 @@ static int tracker_locate_storage_sync_server(FDFSGroups *pGroups, \
|
|||
{
|
||||
snprintf(buff, sizeof(buff), \
|
||||
"in the file \"%s/data/%s\", ", \
|
||||
g_fdfs_base_path, \
|
||||
SF_G_BASE_PATH_STR, \
|
||||
STORAGE_SERVERS_LIST_FILENAME_NEW);
|
||||
}
|
||||
else
|
||||
|
|
@ -1600,7 +1571,7 @@ static int tracker_load_data(FDFSGroups *pGroups)
|
|||
FDFSStorageSync *pTrunkServers;
|
||||
int nTrunkServerCount;
|
||||
|
||||
snprintf(data_path, sizeof(data_path), "%s/data", g_fdfs_base_path);
|
||||
snprintf(data_path, sizeof(data_path), "%s/data", SF_G_BASE_PATH_STR);
|
||||
if (!fileExists(data_path))
|
||||
{
|
||||
if (mkdir(data_path, 0755) != 0)
|
||||
|
|
@ -1611,7 +1582,7 @@ static int tracker_load_data(FDFSGroups *pGroups)
|
|||
__LINE__, data_path, errno, STRERROR(errno));
|
||||
return errno != 0 ? errno : ENOENT;
|
||||
}
|
||||
TRACKER_CHOWN(data_path, geteuid(), getegid())
|
||||
SF_CHOWN_TO_RUNBY_RETURN_ON_ERROR(data_path);
|
||||
}
|
||||
|
||||
if (chdir(data_path) != 0)
|
||||
|
|
@ -1681,7 +1652,7 @@ int tracker_save_groups()
|
|||
tracker_mem_file_lock();
|
||||
|
||||
snprintf(trueFilename, sizeof(trueFilename), "%s/data/%s", \
|
||||
g_fdfs_base_path, STORAGE_GROUPS_LIST_FILENAME_NEW);
|
||||
SF_G_BASE_PATH_STR, STORAGE_GROUPS_LIST_FILENAME_NEW);
|
||||
snprintf(tmpFilename, sizeof(tmpFilename), "%s.tmp", trueFilename);
|
||||
if ((fd=open(tmpFilename, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0)
|
||||
{
|
||||
|
|
@ -1788,7 +1759,7 @@ int tracker_save_groups()
|
|||
result = errno != 0 ? errno : EIO;
|
||||
}
|
||||
|
||||
TRACKER_CHOWN(trueFilename, geteuid(), getegid())
|
||||
SF_CHOWN_TO_RUNBY_RETURN_ON_ERROR(trueFilename);
|
||||
}
|
||||
|
||||
if (result != 0)
|
||||
|
|
@ -1820,7 +1791,7 @@ int tracker_save_storages()
|
|||
tracker_mem_file_lock();
|
||||
|
||||
snprintf(trueFilename, sizeof(trueFilename), "%s/data/%s", \
|
||||
g_fdfs_base_path, STORAGE_SERVERS_LIST_FILENAME_NEW);
|
||||
SF_G_BASE_PATH_STR, STORAGE_SERVERS_LIST_FILENAME_NEW);
|
||||
snprintf(tmpFilename, sizeof(tmpFilename), "%s.tmp", trueFilename);
|
||||
if ((fd=open(tmpFilename, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0)
|
||||
{
|
||||
|
|
@ -2078,7 +2049,7 @@ int tracker_save_storages()
|
|||
result = errno != 0 ? errno : EIO;
|
||||
}
|
||||
|
||||
TRACKER_CHOWN(trueFilename, geteuid(), getegid())
|
||||
SF_CHOWN_TO_RUNBY_RETURN_ON_ERROR(trueFilename);
|
||||
}
|
||||
|
||||
if (result != 0)
|
||||
|
|
@ -2108,7 +2079,7 @@ int tracker_save_sync_timestamps()
|
|||
tracker_mem_file_lock();
|
||||
|
||||
snprintf(trueFilename, sizeof(trueFilename), "%s/data/%s", \
|
||||
g_fdfs_base_path, STORAGE_SYNC_TIMESTAMP_FILENAME);
|
||||
SF_G_BASE_PATH_STR, STORAGE_SYNC_TIMESTAMP_FILENAME);
|
||||
snprintf(tmpFilename, sizeof(tmpFilename), "%s.tmp", trueFilename);
|
||||
if ((fd=open(tmpFilename, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0)
|
||||
{
|
||||
|
|
@ -2197,7 +2168,7 @@ int tracker_save_sync_timestamps()
|
|||
result = errno != 0 ? errno : EIO;
|
||||
}
|
||||
|
||||
TRACKER_CHOWN(trueFilename, geteuid(), getegid())
|
||||
SF_CHOWN_TO_RUNBY_RETURN_ON_ERROR(trueFilename);
|
||||
}
|
||||
|
||||
if (result != 0)
|
||||
|
|
@ -2232,7 +2203,7 @@ static int tracker_open_changlog_file()
|
|||
char data_path[MAX_PATH_SIZE];
|
||||
char filename[MAX_PATH_SIZE];
|
||||
|
||||
snprintf(data_path, sizeof(data_path), "%s/data", g_fdfs_base_path);
|
||||
snprintf(data_path, sizeof(data_path), "%s/data", SF_G_BASE_PATH_STR);
|
||||
if (!fileExists(data_path))
|
||||
{
|
||||
if (mkdir(data_path, 0755) != 0)
|
||||
|
|
@ -2243,11 +2214,11 @@ static int tracker_open_changlog_file()
|
|||
__LINE__, data_path, errno, STRERROR(errno));
|
||||
return errno != 0 ? errno : ENOENT;
|
||||
}
|
||||
TRACKER_CHOWN(data_path, geteuid(), getegid())
|
||||
SF_CHOWN_TO_RUNBY_RETURN_ON_ERROR(data_path);
|
||||
}
|
||||
|
||||
snprintf(filename, sizeof(filename), "%s/data/%s", \
|
||||
g_fdfs_base_path, STORAGE_SERVERS_CHANGELOG_FILENAME);
|
||||
SF_G_BASE_PATH_STR, STORAGE_SERVERS_CHANGELOG_FILENAME);
|
||||
changelog_fd = open(filename, O_WRONLY | O_CREAT | O_APPEND, 0644);
|
||||
if (changelog_fd < 0)
|
||||
{
|
||||
|
|
@ -2268,7 +2239,7 @@ static int tracker_open_changlog_file()
|
|||
return errno != 0 ? errno : EIO;
|
||||
}
|
||||
|
||||
TRACKER_FCHOWN(changelog_fd, filename, geteuid(), getegid())
|
||||
SF_FCHOWN_TO_RUNBY_RETURN_ON_ERROR(changelog_fd, filename);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -3810,7 +3781,7 @@ static int _tracker_mem_add_storage(FDFSGroupInfo *pGroup,
|
|||
|
||||
void tracker_calc_running_times(TrackerRunningStatus *pStatus)
|
||||
{
|
||||
pStatus->running_time = g_current_time - g_up_time;
|
||||
pStatus->running_time = g_current_time - g_sf_global_vars.up_time;
|
||||
|
||||
if (g_tracker_last_status.last_check_time == 0)
|
||||
{
|
||||
|
|
@ -3818,7 +3789,7 @@ void tracker_calc_running_times(TrackerRunningStatus *pStatus)
|
|||
}
|
||||
else
|
||||
{
|
||||
pStatus->restart_interval = g_up_time - \
|
||||
pStatus->restart_interval = g_sf_global_vars.up_time -
|
||||
g_tracker_last_status.last_check_time;
|
||||
}
|
||||
|
||||
|
|
@ -3852,7 +3823,7 @@ static int tracker_mem_get_sys_file_piece(ConnectionInfo *pTrackerServer, \
|
|||
*p++ = file_index;
|
||||
long2buff(*offset, p);
|
||||
if ((result=tcpsenddata_nb(pTrackerServer->sock, out_buff, \
|
||||
sizeof(out_buff), g_fdfs_network_timeout)) != 0)
|
||||
sizeof(out_buff), SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"send data to tracker server %s:%d fail, " \
|
||||
|
|
@ -3934,7 +3905,7 @@ static int tracker_mem_get_one_sys_file(ConnectionInfo *pTrackerServer, \
|
|||
int64_t file_size;
|
||||
|
||||
snprintf(full_filename, sizeof(full_filename), "%s/data/%s", \
|
||||
g_fdfs_base_path, g_tracker_sys_filenames[file_index]);
|
||||
SF_G_BASE_PATH_STR, g_tracker_sys_filenames[file_index]);
|
||||
fd = open(full_filename, O_WRONLY | O_CREAT | O_TRUNC, 0644);
|
||||
if (fd < 0)
|
||||
{
|
||||
|
|
@ -3946,7 +3917,7 @@ static int tracker_mem_get_one_sys_file(ConnectionInfo *pTrackerServer, \
|
|||
return errno != 0 ? errno : EACCES;
|
||||
}
|
||||
|
||||
TRACKER_FCHOWN(fd, full_filename, geteuid(), getegid())
|
||||
SF_FCHOWN_TO_RUNBY_RETURN_ON_ERROR(fd, full_filename);
|
||||
|
||||
offset = 0;
|
||||
file_size = 0;
|
||||
|
|
@ -4040,7 +4011,7 @@ static int find_my_ip_in_tracker_list()
|
|||
while ((current_ip=get_next_local_ip(previous_ip)) != NULL)
|
||||
{
|
||||
pServer = fdfs_tracker_group_get_server(&g_tracker_servers,
|
||||
current_ip, g_server_port);
|
||||
current_ip, SF_G_INNER_PORT);
|
||||
if (pServer != NULL)
|
||||
{
|
||||
if (pServer->count > 1)
|
||||
|
|
@ -4275,7 +4246,7 @@ static int tracker_mem_get_tracker_server(FDFSStorageJoinBody *pJoinBody, \
|
|||
for (pTrackerServer=pJoinBody->tracker_servers;
|
||||
pTrackerServer<pTrackerEnd; pTrackerServer++)
|
||||
{
|
||||
if (fdfs_server_contain_local_service(pTrackerServer, g_server_port))
|
||||
if (fdfs_server_contain_local_service(pTrackerServer, SF_G_INNER_PORT))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
@ -4420,8 +4391,8 @@ int tracker_mem_add_group_and_storage(TrackerClientInfo *pClientInfo, \
|
|||
|
||||
if (need_get_sys_files)
|
||||
{
|
||||
if (g_tracker_last_status.last_check_time > 0 && \
|
||||
g_up_time - g_tracker_last_status.last_check_time > \
|
||||
if (g_tracker_last_status.last_check_time > 0 && g_sf_global_vars.
|
||||
up_time - g_tracker_last_status.last_check_time >
|
||||
2 * TRACKER_SYNC_STATUS_FILE_INTERVAL)
|
||||
{ /* stop time exceeds 2 * interval */
|
||||
TrackerRunningStatus runningStatus;
|
||||
|
|
@ -5018,7 +4989,7 @@ static int _storage_get_trunk_binlog_size(
|
|||
memset(out_buff, 0, sizeof(out_buff));
|
||||
pHeader->cmd = STORAGE_PROTO_CMD_TRUNK_GET_BINLOG_SIZE;
|
||||
if ((result=tcpsenddata_nb(pStorageServer->sock, out_buff, \
|
||||
sizeof(out_buff), g_fdfs_network_timeout)) != 0)
|
||||
sizeof(out_buff), SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"storage server %s:%d, send data fail, " \
|
||||
|
|
@ -5094,7 +5065,7 @@ static int tracker_write_to_trunk_change_log(FDFSGroupInfo *pGroup, \
|
|||
tracker_mem_file_lock();
|
||||
|
||||
snprintf(full_filename, sizeof(full_filename), "%s/logs/%s", \
|
||||
g_fdfs_base_path, TRUNK_SERVER_CHANGELOG_FILENAME);
|
||||
SF_G_BASE_PATH_STR, TRUNK_SERVER_CHANGELOG_FILENAME);
|
||||
if ((fd=open(full_filename, O_WRONLY | O_CREAT | O_APPEND, 0644)) < 0)
|
||||
{
|
||||
tracker_mem_file_unlock();
|
||||
|
|
|
|||
|
|
@ -1,444 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2008 Happy Fish / YuQing
|
||||
*
|
||||
* FastDFS may be copied only under the terms of the GNU General
|
||||
* Public License V3, which may be found in the FastDFS source kit.
|
||||
* Please visit the FastDFS Home Page http://www.fastken.com/ for more detail.
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <pthread.h>
|
||||
#include "fastcommon/shared_func.h"
|
||||
#include "fastcommon/sched_thread.h"
|
||||
#include "fdfs_global.h"
|
||||
#include "fastcommon/logger.h"
|
||||
#include "fastcommon/sockopt.h"
|
||||
#include "fastcommon/fast_task_queue.h"
|
||||
#include "tracker_types.h"
|
||||
#include "tracker_proto.h"
|
||||
#include "tracker_mem.h"
|
||||
#include "tracker_global.h"
|
||||
#include "tracker_service.h"
|
||||
#include "fastcommon/ioevent_loop.h"
|
||||
#include "tracker_nio.h"
|
||||
|
||||
static void client_sock_read(int sock, short event, void *arg);
|
||||
static void client_sock_write(int sock, short event, void *arg);
|
||||
|
||||
void task_finish_clean_up(struct fast_task_info *pTask)
|
||||
{
|
||||
TrackerClientInfo *pClientInfo;
|
||||
|
||||
pClientInfo = (TrackerClientInfo *)pTask->arg;
|
||||
|
||||
if (pTask->finish_callback != NULL)
|
||||
{
|
||||
pTask->finish_callback(pTask);
|
||||
pTask->finish_callback = NULL;
|
||||
}
|
||||
|
||||
if (pClientInfo->pGroup != NULL)
|
||||
{
|
||||
if (pClientInfo->pStorage != NULL)
|
||||
{
|
||||
tracker_mem_offline_store_server(pClientInfo->pGroup, \
|
||||
pClientInfo->pStorage);
|
||||
}
|
||||
}
|
||||
|
||||
ioevent_detach(&pTask->thread_data->ev_puller, pTask->event.fd);
|
||||
close(pTask->event.fd);
|
||||
pTask->event.fd = -1;
|
||||
|
||||
if (pTask->event.timer.expires > 0)
|
||||
{
|
||||
fast_timer_remove(&pTask->thread_data->timer,
|
||||
&pTask->event.timer);
|
||||
pTask->event.timer.expires = 0;
|
||||
}
|
||||
|
||||
memset(pTask->arg, 0, sizeof(TrackerClientInfo));
|
||||
free_queue_push(pTask);
|
||||
__sync_fetch_and_sub(&g_connection_stat.current_count, 1);
|
||||
}
|
||||
|
||||
void recv_notify_read(int sock, short event, void *arg)
|
||||
{
|
||||
int bytes;
|
||||
int incomesock;
|
||||
struct nio_thread_data *pThreadData;
|
||||
struct fast_task_info *pTask;
|
||||
char szClientIp[IP_ADDRESS_SIZE];
|
||||
in_addr_t client_addr;
|
||||
|
||||
while (1)
|
||||
{
|
||||
if ((bytes=read(sock, &incomesock, sizeof(incomesock))) < 0)
|
||||
{
|
||||
if (!(errno == EAGAIN || errno == EWOULDBLOCK))
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"call read failed, " \
|
||||
"errno: %d, error info: %s", \
|
||||
__LINE__, errno, STRERROR(errno));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
else if (bytes == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (incomesock < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
client_addr = getPeerIpaddr(incomesock, \
|
||||
szClientIp, IP_ADDRESS_SIZE);
|
||||
if (g_allow_ip_count >= 0)
|
||||
{
|
||||
if (bsearch(&client_addr, g_allow_ip_addrs, \
|
||||
g_allow_ip_count, sizeof(in_addr_t), \
|
||||
cmp_by_ip_addr_t) == NULL)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"ip addr %s is not allowed to access", \
|
||||
__LINE__, szClientIp);
|
||||
|
||||
close(incomesock);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (tcpsetnonblockopt(incomesock) != 0)
|
||||
{
|
||||
close(incomesock);
|
||||
continue;
|
||||
}
|
||||
|
||||
pTask = free_queue_pop();
|
||||
if (pTask == NULL)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"malloc task buff fail, you should "
|
||||
"increase the parameter \"max_connections\" "
|
||||
"in tracker.conf, or check your applications "
|
||||
"for connection leaks", __LINE__);
|
||||
close(incomesock);
|
||||
continue;
|
||||
}
|
||||
|
||||
strcpy(pTask->client_ip, szClientIp);
|
||||
|
||||
pThreadData = g_thread_data + incomesock % g_work_threads;
|
||||
if (ioevent_set(pTask, pThreadData, incomesock, IOEVENT_READ,
|
||||
client_sock_read, g_fdfs_network_timeout) != 0)
|
||||
{
|
||||
task_finish_clean_up(pTask);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int set_send_event(struct fast_task_info *pTask)
|
||||
{
|
||||
int result;
|
||||
|
||||
if (pTask->event.callback == client_sock_write)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
pTask->event.callback = client_sock_write;
|
||||
if (ioevent_modify(&pTask->thread_data->ev_puller,
|
||||
pTask->event.fd, IOEVENT_WRITE, pTask) != 0)
|
||||
{
|
||||
result = errno != 0 ? errno : ENOENT;
|
||||
task_finish_clean_up(pTask);
|
||||
|
||||
logError("file: "__FILE__", line: %d, "\
|
||||
"ioevent_modify fail, " \
|
||||
"errno: %d, error info: %s", \
|
||||
__LINE__, result, STRERROR(result));
|
||||
return result;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int send_add_event(struct fast_task_info *pTask)
|
||||
{
|
||||
pTask->offset = 0;
|
||||
|
||||
/* direct send */
|
||||
client_sock_write(pTask->event.fd, IOEVENT_WRITE, pTask);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void client_sock_read(int sock, short event, void *arg)
|
||||
{
|
||||
int bytes;
|
||||
int recv_bytes;
|
||||
struct fast_task_info *pTask;
|
||||
|
||||
pTask = (struct fast_task_info *)arg;
|
||||
|
||||
if (event & IOEVENT_TIMEOUT)
|
||||
{
|
||||
if (pTask->offset == 0)
|
||||
{
|
||||
if (pTask->req_count > 0)
|
||||
{
|
||||
pTask->event.timer.expires = g_current_time +
|
||||
g_fdfs_network_timeout;
|
||||
fast_timer_add(&pTask->thread_data->timer,
|
||||
&pTask->event.timer);
|
||||
}
|
||||
else
|
||||
{
|
||||
logWarning("file: "__FILE__", line: %d, "
|
||||
"client ip: %s, recv timeout. "
|
||||
"after the connection is established, "
|
||||
"you must send a request before %ds timeout, "
|
||||
"maybe connections leak in you application.",
|
||||
__LINE__, pTask->client_ip, g_fdfs_network_timeout);
|
||||
task_finish_clean_up(pTask);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"client ip: %s, recv timeout, "
|
||||
"recv offset: %d, expect length: %d, "
|
||||
"req_count: %"PRId64, __LINE__, pTask->client_ip,
|
||||
pTask->offset, pTask->length, pTask->req_count);
|
||||
task_finish_clean_up(pTask);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (event & IOEVENT_ERROR)
|
||||
{
|
||||
logDebug("file: "__FILE__", line: %d, " \
|
||||
"client ip: %s, recv error event: %d, "
|
||||
"close connection", __LINE__, pTask->client_ip, event);
|
||||
|
||||
task_finish_clean_up(pTask);
|
||||
return;
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
fast_timer_modify(&pTask->thread_data->timer,
|
||||
&pTask->event.timer, g_current_time +
|
||||
g_fdfs_network_timeout);
|
||||
if (pTask->length == 0) //recv header
|
||||
{
|
||||
recv_bytes = sizeof(TrackerHeader) - pTask->offset;
|
||||
}
|
||||
else
|
||||
{
|
||||
recv_bytes = pTask->length - pTask->offset;
|
||||
}
|
||||
|
||||
bytes = recv(sock, pTask->data + pTask->offset, recv_bytes, 0);
|
||||
if (bytes < 0)
|
||||
{
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK)
|
||||
{
|
||||
}
|
||||
else if (errno == EINTR)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"client ip: %s, recv failed, " \
|
||||
"errno: %d, error info: %s", \
|
||||
__LINE__, pTask->client_ip, \
|
||||
errno, STRERROR(errno));
|
||||
|
||||
task_finish_clean_up(pTask);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else if (bytes == 0)
|
||||
{
|
||||
logDebug("file: "__FILE__", line: %d, " \
|
||||
"client ip: %s, recv failed, " \
|
||||
"connection disconnected.", \
|
||||
__LINE__, pTask->client_ip);
|
||||
|
||||
task_finish_clean_up(pTask);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pTask->length == 0) //header
|
||||
{
|
||||
if (pTask->offset + bytes < sizeof(TrackerHeader))
|
||||
{
|
||||
pTask->offset += bytes;
|
||||
return;
|
||||
}
|
||||
|
||||
pTask->length = buff2long(((TrackerHeader *) \
|
||||
pTask->data)->pkg_len);
|
||||
if (pTask->length < 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"client ip: %s, pkg length: %d < 0", \
|
||||
__LINE__, pTask->client_ip, \
|
||||
pTask->length);
|
||||
|
||||
task_finish_clean_up(pTask);
|
||||
return;
|
||||
}
|
||||
|
||||
pTask->length += sizeof(TrackerHeader);
|
||||
if (pTask->length > TRACKER_MAX_PACKAGE_SIZE)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"client ip: %s, pkg length: %d > " \
|
||||
"max pkg size: %d", __LINE__, \
|
||||
pTask->client_ip, pTask->length, \
|
||||
TRACKER_MAX_PACKAGE_SIZE);
|
||||
|
||||
task_finish_clean_up(pTask);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
pTask->offset += bytes;
|
||||
if (pTask->offset >= pTask->length) //recv done
|
||||
{
|
||||
pTask->req_count++;
|
||||
tracker_deal_task(pTask);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void client_sock_write(int sock, short event, void *arg)
|
||||
{
|
||||
int bytes;
|
||||
int result;
|
||||
struct fast_task_info *pTask;
|
||||
|
||||
pTask = (struct fast_task_info *)arg;
|
||||
if (event & IOEVENT_TIMEOUT)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"send timeout", __LINE__);
|
||||
|
||||
task_finish_clean_up(pTask);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (event & IOEVENT_ERROR)
|
||||
{
|
||||
logDebug("file: "__FILE__", line: %d, " \
|
||||
"client ip: %s, recv error event: %d, "
|
||||
"close connection", __LINE__, pTask->client_ip, event);
|
||||
|
||||
task_finish_clean_up(pTask);
|
||||
return;
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
fast_timer_modify(&pTask->thread_data->timer,
|
||||
&pTask->event.timer, g_current_time +
|
||||
g_fdfs_network_timeout);
|
||||
|
||||
bytes = send(sock, pTask->data + pTask->offset, \
|
||||
pTask->length - pTask->offset, 0);
|
||||
//printf("%08X sended %d bytes\n", (int)pTask, bytes);
|
||||
if (bytes < 0)
|
||||
{
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK)
|
||||
{
|
||||
set_send_event(pTask);
|
||||
}
|
||||
else if (errno == EINTR)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"client ip: %s, recv failed, " \
|
||||
"errno: %d, error info: %s", \
|
||||
__LINE__, pTask->client_ip, \
|
||||
errno, STRERROR(errno));
|
||||
|
||||
task_finish_clean_up(pTask);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else if (bytes == 0)
|
||||
{
|
||||
logWarning("file: "__FILE__", line: %d, " \
|
||||
"send failed, connection disconnected.", \
|
||||
__LINE__);
|
||||
|
||||
task_finish_clean_up(pTask);
|
||||
return;
|
||||
}
|
||||
|
||||
pTask->offset += bytes;
|
||||
if (pTask->offset >= pTask->length)
|
||||
{
|
||||
if (pTask->length == sizeof(TrackerHeader) && \
|
||||
((TrackerHeader *)pTask->data)->status == EINVAL)
|
||||
{
|
||||
logDebug("file: "__FILE__", line: %d, "\
|
||||
"close conn: #%d, client ip: %s", \
|
||||
__LINE__, pTask->event.fd,
|
||||
pTask->client_ip);
|
||||
task_finish_clean_up(pTask);
|
||||
return;
|
||||
}
|
||||
|
||||
pTask->offset = 0;
|
||||
pTask->length = 0;
|
||||
|
||||
pTask->event.callback = client_sock_read;
|
||||
if (ioevent_modify(&pTask->thread_data->ev_puller,
|
||||
pTask->event.fd, IOEVENT_READ, pTask) != 0)
|
||||
{
|
||||
result = errno != 0 ? errno : ENOENT;
|
||||
task_finish_clean_up(pTask);
|
||||
|
||||
logError("file: "__FILE__", line: %d, "\
|
||||
"ioevent_modify fail, " \
|
||||
"errno: %d, error info: %s", \
|
||||
__LINE__, result, STRERROR(result));
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2008 Happy Fish / YuQing
|
||||
*
|
||||
* FastDFS may be copied only under the terms of the GNU General
|
||||
* Public License V3, which may be found in the FastDFS source kit.
|
||||
* Please visit the FastDFS Home Page http://www.fastken.com/ for more detail.
|
||||
**/
|
||||
|
||||
//tracker_nio.h
|
||||
|
||||
#ifndef _TRACKER_NIO_H
|
||||
#define _TRACKER_NIO_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "fastcommon/fast_task_queue.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void recv_notify_read(int sock, short event, void *arg);
|
||||
int send_add_event(struct fast_task_info *pTask);
|
||||
|
||||
void task_finish_clean_up(struct fast_task_info *pTask);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -24,6 +24,20 @@
|
|||
#include "tracker_proto.h"
|
||||
#include "fdfs_shared_func.h"
|
||||
|
||||
int fdfs_set_body_length(struct fast_task_info *pTask)
|
||||
{
|
||||
pTask->length = buff2long(((TrackerHeader *)pTask->data)->pkg_len);
|
||||
if (pTask->length < 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"client ip: %s, pkg length: %d < 0",
|
||||
__LINE__, pTask->client_ip, pTask->length);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fdfs_recv_header_ex(ConnectionInfo *pTrackerServer,
|
||||
const int network_timeout, int64_t *in_bytes)
|
||||
{
|
||||
|
|
@ -119,7 +133,7 @@ int fdfs_recv_response(ConnectionInfo *pTrackerServer, \
|
|||
}
|
||||
|
||||
if ((result=tcprecvdata_nb(pTrackerServer->sock, *buff, \
|
||||
*in_bytes, g_fdfs_network_timeout)) != 0)
|
||||
*in_bytes, SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"tracker server: %s:%d, recv data fail, " \
|
||||
|
|
@ -147,7 +161,7 @@ int fdfs_quit(ConnectionInfo *pTrackerServer)
|
|||
memset(&header, 0, sizeof(header));
|
||||
header.cmd = FDFS_PROTO_CMD_QUIT;
|
||||
result = tcpsenddata_nb(pTrackerServer->sock, &header, \
|
||||
sizeof(header), g_fdfs_network_timeout);
|
||||
sizeof(header), SF_G_NETWORK_TIMEOUT);
|
||||
if(result != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
|
|
@ -171,7 +185,7 @@ int fdfs_deal_no_body_cmd(ConnectionInfo *pTrackerServer, const int cmd)
|
|||
memset(&header, 0, sizeof(header));
|
||||
header.cmd = cmd;
|
||||
result = tcpsenddata_nb(pTrackerServer->sock, &header, \
|
||||
sizeof(header), g_fdfs_network_timeout);
|
||||
sizeof(header), SF_G_NETWORK_TIMEOUT);
|
||||
if(result != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
|
|
@ -485,7 +499,7 @@ ConnectionInfo *tracker_connect_server_no_pool_ex(TrackerServerInfo *pServerInfo
|
|||
}
|
||||
|
||||
*err_no = conn_pool_connect_server_ex(pServerInfo->connections
|
||||
+ pServerInfo->index, g_fdfs_connect_timeout,
|
||||
+ pServerInfo->index, SF_G_CONNECT_TIMEOUT,
|
||||
bind_addr, log_connect_error);
|
||||
if (*err_no == 0)
|
||||
{
|
||||
|
|
@ -504,7 +518,7 @@ ConnectionInfo *tracker_connect_server_no_pool_ex(TrackerServerInfo *pServerInfo
|
|||
if (current_index != pServerInfo->index)
|
||||
{
|
||||
if ((*err_no=conn_pool_connect_server_ex(conn,
|
||||
g_fdfs_connect_timeout, bind_addr,
|
||||
SF_G_CONNECT_TIMEOUT, bind_addr,
|
||||
log_connect_error)) == 0)
|
||||
{
|
||||
pServerInfo->index = current_index;
|
||||
|
|
@ -586,7 +600,7 @@ static int fdfs_do_parameter_req(ConnectionInfo *pTrackerServer, \
|
|||
pHeader = (TrackerHeader *)out_buff;
|
||||
pHeader->cmd = TRACKER_PROTO_CMD_STORAGE_PARAMETER_REQ;
|
||||
if((result=tcpsenddata_nb(pTrackerServer->sock, out_buff, \
|
||||
sizeof(TrackerHeader), g_fdfs_network_timeout)) != 0)
|
||||
sizeof(TrackerHeader), SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"tracker server %s:%d, send data fail, " \
|
||||
|
|
@ -726,7 +740,7 @@ int fdfs_get_tracker_status(TrackerServerInfo *pTrackerServer,
|
|||
memset(&header, 0, sizeof(header));
|
||||
header.cmd = TRACKER_PROTO_CMD_TRACKER_GET_STATUS;
|
||||
if ((result=tcpsenddata_nb(conn->sock, &header,
|
||||
sizeof(header), g_fdfs_network_timeout)) != 0)
|
||||
sizeof(header), SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"send data to tracker server %s:%d fail, "
|
||||
|
|
|
|||
|
|
@ -217,10 +217,12 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#define tracker_connect_server(pServerInfo, err_no) \
|
||||
tracker_connect_server_ex(pServerInfo, g_fdfs_connect_timeout, err_no)
|
||||
tracker_connect_server_ex(pServerInfo, SF_G_CONNECT_TIMEOUT, err_no)
|
||||
|
||||
#define tracker_make_connection(conn, err_no) \
|
||||
tracker_make_connection_ex(conn, g_fdfs_connect_timeout, err_no)
|
||||
tracker_make_connection_ex(conn, SF_G_CONNECT_TIMEOUT, err_no)
|
||||
|
||||
int fdfs_set_body_length(struct fast_task_info *pTask);
|
||||
|
||||
/**
|
||||
* connect to the tracker server
|
||||
|
|
@ -295,7 +297,7 @@ static inline int fdfs_recv_header(ConnectionInfo *pTrackerServer,
|
|||
int64_t *in_bytes)
|
||||
{
|
||||
return fdfs_recv_header_ex(pTrackerServer,
|
||||
g_fdfs_network_timeout, in_bytes);
|
||||
SF_G_NETWORK_TIMEOUT, in_bytes);
|
||||
}
|
||||
|
||||
int fdfs_recv_response(ConnectionInfo *pTrackerServer, \
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ static int fdfs_ping_leader(ConnectionInfo *pTrackerServer)
|
|||
memset(&header, 0, sizeof(header));
|
||||
header.cmd = TRACKER_PROTO_CMD_TRACKER_PING_LEADER;
|
||||
result = tcpsenddata_nb(pTrackerServer->sock, &header, \
|
||||
sizeof(header), g_fdfs_network_timeout);
|
||||
sizeof(header), SF_G_NETWORK_TIMEOUT);
|
||||
if(result != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
|
|
@ -180,7 +180,7 @@ static int relationship_cmp_tracker_status(const void *p1, const void *p2)
|
|||
static int relationship_get_tracker_status(TrackerRunningStatus *pStatus)
|
||||
{
|
||||
if (fdfs_server_contain_local_service(pStatus->pTrackerServer,
|
||||
g_server_port))
|
||||
SF_G_INNER_PORT))
|
||||
{
|
||||
tracker_calc_running_times(pStatus);
|
||||
pStatus->if_leader = g_if_leader_self;
|
||||
|
|
@ -280,7 +280,7 @@ static int do_notify_leader_changed(TrackerServerInfo *pTrackerServer, \
|
|||
pLeader->ip_addr, pLeader->port);
|
||||
long2buff(FDFS_PROTO_IP_PORT_SIZE, pHeader->pkg_len);
|
||||
if ((result=tcpsenddata_nb(conn->sock, out_buff, \
|
||||
sizeof(out_buff), g_fdfs_network_timeout)) != 0)
|
||||
sizeof(out_buff), SF_G_NETWORK_TIMEOUT)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"send data to tracker server %s:%d fail, "
|
||||
|
|
@ -314,7 +314,7 @@ static int do_notify_leader_changed(TrackerServerInfo *pTrackerServer, \
|
|||
}
|
||||
} while (0);
|
||||
|
||||
if (conn->port == g_server_port &&
|
||||
if (conn->port == SF_G_INNER_PORT &&
|
||||
is_local_host_ip(conn->ip_addr))
|
||||
{
|
||||
tracker_close_connection_ex(conn, true);
|
||||
|
|
@ -474,7 +474,7 @@ static int relationship_select_leader()
|
|||
|
||||
conn = trackerStatus.pTrackerServer->connections;
|
||||
if (fdfs_server_contain_local_service(trackerStatus.
|
||||
pTrackerServer, g_server_port))
|
||||
pTrackerServer, SF_G_INNER_PORT))
|
||||
{
|
||||
if ((result=relationship_notify_leader_changed(
|
||||
&trackerStatus)) != 0)
|
||||
|
|
@ -563,7 +563,7 @@ static void *relationship_thread_entrance(void* arg)
|
|||
|
||||
fail_count = 0;
|
||||
sleep_seconds = 1;
|
||||
while (g_continue_flag)
|
||||
while (SF_G_CONTINUE_FLAG)
|
||||
{
|
||||
if (g_tracker_servers.servers != NULL)
|
||||
{
|
||||
|
|
@ -643,7 +643,7 @@ int tracker_relationship_init()
|
|||
pthread_t tid;
|
||||
pthread_attr_t thread_attr;
|
||||
|
||||
if ((result=init_pthread_attr(&thread_attr, g_thread_stack_size)) != 0)
|
||||
if ((result=init_pthread_attr(&thread_attr, SF_G_THREAD_STACK_SIZE)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"init_pthread_attr fail, program exit!", __LINE__);
|
||||
|
|
|
|||
|
|
@ -26,322 +26,89 @@
|
|||
#include "fastcommon/shared_func.h"
|
||||
#include "fastcommon/pthread_func.h"
|
||||
#include "fastcommon/sched_thread.h"
|
||||
#include "sf/sf_service.h"
|
||||
#include "sf/sf_nio.h"
|
||||
#include "tracker_types.h"
|
||||
#include "tracker_global.h"
|
||||
#include "tracker_mem.h"
|
||||
#include "tracker_func.h"
|
||||
#include "tracker_proto.h"
|
||||
#include "tracker_nio.h"
|
||||
#include "tracker_relationship.h"
|
||||
#include "fdfs_shared_func.h"
|
||||
#include "fastcommon/ioevent_loop.h"
|
||||
#include "tracker_service.h"
|
||||
|
||||
#define PKG_LEN_PRINTF_FORMAT "%d"
|
||||
|
||||
static pthread_mutex_t tracker_thread_lock;
|
||||
static pthread_mutex_t lb_thread_lock;
|
||||
|
||||
int g_tracker_thread_count = 0;
|
||||
struct nio_thread_data *g_thread_data = NULL;
|
||||
|
||||
static int lock_by_client_count = 0;
|
||||
|
||||
static void *work_thread_entrance(void* arg);
|
||||
static void wait_for_work_threads_exit();
|
||||
static void tracker_find_max_free_space_group();
|
||||
|
||||
static int tracker_deal_task(struct fast_task_info *pTask, const int stage);
|
||||
|
||||
static void task_finish_clean_up(struct fast_task_info *pTask)
|
||||
{
|
||||
TrackerClientInfo *pClientInfo;
|
||||
|
||||
pClientInfo = (TrackerClientInfo *)pTask->arg;
|
||||
if (pClientInfo->pGroup != NULL)
|
||||
{
|
||||
if (pClientInfo->pStorage != NULL)
|
||||
{
|
||||
tracker_mem_offline_store_server(pClientInfo->pGroup,
|
||||
pClientInfo->pStorage);
|
||||
}
|
||||
}
|
||||
memset(pTask->arg, 0, sizeof(TrackerClientInfo));
|
||||
|
||||
sf_task_finish_clean_up(pTask);
|
||||
}
|
||||
|
||||
static int sock_accept_done_callback(struct fast_task_info *task,
|
||||
const in_addr_t client_addr, const bool bInnerPort)
|
||||
{
|
||||
if (g_allow_ip_count >= 0)
|
||||
{
|
||||
if (bsearch(&client_addr, g_allow_ip_addrs,
|
||||
g_allow_ip_count, sizeof(in_addr_t),
|
||||
cmp_by_ip_addr_t) == NULL)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"ip addr %s is not allowed to access",
|
||||
__LINE__, task->client_ip);
|
||||
return EPERM;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tracker_service_init()
|
||||
{
|
||||
#define ALLOC_CONNECTIONS_ONCE 1024
|
||||
int result;
|
||||
int bytes;
|
||||
int init_connections;
|
||||
struct nio_thread_data *pThreadData;
|
||||
struct nio_thread_data *pDataEnd;
|
||||
pthread_t tid;
|
||||
pthread_attr_t thread_attr;
|
||||
|
||||
if ((result=init_pthread_lock(&tracker_thread_lock)) != 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
if ((result=init_pthread_lock(&lb_thread_lock)) != 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
if ((result=init_pthread_attr(&thread_attr, g_thread_stack_size)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"init_pthread_attr fail, program exit!", __LINE__);
|
||||
result = sf_service_init("fdfs_trackerd", NULL, NULL,
|
||||
sock_accept_done_callback, fdfs_set_body_length, NULL,
|
||||
tracker_deal_task, task_finish_clean_up, NULL, 1000,
|
||||
sizeof(TrackerHeader), sizeof(TrackerClientInfo));
|
||||
sf_enable_thread_notify(false);
|
||||
sf_set_remove_from_ready_list(false);
|
||||
return result;
|
||||
}
|
||||
|
||||
init_connections = g_max_connections < ALLOC_CONNECTIONS_ONCE ?
|
||||
g_max_connections : ALLOC_CONNECTIONS_ONCE;
|
||||
if ((result=free_queue_init_ex(g_max_connections, init_connections,
|
||||
ALLOC_CONNECTIONS_ONCE, g_min_buff_size,
|
||||
g_max_buff_size, sizeof(TrackerClientInfo))) != 0)
|
||||
void tracker_service_destroy()
|
||||
{
|
||||
return result;
|
||||
}
|
||||
bytes = sizeof(struct nio_thread_data) * g_work_threads;
|
||||
g_thread_data = (struct nio_thread_data *)malloc(bytes );
|
||||
if (g_thread_data == NULL)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"malloc %d bytes fail, errno: %d, error info: %s", \
|
||||
__LINE__, bytes, errno, STRERROR(errno));
|
||||
return errno != 0 ? errno : ENOMEM;
|
||||
}
|
||||
memset(g_thread_data, 0, bytes);
|
||||
|
||||
g_tracker_thread_count = 0;
|
||||
pDataEnd = g_thread_data + g_work_threads;
|
||||
for (pThreadData=g_thread_data; pThreadData<pDataEnd; pThreadData++)
|
||||
{
|
||||
if (ioevent_init(&pThreadData->ev_puller,
|
||||
g_max_connections + 2, 1000, 0) != 0)
|
||||
{
|
||||
result = errno != 0 ? errno : ENOMEM;
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"ioevent_init fail, " \
|
||||
"errno: %d, error info: %s", \
|
||||
__LINE__, result, STRERROR(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
result = fast_timer_init(&pThreadData->timer,
|
||||
2 * g_fdfs_network_timeout, g_current_time);
|
||||
if (result != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"fast_timer_init fail, " \
|
||||
"errno: %d, error info: %s", \
|
||||
__LINE__, result, STRERROR(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
if (pipe(pThreadData->pipe_fds) != 0)
|
||||
{
|
||||
result = errno != 0 ? errno : EPERM;
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"call pipe fail, " \
|
||||
"errno: %d, error info: %s", \
|
||||
__LINE__, result, STRERROR(result));
|
||||
break;
|
||||
}
|
||||
|
||||
#if defined(OS_LINUX)
|
||||
if ((result=fd_add_flags(pThreadData->pipe_fds[0], \
|
||||
O_NONBLOCK | O_NOATIME)) != 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
#else
|
||||
if ((result=fd_add_flags(pThreadData->pipe_fds[0], \
|
||||
O_NONBLOCK)) != 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((result=pthread_create(&tid, &thread_attr, \
|
||||
work_thread_entrance, pThreadData)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"create thread failed, startup threads: %d, " \
|
||||
"errno: %d, error info: %s", \
|
||||
__LINE__, g_tracker_thread_count, \
|
||||
result, STRERROR(result));
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((result=pthread_mutex_lock(&tracker_thread_lock)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"call pthread_mutex_lock fail, " \
|
||||
"errno: %d, error info: %s", \
|
||||
__LINE__, result, STRERROR(result));
|
||||
}
|
||||
g_tracker_thread_count++;
|
||||
if ((result=pthread_mutex_unlock(&tracker_thread_lock)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"call pthread_mutex_lock fail, " \
|
||||
"errno: %d, error info: %s", \
|
||||
__LINE__, result, STRERROR(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pthread_attr_destroy(&thread_attr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tracker_terminate_threads()
|
||||
{
|
||||
struct nio_thread_data *pThreadData;
|
||||
struct nio_thread_data *pDataEnd;
|
||||
int quit_sock;
|
||||
|
||||
if (g_thread_data != NULL)
|
||||
{
|
||||
pDataEnd = g_thread_data + g_work_threads;
|
||||
quit_sock = 0;
|
||||
for (pThreadData=g_thread_data; pThreadData<pDataEnd; \
|
||||
pThreadData++)
|
||||
{
|
||||
quit_sock--;
|
||||
if (write(pThreadData->pipe_fds[1], &quit_sock, \
|
||||
sizeof(quit_sock)) != sizeof(quit_sock))
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"write to pipe fail, " \
|
||||
"errno: %d, error info: %s", \
|
||||
__LINE__, errno, STRERROR(errno));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void wait_for_work_threads_exit()
|
||||
{
|
||||
while (g_tracker_thread_count != 0)
|
||||
while (SF_G_ALIVE_THREAD_COUNT != 0)
|
||||
{
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
int tracker_service_destroy()
|
||||
{
|
||||
wait_for_work_threads_exit();
|
||||
pthread_mutex_destroy(&tracker_thread_lock);
|
||||
pthread_mutex_destroy(&lb_thread_lock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void *accept_thread_entrance(void* arg)
|
||||
{
|
||||
int server_sock;
|
||||
int incomesock;
|
||||
struct sockaddr_in inaddr;
|
||||
socklen_t sockaddr_len;
|
||||
struct nio_thread_data *pThreadData;
|
||||
|
||||
server_sock = (long)arg;
|
||||
while (g_continue_flag)
|
||||
{
|
||||
sockaddr_len = sizeof(inaddr);
|
||||
incomesock = accept(server_sock, (struct sockaddr*)&inaddr, &sockaddr_len);
|
||||
if (incomesock < 0) //error
|
||||
{
|
||||
if (!(errno == EINTR || errno == EAGAIN))
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"accept failed, " \
|
||||
"errno: %d, error info: %s", \
|
||||
__LINE__, errno, STRERROR(errno));
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
pThreadData = g_thread_data + incomesock % g_work_threads;
|
||||
if (write(pThreadData->pipe_fds[1], &incomesock, \
|
||||
sizeof(incomesock)) != sizeof(incomesock))
|
||||
{
|
||||
close(incomesock);
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"call write failed, " \
|
||||
"errno: %d, error info: %s", \
|
||||
__LINE__, errno, STRERROR(errno));
|
||||
}
|
||||
else
|
||||
{
|
||||
int current_connections;
|
||||
current_connections = __sync_add_and_fetch(&g_connection_stat.
|
||||
current_count, 1);
|
||||
if (current_connections > g_connection_stat.max_count) {
|
||||
g_connection_stat.max_count = current_connections;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void tracker_accept_loop(int server_sock)
|
||||
{
|
||||
if (g_accept_threads > 1)
|
||||
{
|
||||
pthread_t tid;
|
||||
pthread_attr_t thread_attr;
|
||||
int result;
|
||||
int i;
|
||||
|
||||
if ((result=init_pthread_attr(&thread_attr, g_thread_stack_size)) != 0)
|
||||
{
|
||||
logWarning("file: "__FILE__", line: %d, " \
|
||||
"init_pthread_attr fail!", __LINE__);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i=1; i<g_accept_threads; i++)
|
||||
{
|
||||
if ((result=pthread_create(&tid, &thread_attr, \
|
||||
accept_thread_entrance, \
|
||||
(void *)(long)server_sock)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"create thread failed, startup threads: %d, " \
|
||||
"errno: %d, error info: %s", \
|
||||
__LINE__, i, result, STRERROR(result));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pthread_attr_destroy(&thread_attr);
|
||||
}
|
||||
}
|
||||
|
||||
accept_thread_entrance((void *)(long)server_sock);
|
||||
}
|
||||
|
||||
static void *work_thread_entrance(void* arg)
|
||||
{
|
||||
int result;
|
||||
struct nio_thread_data *pThreadData;
|
||||
|
||||
pThreadData = (struct nio_thread_data *)arg;
|
||||
ioevent_loop(pThreadData, recv_notify_read, task_finish_clean_up,
|
||||
&g_continue_flag);
|
||||
ioevent_destroy(&pThreadData->ev_puller);
|
||||
|
||||
if ((result=pthread_mutex_lock(&tracker_thread_lock)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"call pthread_mutex_lock fail, " \
|
||||
"errno: %d, error info: %s", \
|
||||
__LINE__, result, STRERROR(result));
|
||||
}
|
||||
g_tracker_thread_count--;
|
||||
if ((result=pthread_mutex_unlock(&tracker_thread_lock)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"call pthread_mutex_lock fail, " \
|
||||
"errno: %d, error info: %s", \
|
||||
__LINE__, result, STRERROR(result));
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -486,7 +253,7 @@ static int tracker_changelog_response(struct fast_task_info *pTask, \
|
|||
chg_len = TRACKER_MAX_PACKAGE_SIZE - sizeof(TrackerHeader);
|
||||
}
|
||||
|
||||
snprintf(filename, sizeof(filename), "%s/data/%s", g_fdfs_base_path,\
|
||||
snprintf(filename, sizeof(filename), "%s/data/%s", SF_G_BASE_PATH_STR,\
|
||||
STORAGE_SERVERS_CHANGELOG_FILENAME);
|
||||
fd = open(filename, O_RDONLY);
|
||||
if (fd < 0)
|
||||
|
|
@ -914,7 +681,7 @@ static int tracker_deal_notify_next_leader(struct fast_task_info *pTask)
|
|||
return ENOENT;
|
||||
}
|
||||
|
||||
if (g_if_leader_self && !(leader.port == g_server_port &&
|
||||
if (g_if_leader_self && !(leader.port == SF_G_INNER_PORT &&
|
||||
is_local_host_ip(leader.ip_addr)))
|
||||
{
|
||||
g_if_leader_self = false;
|
||||
|
|
@ -987,7 +754,7 @@ static int tracker_deal_commit_next_leader(struct fast_task_info *pTask)
|
|||
return EINVAL;
|
||||
}
|
||||
|
||||
leader_self = (leader.port == g_server_port) &&
|
||||
leader_self = (leader.port == SF_G_INNER_PORT) &&
|
||||
is_local_host_ip(leader.ip_addr);
|
||||
relationship_set_tracker_leader(server_index, &leader, leader_self);
|
||||
|
||||
|
|
@ -2098,7 +1865,7 @@ static int tracker_deal_get_one_sys_file(struct fast_task_info *pTask)
|
|||
}
|
||||
|
||||
snprintf(full_filename, sizeof(full_filename), "%s/data/%s", \
|
||||
g_fdfs_base_path, g_tracker_sys_filenames[index]);
|
||||
SF_G_BASE_PATH_STR, g_tracker_sys_filenames[index]);
|
||||
if (stat(full_filename, &file_stat) != 0)
|
||||
{
|
||||
result = errno != 0 ? errno : ENOENT;
|
||||
|
|
@ -3118,10 +2885,11 @@ static int tracker_deal_server_list_all_groups(struct fast_task_info *pTask)
|
|||
return EINVAL;
|
||||
}
|
||||
|
||||
expect_size = sizeof(TrackerHeader) + g_groups.count * sizeof(TrackerGroupStat);
|
||||
if (expect_size > g_min_buff_size)
|
||||
expect_size = sizeof(TrackerHeader) + g_groups.count *
|
||||
sizeof(TrackerGroupStat);
|
||||
if (expect_size > g_sf_global_vars.min_buff_size)
|
||||
{
|
||||
if (expect_size <= g_max_buff_size)
|
||||
if (expect_size <= g_sf_global_vars.max_buff_size)
|
||||
{
|
||||
if ((result=free_queue_set_buffer_size(pTask, expect_size)) != 0)
|
||||
{
|
||||
|
|
@ -3136,7 +2904,8 @@ static int tracker_deal_server_list_all_groups(struct fast_task_info *pTask)
|
|||
"expect buffer size: %d > max_buff_size: %d, "
|
||||
"you should increase max_buff_size in tracker.conf",
|
||||
__LINE__, TRACKER_PROTO_CMD_SERVER_LIST_ALL_GROUPS,
|
||||
pTask->client_ip, expect_size, g_max_buff_size);
|
||||
pTask->client_ip, expect_size,
|
||||
g_sf_global_vars.max_buff_size);
|
||||
pTask->length = sizeof(TrackerHeader);
|
||||
return ENOSPC;
|
||||
}
|
||||
|
|
@ -3904,7 +3673,7 @@ static int tracker_deal_storage_beat(struct fast_task_info *pTask)
|
|||
} \
|
||||
|
||||
|
||||
int tracker_deal_task(struct fast_task_info *pTask)
|
||||
static int tracker_deal_task(struct fast_task_info *pTask, const int stage)
|
||||
{
|
||||
TrackerHeader *pHeader;
|
||||
int result;
|
||||
|
|
@ -4077,9 +3846,7 @@ int tracker_deal_task(struct fast_task_info *pTask)
|
|||
pHeader->status = result;
|
||||
pHeader->cmd = TRACKER_PROTO_CMD_RESP;
|
||||
long2buff(pTask->length - sizeof(TrackerHeader), pHeader->pkg_len);
|
||||
|
||||
send_add_event(pTask);
|
||||
sf_send_add_event(pTask);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,18 +22,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
//typedef struct nio_thread_data struct nio_thread_data;
|
||||
|
||||
extern int g_tracker_thread_count;
|
||||
extern struct nio_thread_data *g_thread_data;
|
||||
|
||||
int tracker_service_init();
|
||||
int tracker_service_destroy();
|
||||
|
||||
int tracker_terminate_threads();
|
||||
|
||||
void tracker_accept_loop(int server_sock);
|
||||
int tracker_deal_task(struct fast_task_info *pTask);
|
||||
void tracker_service_destroy();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,11 +38,11 @@ int tracker_write_status_to_file(void *args)
|
|||
int len;
|
||||
|
||||
snprintf(full_filename, sizeof(full_filename), "%s/data/%s", \
|
||||
g_fdfs_base_path, TRACKER_STATUS_FILENAME);
|
||||
SF_G_BASE_PATH_STR, TRACKER_STATUS_FILENAME);
|
||||
|
||||
len = sprintf(buff, "%s=%d\n" \
|
||||
"%s=%d\n",
|
||||
TRACKER_STATUS_ITEM_UP_TIME, (int)g_up_time,
|
||||
TRACKER_STATUS_ITEM_UP_TIME, (int)g_sf_global_vars.up_time,
|
||||
TRACKER_STATUS_ITEM_LAST_CHECK_TIME, (int)g_current_time
|
||||
);
|
||||
|
||||
|
|
@ -56,7 +56,7 @@ int tracker_load_status_from_file(TrackerStatus *pStatus)
|
|||
int result;
|
||||
|
||||
snprintf(full_filename, sizeof(full_filename), "%s/data/%s", \
|
||||
g_fdfs_base_path, TRACKER_STATUS_FILENAME);
|
||||
SF_G_BASE_PATH_STR, TRACKER_STATUS_FILENAME);
|
||||
if (!fileExists(full_filename))
|
||||
{
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -471,10 +471,5 @@ typedef struct {
|
|||
bool if_leader; //if leader
|
||||
} TrackerRunningStatus;
|
||||
|
||||
typedef struct fdfs_connection_stat {
|
||||
volatile int current_count;
|
||||
int max_count;
|
||||
} FDFSConnectionStat;
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue