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

taosdata / TDengine / #4069

12 May 2025 05:35AM UTC coverage: 63.048% (+0.5%) from 62.547%
#4069

push

travis-ci

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

merge: from main to 3.0 branch

157521 of 317858 branches covered (49.56%)

Branch coverage included in aggregate %.

374 of 573 new or added lines in 31 files covered. (65.27%)

4949 existing lines in 87 files now uncovered.

242707 of 316936 relevant lines covered (76.58%)

18229906.31 hits per line

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

70.42
/source/dnode/mnode/impl/src/mndPerfSchema.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
#define _DEFAULT_SOURCE
17
#include "mndInt.h"
18
#include "systable.h"
19

20
// connection/application/
21
int32_t mndInitPerfsTableSchema(const SSysDbTableSchema *pSrc, int32_t colNum, SSchema **pDst) {
10,940✔
22
  int32_t  code = 0;
10,940✔
23
  SSchema *schema = taosMemoryCalloc(colNum, sizeof(SSchema));
10,940!
24
  if (NULL == schema) {
10,940!
25
    code = terrno;
×
26
    TAOS_RETURN(code);
×
27
  }
28

29
  for (int32_t i = 0; i < colNum; ++i) {
144,408✔
30
    tstrncpy(schema[i].name, pSrc[i].name, sizeof(schema[i].name));
133,468✔
31

32
    schema[i].type = pSrc[i].type;
133,468✔
33
    schema[i].colId = i + 1;
133,468✔
34
    schema[i].bytes = pSrc[i].bytes;
133,468✔
35
  }
36

37
  *pDst = schema;
10,940✔
38
  TAOS_RETURN(code);
10,940✔
39
}
40

41
int32_t mndPerfsInitMeta(SHashObj *hash) {
2,188✔
42
  int32_t       code = 0;
2,188✔
43
  STableMetaRsp meta = {0};
2,188✔
44

45
  tstrncpy(meta.dbFName, TSDB_PERFORMANCE_SCHEMA_DB, sizeof(meta.dbFName));
2,188✔
46
  meta.tableType = TSDB_SYSTEM_TABLE;
2,188✔
47
  meta.sversion = 1;
2,188✔
48
  meta.tversion = 1;
2,188✔
49
  meta.rversion = 1;
2,188✔
50
  meta.virtualStb = false;
2,188✔
51

52
  size_t               size = 0;
2,188✔
53
  const SSysTableMeta *pSysDbTableMeta = NULL;
2,188✔
54
  getPerfDbMeta(&pSysDbTableMeta, &size);
2,188✔
55

56
  for (int32_t i = 0; i < size; ++i) {
13,128✔
57
    tstrncpy(meta.tbName, pSysDbTableMeta[i].name, sizeof(meta.tbName));
10,940✔
58
    meta.numOfColumns = pSysDbTableMeta[i].colNum;
10,940✔
59

60
    TAOS_CHECK_RETURN(mndInitPerfsTableSchema(pSysDbTableMeta[i].schema, pSysDbTableMeta[i].colNum, &meta.pSchemas));
10,940!
61

62
    if (taosHashPut(hash, meta.tbName, strlen(meta.tbName), &meta, sizeof(meta))) {
10,940!
UNCOV
63
      code = terrno;
×
64
      TAOS_RETURN(code);
×
65
    }
66
  }
67

68
  TAOS_RETURN(code);
2,188✔
69
}
70

71
int32_t mndBuildPerfsTableSchema(SMnode *pMnode, const char *dbFName, const char *tbName, STableMetaRsp *pRsp) {
53,560✔
72
  int32_t code = 0;
53,560✔
73
  if (NULL == pMnode->perfsMeta) {
53,560!
UNCOV
74
    code = TSDB_CODE_APP_ERROR;
×
75
    TAOS_RETURN(code);
×
76
  }
77

78
  STableMetaRsp *meta = (STableMetaRsp *)taosHashGet(pMnode->perfsMeta, tbName, strlen(tbName));
53,560✔
79
  if (NULL == meta) {
53,560✔
80
    mError("invalid performance schema table name:%s", tbName);
214!
81
    code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
214✔
82
    TAOS_RETURN(code);
214✔
83
  }
84

85
  *pRsp = *meta;
53,346✔
86

87
  pRsp->pSchemas = taosMemoryCalloc(meta->numOfColumns, sizeof(SSchema));
53,346!
88
  if (pRsp->pSchemas == NULL) {
53,346!
UNCOV
89
    code = terrno;
×
90
    pRsp->pSchemas = NULL;
×
91
    TAOS_RETURN(code);
×
92
  }
93

94
  memcpy(pRsp->pSchemas, meta->pSchemas, meta->numOfColumns * sizeof(SSchema));
53,346✔
95
  TAOS_RETURN(code);
53,346✔
96
}
97

98
int32_t mndBuildPerfsTableCfg(SMnode *pMnode, const char *dbFName, const char *tbName, STableCfgRsp *pRsp) {
10✔
99
  int32_t code = 0;
10✔
100
  if (NULL == pMnode->perfsMeta) {
10!
UNCOV
101
    code = TSDB_CODE_APP_ERROR;
×
102
    TAOS_RETURN(code);
×
103
  }
104

105
  STableMetaRsp *pMeta = taosHashGet(pMnode->perfsMeta, tbName, strlen(tbName));
10✔
106
  if (NULL == pMeta) {
10!
UNCOV
107
    mError("invalid performance schema table name:%s", tbName);
×
108
    code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
×
109
    TAOS_RETURN(code);
×
110
  }
111

112
  tstrncpy(pRsp->tbName, pMeta->tbName, sizeof(pRsp->tbName));
10✔
113
  tstrncpy(pRsp->stbName, pMeta->stbName, sizeof(pRsp->stbName));
10✔
114
  tstrncpy(pRsp->dbFName, pMeta->dbFName, sizeof(pRsp->dbFName));
10✔
115
  pRsp->numOfTags = pMeta->numOfTags;
10✔
116
  pRsp->numOfColumns = pMeta->numOfColumns;
10✔
117
  pRsp->tableType = pMeta->tableType;
10✔
118
  pRsp->virtualStb = pMeta->virtualStb;
10✔
119

120
  pRsp->pSchemas = taosMemoryCalloc(pMeta->numOfColumns, sizeof(SSchema));
10!
121
  if (pRsp->pSchemas == NULL) {
10!
UNCOV
122
    code = terrno;
×
123
    pRsp->pSchemas = NULL;
×
124
    TAOS_RETURN(code);
×
125
  }
126

127
  memcpy(pRsp->pSchemas, pMeta->pSchemas, pMeta->numOfColumns * sizeof(SSchema));
10✔
128
  TAOS_RETURN(code);
10✔
129
}
130

131
int32_t mndInitPerfs(SMnode *pMnode) {
2,188✔
132
  int32_t code = 0;
2,188✔
133
  pMnode->perfsMeta = taosHashInit(20, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
2,188✔
134
  if (pMnode->perfsMeta == NULL) {
2,188!
UNCOV
135
    code = terrno;
×
136
    TAOS_RETURN(code);
×
137
  }
138

139
  return mndPerfsInitMeta(pMnode->perfsMeta);
2,188✔
140
}
141

142
void mndCleanupPerfs(SMnode *pMnode) {
2,187✔
143
  if (NULL == pMnode->perfsMeta) {
2,187!
UNCOV
144
    return;
×
145
  }
146

147
  void *pIter = taosHashIterate(pMnode->perfsMeta, NULL);
2,187✔
148
  while (pIter) {
13,122✔
149
    STableMetaRsp *meta = (STableMetaRsp *)pIter;
10,935✔
150

151
    taosMemoryFreeClear(meta->pSchemas);
10,935!
152

153
    pIter = taosHashIterate(pMnode->perfsMeta, pIter);
10,935✔
154
  }
155

156
  taosHashCleanup(pMnode->perfsMeta);
2,187✔
157
  pMnode->perfsMeta = NULL;
2,187✔
158
}
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