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

taosdata / TDengine / #3599

08 Feb 2025 11:23AM UTC coverage: 1.77% (-61.6%) from 63.396%
#3599

push

travis-ci

web-flow
Merge pull request #29712 from taosdata/fix/TD-33652-3.0

fix: reduce write rows from 30w to 3w

3776 of 278949 branches covered (1.35%)

Branch coverage included in aggregate %.

6012 of 274147 relevant lines covered (2.19%)

1642.73 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

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

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

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

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

66
  TAOS_RETURN(code);
×
67
}
68

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

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

83
  *pRsp = *meta;
×
84

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

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

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

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

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

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

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

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

136
  return mndPerfsInitMeta(pMnode->perfsMeta);
×
137
}
138

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

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

148
    taosMemoryFreeClear(meta->pSchemas);
×
149

150
    pIter = taosHashIterate(pMnode->perfsMeta, pIter);
×
151
  }
152

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