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

taosdata / TDengine / #4912

04 Jan 2026 09:05AM UTC coverage: 64.888% (-0.1%) from 65.028%
#4912

push

travis-ci

web-flow
merge: from main to 3.0 branch #34156

1206 of 4524 new or added lines in 22 files covered. (26.66%)

5351 existing lines in 123 files now uncovered.

194856 of 300296 relevant lines covered (64.89%)

118198896.2 hits per line

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

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

28
  for (int32_t i = 0; i < colNum; ++i) {
206,482,786✔
29
    tstrncpy(schema[i].name, pSrc[i].name, sizeof(schema[i].name));
184,222,560✔
30
    schema[i].type = pSrc[i].type;
184,222,560✔
31
    schema[i].colId = i + 1;
184,222,560✔
32
    schema[i].bytes = pSrc[i].bytes;
184,222,560✔
33
    if (pSrc[i].sysInfo) {
184,222,560✔
34
      schema[i].flags |= COL_IS_SYSINFO;
80,213,573✔
35
    }
36
  }
37

38
  *pDst = schema;
22,260,226✔
39
  TAOS_RETURN(code);
22,260,226✔
40
}
41

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

46
  tstrncpy(meta.dbFName, TSDB_INFORMATION_SCHEMA_DB, sizeof(meta.dbFName));
383,797✔
47
  meta.tableType = TSDB_SYSTEM_TABLE;
383,797✔
48
  meta.sversion = 1;
383,797✔
49
  meta.tversion = 1;
383,797✔
50
  meta.rversion = 1;
383,797✔
51
  meta.virtualStb = false;
383,797✔
52

53
  size_t               size = 0;
383,797✔
54
  const SSysTableMeta *pInfosTableMeta = NULL;
383,797✔
55
  getInfosDbMeta(&pInfosTableMeta, &size);
383,797✔
56

57
  for (int32_t i = 0; i < size; ++i) {
22,644,023✔
58
    tstrncpy(meta.tbName, pInfosTableMeta[i].name, sizeof(meta.tbName));
22,260,226✔
59
    meta.numOfColumns = pInfosTableMeta[i].colNum;
22,260,226✔
60
    meta.sysInfo = pInfosTableMeta[i].sysInfo;
22,260,226✔
61

62
    TAOS_CHECK_RETURN(mndInitInfosTableSchema(pInfosTableMeta[i].schema, pInfosTableMeta[i].colNum, &meta.pSchemas));
22,260,226✔
63

64
    if (taosHashPut(hash, meta.tbName, strlen(meta.tbName), &meta, sizeof(meta))) {
22,260,226✔
65
      code = terrno;
×
66
      TAOS_RETURN(code);
×
67
    }
68
  }
69

70
  TAOS_RETURN(code);
383,797✔
71
}
72

73
int32_t mndBuildInsTableSchema(SMnode *pMnode, const char *dbFName, const char *tbName, bool sysinfo,
1,521,362✔
74
                               STableMetaRsp *pRsp) {
75
  int32_t code = 0;
1,521,362✔
76
  if (NULL == pMnode->infosMeta) {
1,521,362✔
77
    code = TSDB_CODE_APP_ERROR;
×
78
    TAOS_RETURN(code);
×
79
  }
80

81
  STableMetaRsp *pMeta = NULL;
1,521,362✔
82
  if (strcmp(tbName, TSDB_INS_TABLE_USERS_FULL) == 0) {
1,521,362✔
83
    pMeta = taosHashGet(pMnode->infosMeta, TSDB_INS_TABLE_USERS_FULL, strlen(tbName));
×
84
  } else {
85
    pMeta = taosHashGet(pMnode->infosMeta, tbName, strlen(tbName));
1,521,362✔
86
  }
87

88
  if (NULL == pMeta) {
1,521,362✔
89
    mError("invalid information schema table name:%s", tbName);
23,949✔
90
    code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
23,949✔
91
    TAOS_RETURN(code);
23,949✔
92
  }
93

94
  bool isShowAnodes = (strcmp(tbName, TSDB_INS_TABLE_ANODES) == 0 || strcmp(tbName, TSDB_INS_TABLE_ANODES_FULL) == 0);
1,497,413✔
95
  bool isShowXnodes = (strcmp(tbName, TSDB_INS_TABLE_XNODES) == 0 || strcmp(tbName, TSDB_INS_TABLE_XNODES_FULL) == 0);
1,497,413✔
96

97
  if (!isShowAnodes && !isShowXnodes && !sysinfo && pMeta->sysInfo) {
1,497,413✔
98
    mError("no permission to get schema of table name:%s", tbName);
3,807✔
99
    code = TSDB_CODE_PAR_PERMISSION_DENIED;
3,807✔
100
    TAOS_RETURN(code);
3,807✔
101
  }
102

103

104
  *pRsp = *pMeta;
1,493,606✔
105

106
  pRsp->pSchemas = taosMemoryCalloc(pMeta->numOfColumns, sizeof(SSchema));
1,493,606✔
107
  if (pRsp->pSchemas == NULL) {
1,493,606✔
UNCOV
108
    code = terrno;
×
UNCOV
109
    pRsp->pSchemas = NULL;
×
110
    TAOS_RETURN(code);
×
111
  }
112

113
  memcpy(pRsp->pSchemas, pMeta->pSchemas, pMeta->numOfColumns * sizeof(SSchema));
1,493,606✔
114
  TAOS_RETURN(code);
1,493,606✔
115
}
116

117
int32_t mndBuildInsTableCfg(SMnode *pMnode, const char *dbFName, const char *tbName, STableCfgRsp *pRsp) {
3,120✔
118
  int32_t code = 0;
3,120✔
119
  if (NULL == pMnode->infosMeta) {
3,120✔
UNCOV
120
    code = TSDB_CODE_APP_ERROR;
×
UNCOV
121
    TAOS_RETURN(code);
×
122
  }
123

124
  STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, tbName, strlen(tbName));
3,120✔
125
  if (NULL == pMeta) {
3,120✔
UNCOV
126
    mError("invalid information schema table name:%s", tbName);
×
UNCOV
127
    code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
×
128
    TAOS_RETURN(code);
×
129
  }
130

131
  tstrncpy(pRsp->tbName, pMeta->tbName, sizeof(pRsp->tbName));
3,120✔
132
  tstrncpy(pRsp->stbName, pMeta->stbName, sizeof(pRsp->stbName));
3,120✔
133
  tstrncpy(pRsp->dbFName, pMeta->dbFName, sizeof(pRsp->dbFName));
3,120✔
134
  pRsp->numOfTags = pMeta->numOfTags;
3,120✔
135
  pRsp->numOfColumns = pMeta->numOfColumns;
3,120✔
136
  pRsp->tableType = pMeta->tableType;
3,120✔
137
  pRsp->virtualStb = pMeta->virtualStb;
3,120✔
138

139
  pRsp->pSchemas = taosMemoryCalloc(pMeta->numOfColumns, sizeof(SSchema));
3,120✔
140
  if (pRsp->pSchemas == NULL) {
3,120✔
UNCOV
141
    code = terrno;
×
UNCOV
142
    pRsp->pSchemas = NULL;
×
143
    TAOS_RETURN(code);
×
144
  }
145

146
  memcpy(pRsp->pSchemas, pMeta->pSchemas, pMeta->numOfColumns * sizeof(SSchema));
3,120✔
147

148
  pRsp->pSchemaExt = taosMemoryCalloc(pMeta->numOfColumns, sizeof(SSchemaExt));
3,120✔
149
  pRsp->pColRefs = taosMemCalloc(pMeta->numOfColumns, sizeof(SColRef));
3,120✔
150
  TAOS_RETURN(code);
3,120✔
151
}
152

153
int32_t mndInitInfos(SMnode *pMnode) {
383,797✔
154
  pMnode->infosMeta = taosHashInit(20, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), false, HASH_NO_LOCK);
383,797✔
155
  if (pMnode->infosMeta == NULL) {
383,797✔
UNCOV
156
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
157
  }
158

159
  return mndInsInitMeta(pMnode->infosMeta);
383,797✔
160
}
161

162
void mndCleanupInfos(SMnode *pMnode) {
383,736✔
163
  if (NULL == pMnode->infosMeta) {
383,736✔
UNCOV
164
    return;
×
165
  }
166

167
  STableMetaRsp *pMeta = taosHashIterate(pMnode->infosMeta, NULL);
383,736✔
168
  while (pMeta) {
22,640,424✔
169
    taosMemoryFreeClear(pMeta->pSchemas);
22,256,688✔
170
    pMeta = taosHashIterate(pMnode->infosMeta, pMeta);
22,256,688✔
171
  }
172

173
  taosHashCleanup(pMnode->infosMeta);
383,736✔
174
  pMnode->infosMeta = NULL;
383,736✔
175
}
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