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

taosdata / TDengine / #4944

30 Jan 2026 06:19AM UTC coverage: 66.849% (+0.1%) from 66.718%
#4944

push

travis-ci

web-flow
merge: from main to 3.0 #34453

1124 of 2018 new or added lines in 72 files covered. (55.7%)

13677 existing lines in 155 files now uncovered.

205211 of 306978 relevant lines covered (66.85%)

125657591.7 hits per line

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

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

28
  for (int32_t i = 0; i < colNum; ++i) {
224,543,554✔
29
    tstrncpy(schema[i].name, pSrc[i].name, sizeof(schema[i].name));
200,514,908✔
30
    schema[i].type = pSrc[i].type;
200,514,908✔
31
    schema[i].colId = i + 1;
200,514,908✔
32
    schema[i].bytes = pSrc[i].bytes;
200,514,908✔
33
    if (pSrc[i].sysInfo) {
200,514,908✔
34
      schema[i].flags |= COL_IS_SYSINFO;
87,000,270✔
35
    }
36
  }
37

38
  *pDst = schema;
24,028,646✔
39
  TAOS_RETURN(code);
24,028,646✔
40
}
41

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

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

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

57
  for (int32_t i = 0; i < size; ++i) {
24,442,933✔
58
    tstrncpy(meta.tbName, pInfosTableMeta[i].name, sizeof(meta.tbName));
24,028,646✔
59
    meta.numOfColumns = pInfosTableMeta[i].colNum;
24,028,646✔
60
    meta.sysInfo = pInfosTableMeta[i].sysInfo;
24,028,646✔
61
    meta.privCat = pInfosTableMeta[i].privCat;
24,028,646✔
62

63
    TAOS_CHECK_RETURN(mndInitInfosTableSchema(pInfosTableMeta[i].schema, pInfosTableMeta[i].colNum, &meta.pSchemas));
24,028,646✔
64

65
    if (taosHashPut(hash, meta.tbName, strlen(meta.tbName), &meta, sizeof(meta))) {
24,028,646✔
UNCOV
66
      code = terrno;
×
67
      TAOS_RETURN(code);
×
68
    }
69
  }
70

71
  TAOS_RETURN(code);
414,287✔
72
}
73

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

82
  STableMetaRsp *pMeta = NULL;
1,727,278✔
83
  if (strcmp(tbName, TSDB_INS_TABLE_USERS_FULL) == 0) {
1,727,278✔
84
    pMeta = taosHashGet(pMnode->infosMeta, TSDB_INS_TABLE_USERS_FULL, strlen(tbName));
138✔
85
  } else {
86
    pMeta = taosHashGet(pMnode->infosMeta, tbName, strlen(tbName));
1,727,140✔
87
  }
88

89
  if (NULL == pMeta) {
1,727,278✔
90
    mError("invalid information schema table name:%s", tbName);
71,036✔
91
    code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
71,036✔
92
    TAOS_RETURN(code);
71,036✔
93
  }
94

95
  if (!sysinfo && pMeta->sysInfo) {
1,656,242✔
96
    if (!(strcmp(tbName, TSDB_INS_TABLE_ANODES) == 0 || strcmp(tbName, TSDB_INS_TABLE_ANODES_FULL) == 0 ||
5,177✔
97
          strcmp(tbName, TSDB_INS_TABLE_XNODES) == 0 || strcmp(tbName, TSDB_INS_TABLE_XNODES_FULL) == 0 ||
5,010✔
98
          strcmp(tbName, TSDB_INS_TABLE_LICENCES) == 0)) {
5,010✔
99
      mError("no permission to get schema of table name:%s", tbName);
4,843✔
100
      code = TSDB_CODE_PAR_PERMISSION_DENIED;
4,843✔
101
      TAOS_RETURN(code);
4,843✔
102
    }
103
  }
104

105
  *pRsp = *pMeta;
1,651,399✔
106

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

114
  memcpy(pRsp->pSchemas, pMeta->pSchemas, pMeta->numOfColumns * sizeof(SSchema));
1,651,399✔
115
  TAOS_RETURN(code);
1,651,399✔
116
}
117

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

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

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

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

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

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

154
int32_t mndInitInfos(SMnode *pMnode) {
414,287✔
155
  size_t size = 0;
414,287✔
156
  getInfosDbMeta(NULL, &size);
414,287✔
157
  pMnode->infosMeta = taosHashInit(size, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), false, HASH_NO_LOCK);
414,287✔
158
  if (pMnode->infosMeta == NULL) {
414,287✔
UNCOV
159
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
160
  }
161

162
  return mndInsInitMeta(pMnode->infosMeta);
414,287✔
163
}
164

165
void mndCleanupInfos(SMnode *pMnode) {
414,227✔
166
  if (NULL == pMnode->infosMeta) {
414,227✔
UNCOV
167
    return;
×
168
  }
169

170
  STableMetaRsp *pMeta = taosHashIterate(pMnode->infosMeta, NULL);
414,227✔
171
  while (pMeta) {
24,439,393✔
172
    taosMemoryFreeClear(pMeta->pSchemas);
24,025,166✔
173
    pMeta = taosHashIterate(pMnode->infosMeta, pMeta);
24,025,166✔
174
  }
175

176
  taosHashCleanup(pMnode->infosMeta);
414,227✔
177
  pMnode->infosMeta = NULL;
414,227✔
178
}
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