From d7219d1aaaa48d4c86337671d4505fdf59726832 Mon Sep 17 00:00:00 2001 From: lichuang Date: Fri, 4 Jun 2021 14:50:47 +0800 Subject: [PATCH] [TD-3963]sync config change msg and wait for the config applied --- src/tsdb/inc/tsdbMemTable.h | 2 +- src/tsdb/src/tsdbMain.c | 4 ++-- src/tsdb/src/tsdbMemTable.c | 11 ++++++++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/tsdb/inc/tsdbMemTable.h b/src/tsdb/inc/tsdbMemTable.h index 868a10d361..babb7024b2 100644 --- a/src/tsdb/inc/tsdbMemTable.h +++ b/src/tsdb/inc/tsdbMemTable.h @@ -66,7 +66,7 @@ int tsdbTakeMemSnapshot(STsdbRepo* pRepo, SMemSnapshot* pSnapshot, SArray* pAT void tsdbUnTakeMemSnapShot(STsdbRepo* pRepo, SMemSnapshot* pSnapshot); void* tsdbAllocBytes(STsdbRepo* pRepo, int bytes); int tsdbAsyncCommit(STsdbRepo* pRepo); -int tsdbAsyncCommitConfig(STsdbRepo* pRepo); +int tsdbSyncCommitConfig(STsdbRepo* pRepo); int tsdbLoadDataFromCache(STable* pTable, SSkipListIterator* pIter, TSKEY maxKey, int maxRowsToRead, SDataCols* pCols, TKEY* filterKeys, int nFilterKeys, bool keepDup, SMergeInfo* pMergeInfo); void* tsdbCommitData(STsdbRepo* pRepo); diff --git a/src/tsdb/src/tsdbMain.c b/src/tsdb/src/tsdbMain.c index 5a4c785f02..ce20bf1821 100644 --- a/src/tsdb/src/tsdbMain.c +++ b/src/tsdb/src/tsdbMain.c @@ -270,8 +270,8 @@ int32_t tsdbConfigRepo(STsdbRepo *repo, STsdbCfg *pCfg) { pthread_mutex_unlock(&repo->save_mutex); - // schedule a commit msg then the new config will be applied immediatly - tsdbAsyncCommitConfig(repo); + // schedule a commit msg and wait for the new config applied + tsdbSyncCommitConfig(repo); return 0; #if 0 diff --git a/src/tsdb/src/tsdbMemTable.c b/src/tsdb/src/tsdbMemTable.c index ec773dbb38..9d8b1ca7f2 100644 --- a/src/tsdb/src/tsdbMemTable.c +++ b/src/tsdb/src/tsdbMemTable.c @@ -271,7 +271,7 @@ void *tsdbAllocBytes(STsdbRepo *pRepo, int bytes) { return ptr; } -int tsdbAsyncCommitConfig(STsdbRepo* pRepo) { +int tsdbSyncCommitConfig(STsdbRepo* pRepo) { ASSERT(pRepo->config_changed == true); tsem_wait(&(pRepo->readyToCommit)); @@ -283,6 +283,15 @@ int tsdbAsyncCommitConfig(STsdbRepo* pRepo) { tsdbScheduleCommit(pRepo, COMMIT_CONFIG_REQ); if (tsdbUnlockRepo(pRepo) < 0) return -1; + tsem_wait(&(pRepo->readyToCommit)); + tsem_post(&(pRepo->readyToCommit)); + + if (pRepo->code != TSDB_CODE_SUCCESS) { + terrno = pRepo->code; + return -1; + } + + terrno = TSDB_CODE_SUCCESS; return 0; } -- GitLab