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

taosdata / TDengine / #4548

22 Jul 2025 02:37AM UTC coverage: 54.273% (-3.0%) from 57.287%
#4548

push

travis-ci

GitHub
Merge pull request #32061 from taosdata/new_testcases

132738 of 315239 branches covered (42.11%)

Branch coverage included in aggregate %.

201371 of 300373 relevant lines covered (67.04%)

3475977.14 hits per line

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

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

28
  for (int32_t i = 0; i < colNum; ++i) {
720,090✔
29
    tstrncpy(schema[i].name, pSrc[i].name, sizeof(schema[i].name));
640,080✔
30
    schema[i].type = pSrc[i].type;
640,080✔
31
    schema[i].colId = i + 1;
640,080✔
32
    schema[i].bytes = pSrc[i].bytes;
640,080✔
33
    if (pSrc[i].sysInfo) {
640,080✔
34
      schema[i].flags |= COL_IS_SYSINFO;
304,800✔
35
    }
36
  }
37

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

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

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

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

57
  for (int32_t i = 0; i < size; ++i) {
81,915✔
58
    tstrncpy(meta.tbName, pInfosTableMeta[i].name, sizeof(meta.tbName));
80,010✔
59
    meta.numOfColumns = pInfosTableMeta[i].colNum;
80,010✔
60
    meta.sysInfo = pInfosTableMeta[i].sysInfo;
80,010✔
61

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

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

70
  TAOS_RETURN(code);
1,905✔
71
}
72

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

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

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

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

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

102
  *pRsp = *pMeta;
4,777✔
103

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

111
  memcpy(pRsp->pSchemas, pMeta->pSchemas, pMeta->numOfColumns * sizeof(SSchema));
4,777✔
112
  TAOS_RETURN(code);
4,777✔
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) {
1,905✔
152
  pMnode->infosMeta = taosHashInit(20, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), false, HASH_NO_LOCK);
1,905✔
153
  if (pMnode->infosMeta == NULL) {
1,905!
154
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
155
  }
156

157
  return mndInsInitMeta(pMnode->infosMeta);
1,905✔
158
}
159

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

165
  STableMetaRsp *pMeta = taosHashIterate(pMnode->infosMeta, NULL);
1,905✔
166
  while (pMeta) {
81,915✔
167
    taosMemoryFreeClear(pMeta->pSchemas);
80,010!
168
    pMeta = taosHashIterate(pMnode->infosMeta, pMeta);
80,010✔
169
  }
170

171
  taosHashCleanup(pMnode->infosMeta);
1,905✔
172
  pMnode->infosMeta = NULL;
1,905✔
173
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc