• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #4986

15 Mar 2026 08:32AM UTC coverage: 37.305% (-31.3%) from 68.601%
#4986

push

travis-ci

tomchon
test: keep docs and unit test

125478 of 336361 relevant lines covered (37.3%)

1134847.06 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

74.07
/source/dnode/vnode/src/meta/metaCommit.c
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#include "meta.h"
17
#include "vnd.h"
18
#include "tdbUtil.h"
19

20
static FORCE_INLINE void *metaMalloc(void *pPool, size_t size) {
×
21
  SVBufPool *pool = (SVBufPool *)pPool;
×
22
  SVnode    *pVnode = pool->pVnode;
×
23

24
  if (pVnode->inUse && pVnode->inUse->size > pVnode->inUse->node.size) {
×
25
    return NULL;
×
26
  }
27

28
  return vnodeBufPoolMallocAligned((SVBufPool *)pPool, size);
×
29
}
30

31
static FORCE_INLINE void metaFree(void *pPool, void *p) { vnodeBufPoolFree((SVBufPool *)pPool, p); }
×
32

33
// begin a meta txn
34
int32_t metaBegin(SMeta *pMeta, int8_t heap) {
44✔
35
  int32_t code = 0;
44✔
36
  int32_t lino;
37

38
  void *(*xMalloc)(void *, size_t) = NULL;
44✔
39
  void (*xFree)(void *, void *) = NULL;
44✔
40
  void *xArg = NULL;
44✔
41

42
  // default heap to META_BEGIN_HEAP_NIL
43
  if (heap == META_BEGIN_HEAP_OS) {
44✔
44
    xMalloc = tdbDefaultMalloc;
×
45
    xFree = tdbDefaultFree;
×
46
  } else if (heap == META_BEGIN_HEAP_BUFFERPOOL) {
44✔
47
    xMalloc = metaMalloc;
44✔
48
    xFree = metaFree;
44✔
49
    xArg = pMeta->pVnode->inUse;
44✔
50
  }
51

52
  code = tdbBegin(pMeta->pEnv, &pMeta->txn, xMalloc, xFree, xArg, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED);
44✔
53
  TSDB_CHECK_CODE(code, lino, _exit);
44✔
54

55
  code = tdbCommit(pMeta->pEnv, pMeta->txn);
44✔
56
  TSDB_CHECK_CODE(code, lino, _exit);
44✔
57

58
_exit:
44✔
59
  if (code) {
44✔
60
    metaError("vgId:%d %s failed at %s:%d since %s", TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__,
×
61
              tstrerror(terrno));
62
  } else {
63
    metaDebug("vgId:%d %s success", TD_VID(pMeta->pVnode), __func__);
44✔
64
  }
65

66
  TAOS_RETURN(code);
44✔
67
}
68

69
// commit the meta txn
70
TXN *metaGetTxn(SMeta *pMeta) { return pMeta->txn; }
4✔
71
int  metaCommit(SMeta *pMeta, TXN *txn) { return tdbCommit(pMeta->pEnv, txn); }
×
72
int  metaFinishCommit(SMeta *pMeta, TXN *txn) { return tdbPostCommit(pMeta->pEnv, txn); }
4✔
73

74
int metaPrepareAsyncCommit(SMeta *pMeta) {
4✔
75
  // return tdbPrepareAsyncCommit(pMeta->pEnv, pMeta->txn);
76
  int     code = 0;
4✔
77
  int32_t lino;
78

79
  metaWLock(pMeta);
4✔
80
  int32_t ret = ttlMgrFlush(pMeta->pTtlMgr, pMeta->txn);
4✔
81
  if (ret < 0) {
4✔
82
    metaError("vgId:%d, failed to flush ttl since %s", TD_VID(pMeta->pVnode), tstrerror(ret));
×
83
  }
84
  metaULock(pMeta);
4✔
85

86
  code = tdbCommit(pMeta->pEnv, pMeta->txn);
4✔
87
  TSDB_CHECK_CODE(code, lino, _exit);
4✔
88
  pMeta->changed = false;
4✔
89

90
  pMeta->txn = NULL;
4✔
91

92
_exit:
4✔
93
  if (code) {
4✔
94
    metaError("vgId:%d %s failed at %s:%d since %s", TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__,
×
95
              tstrerror(terrno));
96
  } else {
97
    metaDebug("vgId:%d %s success", TD_VID(pMeta->pVnode), __func__);
4✔
98
  }
99

100
  TAOS_RETURN(code);
4✔
101
}
102

103
// abort the meta txn
104
int metaAbort(SMeta *pMeta) {
40✔
105
  if (!pMeta->txn) {
40✔
106
    return 0;
×
107
  }
108

109
  metaCacheClear(pMeta);
40✔
110
  tdbAbort(pMeta->pEnv, pMeta->txn);
40✔
111
  pMeta->txn = NULL;
40✔
112
  return 0;
40✔
113
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc