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

taosdata / TDengine / #4800

16 Oct 2025 09:19AM UTC coverage: 53.935% (-7.1%) from 61.083%
#4800

push

travis-ci

web-flow
Merge b32e3a393 into a190048d5

134724 of 323629 branches covered (41.63%)

Branch coverage included in aggregate %.

184803 of 268802 relevant lines covered (68.75%)

69058627.2 hits per line

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

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

28
  for (int32_t i = 0; i < colNum; ++i) {
70,447,741✔
29
    tstrncpy(schema[i].name, pSrc[i].name, sizeof(schema[i].name));
62,528,557!
30
    schema[i].type = pSrc[i].type;
62,528,557✔
31
    schema[i].colId = i + 1;
62,528,557✔
32
    schema[i].bytes = pSrc[i].bytes;
62,528,557✔
33
    if (pSrc[i].sysInfo) {
62,528,557✔
34
      schema[i].flags |= COL_IS_SYSINFO;
26,397,280✔
35
    }
36
  }
37

38
  *pDst = schema;
7,919,184✔
39
  TAOS_RETURN(code);
7,919,184✔
40
}
41

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

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

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

57
  for (int32_t i = 0; i < size; ++i) {
8,084,167✔
58
    tstrncpy(meta.tbName, pInfosTableMeta[i].name, sizeof(meta.tbName));
7,919,184!
59
    meta.numOfColumns = pInfosTableMeta[i].colNum;
7,919,184✔
60
    meta.sysInfo = pInfosTableMeta[i].sysInfo;
7,919,184!
61

62
    TAOS_CHECK_RETURN(mndInitInfosTableSchema(pInfosTableMeta[i].schema, pInfosTableMeta[i].colNum, &meta.pSchemas));
7,919,184!
63

64
    if (taosHashPut(hash, meta.tbName, strlen(meta.tbName), &meta, sizeof(meta))) {
7,919,184!
65
      code = terrno;
×
66
      TAOS_RETURN(code);
×
67
    }
68
  }
69

70
  TAOS_RETURN(code);
164,983✔
71
}
72

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

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

88
  if (NULL == pMeta) {
703,830✔
89
    mError("invalid information schema table name:%s", tbName);
39,714!
90
    code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
39,714✔
91
    TAOS_RETURN(code);
39,714✔
92
  }
93

94
  bool isShowAnodes = (strcmp(tbName, TSDB_INS_TABLE_ANODES) == 0 || strcmp(tbName, TSDB_INS_TABLE_ANODES_FULL) == 0);
664,116!
95

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

102
  *pRsp = *pMeta;
660,468✔
103

104
  pRsp->pSchemas = taosMemoryCalloc(pMeta->numOfColumns, sizeof(SSchema));
660,468!
105
  if (pRsp->pSchemas == NULL) {
660,468!
106
    code = terrno;
×
107
    pRsp->pSchemas = NULL;
×
108
    TAOS_RETURN(code);
×
109
  }
110

111
  memcpy(pRsp->pSchemas, pMeta->pSchemas, pMeta->numOfColumns * sizeof(SSchema));
660,468!
112
  TAOS_RETURN(code);
660,468✔
113
}
114

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

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

129
  tstrncpy(pRsp->tbName, pMeta->tbName, sizeof(pRsp->tbName));
×
130
  tstrncpy(pRsp->stbName, pMeta->stbName, sizeof(pRsp->stbName));
×
131
  tstrncpy(pRsp->dbFName, pMeta->dbFName, sizeof(pRsp->dbFName));
×
132
  pRsp->numOfTags = pMeta->numOfTags;
×
133
  pRsp->numOfColumns = pMeta->numOfColumns;
×
134
  pRsp->tableType = pMeta->tableType;
×
135
  pRsp->virtualStb = pMeta->virtualStb;
×
136

137
  pRsp->pSchemas = taosMemoryCalloc(pMeta->numOfColumns, sizeof(SSchema));
×
138
  if (pRsp->pSchemas == NULL) {
×
139
    code = terrno;
×
140
    pRsp->pSchemas = NULL;
×
141
    TAOS_RETURN(code);
×
142
  }
143

144
  memcpy(pRsp->pSchemas, pMeta->pSchemas, pMeta->numOfColumns * sizeof(SSchema));
×
145

146
  pRsp->pSchemaExt = taosMemoryCalloc(pMeta->numOfColumns, sizeof(SSchemaExt));
×
147
  pRsp->pColRefs = taosMemCalloc(pMeta->numOfColumns, sizeof(SColRef));
×
148
  TAOS_RETURN(code);
×
149
}
150

151
int32_t mndInitInfos(SMnode *pMnode) {
164,983✔
152
  pMnode->infosMeta = taosHashInit(20, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), false, HASH_NO_LOCK);
164,983✔
153
  if (pMnode->infosMeta == NULL) {
164,983!
154
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
155
  }
156

157
  return mndInsInitMeta(pMnode->infosMeta);
164,983✔
158
}
159

160
void mndCleanupInfos(SMnode *pMnode) {
164,939✔
161
  if (NULL == pMnode->infosMeta) {
164,939!
162
    return;
×
163
  }
164

165
  STableMetaRsp *pMeta = taosHashIterate(pMnode->infosMeta, NULL);
164,939✔
166
  while (pMeta) {
8,082,011✔
167
    taosMemoryFreeClear(pMeta->pSchemas);
7,917,072!
168
    pMeta = taosHashIterate(pMnode->infosMeta, pMeta);
7,917,072✔
169
  }
170

171
  taosHashCleanup(pMnode->infosMeta);
164,939✔
172
  pMnode->infosMeta = NULL;
164,939✔
173
}
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