From 1b39147496546e3cb1909936d71954632498d725 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 1 Aug 2023 11:36:37 +0800 Subject: [PATCH] more refact --- source/dnode/vnode/src/tsdb/tsdbRetention.c | 32 +++++++++++++-------- source/dnode/vnode/src/vnd/vnodeRetention.c | 23 ++------------- 2 files changed, 22 insertions(+), 33 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbRetention.c b/source/dnode/vnode/src/tsdb/tsdbRetention.c index 043de33728..3af9d2a07a 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRetention.c +++ b/source/dnode/vnode/src/tsdb/tsdbRetention.c @@ -125,6 +125,7 @@ _exit: typedef struct { STsdb *tsdb; + int32_t sync; int64_t now; } SRtnArg; @@ -254,23 +255,30 @@ _exit: return code; } -int32_t tsdbAsyncRetention(STsdb *tsdb, int64_t now, int64_t *taskid) { +static void tsdbFreeRtnArg(void *arg) { + SRtnArg *rArg = (SRtnArg *)arg; + if (rArg->sync) { + tsem_post(&rArg->tsdb->pVnode->canCommit); + } + taosMemoryFree(arg); +} + +int32_t tsdbRetention(STsdb *tsdb, int64_t now, int32_t sync) { SRtnArg *arg = taosMemoryMalloc(sizeof(*arg)); if (arg == NULL) return TSDB_CODE_OUT_OF_MEMORY; - arg->tsdb = tsdb; + arg->sync = sync; arg->now = now; - int32_t code = tsdbFSScheduleBgTask(tsdb->pFS, TSDB_BG_TASK_RETENTION, tsdbDoRetention2, taosMemoryFree, arg, taskid); - if (code) taosMemoryFree(arg); - return code; -} + if (sync) { + tsem_wait(&tsdb->pVnode->canCommit); + } -int32_t tsdbSyncRetention(STsdb *tsdb, int64_t now) { int64_t taskid; - - int32_t code = tsdbAsyncRetention(tsdb, now, &taskid); - if (code) return code; - - return tsdbFSWaitBgTask(tsdb->pFS, taskid); + int32_t code = + tsdbFSScheduleBgTask(tsdb->pFS, TSDB_BG_TASK_RETENTION, tsdbDoRetention2, tsdbFreeRtnArg, arg, &taskid); + if (code) { + tsdbFreeRtnArg(arg); + } + return code; } \ No newline at end of file diff --git a/source/dnode/vnode/src/vnd/vnodeRetention.c b/source/dnode/vnode/src/vnd/vnodeRetention.c index 7af1f8e28f..f3344d1d7d 100644 --- a/source/dnode/vnode/src/vnd/vnodeRetention.c +++ b/source/dnode/vnode/src/vnd/vnodeRetention.c @@ -15,27 +15,8 @@ #include "vnd.h" -extern int32_t tsdbSyncRetention(STsdb *tsdb, int64_t now); -extern int32_t tsdbAsyncRetention(STsdb *tsdb, int64_t now, int64_t *taskid); +extern int32_t tsdbRetention(STsdb *tsdb, int64_t now, int32_t sync); int32_t vnodeDoRetention(SVnode *pVnode, int64_t now) { - int32_t code; - int32_t lino; - - if (pVnode->config.sttTrigger == 1) { - tsem_wait(&pVnode->canCommit); - code = tsdbSyncRetention(pVnode->pTsdb, now); - TSDB_CHECK_CODE(code, lino, _exit); - - // code = smaDoRetention(pVnode->pSma, now); - // TSDB_CHECK_CODE(code, lino, _exit); - tsem_post(&pVnode->canCommit); - } else { - int64_t taskid; - code = tsdbAsyncRetention(pVnode->pTsdb, now, &taskid); - TSDB_CHECK_CODE(code, lino, _exit); - } - -_exit: - return code; + return tsdbRetention(pVnode->pTsdb, now, pVnode->config.sttTrigger == 1); } \ No newline at end of file -- GitLab