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

taosdata / TDengine / #4788

14 Oct 2025 11:21AM UTC coverage: 60.992% (-2.3%) from 63.264%
#4788

push

travis-ci

web-flow
Merge 7ca9b50f9 into 19574fe21

154868 of 324306 branches covered (47.75%)

Branch coverage included in aggregate %.

207304 of 269498 relevant lines covered (76.92%)

125773493.22 hits per line

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

77.91
/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) {
113,400,051✔
21
  SVBufPool *pool = (SVBufPool *)pPool;
113,400,051✔
22
  SVnode    *pVnode = pool->pVnode;
113,400,051✔
23

24
  if (pVnode->inUse && pVnode->inUse->size > pVnode->inUse->node.size) {
113,400,051!
25
    return NULL;
81,795✔
26
  }
27

28
  return vnodeBufPoolMallocAligned((SVBufPool *)pPool, size);
113,318,256✔
29
}
30

31
static FORCE_INLINE void metaFree(void *pPool, void *p) { vnodeBufPoolFree((SVBufPool *)pPool, p); }
113,318,256✔
32

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

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

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

52
  code = tdbBegin(pMeta->pEnv, &pMeta->txn, xMalloc, xFree, xArg, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED);
10,313,653✔
53
  TSDB_CHECK_CODE(code, lino, _exit);
10,315,459!
54

55
  code = tdbCommit(pMeta->pEnv, pMeta->txn);
10,315,459✔
56
  TSDB_CHECK_CODE(code, lino, _exit);
10,311,988!
57

58
_exit:
10,311,988✔
59
  if (code) {
10,311,988!
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__);
10,311,988✔
64
  }
65

66
  TAOS_RETURN(code);
10,311,988✔
67
}
68

69
// commit the meta txn
70
TXN *metaGetTxn(SMeta *pMeta) { return pMeta->txn; }
6,278,726✔
71
int  metaCommit(SMeta *pMeta, TXN *txn) { return tdbCommit(pMeta->pEnv, txn); }
7,840✔
72
int  metaFinishCommit(SMeta *pMeta, TXN *txn) { return tdbPostCommit(pMeta->pEnv, txn); }
6,288,129✔
73

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

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

86
  code = tdbCommit(pMeta->pEnv, pMeta->txn);
6,274,846✔
87
  TSDB_CHECK_CODE(code, lino, _exit);
6,277,220!
88
  pMeta->changed = false;
6,277,220✔
89

90
  pMeta->txn = NULL;
6,278,649✔
91

92
_exit:
6,269,691✔
93
  if (code) {
6,269,691!
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__);
6,269,691✔
98
  }
99

100
  TAOS_RETURN(code);
6,269,691✔
101
}
102

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

109
  metaCacheClear(pMeta);
4,029,235✔
110
  tdbAbort(pMeta->pEnv, pMeta->txn);
4,029,235✔
111
  pMeta->txn = NULL;
4,029,235✔
112
  return 0;
4,029,235✔
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