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

taosdata / TDengine / #4844

09 Nov 2025 03:44PM UTC coverage: 63.058% (-0.5%) from 63.514%
#4844

push

travis-ci

web-flow
test: minor changes (#33510)

117164 of 185804 relevant lines covered (63.06%)

115657269.29 hits per line

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

88.89
/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) {
13,977,864✔
21
  SVBufPool *pool = (SVBufPool *)pPool;
13,977,864✔
22
  SVnode    *pVnode = pool->pVnode;
13,977,864✔
23

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

28
  return vnodeBufPoolMallocAligned((SVBufPool *)pPool, size);
13,977,864✔
29
}
30

31
static FORCE_INLINE void metaFree(void *pPool, void *p) { vnodeBufPoolFree((SVBufPool *)pPool, p); }
13,977,864✔
32

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

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

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

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

55
  code = tdbCommit(pMeta->pEnv, pMeta->txn);
9,157,155✔
56
  TSDB_CHECK_CODE(code, lino, _exit);
9,156,960✔
57

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

66
  TAOS_RETURN(code);
9,156,960✔
67
}
68

69
// commit the meta txn
70
TXN *metaGetTxn(SMeta *pMeta) { return pMeta->txn; }
5,118,585✔
71
int  metaCommit(SMeta *pMeta, TXN *txn) { return tdbCommit(pMeta->pEnv, txn); }
17,515✔
72
int  metaFinishCommit(SMeta *pMeta, TXN *txn) { return tdbPostCommit(pMeta->pEnv, txn); }
5,135,212✔
73

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

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

86
  code = tdbCommit(pMeta->pEnv, pMeta->txn);
5,113,731✔
87
  TSDB_CHECK_CODE(code, lino, _exit);
5,112,300✔
88
  pMeta->changed = false;
5,112,300✔
89

90
  pMeta->txn = NULL;
5,114,560✔
91

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

100
  TAOS_RETURN(code);
5,107,111✔
101
}
102

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

109
  metaCacheClear(pMeta);
4,023,279✔
110
  tdbAbort(pMeta->pEnv, pMeta->txn);
4,023,279✔
111
  pMeta->txn = NULL;
4,022,574✔
112
  return 0;
4,022,341✔
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