tsdbCommit.c 12.2 KB
Newer Older
H
Hongze Cheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * 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/>.
 */

H
Hongze Cheng 已提交
16
#include "inc/tsdbCommit.h"
H
Hongze Cheng 已提交
17

H
Hongze Cheng 已提交
18
// extern dependencies
H
Hongze Cheng 已提交
19 20
typedef struct {
  STsdb *pTsdb;
H
Hongze Cheng 已提交
21

H
Hongze Cheng 已提交
22 23 24 25 26 27 28
  // config
  int32_t minutes;
  int8_t  precision;
  int32_t minRow;
  int32_t maxRow;
  int8_t  cmprAlg;
  int8_t  sttTrigger;
H
Hongze Cheng 已提交
29 30 31

  SArray *aTbDataP;  // SArray<STbData *>
  SArray *aFileOp;   // SArray<STFileOp>
H
Hongze Cheng 已提交
32
  int64_t eid;       // edit id
H
Hongze Cheng 已提交
33

H
Hongze Cheng 已提交
34
  // context
H
Hongze Cheng 已提交
35 36 37 38 39 40
  TSKEY            nextKey;
  int32_t          fid;
  int32_t          expLevel;
  TSKEY            minKey;
  TSKEY            maxKey;
  const STFileSet *pFileSet;
H
Hongze Cheng 已提交
41

H
Hongze Cheng 已提交
42
  // writer
H
Hongze Cheng 已提交
43
  SSttFileWriter *pWriter;
H
Hongze Cheng 已提交
44
} SCommitter;
H
Hongze Cheng 已提交
45

H
Hongze Cheng 已提交
46
static int32_t open_committer_writer(SCommitter *pCommitter) {
H
Hongze Cheng 已提交
47
  int32_t code = 0;
H
Hongze Cheng 已提交
48 49 50
  int32_t lino = 0;
  STsdb  *pTsdb = pCommitter->pTsdb;
  int32_t vid = TD_VID(pTsdb->pVnode);
H
Hongze Cheng 已提交
51

H
Hongze Cheng 已提交
52
  SSttFileWriterConfig config = {
H
Hongze Cheng 已提交
53 54
      .pTsdb = pCommitter->pTsdb,
      .maxRow = pCommitter->maxRow,
H
Hongze Cheng 已提交
55
      .szPage = pTsdb->pVnode->config.tsdbPageSize,
H
Hongze Cheng 已提交
56
      .cmprAlg = pCommitter->cmprAlg,
H
Hongze Cheng 已提交
57 58
      .pSkmTb = NULL,
      .pSkmRow = NULL,
H
Hongze Cheng 已提交
59 60
      .aBuf = NULL,
  };
H
Hongze Cheng 已提交
61

H
Hongze Cheng 已提交
62
  if (pCommitter->pFileSet) {
H
Hongze Cheng 已提交
63 64
    // TODO
    ASSERT(0);
H
Hongze Cheng 已提交
65
  } else {
H
Hongze Cheng 已提交
66
    config.file.type = TSDB_FTYPE_STT;
H
Hongze Cheng 已提交
67

H
Hongze Cheng 已提交
68
    if (tfsAllocDisk(pTsdb->pVnode->pTfs, pCommitter->expLevel, &config.file.did) < 0) {
H
Hongze Cheng 已提交
69 70 71 72
      code = TSDB_CODE_FS_NO_VALID_DISK;
      TSDB_CHECK_CODE(code, lino, _exit);
    }

H
Hongze Cheng 已提交
73 74 75
    config.file.fid = pCommitter->fid;
    config.file.cid = pCommitter->eid;
    config.file.size = 0;
H
Hongze Cheng 已提交
76
    config.file.stt.level = 0;
H
Hongze Cheng 已提交
77
    config.file.stt.nseg = 0;
H
Hongze Cheng 已提交
78

H
Hongze Cheng 已提交
79
    tsdbTFileInit(pTsdb, &config.file);
H
Hongze Cheng 已提交
80
  }
H
Hongze Cheng 已提交
81

H
Hongze Cheng 已提交
82
  code = tsdbSttFWriterOpen(&config, &pCommitter->pWriter);
H
Hongze Cheng 已提交
83 84 85 86
  TSDB_CHECK_CODE(code, lino, _exit);

_exit:
  if (code) {
H
Hongze Cheng 已提交
87
    tsdbError("vgId:%d %s failed at line %d since %s, fid:%d", vid, __func__, lino, tstrerror(code), pCommitter->fid);
H
Hongze Cheng 已提交
88
  }
H
Hongze Cheng 已提交
89 90 91
  return code;
}

H
Hongze Cheng 已提交
92
static int32_t tsdbCommitWriteTSData(SCommitter *pCommitter, TABLEID *tbid, TSDBROW *pRow) {
H
Hongze Cheng 已提交
93
  int32_t code = 0;
H
Hongze Cheng 已提交
94 95
  int32_t lino = 0;
  int32_t vid = TD_VID(pCommitter->pTsdb->pVnode);
H
Hongze Cheng 已提交
96 97

  if (pCommitter->pWriter == NULL) {
H
Hongze Cheng 已提交
98
    code = open_committer_writer(pCommitter);
H
Hongze Cheng 已提交
99 100 101
    TSDB_CHECK_CODE(code, lino, _exit);
  }

H
Hongze Cheng 已提交
102
  code = tsdbSttFWriteTSData(pCommitter->pWriter, tbid, pRow);
H
Hongze Cheng 已提交
103 104 105 106
  TSDB_CHECK_CODE(code, lino, _exit);

_exit:
  if (code) {
H
Hongze Cheng 已提交
107
    tsdbError("vgId:%d failed at line %d since %s", vid, lino, tstrerror(code));
H
Hongze Cheng 已提交
108
  } else {
H
Hongze Cheng 已提交
109 110
    tsdbTrace("vgId:%d %s done, fid:%d suid:%" PRId64 " uid:%" PRId64 " ts:%" PRId64 " version:%" PRId64, vid, __func__,
              pCommitter->fid, tbid->suid, tbid->uid, TSDBROW_KEY(pRow).ts, TSDBROW_KEY(pRow).version);
H
Hongze Cheng 已提交
111
  }
H
Hongze Cheng 已提交
112
  return 0;
H
Hongze Cheng 已提交
113 114
}

H
Hongze Cheng 已提交
115 116 117 118 119 120 121
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;
}

H
Hongze Cheng 已提交
122
static int32_t commit_timeseries_data(SCommitter *pCommitter) {
H
Hongze Cheng 已提交
123 124
  int32_t    code = 0;
  int32_t    lino = 0;
H
Hongze Cheng 已提交
125
  int64_t    nRow = 0;
H
Hongze Cheng 已提交
126 127 128
  STsdb     *pTsdb = pCommitter->pTsdb;
  int32_t    vid = TD_VID(pTsdb->pVnode);
  SMemTable *pMem = pTsdb->imem;
H
Hongze Cheng 已提交
129

H
Hongze Cheng 已提交
130
  if (pMem->nRow == 0) goto _exit;
H
Hongze Cheng 已提交
131

H
Hongze Cheng 已提交
132
  TSDBKEY from = {.ts = pCommitter->minKey, .version = VERSION_MIN};
H
Hongze Cheng 已提交
133 134
  for (int32_t iTbData = 0; iTbData < taosArrayGetSize(pCommitter->aTbDataP); iTbData++) {
    STbDataIter iter;
H
Hongze Cheng 已提交
135 136
    STbData    *pTbData = (STbData *)taosArrayGetP(pCommitter->aTbDataP, iTbData);

H
Hongze Cheng 已提交
137 138 139 140 141 142
    tsdbTbDataIterOpen(pTbData, &from, 0, &iter);

    for (TSDBROW *pRow; (pRow = tsdbTbDataIterGet(&iter)) != NULL; tsdbTbDataIterNext(&iter)) {
      TSDBKEY rowKey = TSDBROW_KEY(pRow);

      if (rowKey.ts > pCommitter->maxKey) {
H
Hongze Cheng 已提交
143
        pCommitter->nextKey = TMIN(pCommitter->nextKey, rowKey.ts);
H
Hongze Cheng 已提交
144 145 146
        break;
      }

H
Hongze Cheng 已提交
147
      code = tsdbCommitWriteTSData(pCommitter, (TABLEID *)pTbData, pRow);
H
Hongze Cheng 已提交
148
      TSDB_CHECK_CODE(code, lino, _exit);
H
Hongze Cheng 已提交
149 150

      nRow++;
H
Hongze Cheng 已提交
151 152 153 154 155
    }
  }

_exit:
  if (code) {
H
Hongze Cheng 已提交
156
    tsdbError("vgId:%d %s failed at line %d since %s", vid, __func__, lino, tstrerror(code));
H
Hongze Cheng 已提交
157
  } else {
H
Hongze Cheng 已提交
158
    tsdbDebug("vgId:%d %s done, fid:%d nRow:%" PRId64, vid, __func__, pCommitter->fid, nRow);
H
Hongze Cheng 已提交
159 160 161 162
  }
  return code;
}

H
Hongze Cheng 已提交
163
static int32_t commit_delete_data(SCommitter *pCommitter) {
H
Hongze Cheng 已提交
164 165 166
  int32_t code = 0;
  int32_t lino;

H
Hongze Cheng 已提交
167 168
  return 0;

H
Hongze Cheng 已提交
169
  ASSERTS(0, "TODO: Not implemented yet");
H
Hongze Cheng 已提交
170

H
Hongze Cheng 已提交
171
  int64_t    nDel = 0;
H
Hongze Cheng 已提交
172 173
  SMemTable *pMem = pCommitter->pTsdb->imem;

H
Hongze Cheng 已提交
174 175 176
  if (pMem->nDel == 0) {  // no del data
    goto _exit;
  }
H
Hongze Cheng 已提交
177 178 179 180 181

  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) {
H
Hongze Cheng 已提交
182 183 184 185 186
      if (pDelData->eKey < pCommitter->minKey) continue;
      if (pDelData->sKey > pCommitter->maxKey) {
        pCommitter->nextKey = TMIN(pCommitter->nextKey, pDelData->sKey);
        continue;
      }
H
Hongze Cheng 已提交
187

H
Hongze Cheng 已提交
188 189
      code = tsdbCommitWriteDelData(pCommitter, pTbData->suid, pTbData->uid, pDelData->version,
                                    pDelData->sKey /* TODO */, pDelData->eKey /* TODO */);
H
Hongze Cheng 已提交
190 191 192 193 194 195 196 197 198 199 200 201 202 203
      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;
}

H
Hongze Cheng 已提交
204 205 206 207
static int32_t commit_fset_start(SCommitter *pCommitter) {
  STsdb  *pTsdb = pCommitter->pTsdb;
  int32_t vid = TD_VID(pTsdb->pVnode);

H
Hongze Cheng 已提交
208 209 210
  pCommitter->fid = tsdbKeyFid(pCommitter->nextKey, pCommitter->minutes, pCommitter->precision);
  tsdbFidKeyRange(pCommitter->fid, pCommitter->minutes, pCommitter->precision, &pCommitter->minKey,
                  &pCommitter->maxKey);
H
Hongze Cheng 已提交
211
  pCommitter->expLevel = tsdbFidLevel(pCommitter->fid, &pTsdb->keepCfg, taosGetTimestampSec());
H
Hongze Cheng 已提交
212
  pCommitter->nextKey = TSKEY_MAX;
H
Hongze Cheng 已提交
213

H
Hongze Cheng 已提交
214
  tsdbFSGetFSet(pTsdb->pFS, pCommitter->fid, &pCommitter->pFileSet);
H
Hongze Cheng 已提交
215

H
Hongze Cheng 已提交
216 217
  tsdbDebug("vgId:%d %s done, fid:%d minKey:%" PRId64 " maxKey:%" PRId64 " expLevel:%d", vid, __func__, pCommitter->fid,
            pCommitter->minKey, pCommitter->maxKey, pCommitter->expLevel);
H
Hongze Cheng 已提交
218
  return 0;
H
Hongze Cheng 已提交
219 220
}

H
Hongze Cheng 已提交
221
static int32_t commit_fset_end(SCommitter *pCommitter) {
H
Hongze Cheng 已提交
222
  int32_t code = 0;
H
Hongze Cheng 已提交
223 224
  int32_t lino = 0;
  int32_t vid = TD_VID(pCommitter->pTsdb->pVnode);
H
Hongze Cheng 已提交
225

H
Hongze Cheng 已提交
226 227
  if (pCommitter->pWriter == NULL) return 0;

H
Hongze Cheng 已提交
228
  struct STFileOp *pFileOp = taosArrayReserve(pCommitter->aFileOp, 1);
H
Hongze Cheng 已提交
229 230 231 232 233
  if (pFileOp == NULL) {
    code = TSDB_CODE_OUT_OF_MEMORY;
    TSDB_CHECK_CODE(code, lino, _exit);
  }

H
Hongze Cheng 已提交
234 235
  code = tsdbSttFWriterClose(&pCommitter->pWriter, 0, pFileOp);
  TSDB_CHECK_CODE(code, lino, _exit);
H
Hongze Cheng 已提交
236 237 238

_exit:
  if (code) {
H
Hongze Cheng 已提交
239
    tsdbError("vgId:%d failed at line %d since %s", vid, lino, tstrerror(code));
H
Hongze Cheng 已提交
240
  } else {
H
Hongze Cheng 已提交
241
    tsdbDebug("vgId:%d %s done, fid:%d", vid, __func__, pCommitter->fid);
H
Hongze Cheng 已提交
242 243 244 245
  }
  return code;
}

H
Hongze Cheng 已提交
246
static int32_t commit_fset(SCommitter *pCommitter) {
H
Hongze Cheng 已提交
247 248
  int32_t code = 0;
  int32_t lino = 0;
H
Hongze Cheng 已提交
249
  int32_t vid = TD_VID(pCommitter->pTsdb->pVnode);
H
Hongze Cheng 已提交
250

H
Hongze Cheng 已提交
251
  // fset commit start
H
Hongze Cheng 已提交
252
  code = commit_fset_start(pCommitter);
H
Hongze Cheng 已提交
253
  TSDB_CHECK_CODE(code, lino, _exit);
H
Hongze Cheng 已提交
254

H
Hongze Cheng 已提交
255
  // commit fset
H
Hongze Cheng 已提交
256
  code = commit_timeseries_data(pCommitter);
H
Hongze Cheng 已提交
257 258
  TSDB_CHECK_CODE(code, lino, _exit);

H
Hongze Cheng 已提交
259
  code = commit_delete_data(pCommitter);
H
Hongze Cheng 已提交
260 261 262
  TSDB_CHECK_CODE(code, lino, _exit);

  // fset commit end
H
Hongze Cheng 已提交
263
  code = commit_fset_end(pCommitter);
H
Hongze Cheng 已提交
264
  TSDB_CHECK_CODE(code, lino, _exit);
H
Hongze Cheng 已提交
265 266 267

_exit:
  if (code) {
H
Hongze Cheng 已提交
268 269 270
    tsdbError("vgId:%d %s failed at line %d since %s", vid, __func__, lino, tstrerror(code));
  } else {
    tsdbDebug("vgId:%d %s done", vid, __func__);
H
Hongze Cheng 已提交
271 272 273 274
  }
  return code;
}

H
Hongze Cheng 已提交
275
static int32_t open_committer(STsdb *pTsdb, SCommitInfo *pInfo, SCommitter *pCommitter) {
H
Hongze Cheng 已提交
276
  int32_t code = 0;
H
Hongze Cheng 已提交
277
  int32_t lino;
H
Hongze Cheng 已提交
278

H
Hongze Cheng 已提交
279
  // set config
H
Hongze Cheng 已提交
280 281
  memset(pCommitter, 0, sizeof(SCommitter));
  pCommitter->pTsdb = pTsdb;
H
Hongze Cheng 已提交
282 283 284 285 286
  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;
H
Hongze Cheng 已提交
287
  pCommitter->sttTrigger = 2;  // TODO
H
Hongze Cheng 已提交
288 289

  pCommitter->aTbDataP = tsdbMemTableGetTbDataArray(pTsdb->imem);
H
Hongze Cheng 已提交
290 291 292 293 294
  pCommitter->aFileOp = taosArrayInit(16, sizeof(STFileOp));
  if (pCommitter->aTbDataP == NULL || pCommitter->aFileOp == NULL) {
    taosArrayDestroy(pCommitter->aTbDataP);
    taosArrayDestroy(pCommitter->aFileOp);
    TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
H
Hongze Cheng 已提交
295
  }
H
Hongze Cheng 已提交
296
  tsdbFSAllocEid(pTsdb->pFS, &pCommitter->eid);
H
Hongze Cheng 已提交
297

H
Hongze Cheng 已提交
298 299
  // start loop
  pCommitter->nextKey = pTsdb->imem->minKey;  // TODO
H
Hongze Cheng 已提交
300 301 302

_exit:
  if (code) {
H
Hongze Cheng 已提交
303
    tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code));
H
Hongze Cheng 已提交
304
  } else {
H
Hongze Cheng 已提交
305
    tsdbDebug("vgId:%d %s done", TD_VID(pTsdb->pVnode), __func__);
H
Hongze Cheng 已提交
306 307 308 309
  }
  return code;
}

H
Hongze Cheng 已提交
310
static int32_t close_committer(SCommitter *pCommiter, int32_t eno) {
H
Hongze Cheng 已提交
311
  int32_t code = 0;
H
Hongze Cheng 已提交
312 313
  int32_t lino = 0;
  int32_t vid = TD_VID(pCommiter->pTsdb->pVnode);
H
Hongze Cheng 已提交
314

H
Hongze Cheng 已提交
315
  if (eno == 0) {
H
Hongze Cheng 已提交
316 317
    code = tsdbFSEditBegin(pCommiter->pTsdb->pFS, pCommiter->eid, pCommiter->aFileOp, TSDB_FEDIT_COMMIT);
    TSDB_CHECK_CODE(code, lino, _exit);
H
Hongze Cheng 已提交
318
  } else {
H
Hongze Cheng 已提交
319 320
    // TODO
    ASSERT(0);
H
Hongze Cheng 已提交
321
  }
H
Hongze Cheng 已提交
322

H
Hongze Cheng 已提交
323 324 325
  ASSERT(pCommiter->pWriter == NULL);
  taosArrayDestroy(pCommiter->aTbDataP);
  taosArrayDestroy(pCommiter->aFileOp);
H
Hongze Cheng 已提交
326

H
Hongze Cheng 已提交
327
_exit:
H
Hongze Cheng 已提交
328
  if (code) {
H
Hongze Cheng 已提交
329 330
    tsdbError("vgId:%d %s failed at line %d since %s, eid:%" PRId64, vid, __func__, lino, tstrerror(code),
              pCommiter->eid);
H
Hongze Cheng 已提交
331
  } else {
H
Hongze Cheng 已提交
332
    tsdbDebug("vgId:%d %s done, eid:%" PRId64, vid, __func__, pCommiter->eid);
H
Hongze Cheng 已提交
333
  }
H
Hongze Cheng 已提交
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
  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;
H
Hongze Cheng 已提交
351
  SMemTable *pMem = pTsdb->imem;
H
Hongze Cheng 已提交
352

H
Hongze Cheng 已提交
353
  if (pMem->nRow == 0 && pMem->nDel == 0) {
H
Hongze Cheng 已提交
354 355 356
    taosThreadRwlockWrlock(&pTsdb->rwLock);
    pTsdb->imem = NULL;
    taosThreadRwlockUnlock(&pTsdb->rwLock);
H
Hongze Cheng 已提交
357 358 359
    tsdbUnrefMemTable(pMem, NULL, true);
  } else {
    SCommitter committer;
H
Hongze Cheng 已提交
360

H
Hongze Cheng 已提交
361
    code = open_committer(pTsdb, pInfo, &committer);
H
Hongze Cheng 已提交
362
    TSDB_CHECK_CODE(code, lino, _exit);
H
Hongze Cheng 已提交
363

H
Hongze Cheng 已提交
364
    while (committer.nextKey != TSKEY_MAX) {
H
Hongze Cheng 已提交
365 366 367 368 369
      code = commit_fset(&committer);
      if (code) {
        lino = __LINE__;
        break;
      }
H
Hongze Cheng 已提交
370
    }
H
Hongze Cheng 已提交
371

H
Hongze Cheng 已提交
372
    code = close_committer(&committer, code);
H
Hongze Cheng 已提交
373 374
    TSDB_CHECK_CODE(code, lino, _exit);
  }
H
Hongze Cheng 已提交
375 376 377

_exit:
  if (code) {
H
Hongze Cheng 已提交
378
    tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code));
H
Hongze Cheng 已提交
379
  } else {
H
Hongze Cheng 已提交
380
    tsdbInfo("vgId:%d %s done, nRow:%" PRId64 " nDel:%" PRId64, TD_VID(pTsdb->pVnode), __func__, pMem->nRow,
H
Hongze Cheng 已提交
381
             pMem->nDel);
H
Hongze Cheng 已提交
382 383 384 385
  }
  return code;
}

H
Hongze Cheng 已提交
386
int32_t tsdbCommitCommit(STsdb *pTsdb) {
H
Hongze Cheng 已提交
387 388 389
  int32_t code = 0;
  int32_t lino = 0;
  int32_t vid = TD_VID(pTsdb->pVnode);
H
Hongze Cheng 已提交
390

H
Hongze Cheng 已提交
391
  if (pTsdb->imem == NULL) goto _exit;
H
Hongze Cheng 已提交
392

H
Hongze Cheng 已提交
393 394
  SMemTable *pMemTable = pTsdb->imem;
  taosThreadRwlockWrlock(&pTsdb->rwLock);
H
Hongze Cheng 已提交
395
  code = tsdbFSEditCommit(pTsdb->pFS);
H
Hongze Cheng 已提交
396 397 398 399 400 401
  if (code) {
    taosThreadRwlockUnlock(&pTsdb->rwLock);
    TSDB_CHECK_CODE(code, lino, _exit);
  }
  pTsdb->imem = NULL;
  taosThreadRwlockUnlock(&pTsdb->rwLock);
H
Hongze Cheng 已提交
402
  tsdbUnrefMemTable(pMemTable, NULL, true);
H
Hongze Cheng 已提交
403 404 405

_exit:
  if (code) {
H
Hongze Cheng 已提交
406
    tsdbError("vgId:%d, %s failed at line %d since %s", vid, __func__, lino, tstrerror(code));
H
Hongze Cheng 已提交
407
  } else {
H
Hongze Cheng 已提交
408
    tsdbInfo("vgId:%d %s done", vid, __func__);
H
Hongze Cheng 已提交
409 410 411 412 413 414 415
  }
  return code;
}

int32_t tsdbCommitAbort(STsdb *pTsdb) {
  int32_t code = 0;
  int32_t lino = 0;
H
Hongze Cheng 已提交
416 417 418
  int32_t vid = TD_VID(pTsdb->pVnode);

  if (pTsdb->imem == NULL) goto _exit;
H
Hongze Cheng 已提交
419

H
Hongze Cheng 已提交
420
  code = tsdbFSEditAbort(pTsdb->pFS);
H
Hongze Cheng 已提交
421 422 423 424
  TSDB_CHECK_CODE(code, lino, _exit);

_exit:
  if (code) {
H
Hongze Cheng 已提交
425
    tsdbError("vgId:%d, %s failed at line %d since %s", vid, __func__, lino, tstrerror(code));
H
Hongze Cheng 已提交
426
  } else {
H
Hongze Cheng 已提交
427
    tsdbInfo("vgId:%d %s done", vid, __func__);
H
Hongze Cheng 已提交
428 429 430
  }
  return code;
}