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

taosdata / TDengine / #4800

16 Oct 2025 09:19AM UTC coverage: 53.935% (-7.1%) from 61.083%
#4800

push

travis-ci

web-flow
Merge b32e3a393 into a190048d5

134724 of 323629 branches covered (41.63%)

Branch coverage included in aggregate %.

184803 of 268802 relevant lines covered (68.75%)

69058627.2 hits per line

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

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

29
  for (int32_t i = 0; i < colNum; ++i) {
11,045,888✔
30
    tstrncpy(schema[i].name, pSrc[i].name, sizeof(schema[i].name));
10,221,568!
31

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

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

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

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

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

56
  for (int32_t i = 0; i < size; ++i) {
989,184✔
57
    tstrncpy(meta.tbName, pSysDbTableMeta[i].name, sizeof(meta.tbName));
824,320!
58
    meta.numOfColumns = pSysDbTableMeta[i].colNum;
824,320✔
59

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

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

68
  TAOS_RETURN(code);
164,864✔
69
}
70

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

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

85
  *pRsp = *meta;
10,357✔
86

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

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

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

105
  STableMetaRsp *pMeta = taosHashGet(pMnode->perfsMeta, tbName, strlen(tbName));
×
106
  if (NULL == pMeta) {
×
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));
×
113
  tstrncpy(pRsp->stbName, pMeta->stbName, sizeof(pRsp->stbName));
×
114
  tstrncpy(pRsp->dbFName, pMeta->dbFName, sizeof(pRsp->dbFName));
×
115
  pRsp->numOfTags = pMeta->numOfTags;
×
116
  pRsp->numOfColumns = pMeta->numOfColumns;
×
117
  pRsp->tableType = pMeta->tableType;
×
118
  pRsp->virtualStb = pMeta->virtualStb;
×
119

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

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

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

139
  return mndPerfsInitMeta(pMnode->perfsMeta);
164,864✔
140
}
141

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

147
  void *pIter = taosHashIterate(pMnode->perfsMeta, NULL);
164,820✔
148
  while (pIter) {
988,920✔
149
    STableMetaRsp *meta = (STableMetaRsp *)pIter;
824,100✔
150

151
    taosMemoryFreeClear(meta->pSchemas);
824,100!
152

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

156
  taosHashCleanup(pMnode->perfsMeta);
164,820✔
157
  pMnode->perfsMeta = NULL;
164,820✔
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