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

taosdata / TDengine / #4945

30 Jan 2026 06:19AM UTC coverage: 66.87% (+0.02%) from 66.849%
#4945

push

travis-ci

web-flow
merge: from main to 3.0 #34453

1126 of 2018 new or added lines in 72 files covered. (55.8%)

13708 existing lines in 159 files now uncovered.

205277 of 306978 relevant lines covered (66.87%)

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

28
  for (int32_t i = 0; i < colNum; ++i) {
217,058,534✔
29
    tstrncpy(schema[i].name, pSrc[i].name, sizeof(schema[i].name));
193,830,868✔
30
    schema[i].type = pSrc[i].type;
193,830,868✔
31
    schema[i].colId = i + 1;
193,830,868✔
32
    schema[i].bytes = pSrc[i].bytes;
193,830,868✔
33
    if (pSrc[i].sysInfo) {
193,830,868✔
34
      schema[i].flags |= COL_IS_SYSINFO;
84,100,170✔
35
    }
36
  }
37

38
  *pDst = schema;
23,227,666✔
39
  TAOS_RETURN(code);
23,227,666✔
40
}
41

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

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

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

57
  for (int32_t i = 0; i < size; ++i) {
23,628,143✔
58
    tstrncpy(meta.tbName, pInfosTableMeta[i].name, sizeof(meta.tbName));
23,227,666✔
59
    meta.numOfColumns = pInfosTableMeta[i].colNum;
23,227,666✔
60
    meta.sysInfo = pInfosTableMeta[i].sysInfo;
23,227,666✔
61
    meta.privCat = pInfosTableMeta[i].privCat;
23,227,666✔
62

63
    TAOS_CHECK_RETURN(mndInitInfosTableSchema(pInfosTableMeta[i].schema, pInfosTableMeta[i].colNum, &meta.pSchemas));
23,227,666✔
64

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

71
  TAOS_RETURN(code);
400,477✔
72
}
73

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

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

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

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

105
  *pRsp = *pMeta;
1,592,272✔
106

107
  pRsp->pSchemas = taosMemoryCalloc(pMeta->numOfColumns, sizeof(SSchema));
1,592,272✔
108
  if (pRsp->pSchemas == NULL) {
1,592,272✔
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,592,272✔
115
  TAOS_RETURN(code);
1,592,272✔
116
}
117

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

125
  STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, tbName, strlen(tbName));
3,320✔
126
  if (NULL == pMeta) {
3,320✔
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,320✔
133
  tstrncpy(pRsp->stbName, pMeta->stbName, sizeof(pRsp->stbName));
3,320✔
134
  tstrncpy(pRsp->dbFName, pMeta->dbFName, sizeof(pRsp->dbFName));
3,320✔
135
  pRsp->numOfTags = pMeta->numOfTags;
3,320✔
136
  pRsp->numOfColumns = pMeta->numOfColumns;
3,320✔
137
  pRsp->tableType = pMeta->tableType;
3,320✔
138
  pRsp->virtualStb = pMeta->virtualStb;
3,320✔
139

140
  pRsp->pSchemas = taosMemoryCalloc(pMeta->numOfColumns, sizeof(SSchema));
3,320✔
141
  if (pRsp->pSchemas == NULL) {
3,320✔
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,320✔
148

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

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

162
  return mndInsInitMeta(pMnode->infosMeta);
400,477✔
163
}
164

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

170
  STableMetaRsp *pMeta = taosHashIterate(pMnode->infosMeta, NULL);
400,419✔
171
  while (pMeta) {
23,624,721✔
172
    taosMemoryFreeClear(pMeta->pSchemas);
23,224,302✔
173
    pMeta = taosHashIterate(pMnode->infosMeta, pMeta);
23,224,302✔
174
  }
175

176
  taosHashCleanup(pMnode->infosMeta);
400,419✔
177
  pMnode->infosMeta = NULL;
400,419✔
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