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

taosdata / TDengine / #3565

25 Dec 2024 05:34AM UTC coverage: 51.098% (-11.1%) from 62.21%
#3565

push

travis-ci

web-flow
Merge pull request #29316 from taosdata/enh/3.0/TD-33266

enh(ut):Add wal & config UT.

111558 of 284773 branches covered (39.17%)

Branch coverage included in aggregate %.

1 of 2 new or added lines in 2 files covered. (50.0%)

39015 existing lines in 102 files now uncovered.

177882 of 281666 relevant lines covered (63.15%)

15090998.35 hits per line

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

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

22
void tsdbSetKeepCfg(STsdb *pTsdb, STsdbCfg *pCfg) {
18✔
23
  STsdbKeepCfg *pKeepCfg = &pTsdb->keepCfg;
18✔
24
  pKeepCfg->precision = pCfg->precision;
18✔
25
  pKeepCfg->days = pCfg->days;
18✔
26
  pKeepCfg->keep0 = pCfg->keep0;
18✔
27
  pKeepCfg->keep1 = pCfg->keep1;
18✔
28
  pKeepCfg->keep2 = pCfg->keep2;
18✔
29
  pKeepCfg->keepTimeOffset = pCfg->keepTimeOffset;
18✔
30
}
18✔
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

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

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

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

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

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

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

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

83
  code = tsdbOpenCache(pTsdb);
18✔
84
  TSDB_CHECK_CODE(code, lino, _exit);
18!
85

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

90
_exit:
18✔
91
  if (code) {
18!
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 {
97
    tsdbDebug("vgId:%d, tsdb is opened at %s, days:%d, keep:%d,%d,%d, keepTimeoffset:%d", TD_VID(pVnode), pTsdb->path,
18!
98
              pTsdb->keepCfg.days, pTsdb->keepCfg.keep0, pTsdb->keepCfg.keep1, pTsdb->keepCfg.keep2,
99
              pTsdb->keepCfg.keepTimeOffset);
100
    *ppTsdb = pTsdb;
18✔
101
  }
102
  return code;
18✔
103
}
104

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

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