diff --git a/src/vnode/tsdb/src/tsdbMain.c b/src/vnode/tsdb/src/tsdbMain.c index c45a8407cc1216f17bd74a57ce3e80f31ccf5464..0a681a82375c7e6741e040c3873b8c17c15b0fd6 100644 --- a/src/vnode/tsdb/src/tsdbMain.c +++ b/src/vnode/tsdb/src/tsdbMain.c @@ -287,8 +287,29 @@ int32_t tsdbCloseRepo(tsdb_repo_t *repo) { if (pRepo == NULL) return 0; pRepo->state = TSDB_REPO_STATE_CLOSED; + tsdbLockRepo(repo); + if (pRepo->commit) { + tsdbUnLockRepo(repo); + return -1; + } + pRepo->commit = 1; + // Loop to move pData to iData + for (int i = 0; i < pRepo->config.maxTables; i++) { + STable *pTable = pRepo->tsdbMeta->tables[i]; + if (pTable != NULL && pTable->mem != NULL) { + pTable->imem = pTable->mem; + pTable->mem = NULL; + } + } + // TODO: Loop to move mem to imem + pRepo->tsdbCache->imem = pRepo->tsdbCache->mem; + pRepo->tsdbCache->mem = NULL; + pRepo->tsdbCache->curBlock = NULL; + tsdbUnLockRepo(repo); + + tsdbCommitData((void *)repo); - tsdbFlushCache(pRepo); + tsdbCloseFileH(pRepo->tsdbFileH); tsdbFreeMeta(pRepo->tsdbMeta); diff --git a/src/vnode/tsdb/tests/tsdbTests.cpp b/src/vnode/tsdb/tests/tsdbTests.cpp index bc6532984fddd74934c9f87a9e5f1086f08faef3..73caeb6700ffa726c2a935eb473c3ff239c3b613 100644 --- a/src/vnode/tsdb/tests/tsdbTests.cpp +++ b/src/vnode/tsdb/tests/tsdbTests.cpp @@ -78,7 +78,7 @@ TEST(TsdbTest, createRepo) { tsdbCreateTable(pRepo, &tCfg); // // 3. Loop to write some simple data - int nRows = 10000000; + int nRows = 1000000; int rowsPerSubmit = 10; int64_t start_time = 1584081000000; @@ -87,6 +87,7 @@ TEST(TsdbTest, createRepo) { double stime = getCurTime(); for (int k = 0; k < nRows/rowsPerSubmit; k++) { + memset((void *)pMsg, 0, sizeof(SSubmitMsg)); SSubmitBlk *pBlock = pMsg->blocks; pBlock->uid = 987607499877672L; pBlock->tid = 0; @@ -108,6 +109,9 @@ TEST(TsdbTest, createRepo) { } pBlock->len += dataRowLen(row); } + pMsg->length = pMsg->length + sizeof(SSubmitBlk) + pBlock->len; + pMsg->numOfBlocks = 1; + pBlock->len = htonl(pBlock->len); pBlock->numOfRows = htonl(pBlock->numOfRows); pBlock->uid = htobe64(pBlock->uid); @@ -116,7 +120,6 @@ TEST(TsdbTest, createRepo) { pBlock->sversion = htonl(pBlock->sversion); pBlock->padding = htonl(pBlock->padding); - pMsg->length = pMsg->length + sizeof(SSubmitBlk) + pBlock->len; pMsg->length = htonl(pMsg->length); pMsg->numOfBlocks = htonl(pMsg->numOfBlocks); pMsg->compressed = htonl(pMsg->numOfBlocks); @@ -128,9 +131,7 @@ TEST(TsdbTest, createRepo) { printf("Spent %f seconds to write %d records\n", etime - stime, nRows); - - - // tsdbTriggerCommit(pRepo); + tsdbCloseRepo(pRepo); }