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

taosdata / TDengine / #4469

08 Jul 2025 09:38AM UTC coverage: 62.22% (-1.2%) from 63.381%
#4469

push

travis-ci

web-flow
Merge pull request #31712 from taosdata/merge/mainto3.0

merge: from main to 3.0 branch

153678 of 316510 branches covered (48.55%)

Branch coverage included in aggregate %.

56 of 60 new or added lines in 13 files covered. (93.33%)

5035 existing lines in 221 files now uncovered.

238955 of 314529 relevant lines covered (75.97%)

6273248.0 hits per line

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

73.26
/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

19
static FORCE_INLINE void *metaMalloc(void *pPool, size_t size) {
54,397✔
20
  SVBufPool *pool = (SVBufPool *)pPool;
54,397✔
21
  SVnode    *pVnode = pool->pVnode;
54,397✔
22

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

27
  return vnodeBufPoolMallocAligned((SVBufPool *)pPool, size);
54,397✔
28
}
29

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

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

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

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

51
  code = tdbBegin(pMeta->pEnv, &pMeta->txn, xMalloc, xFree, xArg, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED);
38,234✔
52
  TSDB_CHECK_CODE(code, lino, _exit);
38,231!
53

54
  code = tdbCommit(pMeta->pEnv, pMeta->txn);
38,231✔
55
  TSDB_CHECK_CODE(code, lino, _exit);
38,235!
56

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

65
  TAOS_RETURN(code);
38,235✔
66
}
67

68
// commit the meta txn
69
TXN *metaGetTxn(SMeta *pMeta) { return pMeta->txn; }
23,668✔
70
int  metaCommit(SMeta *pMeta, TXN *txn) { return tdbCommit(pMeta->pEnv, txn); }
47✔
71
int  metaFinishCommit(SMeta *pMeta, TXN *txn) { return tdbPostCommit(pMeta->pEnv, txn); }
23,717✔
72

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

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

85
  code = tdbCommit(pMeta->pEnv, pMeta->txn);
23,670✔
86
  TSDB_CHECK_CODE(code, lino, _exit);
23,667!
87
  pMeta->changed = false;
23,667✔
88

89
  pMeta->txn = NULL;
23,667✔
90

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

99
  TAOS_RETURN(code);
23,667✔
100
}
101

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

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