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

taosdata / TDengine / #3621

22 Feb 2025 11:44AM UTC coverage: 2.037% (-61.5%) from 63.573%
#3621

push

travis-ci

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

merge: from main to 3.0 branch

4357 of 287032 branches covered (1.52%)

Branch coverage included in aggregate %.

0 of 174 new or added lines in 18 files covered. (0.0%)

213359 existing lines in 469 files now uncovered.

7260 of 283369 relevant lines covered (2.56%)

23737.72 hits per line

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

0.0
/source/dnode/vnode/src/tsdb/tsdbOpen.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 "tsdb.h"
17
#include "tsdbFS2.h"
18

19
extern int32_t tsdbOpenCompMonitor(STsdb *tsdb);
20
extern void    tsdbCloseCompMonitor(STsdb *tsdb);
21

UNCOV
22
void tsdbSetKeepCfg(STsdb *pTsdb, STsdbCfg *pCfg) {
×
UNCOV
23
  STsdbKeepCfg *pKeepCfg = &pTsdb->keepCfg;
×
UNCOV
24
  pKeepCfg->precision = pCfg->precision;
×
UNCOV
25
  pKeepCfg->days = pCfg->days;
×
UNCOV
26
  pKeepCfg->keep0 = pCfg->keep0;
×
UNCOV
27
  pKeepCfg->keep1 = pCfg->keep1;
×
UNCOV
28
  pKeepCfg->keep2 = pCfg->keep2;
×
UNCOV
29
  pKeepCfg->keepTimeOffset = pCfg->keepTimeOffset;
×
UNCOV
30
}
×
31

UNCOV
32
int64_t tsdbGetEarliestTs(STsdb *pTsdb) {
×
UNCOV
33
  STsdbKeepCfg *pCfg = &pTsdb->keepCfg;
×
34

UNCOV
35
  int64_t now = taosGetTimestamp(pCfg->precision);
×
UNCOV
36
  int64_t ts = now - (tsTickPerMin[pCfg->precision] * pCfg->keep2) + 1;  // needs to add one tick
×
UNCOV
37
  return ts;
×
38
}
39

UNCOV
40
int32_t tsdbOpen(SVnode *pVnode, STsdb **ppTsdb, const char *dir, STsdbKeepCfg *pKeepCfg, int8_t rollback, bool force) {
×
UNCOV
41
  STsdb  *pTsdb = NULL;
×
UNCOV
42
  int     slen = 0;
×
43
  int32_t code;
44
  int32_t lino;
45

UNCOV
46
  *ppTsdb = NULL;
×
UNCOV
47
  slen = strlen(pVnode->path) + strlen(dir) + 2;
×
48

49
  // create handle
UNCOV
50
  pTsdb = (STsdb *)taosMemoryCalloc(1, sizeof(*pTsdb) + slen);
×
UNCOV
51
  if (pTsdb == NULL) {
×
52
    TAOS_CHECK_RETURN(terrno);
×
53
  }
54

UNCOV
55
  pTsdb->path = (char *)&pTsdb[1];
×
UNCOV
56
  snprintf(pTsdb->path, TD_PATH_MAX, "%s%s%s", pVnode->path, TD_DIRSEP, dir);
×
57
  // taosRealPath(pTsdb->path, NULL, slen);
UNCOV
58
  pTsdb->pVnode = pVnode;
×
UNCOV
59
  (void)taosThreadMutexInit(&pTsdb->mutex, NULL);
×
UNCOV
60
  if (!pKeepCfg) {
×
UNCOV
61
    tsdbSetKeepCfg(pTsdb, &pVnode->config.tsdbCfg);
×
62
  } else {
UNCOV
63
    memcpy(&pTsdb->keepCfg, pKeepCfg, sizeof(STsdbKeepCfg));
×
64
  }
65

66
  // create dir
UNCOV
67
  if (pVnode->pTfs) {
×
UNCOV
68
    code = tfsMkdir(pVnode->pTfs, pTsdb->path);
×
UNCOV
69
    TSDB_CHECK_CODE(code, lino, _exit);
×
70
  } else {
71
    code = taosMkDir(pTsdb->path);
×
72
    TSDB_CHECK_CODE(code, lino, _exit);
×
73
  }
74

75
  // open tsdb
UNCOV
76
  code = tsdbOpenFS(pTsdb, &pTsdb->pFS, rollback);
×
UNCOV
77
  TSDB_CHECK_CODE(code, lino, _exit);
×
78

UNCOV
79
  if (pTsdb->pFS->fsstate == TSDB_FS_STATE_INCOMPLETE && force == false) {
×
80
    TAOS_CHECK_GOTO(TSDB_CODE_NEED_RETRY, &lino, _exit);
×
81
  }
82

UNCOV
83
  code = tsdbOpenCache(pTsdb);
×
UNCOV
84
  TSDB_CHECK_CODE(code, lino, _exit);
×
85

86
#ifdef TD_ENTERPRISE
UNCOV
87
  TAOS_CHECK_GOTO(tsdbOpenCompMonitor(pTsdb), &lino, _exit);
×
88
#endif
89

UNCOV
90
_exit:
×
UNCOV
91
  if (code) {
×
92
    tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(pVnode), __func__, __FILE__, lino, tstrerror(code));
×
93
    tsdbCloseFS(&pTsdb->pFS);
×
94
    (void)taosThreadMutexDestroy(&pTsdb->mutex);
×
95
    taosMemoryFree(pTsdb);
×
96
  } else {
UNCOV
97
    tsdbDebug("vgId:%d, tsdb is opened at %s, days:%d, keep:%d,%d,%d, keepTimeoffset:%d", TD_VID(pVnode), pTsdb->path,
×
98
              pTsdb->keepCfg.days, pTsdb->keepCfg.keep0, pTsdb->keepCfg.keep1, pTsdb->keepCfg.keep2,
99
              pTsdb->keepCfg.keepTimeOffset);
UNCOV
100
    *ppTsdb = pTsdb;
×
101
  }
UNCOV
102
  return code;
×
103
}
104

UNCOV
105
void tsdbClose(STsdb **pTsdb) {
×
UNCOV
106
  if (*pTsdb) {
×
UNCOV
107
    STsdb *pdb = *pTsdb;
×
UNCOV
108
    tsdbDebug("vgId:%d, tsdb is close at %s, days:%d, keep:%d,%d,%d, keepTimeOffset:%d", TD_VID(pdb->pVnode), pdb->path,
×
109
              pdb->keepCfg.days, pdb->keepCfg.keep0, pdb->keepCfg.keep1, pdb->keepCfg.keep2,
110
              pdb->keepCfg.keepTimeOffset);
UNCOV
111
    (void)taosThreadMutexLock(&(*pTsdb)->mutex);
×
UNCOV
112
    tsdbMemTableDestroy((*pTsdb)->mem, true);
×
UNCOV
113
    (*pTsdb)->mem = NULL;
×
UNCOV
114
    (void)taosThreadMutexUnlock(&(*pTsdb)->mutex);
×
115

UNCOV
116
    tsdbCloseFS(&(*pTsdb)->pFS);
×
UNCOV
117
    tsdbCloseCache(*pTsdb);
×
118
#ifdef TD_ENTERPRISE
UNCOV
119
    tsdbCloseCompMonitor(*pTsdb);
×
120
#endif
UNCOV
121
    (void)taosThreadMutexDestroy(&(*pTsdb)->mutex);
×
UNCOV
122
    taosMemoryFreeClear(*pTsdb);
×
123
  }
UNCOV
124
  return;
×
125
}
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