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

taosdata / TDengine / #4944

30 Jan 2026 06:19AM UTC coverage: 66.849% (+0.1%) from 66.718%
#4944

push

travis-ci

web-flow
merge: from main to 3.0 #34453

1124 of 2018 new or added lines in 72 files covered. (55.7%)

13677 existing lines in 155 files now uncovered.

205211 of 306978 relevant lines covered (66.85%)

125657591.7 hits per line

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

78.72
/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) {
2,495,544✔
22
  int32_t  code = 0;
2,495,544✔
23
  SSchema *schema = taosMemoryCalloc(colNum, sizeof(SSchema));
2,495,544✔
24
  if (NULL == schema) {
2,495,544✔
25
    code = terrno;
×
26
    TAOS_RETURN(code);
×
27
  }
28

29
  for (int32_t i = 0; i < colNum; ++i) {
32,442,072✔
30
    tstrncpy(schema[i].name, pSrc[i].name, sizeof(schema[i].name));
29,946,528✔
31

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

37
  *pDst = schema;
2,495,544✔
38
  TAOS_RETURN(code);
2,495,544✔
39
}
40

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

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

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

56
  for (int32_t i = 0; i < size; ++i) {
2,911,468✔
57
    tstrncpy(meta.tbName, pSysDbTableMeta[i].name, sizeof(meta.tbName));
2,495,544✔
58
    meta.numOfColumns = pSysDbTableMeta[i].colNum;
2,495,544✔
59
    meta.sysInfo = pSysDbTableMeta[i].sysInfo;
2,495,544✔
60
    meta.privCat = pSysDbTableMeta[i].privCat;
2,495,544✔
61

62
    TAOS_CHECK_RETURN(mndInitPerfsTableSchema(pSysDbTableMeta[i].schema, pSysDbTableMeta[i].colNum, &meta.pSchemas));
2,495,544✔
63

64
    if (taosHashPut(hash, meta.tbName, strlen(meta.tbName), &meta, sizeof(meta))) {
2,495,544✔
UNCOV
65
      code = terrno;
×
UNCOV
66
      TAOS_RETURN(code);
×
67
    }
68
  }
69

70
  TAOS_RETURN(code);
415,924✔
71
}
72

73
int32_t mndBuildPerfsTableSchema(SMnode *pMnode, const char *dbFName, const char *tbName, STableMetaRsp *pRsp) {
134,811✔
74
  int32_t code = 0;
134,811✔
75
  if (NULL == pMnode->perfsMeta) {
134,811✔
UNCOV
76
    code = TSDB_CODE_APP_ERROR;
×
UNCOV
77
    TAOS_RETURN(code);
×
78
  }
79

80
  STableMetaRsp *meta = (STableMetaRsp *)taosHashGet(pMnode->perfsMeta, tbName, strlen(tbName));
134,811✔
81
  if (NULL == meta) {
134,811✔
82
    mError("invalid performance schema table name:%s", tbName);
89,900✔
83
    code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
89,900✔
84
    TAOS_RETURN(code);
89,900✔
85
  }
86

87
  *pRsp = *meta;
44,911✔
88

89
  pRsp->pSchemas = taosMemoryCalloc(meta->numOfColumns, sizeof(SSchema));
44,911✔
90
  if (pRsp->pSchemas == NULL) {
44,911✔
UNCOV
91
    code = terrno;
×
UNCOV
92
    pRsp->pSchemas = NULL;
×
93
    TAOS_RETURN(code);
×
94
  }
95

96
  memcpy(pRsp->pSchemas, meta->pSchemas, meta->numOfColumns * sizeof(SSchema));
44,911✔
97
  TAOS_RETURN(code);
44,911✔
98
}
99

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

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

114
  tstrncpy(pRsp->tbName, pMeta->tbName, sizeof(pRsp->tbName));
1,710✔
115
  tstrncpy(pRsp->stbName, pMeta->stbName, sizeof(pRsp->stbName));
1,710✔
116
  tstrncpy(pRsp->dbFName, pMeta->dbFName, sizeof(pRsp->dbFName));
1,710✔
117
  pRsp->numOfTags = pMeta->numOfTags;
1,710✔
118
  pRsp->numOfColumns = pMeta->numOfColumns;
1,710✔
119
  pRsp->tableType = pMeta->tableType;
1,710✔
120
  pRsp->virtualStb = pMeta->virtualStb;
1,710✔
121

122
  pRsp->pSchemas = taosMemoryCalloc(pMeta->numOfColumns, sizeof(SSchema));
1,710✔
123
  if (pRsp->pSchemas == NULL) {
1,710✔
UNCOV
124
    code = terrno;
×
UNCOV
125
    pRsp->pSchemas = NULL;
×
126
    TAOS_RETURN(code);
×
127
  }
128

129
  memcpy(pRsp->pSchemas, pMeta->pSchemas, pMeta->numOfColumns * sizeof(SSchema));
1,710✔
130
  TAOS_RETURN(code);
1,710✔
131
}
132

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

141
  return mndPerfsInitMeta(pMnode->perfsMeta);
415,924✔
142
}
143

144
void mndCleanupPerfs(SMnode *pMnode) {
415,864✔
145
  if (NULL == pMnode->perfsMeta) {
415,864✔
UNCOV
146
    return;
×
147
  }
148

149
  void *pIter = taosHashIterate(pMnode->perfsMeta, NULL);
415,864✔
150
  while (pIter) {
2,911,048✔
151
    STableMetaRsp *meta = (STableMetaRsp *)pIter;
2,495,184✔
152

153
    taosMemoryFreeClear(meta->pSchemas);
2,495,184✔
154

155
    pIter = taosHashIterate(pMnode->perfsMeta, pIter);
2,495,184✔
156
  }
157

158
  taosHashCleanup(pMnode->perfsMeta);
415,864✔
159
  pMnode->perfsMeta = NULL;
415,864✔
160
}
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