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

taosdata / TDengine / #4829

30 Oct 2025 09:25AM UTC coverage: 49.734% (-11.3%) from 61.071%
#4829

push

travis-ci

web-flow
Merge pull request #33435 from taosdata/3.0

merge 3.0

123072 of 323930 branches covered (37.99%)

Branch coverage included in aggregate %.

7 of 25 new or added lines in 3 files covered. (28.0%)

35232 existing lines in 327 files now uncovered.

172062 of 269495 relevant lines covered (63.85%)

70709785.06 hits per line

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

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

28
  for (int32_t i = 0; i < colNum; ++i) {
52,130,295✔
29
    tstrncpy(schema[i].name, pSrc[i].name, sizeof(schema[i].name));
46,270,215!
30
    schema[i].type = pSrc[i].type;
46,270,215✔
31
    schema[i].colId = i + 1;
46,270,215✔
32
    schema[i].bytes = pSrc[i].bytes;
46,270,215✔
33
    if (pSrc[i].sysInfo) {
46,270,215✔
34
      schema[i].flags |= COL_IS_SYSINFO;
19,533,600✔
35
    }
36
  }
37

38
  *pDst = schema;
5,860,080✔
39
  TAOS_RETURN(code);
5,860,080✔
40
}
41

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

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

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

57
  for (int32_t i = 0; i < size; ++i) {
5,982,165✔
58
    tstrncpy(meta.tbName, pInfosTableMeta[i].name, sizeof(meta.tbName));
5,860,080!
59
    meta.numOfColumns = pInfosTableMeta[i].colNum;
5,860,080✔
60
    meta.sysInfo = pInfosTableMeta[i].sysInfo;
5,860,080!
61

62
    TAOS_CHECK_RETURN(mndInitInfosTableSchema(pInfosTableMeta[i].schema, pInfosTableMeta[i].colNum, &meta.pSchemas));
5,860,080!
63

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

70
  TAOS_RETURN(code);
122,085✔
71
}
72

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

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

88
  if (NULL == pMeta) {
441,359!
UNCOV
89
    mError("invalid information schema table name:%s", tbName);
×
UNCOV
90
    code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
×
UNCOV
91
    TAOS_RETURN(code);
×
92
  }
93

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

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

102
  *pRsp = *pMeta;
441,359✔
103

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

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

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

UNCOV
122
  STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, tbName, strlen(tbName));
×
UNCOV
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

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

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

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

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

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

157
  return mndInsInitMeta(pMnode->infosMeta);
122,085✔
158
}
159

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

165
  STableMetaRsp *pMeta = taosHashIterate(pMnode->infosMeta, NULL);
122,015✔
166
  while (pMeta) {
5,978,735✔
167
    taosMemoryFreeClear(pMeta->pSchemas);
5,856,720!
168
    pMeta = taosHashIterate(pMnode->infosMeta, pMeta);
5,856,720✔
169
  }
170

171
  taosHashCleanup(pMnode->infosMeta);
122,015✔
172
  pMnode->infosMeta = NULL;
122,015✔
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