tracker nio use libserverframe

use_libserverframe
YuQing 2022-09-12 10:48:28 +08:00
parent 1d7b15d1be
commit 8f538108ce
34 changed files with 324 additions and 1511 deletions

View File

@ -22,7 +22,7 @@
int g_fdfs_connect_timeout = DEFAULT_CONNECT_TIMEOUT;
int g_fdfs_network_timeout = DEFAULT_NETWORK_TIMEOUT;
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;

View File

@ -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.18
%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.18
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.18
Requires: %{FDFSConfig}
Summary: The client dynamic library of fastdfs

View File

@ -168,9 +168,9 @@ int main(int argc, char *argv[])
return result;
}
memset(g_bind_addr, 0, sizeof(g_bind_addr));
memset(SF_G_INNER_BIND_ADDR, 0, sizeof(SF_G_INNER_BIND_ADDR));
if ((result=storage_func_init(conf_filename, \
g_bind_addr, sizeof(g_bind_addr))) != 0)
SF_G_INNER_BIND_ADDR, sizeof(SF_G_INNER_BIND_ADDR))) != 0)
{
logCrit("exit abnormally!\n");
delete_pid_file(pidFilename);
@ -178,7 +178,7 @@ int main(int argc, char *argv[])
return result;
}
sock = socketServer(g_bind_addr, g_server_port, &result);
sock = socketServer(SF_G_INNER_BIND_ADDR, SF_G_INNER_PORT, &result);
if (sock < 0)
{
logCrit("exit abnormally!\n");
@ -199,7 +199,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;
}
@ -207,7 +207,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;
}
@ -215,7 +215,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;
}
@ -223,7 +223,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;
}
@ -231,7 +231,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, " \
@ -246,7 +246,7 @@ 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;
@ -343,7 +343,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...", \
@ -363,15 +363,15 @@ 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)
@ -518,7 +518,7 @@ static int setupSchedules(pthread_t *schedule_tid)
}
if ((result=sched_start(&scheduleArray, schedule_tid,
g_thread_stack_size, (bool * volatile)&g_continue_flag)) != 0)
SF_G_THREAD_STACK_SIZE, (bool * volatile)&SF_G_CONTINUE_FLAG)) != 0)
{
return result;
}

View File

@ -55,7 +55,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__);
@ -741,7 +741,7 @@ 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)
{

View File

@ -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(
&current_recovery_thread_count, 0) > 0);
if (__sync_fetch_and_add(&current_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;
}

View File

@ -46,9 +46,9 @@ static int fdfs_dump_global_vars(char *buff, const int buffSize)
"g_fdfs_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"
@ -94,11 +94,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"
@ -140,9 +140,9 @@ static int fdfs_dump_global_vars(char *buff, const int buffSize)
, g_fdfs_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
, SF_G_INNER_PORT
, g_max_connections
, g_storage_thread_count
, g_group_name
@ -190,11 +190,11 @@ 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",
szUptime, sizeof(szUptime))

View File

@ -148,7 +148,7 @@ 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)
@ -472,7 +472,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;
}
@ -693,7 +693,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;
}
@ -715,7 +715,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 +775,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;
@ -1086,7 +1086,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 +1121,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 +1200,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 +1241,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 +1270,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)
@ -1480,11 +1480,11 @@ int storage_func_init(const char *filename, \
g_fdfs_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, \
@ -1877,13 +1877,13 @@ int storage_func_init(const char *filename, \
{
break;
}
g_thread_stack_size = (int)thread_stack_size;
SF_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;
@ -2189,7 +2189,7 @@ int storage_func_init(const char *filename, \
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, \
SF_G_INNER_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, \
@ -2204,7 +2204,7 @@ int storage_func_init(const char *filename, \
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, \
SF_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 \
? "hash" : "md5",

View File

@ -43,36 +43,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);

View File

@ -14,17 +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;
@ -55,7 +50,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 +73,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 +87,8 @@ 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};
char SF_G_INNER_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 +98,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,9 +109,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;

View File

@ -59,19 +59,13 @@ typedef struct
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
@ -101,7 +95,6 @@ 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_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 +121,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 +135,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 +145,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,9 +156,7 @@ 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

View File

@ -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;
}

View File

@ -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;
}

View File

@ -1598,7 +1598,7 @@ int storage_service_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__);
@ -1790,7 +1790,7 @@ static void *accept_thread_entrance(void* arg)
struct storage_nio_thread_data *pThreadData;
server_sock = (long)arg;
while (g_continue_flag)
while (SF_G_CONTINUE_FLAG)
{
sockaddr_len = sizeof(inaddr);
incomesock = accept(server_sock, (struct sockaddr*)&inaddr, \
@ -1886,7 +1886,7 @@ void storage_accept_loop(int server_sock)
int result;
int i;
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)
{
logWarning("file: "__FILE__", line: %d, " \
"init_pthread_attr fail!", __LINE__);
@ -1958,7 +1958,7 @@ static void *work_thread_entrance(void* arg)
}
ioevent_loop(&pThreadData->thread_data, storage_recv_notify_read,
task_finish_clean_up, &g_continue_flag);
task_finish_clean_up, &SF_G_CONTINUE_FLAG);
ioevent_destroy(&pThreadData->thread_data.ev_puller);
if (g_check_file_duplicate)
@ -4359,9 +4359,9 @@ static int storage_server_fetch_one_path_binlog_dealer(
{
break;
}
} while (g_continue_flag);
} while (SF_G_CONTINUE_FLAG);
if (!g_continue_flag)
if (!SF_G_CONTINUE_FLAG)
{
if (result == 0)
{

View File

@ -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;
}
}
@ -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!", \
@ -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))
{
@ -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;
}

View File

@ -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,17 +85,17 @@ 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,
conn->ip_addr, SF_G_INNER_PORT,
g_fdfs_connect_timeout)) == 0)
{
char szFailPrompt[64];
@ -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]));
}
}

View File

@ -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,7 +278,7 @@ 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;
}
@ -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);
}
@ -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, " \
@ -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;
@ -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);
@ -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;
}

View File

@ -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;
@ -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))
{
@ -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;
}

View File

@ -9,7 +9,7 @@ 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)

View File

@ -52,8 +52,6 @@ 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);
@ -71,17 +69,37 @@ static void sigDumpHandler(int sig);
#define SCHEDULE_ENTRIES_COUNT 5
static int setup_schedule_tasks()
{
ScheduleEntry scheduleEntries[SCHEDULE_ENTRIES_COUNT];
ScheduleArray scheduleArray;
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_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++;
return sched_add_entries(&scheduleArray);
}
int main(int argc, char *argv[])
{
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;
@ -99,8 +117,6 @@ int main(int argc, char *argv[])
}
g_current_time = time(NULL);
g_up_time = g_current_time;
srand(g_up_time);
log_init2();
if ((result=sf_get_base_path_from_conf_file(conf_filename)) != 0)
@ -136,9 +152,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();
@ -167,17 +181,8 @@ 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)
{
logCrit("exit abnormally!\n");
log_destroy();
return result;
}
@ -283,7 +288,7 @@ int main(int argc, char *argv[])
#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!", \
@ -302,55 +307,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;
}
@ -367,13 +339,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)
@ -388,7 +360,7 @@ 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)
{
/*
@ -450,7 +422,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);
@ -459,12 +431,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);
}
@ -480,15 +452,15 @@ 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)

View File

@ -295,9 +295,9 @@ static int fdfs_dump_global_vars(char *buff, const int buffSize)
"g_fdfs_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"
@ -349,22 +349,22 @@ static int fdfs_dump_global_vars(char *buff, const int buffSize)
, g_fdfs_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

View File

@ -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,25 @@ 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;
char *pSlotMinSize;
char *pSlotMaxSize;
char *pSpaceThreshold;
char *pTrunkFileSize;
char *pRotateErrorLogSize;
char *pMinBuffSize;
char *pMaxBuffSize;
#ifdef WITH_HTTPD
char *pHttpCheckUri;
char *pHttpCheckType;
#endif
IniContext iniContext;
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,71 +167,13 @@ int tracker_load_from_conf_file(const char *filename, \
break;
}
pBasePath = iniGetStrValue(NULL, "base_path", &iniContext);
if (pBasePath == NULL)
sf_set_current_time();
if ((result=sf_load_config("trackerd", filename, &iniContext,
"service", FDFS_TRACKER_SERVER_DEF_PORT,
FDFS_TRACKER_SERVER_DEF_PORT,
task_buffer_extra_size)) != 0)
{
logError("file: "__FILE__", line: %d, " \
"conf file \"%s\" must have item " \
"\"base_path\"!", __LINE__, filename);
result = ENOENT;
break;
}
snprintf(SF_G_BASE_PATH_STR, sizeof(SF_G_BASE_PATH_STR), "%s", pBasePath);
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__, SF_G_BASE_PATH_STR, STRERROR(errno));
result = errno != 0 ? errno : ENOENT;
break;
}
if (!isDir(SF_G_BASE_PATH_STR))
{
logError("file: "__FILE__", line: %d, " \
"\"%s\" is not a directory!", \
__LINE__, SF_G_BASE_PATH_STR);
result = ENOTDIR;
break;
}
load_log_level(&iniContext);
if ((result=log_set_prefix(SF_G_BASE_PATH_STR, \
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);
return result;
}
if ((result=tracker_load_store_lookup(filename, \
@ -303,119 +234,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 +248,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 +421,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 +429,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)
@ -747,26 +480,17 @@ 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 +514,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,
SF_G_BASE_PATH_STR, 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 +549,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);

View File

@ -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
}

View File

@ -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
@ -80,7 +61,4 @@ bool g_http_servers_dirty = false;
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};

View File

@ -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,8 +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

View File

@ -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,7 +59,7 @@ 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)

View File

@ -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;
@ -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)
@ -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)
@ -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)
@ -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)
@ -2243,7 +2214,7 @@ 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", \
@ -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;
}
@ -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;

View File

@ -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;
}
}
}

View File

@ -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

View File

@ -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)
{

View File

@ -222,6 +222,8 @@ extern "C" {
#define tracker_make_connection(conn, err_no) \
tracker_make_connection_ex(conn, g_fdfs_connect_timeout, err_no)
int fdfs_set_body_length(struct fast_task_info *pTask);
/**
* connect to the tracker server
* params:

View File

@ -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;
@ -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__);

View File

@ -26,322 +26,61 @@
#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 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);
}
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)
{
result = sf_service_init("fdfs_trackerd", NULL, NULL, NULL,
fdfs_set_body_length, 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;
}
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__);
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)
{
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()
void tracker_service_destroy()
{
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;
}
/*
@ -914,7 +653,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 +726,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);
@ -3118,10 +2857,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 +2876,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 +3645,7 @@ static int tracker_deal_storage_beat(struct fast_task_info *pTask)
} \
int tracker_deal_task(struct fast_task_info *pTask)
int tracker_deal_task(struct fast_task_info *pTask, const int stage)
{
TrackerHeader *pHeader;
int result;
@ -4077,9 +3818,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;
}

View File

@ -22,18 +22,11 @@
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_service_destroy();
void tracker_accept_loop(int server_sock);
int tracker_deal_task(struct fast_task_info *pTask);
int tracker_deal_task(struct fast_task_info *pTask, const int stage);
#ifdef __cplusplus
}

View File

@ -42,7 +42,7 @@ int tracker_write_status_to_file(void *args)
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
);