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

taosdata / TDengine / #3798

31 Mar 2025 10:39AM UTC coverage: 9.424% (-20.9%) from 30.372%
#3798

push

travis-ci

happyguoxy
test:add test cases

21549 of 307601 branches covered (7.01%)

Branch coverage included in aggregate %.

36084 of 303967 relevant lines covered (11.87%)

58620.7 hits per line

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

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

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

32
    schema[i].type = pSrc[i].type;
×
33
    schema[i].colId = i + 1;
×
34
    schema[i].bytes = pSrc[i].bytes;
×
35
  }
36

37
  *pDst = schema;
×
38
  TAOS_RETURN(code);
×
39
}
40

41
int32_t mndPerfsInitMeta(SHashObj *hash) {
×
42
  int32_t       code = 0;
×
43
  STableMetaRsp meta = {0};
×
44

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

51
  size_t               size = 0;
×
52
  const SSysTableMeta *pSysDbTableMeta = NULL;
×
53
  getPerfDbMeta(&pSysDbTableMeta, &size);
×
54

55
  for (int32_t i = 0; i < size; ++i) {
×
56
    tstrncpy(meta.tbName, pSysDbTableMeta[i].name, sizeof(meta.tbName));
×
57
    meta.numOfColumns = pSysDbTableMeta[i].colNum;
×
58

59
    TAOS_CHECK_RETURN(mndInitPerfsTableSchema(pSysDbTableMeta[i].schema, pSysDbTableMeta[i].colNum, &meta.pSchemas));
×
60

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

67
  TAOS_RETURN(code);
×
68
}
69

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

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

84
  *pRsp = *meta;
×
85

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

93
  memcpy(pRsp->pSchemas, meta->pSchemas, meta->numOfColumns * sizeof(SSchema));
×
94
  TAOS_RETURN(code);
×
95
}
96

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

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

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

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

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

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

138
  return mndPerfsInitMeta(pMnode->perfsMeta);
×
139
}
140

141
void mndCleanupPerfs(SMnode *pMnode) {
×
142
  if (NULL == pMnode->perfsMeta) {
×
143
    return;
×
144
  }
145

146
  void *pIter = taosHashIterate(pMnode->perfsMeta, NULL);
×
147
  while (pIter) {
×
148
    STableMetaRsp *meta = (STableMetaRsp *)pIter;
×
149

150
    taosMemoryFreeClear(meta->pSchemas);
×
151

152
    pIter = taosHashIterate(pMnode->perfsMeta, pIter);
×
153
  }
154

155
  taosHashCleanup(pMnode->perfsMeta);
×
156
  pMnode->perfsMeta = NULL;
×
157
}
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