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

taosdata / TDengine / #4143

24 May 2025 03:30AM UTC coverage: 32.868% (-29.4%) from 62.238%
#4143

push

travis-ci

web-flow
test: migrate stream cases (#31164)

76401 of 312956 branches covered (24.41%)

Branch coverage included in aggregate %.

128686 of 311012 relevant lines covered (41.38%)

579734.08 hits per line

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

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

28
  for (int32_t i = 0; i < colNum; ++i) {
5,445✔
29
    tstrncpy(schema[i].name, pSrc[i].name, sizeof(schema[i].name));
4,875✔
30
    schema[i].type = pSrc[i].type;
4,875✔
31
    schema[i].colId = i + 1;
4,875✔
32
    schema[i].bytes = pSrc[i].bytes;
4,875✔
33
    if (pSrc[i].sysInfo) {
4,875✔
34
      schema[i].flags |= COL_IS_SYSINFO;
2,175✔
35
    }
36
  }
37

38
  *pDst = schema;
570✔
39
  TAOS_RETURN(code);
570✔
40
}
41

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

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

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

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

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

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

70
  TAOS_RETURN(code);
15✔
71
}
72

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

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

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

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

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

102
  *pRsp = *pMeta;
4✔
103

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

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

157
  return mndInsInitMeta(pMnode->infosMeta);
15✔
158
}
159

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

165
  STableMetaRsp *pMeta = taosHashIterate(pMnode->infosMeta, NULL);
15✔
166
  while (pMeta) {
585✔
167
    taosMemoryFreeClear(pMeta->pSchemas);
570!
168
    pMeta = taosHashIterate(pMnode->infosMeta, pMeta);
570✔
169
  }
170

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