use prctl to set pthread name under Linux
parent
ed12daf5c3
commit
079bc4737b
3
HISTORY
3
HISTORY
|
|
@ -1,4 +1,7 @@
|
|||
|
||||
Version 6.9.3 2022-12-24
|
||||
* use prctl to set pthread name under Linux
|
||||
|
||||
Version 6.9.2 2022-11-28
|
||||
* space size such as total_mb and free_mb use int64_t instead of int
|
||||
* bugfixed: log connection ip_addr and port correctly
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
#include "fastcommon/logger.h"
|
||||
#include "fdfs_global.h"
|
||||
|
||||
Version g_fdfs_version = {6, 9, 2};
|
||||
Version g_fdfs_version = {6, 9, 3};
|
||||
bool g_use_connection_pool = false;
|
||||
ConnectionPool g_connection_pool;
|
||||
int g_connection_pool_max_idle_time = 3600;
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
#include "fastcommon/logger.h"
|
||||
#include "fastcommon/sockopt.h"
|
||||
#include "fastcommon/ioevent_loop.h"
|
||||
#include "fastcommon/fc_atomic.h"
|
||||
#include "sf/sf_service.h"
|
||||
#include "storage_global.h"
|
||||
#include "storage_service.h"
|
||||
|
|
@ -87,13 +88,13 @@ int storage_dio_init()
|
|||
for (pThreadData=g_dio_thread_data; pThreadData<pDataEnd; pThreadData++)
|
||||
{
|
||||
pThreadData->count = threads_count_per_path;
|
||||
pThreadData->contexts = g_dio_contexts + (pThreadData - \
|
||||
pThreadData->contexts = g_dio_contexts + (pThreadData -
|
||||
g_dio_thread_data) * threads_count_per_path;
|
||||
pThreadData->reader = pThreadData->contexts;
|
||||
pThreadData->writer = pThreadData->contexts+g_disk_reader_threads;
|
||||
|
||||
pContextEnd = pThreadData->contexts + pThreadData->count;
|
||||
for (pContext=pThreadData->contexts; pContext<pContextEnd; \
|
||||
for (pContext=pThreadData->contexts; pContext<pContextEnd;
|
||||
pContext++)
|
||||
{
|
||||
if ((result=blocked_queue_init(&(pContext->queue))) != 0)
|
||||
|
|
@ -101,7 +102,25 @@ int storage_dio_init()
|
|||
return result;
|
||||
}
|
||||
|
||||
if ((result=pthread_create(&tid, &thread_attr, \
|
||||
pContext->path_index = pThreadData - g_dio_thread_data;
|
||||
pContext->thread_index = pContext - pThreadData->contexts;
|
||||
if (g_disk_rw_separated)
|
||||
{
|
||||
if (pContext->thread_index < g_disk_reader_threads)
|
||||
{
|
||||
pContext->rw = "r";
|
||||
}
|
||||
else
|
||||
{
|
||||
pContext->rw = "w";
|
||||
pContext->thread_index -= g_disk_reader_threads;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pContext->rw = "rw";
|
||||
}
|
||||
if ((result=pthread_create(&tid, &thread_attr,
|
||||
dio_thread_entrance, pContext)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
|
|
@ -729,6 +748,16 @@ static void *dio_thread_entrance(void* arg)
|
|||
struct fast_task_info *pTask;
|
||||
|
||||
pContext = (struct storage_dio_context *)arg;
|
||||
|
||||
#ifdef OS_LINUX
|
||||
{
|
||||
char thread_name[32];
|
||||
snprintf(thread_name, sizeof(thread_name), "dio-p%02d-%s[%d]",
|
||||
pContext->path_index, pContext->rw, pContext->thread_index);
|
||||
prctl(PR_SET_NAME, thread_name);
|
||||
}
|
||||
#endif
|
||||
|
||||
while (SF_G_CONTINUE_FLAG)
|
||||
{
|
||||
while ((pTask=blocked_queue_pop(&(pContext->queue))) != NULL)
|
||||
|
|
@ -740,9 +769,9 @@ static void *dio_thread_entrance(void* arg)
|
|||
|
||||
__sync_sub_and_fetch(&g_dio_thread_count, 1);
|
||||
|
||||
logDebug("file: "__FILE__", line: %d, " \
|
||||
"dio thread exited, thread count: %d", \
|
||||
__LINE__, g_dio_thread_count);
|
||||
logDebug("file: "__FILE__", line: %d, "
|
||||
"dio thread exited, thread count: %d", __LINE__,
|
||||
FC_ATOMIC_GET(g_dio_thread_count));
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,9 @@
|
|||
|
||||
struct storage_dio_context
|
||||
{
|
||||
int path_index;
|
||||
int thread_index;
|
||||
const char *rw;
|
||||
struct fast_blocked_queue queue;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1653,7 +1653,7 @@ int storage_service_init()
|
|||
NULL, sock_accept_done_callback, storage_set_body_length,
|
||||
sock_send_done_callback, storage_deal_task, task_finish_clean_up,
|
||||
NULL, 1000, sizeof(TrackerHeader), sizeof(StorageClientInfo));
|
||||
sf_enable_thread_notify(false);
|
||||
sf_enable_thread_notify(true);
|
||||
sf_set_remove_from_ready_list(false);
|
||||
|
||||
return result;
|
||||
|
|
|
|||
|
|
@ -19,14 +19,15 @@
|
|||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
#include "fdfs_define.h"
|
||||
#include "fastcommon/logger.h"
|
||||
#include "fdfs_global.h"
|
||||
#include "fastcommon/sockopt.h"
|
||||
#include "fastcommon/shared_func.h"
|
||||
#include "fastcommon/pthread_func.h"
|
||||
#include "fastcommon/sched_thread.h"
|
||||
#include "fastcommon/ini_file_reader.h"
|
||||
#include "fastcommon/fc_atomic.h"
|
||||
#include "fdfs_define.h"
|
||||
#include "fdfs_global.h"
|
||||
#include "tracker_types.h"
|
||||
#include "tracker_proto.h"
|
||||
#include "storage_global.h"
|
||||
|
|
@ -62,7 +63,7 @@ int g_binlog_index = 0;
|
|||
static int64_t binlog_file_size = 0;
|
||||
static int binlog_compress_index = 0;
|
||||
|
||||
int g_storage_sync_thread_count = 0;
|
||||
volatile int g_storage_sync_thread_count = 0;
|
||||
static pthread_mutex_t sync_thread_lock;
|
||||
static char *binlog_write_cache_buff = NULL;
|
||||
static int binlog_write_cache_len = 0;
|
||||
|
|
@ -1551,7 +1552,8 @@ int kill_storage_sync_threads()
|
|||
__LINE__, result, STRERROR(result));
|
||||
}
|
||||
|
||||
kill_res = kill_work_threads(sync_tids, g_storage_sync_thread_count);
|
||||
kill_res = kill_work_threads(sync_tids, FC_ATOMIC_GET(
|
||||
g_storage_sync_thread_count));
|
||||
|
||||
if ((result=pthread_mutex_unlock(&sync_thread_lock)) != 0)
|
||||
{
|
||||
|
|
@ -1561,7 +1563,7 @@ int kill_storage_sync_threads()
|
|||
__LINE__, result, STRERROR(result));
|
||||
}
|
||||
|
||||
while (g_storage_sync_thread_count > 0)
|
||||
while (FC_ATOMIC_GET(g_storage_sync_thread_count) > 0)
|
||||
{
|
||||
usleep(50000);
|
||||
}
|
||||
|
|
@ -2853,6 +2855,7 @@ static void storage_sync_thread_exit(ConnectionInfo *pStorage)
|
|||
{
|
||||
int result;
|
||||
int i;
|
||||
int thread_count;
|
||||
pthread_t tid;
|
||||
|
||||
if ((result=pthread_mutex_lock(&sync_thread_lock)) != 0)
|
||||
|
|
@ -2863,8 +2866,9 @@ static void storage_sync_thread_exit(ConnectionInfo *pStorage)
|
|||
__LINE__, result, STRERROR(result));
|
||||
}
|
||||
|
||||
thread_count = FC_ATOMIC_GET(g_storage_sync_thread_count);
|
||||
tid = pthread_self();
|
||||
for (i=0; i<g_storage_sync_thread_count; i++)
|
||||
for (i=0; i<thread_count; i++)
|
||||
{
|
||||
if (pthread_equal(sync_tids[i], tid))
|
||||
{
|
||||
|
|
@ -2872,13 +2876,13 @@ static void storage_sync_thread_exit(ConnectionInfo *pStorage)
|
|||
}
|
||||
}
|
||||
|
||||
while (i < g_storage_sync_thread_count - 1)
|
||||
while (i < thread_count - 1)
|
||||
{
|
||||
sync_tids[i] = sync_tids[i + 1];
|
||||
i++;
|
||||
}
|
||||
|
||||
g_storage_sync_thread_count--;
|
||||
FC_ATOMIC_DEC(g_storage_sync_thread_count);
|
||||
|
||||
if ((result=pthread_mutex_unlock(&sync_thread_lock)) != 0)
|
||||
{
|
||||
|
|
@ -2914,6 +2918,15 @@ static void* storage_sync_thread_entrance(void* arg)
|
|||
storage_server.port = SF_G_INNER_PORT;
|
||||
storage_server.sock = -1;
|
||||
|
||||
#ifdef OS_LINUX
|
||||
{
|
||||
char thread_name[32];
|
||||
snprintf(thread_name, sizeof(thread_name), "data-sync[%d]",
|
||||
FC_ATOMIC_GET(g_storage_sync_thread_count));
|
||||
prctl(PR_SET_NAME, thread_name);
|
||||
}
|
||||
#endif
|
||||
|
||||
memset(local_ip_addr, 0, sizeof(local_ip_addr));
|
||||
pReader = (StorageBinLogReader *)malloc(sizeof(StorageBinLogReader));
|
||||
if (pReader == NULL)
|
||||
|
|
@ -3253,6 +3266,7 @@ static void* storage_sync_thread_entrance(void* arg)
|
|||
int storage_sync_thread_start(const FDFSStorageBrief *pStorage)
|
||||
{
|
||||
int result;
|
||||
int thread_count;
|
||||
pthread_attr_t pattr;
|
||||
pthread_t tid;
|
||||
|
||||
|
|
@ -3286,12 +3300,11 @@ int storage_sync_thread_start(const FDFSStorageBrief *pStorage)
|
|||
pStorage->ip_addr, g_storage_sync_thread_count);
|
||||
*/
|
||||
|
||||
if ((result=pthread_create(&tid, &pattr, storage_sync_thread_entrance, \
|
||||
if ((result=pthread_create(&tid, &pattr, storage_sync_thread_entrance,
|
||||
(void *)pStorage)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"create thread failed, errno: %d, " \
|
||||
"error info: %s", \
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"create thread failed, errno: %d, error info: %s",
|
||||
__LINE__, result, STRERROR(result));
|
||||
|
||||
pthread_attr_destroy(&pattr);
|
||||
|
|
@ -3306,21 +3319,19 @@ int storage_sync_thread_start(const FDFSStorageBrief *pStorage)
|
|||
__LINE__, result, STRERROR(result));
|
||||
}
|
||||
|
||||
g_storage_sync_thread_count++;
|
||||
sync_tids = (pthread_t *)realloc(sync_tids, sizeof(pthread_t) * \
|
||||
g_storage_sync_thread_count);
|
||||
thread_count = FC_ATOMIC_INC(g_storage_sync_thread_count);
|
||||
sync_tids = (pthread_t *)realloc(sync_tids,
|
||||
sizeof(pthread_t) * thread_count);
|
||||
if (sync_tids == NULL)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"malloc %d bytes fail, " \
|
||||
"errno: %d, error info: %s", \
|
||||
__LINE__, (int)sizeof(pthread_t) * \
|
||||
g_storage_sync_thread_count, \
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"malloc %d bytes fail, errno: %d, error info: %s",
|
||||
__LINE__, (int)sizeof(pthread_t) * thread_count,
|
||||
errno, STRERROR(errno));
|
||||
}
|
||||
else
|
||||
{
|
||||
sync_tids[g_storage_sync_thread_count - 1] = tid;
|
||||
sync_tids[thread_count - 1] = tid;
|
||||
}
|
||||
|
||||
if ((result=pthread_mutex_unlock(&sync_thread_lock)) != 0)
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ typedef struct
|
|||
extern int g_binlog_fd;
|
||||
extern int g_binlog_index;
|
||||
|
||||
extern int g_storage_sync_thread_count;
|
||||
extern volatile int g_storage_sync_thread_count;
|
||||
|
||||
int storage_sync_init();
|
||||
int storage_sync_destroy();
|
||||
|
|
|
|||
|
|
@ -224,6 +224,15 @@ static void *tracker_report_thread_entrance(void *arg)
|
|||
fdfs_server_sock_reset(pTrackerServer);
|
||||
tracker_index = pTrackerServer - g_tracker_group.servers;
|
||||
|
||||
#ifdef OS_LINUX
|
||||
{
|
||||
char thread_name[32];
|
||||
snprintf(thread_name, sizeof(thread_name),
|
||||
"tracker-cli[%d]", tracker_index);
|
||||
prctl(PR_SET_NAME, thread_name);
|
||||
}
|
||||
#endif
|
||||
|
||||
logDebug("file: "__FILE__", line: %d, "
|
||||
"report thread to tracker server %s:%u started",
|
||||
__LINE__, pTrackerServer->connections[0].ip_addr,
|
||||
|
|
|
|||
|
|
@ -21,14 +21,15 @@
|
|||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
#include "fdfs_define.h"
|
||||
#include "fastcommon/logger.h"
|
||||
#include "fdfs_global.h"
|
||||
#include "fastcommon/sockopt.h"
|
||||
#include "fastcommon/shared_func.h"
|
||||
#include "fastcommon/pthread_func.h"
|
||||
#include "fastcommon/sched_thread.h"
|
||||
#include "fastcommon/ini_file_reader.h"
|
||||
#include "fastcommon/fc_atomic.h"
|
||||
#include "fdfs_define.h"
|
||||
#include "fastcommon/logger.h"
|
||||
#include "fdfs_global.h"
|
||||
#include "tracker_types.h"
|
||||
#include "tracker_proto.h"
|
||||
#include "storage_global.h"
|
||||
|
|
@ -49,7 +50,7 @@
|
|||
|
||||
static int trunk_binlog_fd = -1;
|
||||
|
||||
int g_trunk_sync_thread_count = 0;
|
||||
volatile int g_trunk_sync_thread_count = 0;
|
||||
static pthread_mutex_t trunk_sync_thread_lock;
|
||||
static char *trunk_binlog_write_cache_buff = NULL;
|
||||
static int trunk_binlog_write_cache_len = 0;
|
||||
|
|
@ -59,6 +60,7 @@ typedef struct
|
|||
{
|
||||
bool running;
|
||||
bool reset_binlog_offset;
|
||||
int thread_index;
|
||||
const FDFSStorageBrief *pStorage;
|
||||
pthread_t tid;
|
||||
} TrunkSyncThreadInfo;
|
||||
|
|
@ -288,7 +290,7 @@ int kill_trunk_sync_threads()
|
|||
__LINE__, result, STRERROR(result));
|
||||
}
|
||||
|
||||
while (g_trunk_sync_thread_count > 0)
|
||||
while (FC_ATOMIC_GET(g_trunk_sync_thread_count) > 0)
|
||||
{
|
||||
usleep(50000);
|
||||
}
|
||||
|
|
@ -1961,7 +1963,7 @@ static void trunk_sync_thread_exit(TrunkSyncThreadInfo *thread_data,
|
|||
}
|
||||
|
||||
thread_data->running = false;
|
||||
g_trunk_sync_thread_count--;
|
||||
FC_ATOMIC_DEC(g_trunk_sync_thread_count);
|
||||
|
||||
if ((result=pthread_mutex_unlock(&trunk_sync_thread_lock)) != 0)
|
||||
{
|
||||
|
|
@ -2061,6 +2063,16 @@ static void *trunk_sync_thread_entrance(void* arg)
|
|||
time_t current_time;
|
||||
time_t last_keep_alive_time;
|
||||
|
||||
thread_data = (TrunkSyncThreadInfo *)arg;
|
||||
#ifdef OS_LINUX
|
||||
{
|
||||
char thread_name[32];
|
||||
snprintf(thread_name, sizeof(thread_name),
|
||||
"trunk-sync[%d]", thread_data->thread_index);
|
||||
prctl(PR_SET_NAME, thread_name);
|
||||
}
|
||||
#endif
|
||||
|
||||
memset(local_ip_addr, 0, sizeof(local_ip_addr));
|
||||
memset(&reader, 0, sizeof(reader));
|
||||
reader.binlog_fd = -1;
|
||||
|
|
@ -2068,9 +2080,7 @@ static void *trunk_sync_thread_entrance(void* arg)
|
|||
current_time = g_current_time;
|
||||
last_keep_alive_time = 0;
|
||||
|
||||
thread_data = (TrunkSyncThreadInfo *)arg;
|
||||
pStorage = thread_data->pStorage;
|
||||
|
||||
strcpy(storage_server.ip_addr, pStorage->ip_addr);
|
||||
storage_server.port = SF_G_INNER_PORT;
|
||||
storage_server.sock = -1;
|
||||
|
|
@ -2289,7 +2299,8 @@ TrunkSyncThreadInfo *trunk_sync_alloc_thread_data()
|
|||
int alloc_count;
|
||||
int bytes;
|
||||
|
||||
if (g_trunk_sync_thread_count + 1 < sync_thread_info_array.alloc_count)
|
||||
if (FC_ATOMIC_GET(g_trunk_sync_thread_count) + 1 <
|
||||
sync_thread_info_array.alloc_count)
|
||||
{
|
||||
info_end = sync_thread_info_array.thread_data +
|
||||
sync_thread_info_array.alloc_count;
|
||||
|
|
@ -2351,6 +2362,7 @@ TrunkSyncThreadInfo *trunk_sync_alloc_thread_data()
|
|||
}
|
||||
|
||||
memset(*thread_info, 0, sizeof(TrunkSyncThreadInfo));
|
||||
(*thread_info)->thread_index = thread_info - new_thread_data;
|
||||
}
|
||||
|
||||
old_thread_data = sync_thread_info_array.thread_data;
|
||||
|
|
@ -2420,7 +2432,7 @@ int trunk_sync_thread_start(const FDFSStorageBrief *pStorage)
|
|||
break;
|
||||
}
|
||||
|
||||
g_trunk_sync_thread_count++;
|
||||
FC_ATOMIC_INC(g_trunk_sync_thread_count);
|
||||
} while (0);
|
||||
|
||||
if ((lock_res=pthread_mutex_unlock(&trunk_sync_thread_lock)) != 0)
|
||||
|
|
@ -2440,7 +2452,7 @@ void trunk_waiting_sync_thread_exit()
|
|||
int saved_trunk_sync_thread_count;
|
||||
int count;
|
||||
|
||||
saved_trunk_sync_thread_count = g_trunk_sync_thread_count;
|
||||
saved_trunk_sync_thread_count = FC_ATOMIC_GET(g_trunk_sync_thread_count);
|
||||
if (saved_trunk_sync_thread_count > 0)
|
||||
{
|
||||
logInfo("file: "__FILE__", line: %d, "
|
||||
|
|
@ -2449,17 +2461,17 @@ void trunk_waiting_sync_thread_exit()
|
|||
}
|
||||
|
||||
count = 0;
|
||||
while (g_trunk_sync_thread_count > 0 && count < 60)
|
||||
while (FC_ATOMIC_GET(g_trunk_sync_thread_count) > 0 && count < 60)
|
||||
{
|
||||
usleep(50000);
|
||||
count++;
|
||||
}
|
||||
|
||||
if (g_trunk_sync_thread_count > 0)
|
||||
if (FC_ATOMIC_GET(g_trunk_sync_thread_count) > 0)
|
||||
{
|
||||
logWarning("file: "__FILE__", line: %d, "
|
||||
"kill %d trunk sync threads.",
|
||||
__LINE__, g_trunk_sync_thread_count);
|
||||
__LINE__, FC_ATOMIC_GET(g_trunk_sync_thread_count));
|
||||
kill_trunk_sync_threads();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ typedef struct
|
|||
FDFSTrunkFullInfo trunk;
|
||||
} TrunkBinLogRecord;
|
||||
|
||||
extern int g_trunk_sync_thread_count;
|
||||
extern volatile int g_trunk_sync_thread_count;
|
||||
|
||||
int trunk_sync_init();
|
||||
int trunk_sync_destroy();
|
||||
|
|
|
|||
|
|
@ -561,6 +561,12 @@ static void *relationship_thread_entrance(void* arg)
|
|||
int fail_count;
|
||||
int sleep_seconds;
|
||||
|
||||
#ifdef OS_LINUX
|
||||
{
|
||||
prctl(PR_SET_NAME, "relationship");
|
||||
}
|
||||
#endif
|
||||
|
||||
fail_count = 0;
|
||||
sleep_seconds = 1;
|
||||
while (SF_G_CONTINUE_FLAG)
|
||||
|
|
|
|||
Loading…
Reference in New Issue