From 86eef2069d0a9c06755f4503f0add3d4c60770d1 Mon Sep 17 00:00:00 2001 From: yuqing Date: Sun, 24 Aug 2014 11:10:16 +0800 Subject: [PATCH] tracker server adjust storage status to newer by anyway --- HISTORY | 6 +++++- storage/tracker_client_thread.c | 21 +++++++++++++++++++++ tracker/tracker_mem.c | 18 +++++++++++++++--- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/HISTORY b/HISTORY index 54de29f..7373a01 100644 --- a/HISTORY +++ b/HISTORY @@ -1,7 +1,11 @@ -Version 5.04 2014-08-19 +Version 5.04 2014-08-24 * add fastdfs.spec for build RPM on Linux * depend on libfastcommon + * in multi tracker servers case, when receive higher status like + online / active and the storage status is wait_sync or syncing, + the tracker adjust storage status to newer, and the storage rejoin + to the tracker server Version 5.03 2014-08-10 * network send and recv retry when error EINTR happen diff --git a/storage/tracker_client_thread.c b/storage/tracker_client_thread.c index 1c8078a..503e507 100644 --- a/storage/tracker_client_thread.c +++ b/storage/tracker_client_thread.c @@ -44,6 +44,7 @@ static pthread_mutex_t reporter_thread_lock; static pthread_t *report_tids = NULL; static int *src_storage_status = NULL; //returned by tracker server static signed char *my_report_status = NULL; //returned by tracker server +static bool need_rejoin_tracker = false; static int tracker_heart_beat(ConnectionInfo *pTrackerServer, \ int *pstat_chg_sync_count, bool *bServerPortChanged); @@ -540,6 +541,11 @@ static void *tracker_report_thread_entrance(void *arg) } } + if (need_rejoin_tracker) + { + need_rejoin_tracker = false; + break; + } sleep(1); } @@ -844,6 +850,21 @@ static int tracker_merge_servers(ConnectionInfo *pTrackerServer, \ FDFS_STORAGE_STATUS_SYNCING)) && \ ((*ppFound)->server.status > pServer->status)) { + *(pServer->ip_addr + IP_ADDRESS_SIZE - 1) = '\0'; + if (is_local_host_ip(pServer->ip_addr) && \ + buff2int(pServer->port) == g_server_port) + { + need_rejoin_tracker = true; + logWarning("file: "__FILE__", line: %d, " \ + "tracker response status: %d, " \ + "local status: %d, need rejoin " \ + "tracker server: %s:%d", \ + __LINE__, pServer->status, \ + (*ppFound)->server.status, \ + pTrackerServer->ip_addr, + pTrackerServer->port); + } + memcpy(pDiffServer++, &((*ppFound)->server), \ sizeof(FDFSStorageBrief)); } diff --git a/tracker/tracker_mem.c b/tracker/tracker_mem.c index b447a19..dbbe1ea 100644 --- a/tracker/tracker_mem.c +++ b/tracker/tracker_mem.c @@ -4690,9 +4690,7 @@ int tracker_mem_sync_storages(FDFSGroupInfo *pGroup, \ { pServer->id[FDFS_STORAGE_ID_MAX_SIZE - 1] = '\0'; pServer->ip_addr[IP_ADDRESS_SIZE - 1] = '\0'; - if (pServer->status == FDFS_STORAGE_STATUS_NONE \ - || pServer->status == FDFS_STORAGE_STATUS_ACTIVE \ - || pServer->status == FDFS_STORAGE_STATUS_ONLINE) + if (pServer->status == FDFS_STORAGE_STATUS_NONE) { continue; } @@ -4708,6 +4706,8 @@ int tracker_mem_sync_storages(FDFSGroupInfo *pGroup, \ tracker_mem_cmp_by_storage_id)) != NULL) { if ((*ppFound)->status == pServer->status \ + || (*ppFound)->status == \ + FDFS_STORAGE_STATUS_INIT \ || (*ppFound)->status == \ FDFS_STORAGE_STATUS_ONLINE \ || (*ppFound)->status == \ @@ -4718,6 +4718,13 @@ int tracker_mem_sync_storages(FDFSGroupInfo *pGroup, \ continue; } + logWarning("file: "__FILE__", line: %d, " + "storage server: %s:%d, dest status: %d, " + "my status: %d, should change my status!", + __LINE__, (*ppFound)->ip_addr, + (*ppFound)->storage_port, + pServer->status, (*ppFound)->status); + if (pServer->status == \ FDFS_STORAGE_STATUS_DELETED || pServer->status == \ @@ -4739,6 +4746,11 @@ int tracker_mem_sync_storages(FDFSGroupInfo *pGroup, \ { //ignore deleted storage server } + else if (pServer->status == FDFS_STORAGE_STATUS_ACTIVE + || pServer->status == FDFS_STORAGE_STATUS_ONLINE) + { + //ignore online or active storage server + } else { FDFSStorageDetail *pStorageServer;