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

taosdata / TDengine / #3548

04 Dec 2024 01:03PM UTC coverage: 59.846% (-0.8%) from 60.691%
#3548

push

travis-ci

web-flow
Merge pull request #29033 from taosdata/fix/calculate-vnode-memory-used

fix/calculate-vnode-memory-used

118484 of 254183 branches covered (46.61%)

Branch coverage included in aggregate %.

199691 of 277471 relevant lines covered (71.97%)

18794141.86 hits per line

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

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

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

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

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

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

45
  tstrncpy(meta.dbFName, TSDB_PERFORMANCE_SCHEMA_DB, sizeof(meta.dbFName));
1,701✔
46
  meta.tableType = TSDB_SYSTEM_TABLE;
1,701✔
47
  meta.sversion = 1;
1,701✔
48
  meta.tversion = 1;
1,701✔
49

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

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

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

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

66
  TAOS_RETURN(code);
1,701✔
67
}
68

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

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

83
  *pRsp = *meta;
24,754✔
84

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

92
  memcpy(pRsp->pSchemas, meta->pSchemas, meta->numOfColumns * sizeof(SSchema));
24,754✔
93
  TAOS_RETURN(code);
24,754✔
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
  strcpy(pRsp->tbName, pMeta->tbName);
×
111
  strcpy(pRsp->stbName, pMeta->stbName);
×
112
  strcpy(pRsp->dbFName, pMeta->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) {
1,701✔
129
  int32_t code = 0;
1,701✔
130
  pMnode->perfsMeta = taosHashInit(20, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
1,701✔
131
  if (pMnode->perfsMeta == NULL) {
1,701!
132
    code = terrno;
×
133
    TAOS_RETURN(code);
×
134
  }
135

136
  return mndPerfsInitMeta(pMnode->perfsMeta);
1,701✔
137
}
138

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

144
  void *pIter = taosHashIterate(pMnode->perfsMeta, NULL);
1,701✔
145
  while (pIter) {
10,206✔
146
    STableMetaRsp *meta = (STableMetaRsp *)pIter;
8,505✔
147

148
    taosMemoryFreeClear(meta->pSchemas);
8,505!
149

150
    pIter = taosHashIterate(pMnode->perfsMeta, pIter);
8,505✔
151
  }
152

153
  taosHashCleanup(pMnode->perfsMeta);
1,701✔
154
  pMnode->perfsMeta = NULL;
1,701✔
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

© 2025 Coveralls, Inc