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

taosdata / TDengine / #4754

25 Sep 2025 05:58AM UTC coverage: 57.946% (-1.0%) from 58.977%
#4754

push

travis-ci

web-flow
enh: taos command line support '-uroot' on windows (#33055)

133189 of 293169 branches covered (45.43%)

Branch coverage included in aggregate %.

201677 of 284720 relevant lines covered (70.83%)

5398749.0 hits per line

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

75.58
/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) {
54,720✔
21
  SVBufPool *pool = (SVBufPool *)pPool;
54,720✔
22
  SVnode    *pVnode = pool->pVnode;
54,720✔
23

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

28
  return vnodeBufPoolMallocAligned((SVBufPool *)pPool, size);
54,720✔
29
}
30

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

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

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

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

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

55
  code = tdbCommit(pMeta->pEnv, pMeta->txn);
34,036✔
56
  TSDB_CHECK_CODE(code, lino, _exit);
34,038!
57

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

66
  TAOS_RETURN(code);
34,038✔
67
}
68

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

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

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

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

90
  pMeta->txn = NULL;
21,693✔
91

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

100
  TAOS_RETURN(code);
21,693✔
101
}
102

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

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