TDengine/source/dnode/vnode/src/tsdb/dev/tsdbCommit.c

474 lines
13 KiB
C
Raw Normal View History

2023-03-20 02:59:16 +00:00
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2023-05-10 06:54:13 +00:00
#include "inc/tsdbCommit.h"
2023-03-20 02:59:16 +00:00
2023-03-23 05:15:14 +00:00
// extern dependencies
2023-03-22 06:41:16 +00:00
typedef struct {
STsdb *pTsdb;
2023-05-10 06:54:13 +00:00
2023-03-22 06:41:16 +00:00
// config
int32_t minutes;
int8_t precision;
int32_t minRow;
int32_t maxRow;
int8_t cmprAlg;
int8_t sttTrigger;
2023-05-10 06:54:13 +00:00
2023-05-22 08:28:31 +00:00
SArray *aTbDataP; // SArray<STbData *>
TFileOpArray opArray;
int64_t eid; // edit id
2023-05-10 06:54:13 +00:00
2023-03-22 06:41:16 +00:00
// context
2023-05-23 03:35:44 +00:00
TSKEY nextKey;
int32_t fid;
int32_t expLevel;
TSKEY minKey;
TSKEY maxKey;
STFileSet *fset;
2023-05-10 06:54:13 +00:00
2023-03-23 05:15:14 +00:00
// writer
2023-04-23 09:37:12 +00:00
SSttFileWriter *pWriter;
2023-03-22 06:41:16 +00:00
} SCommitter;
2023-03-20 02:59:16 +00:00
2023-05-18 07:06:21 +00:00
static int32_t open_writer_with_new_stt(SCommitter *pCommitter) {
2023-04-11 06:22:36 +00:00
int32_t code = 0;
2023-05-11 10:16:55 +00:00
int32_t lino = 0;
STsdb *pTsdb = pCommitter->pTsdb;
2023-05-18 07:06:21 +00:00
SVnode *pVnode = pTsdb->pVnode;
int32_t vid = TD_VID(pVnode);
SSttFileWriterConfig config;
SDiskID did;
if (tfsAllocDisk(pVnode->pTfs, pCommitter->expLevel, &did) < 0) {
code = TSDB_CODE_FS_NO_VALID_DISK;
TSDB_CHECK_CODE(code, lino, _exit);
}
config.pTsdb = pTsdb;
config.maxRow = pCommitter->maxRow;
config.szPage = pVnode->config.tsdbPageSize;
config.cmprAlg = pCommitter->cmprAlg;
config.pSkmTb = NULL;
config.pSkmRow = NULL;
config.aBuf = NULL;
config.file.type = TSDB_FTYPE_STT;
config.file.did = did;
config.file.fid = pCommitter->fid;
config.file.cid = pCommitter->eid;
config.file.size = 0;
config.file.stt.level = 0;
config.file.stt.nseg = 0;
code = tsdbSttFWriterOpen(&config, &pCommitter->pWriter);
TSDB_CHECK_CODE(code, lino, _exit);
_exit:
if (code) {
tsdbError("vgId:%d %s failed at line %d since %s", vid, __func__, lino, tstrerror(code));
} else {
tsdbDebug("vgId:%d %s success", vid, __func__);
}
return code;
}
static int32_t open_writer_with_exist_stt(SCommitter *pCommitter, const STFile *pFile) {
int32_t code = 0;
int32_t lino = 0;
STsdb *pTsdb = pCommitter->pTsdb;
SVnode *pVnode = pTsdb->pVnode;
int32_t vid = TD_VID(pVnode);
2023-04-11 06:22:36 +00:00
2023-05-11 10:16:55 +00:00
SSttFileWriterConfig config = {
2023-05-18 07:06:21 +00:00
//
.pTsdb = pTsdb,
2023-03-27 11:12:25 +00:00
.maxRow = pCommitter->maxRow,
2023-05-18 07:06:21 +00:00
.szPage = pVnode->config.tsdbPageSize,
2023-03-27 11:12:25 +00:00
.cmprAlg = pCommitter->cmprAlg,
2023-04-11 03:00:35 +00:00
.pSkmTb = NULL,
.pSkmRow = NULL,
2023-03-27 11:12:25 +00:00
.aBuf = NULL,
2023-05-18 07:06:21 +00:00
.file = *pFile //
2023-03-27 11:12:25 +00:00
};
2023-03-23 08:10:08 +00:00
2023-05-11 10:16:55 +00:00
code = tsdbSttFWriterOpen(&config, &pCommitter->pWriter);
2023-03-23 08:10:08 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
_exit:
if (code) {
2023-05-18 07:06:21 +00:00
tsdbError("vgId:%d %s failed at line %d since %s", vid, __func__, lino, tstrerror(code));
} else {
tsdbDebug("vgId:%d %s success", vid, __func__);
2023-03-23 08:10:08 +00:00
}
2023-03-23 05:15:14 +00:00
return code;
}
2023-05-18 07:06:21 +00:00
static int32_t open_committer_writer(SCommitter *pCommitter) {
if (!pCommitter->fset) {
return open_writer_with_new_stt(pCommitter);
}
2023-05-19 07:16:01 +00:00
const SSttLvl *lvl0 = tsdbTFileSetGetLvl(pCommitter->fset, 0);
2023-05-18 07:06:21 +00:00
if (lvl0 == NULL) {
return open_writer_with_new_stt(pCommitter);
}
2023-05-23 03:45:33 +00:00
ASSERT(TARRAY2_SIZE(&lvl0->farr) > 0);
STFileObj *fobj = TARRAY2_LAST(&lvl0->farr);
if (fobj->f.stt.nseg >= pCommitter->sttTrigger) {
2023-05-18 07:06:21 +00:00
return open_writer_with_new_stt(pCommitter);
} else {
2023-05-23 03:45:33 +00:00
return open_writer_with_exist_stt(pCommitter, &fobj->f);
2023-05-18 07:06:21 +00:00
}
}
2023-03-23 05:15:14 +00:00
2023-05-26 06:49:50 +00:00
static int32_t tsdbCommitWriteTSData(SCommitter *pCommitter, SRowInfo *pRowInfo) {
2023-03-23 05:15:14 +00:00
int32_t code = 0;
2023-05-11 10:16:55 +00:00
int32_t lino = 0;
int32_t vid = TD_VID(pCommitter->pTsdb->pVnode);
2023-03-23 05:15:14 +00:00
if (pCommitter->pWriter == NULL) {
2023-03-30 08:06:07 +00:00
code = open_committer_writer(pCommitter);
2023-03-23 05:15:14 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
}
2023-05-26 06:49:50 +00:00
code = tsdbSttFWriteTSData(pCommitter->pWriter, pRowInfo);
2023-03-23 05:15:14 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
_exit:
if (code) {
2023-05-11 10:16:55 +00:00
tsdbError("vgId:%d failed at line %d since %s", vid, lino, tstrerror(code));
2023-03-23 05:15:14 +00:00
}
2023-03-22 06:41:16 +00:00
return 0;
2023-03-20 02:59:16 +00:00
}
2023-03-23 05:15:14 +00:00
static int32_t tsdbCommitWriteDelData(SCommitter *pCommitter, int64_t suid, int64_t uid, int64_t version, int64_t sKey,
int64_t eKey) {
int32_t code = 0;
// TODO
return code;
}
2023-03-27 08:30:22 +00:00
static int32_t commit_timeseries_data(SCommitter *pCommitter) {
2023-05-11 10:16:55 +00:00
int32_t code = 0;
int32_t lino = 0;
2023-03-23 05:15:14 +00:00
int64_t nRow = 0;
2023-05-11 10:16:55 +00:00
STsdb *pTsdb = pCommitter->pTsdb;
int32_t vid = TD_VID(pTsdb->pVnode);
SMemTable *pMem = pTsdb->imem;
2023-03-22 11:24:40 +00:00
2023-05-11 10:16:55 +00:00
if (pMem->nRow == 0) goto _exit;
2023-03-22 11:24:40 +00:00
2023-03-23 05:15:14 +00:00
TSDBKEY from = {.ts = pCommitter->minKey, .version = VERSION_MIN};
2023-03-22 11:24:40 +00:00
for (int32_t iTbData = 0; iTbData < taosArrayGetSize(pCommitter->aTbDataP); iTbData++) {
STbDataIter iter;
2023-03-23 05:15:14 +00:00
STbData *pTbData = (STbData *)taosArrayGetP(pCommitter->aTbDataP, iTbData);
2023-05-26 06:49:50 +00:00
SRowInfo rowInfo = {.suid = pTbData->suid, .uid = pTbData->uid};
2023-03-23 05:15:14 +00:00
2023-03-22 11:24:40 +00:00
tsdbTbDataIterOpen(pTbData, &from, 0, &iter);
for (TSDBROW *pRow; (pRow = tsdbTbDataIterGet(&iter)) != NULL; tsdbTbDataIterNext(&iter)) {
TSDBKEY rowKey = TSDBROW_KEY(pRow);
if (rowKey.ts > pCommitter->maxKey) {
2023-03-23 05:15:14 +00:00
pCommitter->nextKey = TMIN(pCommitter->nextKey, rowKey.ts);
2023-03-22 11:24:40 +00:00
break;
}
2023-05-26 06:49:50 +00:00
rowInfo.row = *pRow;
code = tsdbCommitWriteTSData(pCommitter, &rowInfo);
2023-03-22 11:24:40 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
2023-04-11 03:00:35 +00:00
nRow++;
2023-03-22 11:24:40 +00:00
}
}
_exit:
if (code) {
2023-05-11 10:16:55 +00:00
tsdbError("vgId:%d %s failed at line %d since %s", vid, __func__, lino, tstrerror(code));
2023-03-22 11:24:40 +00:00
} else {
2023-05-11 10:16:55 +00:00
tsdbDebug("vgId:%d %s done, fid:%d nRow:%" PRId64, vid, __func__, pCommitter->fid, nRow);
2023-03-22 11:24:40 +00:00
}
return code;
}
2023-03-27 08:30:22 +00:00
static int32_t commit_delete_data(SCommitter *pCommitter) {
2023-03-22 11:24:40 +00:00
int32_t code = 0;
int32_t lino;
2023-05-11 10:16:55 +00:00
return 0;
2023-04-11 03:00:35 +00:00
ASSERTS(0, "TODO: Not implemented yet");
2023-03-23 05:26:57 +00:00
2023-03-23 05:15:14 +00:00
int64_t nDel = 0;
2023-03-22 11:24:40 +00:00
SMemTable *pMem = pCommitter->pTsdb->imem;
2023-03-23 05:15:14 +00:00
if (pMem->nDel == 0) { // no del data
goto _exit;
}
2023-03-22 11:24:40 +00:00
for (int32_t iTbData = 0; iTbData < taosArrayGetSize(pCommitter->aTbDataP); iTbData++) {
STbData *pTbData = (STbData *)taosArrayGetP(pCommitter->aTbDataP, iTbData);
for (SDelData *pDelData = pTbData->pHead; pDelData; pDelData = pDelData->pNext) {
2023-03-23 05:15:14 +00:00
if (pDelData->eKey < pCommitter->minKey) continue;
if (pDelData->sKey > pCommitter->maxKey) {
pCommitter->nextKey = TMIN(pCommitter->nextKey, pDelData->sKey);
continue;
}
2023-03-22 11:24:40 +00:00
2023-03-23 05:15:14 +00:00
code = tsdbCommitWriteDelData(pCommitter, pTbData->suid, pTbData->uid, pDelData->version,
pDelData->sKey /* TODO */, pDelData->eKey /* TODO */);
2023-03-22 11:24:40 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
}
}
_exit:
if (code) {
tsdbError("vgId:%d failed at line %d since %s", TD_VID(pCommitter->pTsdb->pVnode), lino, tstrerror(code));
} else {
tsdbDebug("vgId:%d %s done, fid:%d nDel:%" PRId64, TD_VID(pCommitter->pTsdb->pVnode), __func__, pCommitter->fid,
pMem->nDel);
}
return code;
}
2023-05-11 10:16:55 +00:00
static int32_t commit_fset_start(SCommitter *pCommitter) {
STsdb *pTsdb = pCommitter->pTsdb;
int32_t vid = TD_VID(pTsdb->pVnode);
2023-03-22 11:24:40 +00:00
pCommitter->fid = tsdbKeyFid(pCommitter->nextKey, pCommitter->minutes, pCommitter->precision);
tsdbFidKeyRange(pCommitter->fid, pCommitter->minutes, pCommitter->precision, &pCommitter->minKey,
&pCommitter->maxKey);
2023-05-11 10:16:55 +00:00
pCommitter->expLevel = tsdbFidLevel(pCommitter->fid, &pTsdb->keepCfg, taosGetTimestampSec());
2023-03-23 05:26:57 +00:00
pCommitter->nextKey = TSKEY_MAX;
2023-03-22 11:24:40 +00:00
2023-05-18 07:06:21 +00:00
tsdbFSGetFSet(pTsdb->pFS, pCommitter->fid, &pCommitter->fset);
2023-04-11 06:22:36 +00:00
2023-05-11 10:16:55 +00:00
tsdbDebug("vgId:%d %s done, fid:%d minKey:%" PRId64 " maxKey:%" PRId64 " expLevel:%d", vid, __func__, pCommitter->fid,
pCommitter->minKey, pCommitter->maxKey, pCommitter->expLevel);
2023-03-23 08:10:08 +00:00
return 0;
2023-03-20 02:59:16 +00:00
}
2023-05-11 10:16:55 +00:00
static int32_t commit_fset_end(SCommitter *pCommitter) {
2023-03-22 11:24:40 +00:00
int32_t code = 0;
2023-05-11 10:16:55 +00:00
int32_t lino = 0;
int32_t vid = TD_VID(pCommitter->pTsdb->pVnode);
2023-03-22 11:24:40 +00:00
2023-04-11 06:22:36 +00:00
if (pCommitter->pWriter == NULL) return 0;
2023-05-22 10:39:10 +00:00
STFileOp op;
code = tsdbSttFWriterClose(&pCommitter->pWriter, 0, &op);
TSDB_CHECK_CODE(code, lino, _exit);
2023-04-11 06:22:36 +00:00
2023-05-22 10:39:10 +00:00
code = TARRAY2_APPEND(&pCommitter->opArray, op);
TSDB_CHECK_CODE(code, lino, _exit);
2023-03-22 11:24:40 +00:00
_exit:
if (code) {
2023-05-11 10:16:55 +00:00
tsdbError("vgId:%d failed at line %d since %s", vid, lino, tstrerror(code));
2023-04-11 06:22:36 +00:00
} else {
2023-05-11 10:16:55 +00:00
tsdbDebug("vgId:%d %s done, fid:%d", vid, __func__, pCommitter->fid);
2023-03-22 11:24:40 +00:00
}
return code;
}
2023-05-11 10:16:55 +00:00
static int32_t commit_fset(SCommitter *pCommitter) {
2023-03-20 02:59:16 +00:00
int32_t code = 0;
int32_t lino = 0;
2023-05-11 10:16:55 +00:00
int32_t vid = TD_VID(pCommitter->pTsdb->pVnode);
2023-03-20 02:59:16 +00:00
2023-03-22 11:24:40 +00:00
// fset commit start
2023-05-11 10:16:55 +00:00
code = commit_fset_start(pCommitter);
2023-03-22 11:24:40 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
2023-03-20 02:59:16 +00:00
2023-03-22 06:41:16 +00:00
// commit fset
2023-03-27 08:30:22 +00:00
code = commit_timeseries_data(pCommitter);
2023-03-20 02:59:16 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
2023-03-27 08:30:22 +00:00
code = commit_delete_data(pCommitter);
2023-03-22 11:24:40 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
// fset commit end
2023-05-11 10:16:55 +00:00
code = commit_fset_end(pCommitter);
2023-03-22 11:24:40 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
2023-03-20 02:59:16 +00:00
_exit:
if (code) {
2023-05-11 10:16:55 +00:00
tsdbError("vgId:%d %s failed at line %d since %s", vid, __func__, lino, tstrerror(code));
} else {
tsdbDebug("vgId:%d %s done", vid, __func__);
2023-03-20 02:59:16 +00:00
}
return code;
}
2023-03-27 08:30:22 +00:00
static int32_t open_committer(STsdb *pTsdb, SCommitInfo *pInfo, SCommitter *pCommitter) {
2023-03-20 02:59:16 +00:00
int32_t code = 0;
2023-03-23 08:10:08 +00:00
int32_t lino;
2023-03-20 02:59:16 +00:00
2023-03-23 08:10:08 +00:00
// set config
2023-03-22 06:41:16 +00:00
memset(pCommitter, 0, sizeof(SCommitter));
pCommitter->pTsdb = pTsdb;
2023-03-23 08:10:08 +00:00
pCommitter->minutes = pTsdb->keepCfg.days;
pCommitter->precision = pTsdb->keepCfg.precision;
pCommitter->minRow = pInfo->info.config.tsdbCfg.minRows;
pCommitter->maxRow = pInfo->info.config.tsdbCfg.maxRows;
pCommitter->cmprAlg = pInfo->info.config.tsdbCfg.compression;
2023-05-24 01:30:14 +00:00
pCommitter->sttTrigger = pInfo->info.config.sttTrigger;
2023-03-23 08:10:08 +00:00
pCommitter->aTbDataP = tsdbMemTableGetTbDataArray(pTsdb->imem);
2023-05-22 08:28:31 +00:00
if (pCommitter->aTbDataP == NULL) {
2023-05-10 06:54:13 +00:00
taosArrayDestroy(pCommitter->aTbDataP);
TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
2023-04-06 06:27:18 +00:00
}
2023-05-22 08:28:31 +00:00
TARRAY2_INIT(&pCommitter->opArray);
2023-05-11 10:16:55 +00:00
tsdbFSAllocEid(pTsdb->pFS, &pCommitter->eid);
2023-03-20 02:59:16 +00:00
2023-03-23 08:10:08 +00:00
// start loop
pCommitter->nextKey = pTsdb->imem->minKey; // TODO
2023-03-20 02:59:16 +00:00
_exit:
if (code) {
2023-05-10 06:54:13 +00:00
tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code));
2023-03-20 02:59:16 +00:00
} else {
2023-05-10 06:54:13 +00:00
tsdbDebug("vgId:%d %s done", TD_VID(pTsdb->pVnode), __func__);
2023-03-20 02:59:16 +00:00
}
return code;
}
2023-03-27 08:30:22 +00:00
static int32_t close_committer(SCommitter *pCommiter, int32_t eno) {
2023-03-20 02:59:16 +00:00
int32_t code = 0;
2023-05-11 10:16:55 +00:00
int32_t lino = 0;
int32_t vid = TD_VID(pCommiter->pTsdb->pVnode);
2023-04-06 06:27:18 +00:00
2023-04-11 07:34:40 +00:00
if (eno == 0) {
2023-05-22 10:39:10 +00:00
code = tsdbFSEditBegin(pCommiter->pTsdb->pFS, &pCommiter->opArray, TSDB_FEDIT_COMMIT);
2023-05-11 10:16:55 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
2023-04-11 07:34:40 +00:00
} else {
2023-05-11 10:16:55 +00:00
// TODO
ASSERT(0);
2023-04-11 07:34:40 +00:00
}
2023-04-06 06:27:18 +00:00
2023-05-11 10:16:55 +00:00
ASSERT(pCommiter->pWriter == NULL);
taosArrayDestroy(pCommiter->aTbDataP);
2023-05-22 08:28:31 +00:00
TARRAY2_CLEAR_FREE(&pCommiter->opArray, NULL);
2023-04-12 07:18:12 +00:00
2023-04-06 06:27:18 +00:00
_exit:
2023-04-11 07:34:40 +00:00
if (code) {
2023-05-11 10:16:55 +00:00
tsdbError("vgId:%d %s failed at line %d since %s, eid:%" PRId64, vid, __func__, lino, tstrerror(code),
pCommiter->eid);
2023-04-11 07:34:40 +00:00
} else {
2023-05-11 10:16:55 +00:00
tsdbDebug("vgId:%d %s done, eid:%" PRId64, vid, __func__, pCommiter->eid);
2023-04-11 07:34:40 +00:00
}
2023-03-20 02:59:16 +00:00
return code;
}
int32_t tsdbPreCommit(STsdb *pTsdb) {
taosThreadRwlockWrlock(&pTsdb->rwLock);
ASSERT(pTsdb->imem == NULL);
pTsdb->imem = pTsdb->mem;
pTsdb->mem = NULL;
taosThreadRwlockUnlock(&pTsdb->rwLock);
return 0;
}
int32_t tsdbCommitBegin(STsdb *pTsdb, SCommitInfo *pInfo) {
if (!pTsdb) return 0;
int32_t code = 0;
int32_t lino = 0;
2023-03-22 06:41:16 +00:00
SMemTable *pMem = pTsdb->imem;
2023-03-20 02:59:16 +00:00
2023-03-22 06:41:16 +00:00
if (pMem->nRow == 0 && pMem->nDel == 0) {
2023-03-20 02:59:16 +00:00
taosThreadRwlockWrlock(&pTsdb->rwLock);
pTsdb->imem = NULL;
taosThreadRwlockUnlock(&pTsdb->rwLock);
2023-03-22 06:41:16 +00:00
tsdbUnrefMemTable(pMem, NULL, true);
} else {
SCommitter committer;
2023-03-20 02:59:16 +00:00
2023-03-27 08:30:22 +00:00
code = open_committer(pTsdb, pInfo, &committer);
2023-03-22 06:41:16 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
2023-03-20 02:59:16 +00:00
2023-03-23 05:26:57 +00:00
while (committer.nextKey != TSKEY_MAX) {
2023-05-11 10:16:55 +00:00
code = commit_fset(&committer);
if (code) {
lino = __LINE__;
break;
}
2023-03-22 06:41:16 +00:00
}
2023-03-20 02:59:16 +00:00
2023-03-27 08:30:22 +00:00
code = close_committer(&committer, code);
2023-03-22 06:41:16 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
}
2023-03-20 02:59:16 +00:00
_exit:
if (code) {
2023-05-10 06:54:13 +00:00
tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code));
2023-03-22 06:41:16 +00:00
} else {
2023-05-10 06:54:13 +00:00
tsdbInfo("vgId:%d %s done, nRow:%" PRId64 " nDel:%" PRId64, TD_VID(pTsdb->pVnode), __func__, pMem->nRow,
2023-03-22 06:41:16 +00:00
pMem->nDel);
2023-03-20 02:59:16 +00:00
}
return code;
}
2023-04-10 09:52:51 +00:00
int32_t tsdbCommitCommit(STsdb *pTsdb) {
2023-05-11 10:16:55 +00:00
int32_t code = 0;
int32_t lino = 0;
int32_t vid = TD_VID(pTsdb->pVnode);
2023-04-10 09:52:51 +00:00
2023-05-11 10:16:55 +00:00
if (pTsdb->imem == NULL) goto _exit;
2023-04-10 09:52:51 +00:00
2023-05-11 10:16:55 +00:00
SMemTable *pMemTable = pTsdb->imem;
taosThreadRwlockWrlock(&pTsdb->rwLock);
2023-05-09 08:46:23 +00:00
code = tsdbFSEditCommit(pTsdb->pFS);
2023-04-10 09:52:51 +00:00
if (code) {
taosThreadRwlockUnlock(&pTsdb->rwLock);
TSDB_CHECK_CODE(code, lino, _exit);
}
pTsdb->imem = NULL;
taosThreadRwlockUnlock(&pTsdb->rwLock);
2023-05-11 10:16:55 +00:00
tsdbUnrefMemTable(pMemTable, NULL, true);
2023-04-10 09:52:51 +00:00
2023-05-24 03:52:38 +00:00
// TODO: make this call async
code = tsdbMerge(pTsdb);
TSDB_CHECK_CODE(code, lino, _exit);
2023-05-24 01:30:14 +00:00
2023-04-10 09:52:51 +00:00
_exit:
if (code) {
2023-05-11 10:16:55 +00:00
tsdbError("vgId:%d, %s failed at line %d since %s", vid, __func__, lino, tstrerror(code));
2023-04-10 09:52:51 +00:00
} else {
2023-05-11 10:16:55 +00:00
tsdbInfo("vgId:%d %s done", vid, __func__);
2023-04-10 09:52:51 +00:00
}
return code;
}
int32_t tsdbCommitAbort(STsdb *pTsdb) {
int32_t code = 0;
int32_t lino = 0;
2023-05-11 10:16:55 +00:00
int32_t vid = TD_VID(pTsdb->pVnode);
if (pTsdb->imem == NULL) goto _exit;
2023-04-10 09:52:51 +00:00
2023-05-09 08:46:23 +00:00
code = tsdbFSEditAbort(pTsdb->pFS);
2023-04-10 09:52:51 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
_exit:
if (code) {
2023-05-11 10:16:55 +00:00
tsdbError("vgId:%d, %s failed at line %d since %s", vid, __func__, lino, tstrerror(code));
2023-04-10 09:52:51 +00:00
} else {
2023-05-11 10:16:55 +00:00
tsdbInfo("vgId:%d %s done", vid, __func__);
2023-04-10 09:52:51 +00:00
}
return code;
}