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

taosdata / TDengine / #4113

17 May 2025 06:43AM UTC coverage: 62.054% (-0.8%) from 62.857%
#4113

push

travis-ci

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

merge: from main to 3.0 branch

154737 of 318088 branches covered (48.65%)

Branch coverage included in aggregate %.

175 of 225 new or added lines in 20 files covered. (77.78%)

5853 existing lines in 216 files now uncovered.

239453 of 317147 relevant lines covered (75.5%)

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

28
  for (int32_t i = 0; i < colNum; ++i) {
748,506✔
29
    tstrncpy(schema[i].name, pSrc[i].name, sizeof(schema[i].name));
670,150✔
30
    schema[i].type = pSrc[i].type;
670,150✔
31
    schema[i].colId = i + 1;
670,150✔
32
    schema[i].bytes = pSrc[i].bytes;
670,150✔
33
    if (pSrc[i].sysInfo) {
670,150✔
34
      schema[i].flags |= COL_IS_SYSINFO;
298,990✔
35
    }
36
  }
37

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

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

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

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

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

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

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

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

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

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

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

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

96
  if (!isShowAnodes && !sysinfo && pMeta->sysInfo) {
224,124✔
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;
224,084✔
103

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

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

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

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

165
  STableMetaRsp *pMeta = taosHashIterate(pMnode->infosMeta, NULL);
2,061✔
166
  while (pMeta) {
80,379✔
167
    taosMemoryFreeClear(pMeta->pSchemas);
78,318!
168
    pMeta = taosHashIterate(pMnode->infosMeta, pMeta);
78,318✔
169
  }
170

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