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

taosdata / TDengine / #4069

12 May 2025 05:35AM UTC coverage: 63.048% (+0.5%) from 62.547%
#4069

push

travis-ci

web-flow
Merge pull request #31053 from taosdata/merge/mainto3.0

merge: from main to 3.0 branch

157521 of 317858 branches covered (49.56%)

Branch coverage included in aggregate %.

374 of 573 new or added lines in 31 files covered. (65.27%)

4949 existing lines in 87 files now uncovered.

242707 of 316936 relevant lines covered (76.58%)

18229906.31 hits per line

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

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

28
  for (int32_t i = 0; i < colNum; ++i) {
794,244✔
29
    tstrncpy(schema[i].name, pSrc[i].name, sizeof(schema[i].name));
711,100✔
30
    schema[i].type = pSrc[i].type;
711,100✔
31
    schema[i].colId = i + 1;
711,100✔
32
    schema[i].bytes = pSrc[i].bytes;
711,100✔
33
    if (pSrc[i].sysInfo) {
711,100✔
34
      schema[i].flags |= COL_IS_SYSINFO;
317,260✔
35
    }
36
  }
37

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

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

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

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

57
  for (int32_t i = 0; i < size; ++i) {
85,332✔
58
    tstrncpy(meta.tbName, pInfosTableMeta[i].name, sizeof(meta.tbName));
83,144✔
59
    meta.numOfColumns = pInfosTableMeta[i].colNum;
83,144✔
60
    meta.sysInfo = pInfosTableMeta[i].sysInfo;
83,144✔
61

62
    TAOS_CHECK_RETURN(mndInitInfosTableSchema(pInfosTableMeta[i].schema, pInfosTableMeta[i].colNum, &meta.pSchemas));
83,144!
63

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

70
  TAOS_RETURN(code);
2,188✔
71
}
72

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

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

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

94
  bool isShowAnodes = (strcmp(tbName, TSDB_INS_TABLE_ANODES) == 0 || strcmp(tbName, TSDB_INS_TABLE_ANODES_FULL) == 0);
225,144✔
95

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

102
  *pRsp = *pMeta;
225,104✔
103

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

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

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

122
  STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, tbName, strlen(tbName));
20✔
123
  if (NULL == pMeta) {
20!
UNCOV
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));
20✔
130
  tstrncpy(pRsp->stbName, pMeta->stbName, sizeof(pRsp->stbName));
20✔
131
  tstrncpy(pRsp->dbFName, pMeta->dbFName, sizeof(pRsp->dbFName));
20✔
132
  pRsp->numOfTags = pMeta->numOfTags;
20✔
133
  pRsp->numOfColumns = pMeta->numOfColumns;
20✔
134
  pRsp->tableType = pMeta->tableType;
20✔
135
  pRsp->virtualStb = pMeta->virtualStb;
20✔
136

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

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

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

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

157
  return mndInsInitMeta(pMnode->infosMeta);
2,188✔
158
}
159

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

165
  STableMetaRsp *pMeta = taosHashIterate(pMnode->infosMeta, NULL);
2,187✔
166
  while (pMeta) {
85,293✔
167
    taosMemoryFreeClear(pMeta->pSchemas);
83,106!
168
    pMeta = taosHashIterate(pMnode->infosMeta, pMeta);
83,106✔
169
  }
170

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