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

taosdata / TDengine / #3676

22 Mar 2025 04:46PM UTC coverage: 25.147% (-36.8%) from 61.952%
#3676

push

travis-ci

web-flow
fix: userOperTest in linux (#30363)

Co-authored-by: taos-support <it@taosdata.com>

55963 of 304767 branches covered (18.36%)

Branch coverage included in aggregate %.

96374 of 301020 relevant lines covered (32.02%)

582640.8 hits per line

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

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

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

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

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

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

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

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

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

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

69
  TAOS_RETURN(code);
8✔
70
}
71

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

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

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

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

99
  *pRsp = *pMeta;
×
100

101
  pRsp->pSchemas = taosMemoryCalloc(pMeta->numOfColumns, sizeof(SSchema));
×
102
  if (pRsp->pSchemas == NULL) {
×
103
    code = terrno;
×
104
    pRsp->pSchemas = NULL;
×
105
    TAOS_RETURN(code);
×
106
  }
107

108
  memcpy(pRsp->pSchemas, pMeta->pSchemas, pMeta->numOfColumns * sizeof(SSchema));
×
109
  TAOS_RETURN(code);
×
110
}
111

112
int32_t mndBuildInsTableCfg(SMnode *pMnode, const char *dbFName, const char *tbName, STableCfgRsp *pRsp) {
×
113
  int32_t code = 0;
×
114
  if (NULL == pMnode->infosMeta) {
×
115
    code = TSDB_CODE_APP_ERROR;
×
116
    TAOS_RETURN(code);
×
117
  }
118

119
  STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, tbName, strlen(tbName));
×
120
  if (NULL == pMeta) {
×
121
    mError("invalid information schema table name:%s", tbName);
×
122
    code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
×
123
    TAOS_RETURN(code);
×
124
  }
125

126
  tstrncpy(pRsp->tbName, pMeta->tbName, sizeof(pRsp->tbName));
×
127
  tstrncpy(pRsp->stbName, pMeta->stbName, sizeof(pRsp->stbName));
×
128
  tstrncpy(pRsp->dbFName, pMeta->dbFName, sizeof(pRsp->dbFName));
×
129
  pRsp->numOfTags = pMeta->numOfTags;
×
130
  pRsp->numOfColumns = pMeta->numOfColumns;
×
131
  pRsp->tableType = pMeta->tableType;
×
132
  pRsp->virtualStb = pMeta->virtualStb;
×
133

134
  pRsp->pSchemas = taosMemoryCalloc(pMeta->numOfColumns, sizeof(SSchema));
×
135
  if (pRsp->pSchemas == NULL) {
×
136
    code = terrno;
×
137
    pRsp->pSchemas = NULL;
×
138
    TAOS_RETURN(code);
×
139
  }
140

141
  memcpy(pRsp->pSchemas, pMeta->pSchemas, pMeta->numOfColumns * sizeof(SSchema));
×
142

143
  pRsp->pSchemaExt = taosMemoryCalloc(pMeta->numOfColumns, sizeof(SSchemaExt));
×
144
  pRsp->pColRefs = taosMemCalloc(pMeta->numOfColumns, sizeof(SColRef));
×
145
  TAOS_RETURN(code);
×
146
}
147

148
int32_t mndInitInfos(SMnode *pMnode) {
8✔
149
  pMnode->infosMeta = taosHashInit(20, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), false, HASH_NO_LOCK);
8✔
150
  if (pMnode->infosMeta == NULL) {
8!
151
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
152
  }
153

154
  return mndInsInitMeta(pMnode->infosMeta);
8✔
155
}
156

157
void mndCleanupInfos(SMnode *pMnode) {
8✔
158
  if (NULL == pMnode->infosMeta) {
8!
159
    return;
×
160
  }
161

162
  STableMetaRsp *pMeta = taosHashIterate(pMnode->infosMeta, NULL);
8✔
163
  while (pMeta) {
312✔
164
    taosMemoryFreeClear(pMeta->pSchemas);
304!
165
    pMeta = taosHashIterate(pMnode->infosMeta, pMeta);
304✔
166
  }
167

168
  taosHashCleanup(pMnode->infosMeta);
8✔
169
  pMnode->infosMeta = NULL;
8✔
170
}
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