diff --git a/storage/storage_disk_recovery.c b/storage/storage_disk_recovery.c index a4e73ec..2345ef3 100644 --- a/storage/storage_disk_recovery.c +++ b/storage/storage_disk_recovery.c @@ -23,7 +23,6 @@ #include #include "fdfs_define.h" #include "fastcommon/logger.h" -#include "fastcommon/fc_list.h" #include "fastcommon/sockopt.h" #include "fastcommon/avl_tree.h" #include "fastcommon/shared_func.h" @@ -45,9 +44,9 @@ typedef struct { } FDFSTrunkFileIdInfo; typedef struct recovery_thread_data { - struct fc_list_head link; int thread_index; //-1 for global int result; + volatile int alive; bool done; const char *base_path; pthread_t tid; @@ -949,6 +948,8 @@ static void *storage_disk_recovery_restore_entrance(void *arg) ConnectionInfo srcStorage; pThreadData = (RecoveryThreadData *)arg; + pThreadData->tid = pthread_self(); + __sync_add_and_fetch(&pThreadData->alive, 1); __sync_add_and_fetch(¤t_recovery_thread_count, 1); do @@ -979,6 +980,8 @@ static void *storage_disk_recovery_restore_entrance(void *arg) } while (0); __sync_sub_and_fetch(¤t_recovery_thread_count, 1); + __sync_sub_and_fetch(&pThreadData->alive, 1); + sleep(1); return NULL; } @@ -1262,6 +1265,7 @@ static int storage_disk_recovery_do_restore(const char *pBasePath) int thread_count; int bytes; int i; + int k; pthread_t *recovery_tids; void **args; RecoveryThreadData *thread_data; @@ -1305,6 +1309,7 @@ static int storage_disk_recovery_do_restore(const char *pBasePath) thread_data[i].thread_index = i; thread_data[i].result = EINTR; thread_data[i].done = false; + thread_data[i].alive = 0; args[i] = thread_data + i; } @@ -1324,7 +1329,7 @@ static int storage_disk_recovery_do_restore(const char *pBasePath) if (__sync_fetch_and_add(¤t_recovery_thread_count, 0) > 0) { - for (i=0; i<10; i++) + for (i=0; i<30; i++) { if ((thread_count=__sync_fetch_and_add( ¤t_recovery_thread_count, 0)) == 0) @@ -1332,6 +1337,14 @@ static int storage_disk_recovery_do_restore(const char *pBasePath) break; } + for (k=0; k 0) + { + pthread_kill(thread_data[k].tid, SIGINT); + } + } + logInfo("file: "__FILE__", line: %d, " "waiting for recovery threads exit, " "waiting count: %d, current thread count: %d", @@ -1340,6 +1353,7 @@ static int storage_disk_recovery_do_restore(const char *pBasePath) } } + sleep(1); //wait for thread exit free(thread_data); free(args); free(recovery_tids); @@ -1351,7 +1365,7 @@ static int storage_disk_recovery_do_restore(const char *pBasePath) while (g_continue_flag) { - if (storage_report_storage_status(g_my_server_id_str, \ + if (storage_report_storage_status(g_my_server_id_str, g_tracker_client_ip.ips[0].address, saved_storage_status) == 0) {