• 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

60.99
/source/dnode/mnode/impl/src/mndInfoSchema.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
static int32_t mndInitInfosTableSchema(const SSysDbTableSchema *pSrc, int32_t colNum, SSchema **pDst) {
61,236✔
21
  int32_t  code = 0;
61,236✔
22
  SSchema *schema = taosMemoryCalloc(colNum, sizeof(SSchema));
61,236✔
23
  if (NULL == schema) {
61,236!
24
    code = terrno;
×
25
    TAOS_RETURN(code);
×
26
  }
27

28
  for (int32_t i = 0; i < colNum; ++i) {
557,928✔
29
    tstrncpy(schema[i].name, pSrc[i].name, sizeof(schema[i].name));
496,692✔
30
    schema[i].type = pSrc[i].type;
496,692✔
31
    schema[i].colId = i + 1;
496,692✔
32
    schema[i].bytes = pSrc[i].bytes;
496,692✔
33
    if (pSrc[i].sysInfo) {
496,692✔
34
      schema[i].flags |= COL_IS_SYSINFO;
253,449✔
35
    }
36
  }
37

38
  *pDst = schema;
61,236✔
39
  TAOS_RETURN(code);
61,236✔
40
}
41

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

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

51
  size_t               size = 0;
1,701✔
52
  const SSysTableMeta *pInfosTableMeta = NULL;
1,701✔
53
  getInfosDbMeta(&pInfosTableMeta, &size);
1,701✔
54

55
  for (int32_t i = 0; i < size; ++i) {
62,937✔
56
    tstrncpy(meta.tbName, pInfosTableMeta[i].name, sizeof(meta.tbName));
61,236✔
57
    meta.numOfColumns = pInfosTableMeta[i].colNum;
61,236✔
58
    meta.sysInfo = pInfosTableMeta[i].sysInfo;
61,236✔
59

60
    TAOS_CHECK_RETURN(mndInitInfosTableSchema(pInfosTableMeta[i].schema, pInfosTableMeta[i].colNum, &meta.pSchemas));
61,236!
61

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

68
  TAOS_RETURN(code);
1,701✔
69
}
70

71
int32_t mndBuildInsTableSchema(SMnode *pMnode, const char *dbFName, const char *tbName, bool sysinfo,
105,982✔
72
                               STableMetaRsp *pRsp) {
73
  int32_t code = 0;
105,982✔
74
  if (NULL == pMnode->infosMeta) {
105,982!
75
    code = TSDB_CODE_APP_ERROR;
×
76
    TAOS_RETURN(code);
×
77
  }
78

79
  STableMetaRsp *pMeta = NULL;
105,982✔
80
  if (strcmp(tbName, TSDB_INS_TABLE_USERS_FULL) == 0) {
105,982!
81
    pMeta = taosHashGet(pMnode->infosMeta, TSDB_INS_TABLE_USERS_FULL, strlen(tbName));
×
82
  } else {
83
    pMeta = taosHashGet(pMnode->infosMeta, tbName, strlen(tbName));
105,982✔
84
  }
85

86
  if (NULL == pMeta) {
105,982✔
87
    mError("invalid information schema table name:%s", tbName);
120!
88
    code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
120✔
89
    TAOS_RETURN(code);
120✔
90
  }
91

92
  if (!sysinfo && pMeta->sysInfo) {
105,862✔
93
    mError("no permission to get schema of table name:%s", tbName);
25!
94
    code = TSDB_CODE_PAR_PERMISSION_DENIED;
25✔
95
    TAOS_RETURN(code);
25✔
96
  }
97

98
  *pRsp = *pMeta;
105,837✔
99

100
  pRsp->pSchemas = taosMemoryCalloc(pMeta->numOfColumns, sizeof(SSchema));
105,837✔
101
  if (pRsp->pSchemas == NULL) {
105,837!
102
    code = terrno;
×
103
    pRsp->pSchemas = NULL;
×
104
    TAOS_RETURN(code);
×
105
  }
106

107
  memcpy(pRsp->pSchemas, pMeta->pSchemas, pMeta->numOfColumns * sizeof(SSchema));
105,837✔
108
  TAOS_RETURN(code);
105,837✔
109
}
110

111
int32_t mndBuildInsTableCfg(SMnode *pMnode, const char *dbFName, const char *tbName, STableCfgRsp *pRsp) {
×
112
  int32_t code = 0;
×
113
  if (NULL == pMnode->infosMeta) {
×
114
    code = TSDB_CODE_APP_ERROR;
×
115
    TAOS_RETURN(code);
×
116
  }
117

118
  STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, tbName, strlen(tbName));
×
119
  if (NULL == pMeta) {
×
120
    mError("invalid information schema table name:%s", tbName);
×
121
    code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
×
122
    TAOS_RETURN(code);
×
123
  }
124

125
  strcpy(pRsp->tbName, pMeta->tbName);
×
126
  strcpy(pRsp->stbName, pMeta->stbName);
×
127
  strcpy(pRsp->dbFName, pMeta->dbFName);
×
128
  pRsp->numOfTags = pMeta->numOfTags;
×
129
  pRsp->numOfColumns = pMeta->numOfColumns;
×
130
  pRsp->tableType = pMeta->tableType;
×
131

132
  pRsp->pSchemas = taosMemoryCalloc(pMeta->numOfColumns, sizeof(SSchema));
×
133
  if (pRsp->pSchemas == NULL) {
×
134
    code = terrno;
×
135
    pRsp->pSchemas = NULL;
×
136
    TAOS_RETURN(code);
×
137
  }
138

139
  memcpy(pRsp->pSchemas, pMeta->pSchemas, pMeta->numOfColumns * sizeof(SSchema));
×
140

141
  pRsp->pSchemaExt = taosMemoryCalloc(pMeta->numOfColumns, sizeof(SSchemaExt));
×
142
  TAOS_RETURN(code);
×
143
}
144

145
int32_t mndInitInfos(SMnode *pMnode) {
1,701✔
146
  pMnode->infosMeta = taosHashInit(20, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), false, HASH_NO_LOCK);
1,701✔
147
  if (pMnode->infosMeta == NULL) {
1,701!
148
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
149
  }
150

151
  return mndInsInitMeta(pMnode->infosMeta);
1,701✔
152
}
153

154
void mndCleanupInfos(SMnode *pMnode) {
1,701✔
155
  if (NULL == pMnode->infosMeta) {
1,701!
156
    return;
×
157
  }
158

159
  STableMetaRsp *pMeta = taosHashIterate(pMnode->infosMeta, NULL);
1,701✔
160
  while (pMeta) {
62,937✔
161
    taosMemoryFreeClear(pMeta->pSchemas);
61,236!
162
    pMeta = taosHashIterate(pMnode->infosMeta, pMeta);
61,236✔
163
  }
164

165
  taosHashCleanup(pMnode->infosMeta);
1,701✔
166
  pMnode->infosMeta = NULL;
1,701✔
167
}
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