From 4eddef574c4d96c7c314138dfe39b888fe965ce9 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 7 Jan 2022 09:55:23 +0000 Subject: [PATCH] more --- source/dnode/vnode/impl/src/vnodeMain.c | 2 +- source/dnode/vnode/tsdb/src/tsdbCommit.c | 69 +++++++++--------------- 2 files changed, 26 insertions(+), 45 deletions(-) diff --git a/source/dnode/vnode/impl/src/vnodeMain.c b/source/dnode/vnode/impl/src/vnodeMain.c index 88175646ae..30962e726e 100644 --- a/source/dnode/vnode/impl/src/vnodeMain.c +++ b/source/dnode/vnode/impl/src/vnodeMain.c @@ -137,7 +137,7 @@ static int vnodeOpenImpl(SVnode *pVnode) { } static void vnodeCloseImpl(SVnode *pVnode) { - // vnodeSyncCommit(pVnode); + vnodeSyncCommit(pVnode); if (pVnode) { vnodeCloseBufPool(pVnode); metaClose(pVnode->pMeta); diff --git a/source/dnode/vnode/tsdb/src/tsdbCommit.c b/source/dnode/vnode/tsdb/src/tsdbCommit.c index 0080e14181..91c7c84979 100644 --- a/source/dnode/vnode/tsdb/src/tsdbCommit.c +++ b/source/dnode/vnode/tsdb/src/tsdbCommit.c @@ -15,10 +15,14 @@ #include "tsdbDef.h" +#define TSDB_MAX_SUBBLOCKS 8 + +static void tsdbStartCommit(STsdb *pRepo); +static void tsdbEndCommit(STsdb *pTsdb, int eno); + int tsdbPrepareCommit(STsdb *pTsdb) { if (pTsdb->mem == NULL) return 0; - // tsem_wait(&(pTsdb->canCommit)); ASSERT(pTsdb->imem == NULL); pTsdb->imem = pTsdb->mem; @@ -26,9 +30,11 @@ int tsdbPrepareCommit(STsdb *pTsdb) { } int tsdbCommit(STsdb *pTsdb) { - // TODO - pTsdb->imem = NULL; - // tsem_post(&(pTsdb->canCommit)); + if (pTsdb->imem == NULL) return 0; + + tsdbStartCommit(pTsdb); + + tsdbEndCommit(pTsdb, TSDB_CODE_SUCCESS); return 0; } @@ -49,6 +55,21 @@ void tsdbGetRtnSnap(STsdb *pRepo, SRtn *pRtn) { pRtn->minFid, pRtn->midFid, pRtn->maxFid); } +static void tsdbStartCommit(STsdb *pRepo) { + STsdbMemTable *pMem = pRepo->imem; + + tsdbInfo("vgId:%d start to commit", REPO_ID(pRepo)); + + tsdbStartFSTxn(pRepo, 0, 0); +} + +static void tsdbEndCommit(STsdb *pTsdb, int eno) { + tsdbEndFSTxn(pTsdb); + tsdbFreeMemTable(pTsdb, pTsdb->imem); + pTsdb->imem = NULL; + tsdbInfo("vgId:%d commit over, %s", REPO_ID(pTsdb), (eno == TSDB_CODE_SUCCESS) ? "succeed" : "failed"); +} + #if 0 /* * Copyright (c) 2019 TAOS Data, Inc. @@ -68,14 +89,6 @@ void tsdbGetRtnSnap(STsdb *pRepo, SRtn *pRtn) { extern int32_t tsTsdbMetaCompactRatio; -#define TSDB_MAX_SUBBLOCKS 8 -static FORCE_INLINE int TSDB_KEY_FID(TSKEY key, int32_t days, int8_t precision) { - if (key < 0) { - return (int)((key + 1) / tsTickPerDay[precision] / days - 1); - } else { - return (int)((key / tsTickPerDay[precision] / days)); - } -} typedef struct { SRtn rtn; // retention snapshot @@ -709,38 +722,6 @@ static int tsdbCommitTSData(STsdbRepo *pRepo) { return 0; } -static void tsdbStartCommit(STsdbRepo *pRepo) { - SMemTable *pMem = pRepo->imem; - - ASSERT(pMem->numOfRows > 0 || listNEles(pMem->actList) > 0); - - tsdbInfo("vgId:%d start to commit! keyFirst %" PRId64 " keyLast %" PRId64 " numOfRows %" PRId64 " meta rows: %d", - REPO_ID(pRepo), pMem->keyFirst, pMem->keyLast, pMem->numOfRows, listNEles(pMem->actList)); - - tsdbStartFSTxn(pRepo, pMem->pointsAdd, pMem->storageAdd); - - pRepo->code = TSDB_CODE_SUCCESS; -} - -static void tsdbEndCommit(STsdbRepo *pRepo, int eno) { - if (eno != TSDB_CODE_SUCCESS) { - tsdbEndFSTxnWithError(REPO_FS(pRepo)); - } else { - tsdbEndFSTxn(pRepo); - } - - tsdbInfo("vgId:%d commit over, %s", REPO_ID(pRepo), (eno == TSDB_CODE_SUCCESS) ? "succeed" : "failed"); - - if (pRepo->appH.notifyStatus) pRepo->appH.notifyStatus(pRepo->appH.appH, TSDB_STATUS_COMMIT_OVER, eno); - - SMemTable *pIMem = pRepo->imem; - (void)tsdbLockRepo(pRepo); - pRepo->imem = NULL; - (void)tsdbUnlockRepo(pRepo); - tsdbUnRefMemTable(pRepo, pIMem); - tsem_post(&(pRepo->readyToCommit)); -} - #if 0 static bool tsdbHasDataToCommit(SCommitIter *iters, int nIters, TSKEY minKey, TSKEY maxKey) { for (int i = 0; i < nIters; i++) {