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

taosdata / TDengine / #3809

01 Apr 2025 03:03AM UTC coverage: 34.048% (+0.02%) from 34.033%
#3809

push

travis-ci

happyguoxy
test:alter gcda dir

148452 of 599532 branches covered (24.76%)

Branch coverage included in aggregate %.

222312 of 489411 relevant lines covered (45.42%)

761122.82 hits per line

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

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

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

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

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

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

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

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

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

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

69
  TAOS_RETURN(code);
63✔
70
}
71

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

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

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

93
  bool isShowAnodes = (strcmp(tbName, TSDB_INS_TABLE_ANODES) == 0 || strcmp(tbName, TSDB_INS_TABLE_ANODES_FULL) == 0);
99!
94

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

101
  *pRsp = *pMeta;
99✔
102

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

110
  memcpy(pRsp->pSchemas, pMeta->pSchemas, pMeta->numOfColumns * sizeof(SSchema));
99✔
111
  TAOS_RETURN(code);
99✔
112
}
113

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

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

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

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

143
  memcpy(pRsp->pSchemas, pMeta->pSchemas, pMeta->numOfColumns * sizeof(SSchema));
×
144

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

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

156
  return mndInsInitMeta(pMnode->infosMeta);
63✔
157
}
158

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

164
  STableMetaRsp *pMeta = taosHashIterate(pMnode->infosMeta, NULL);
60✔
165
  while (pMeta) {
2,340✔
166
    taosMemoryFreeClear(pMeta->pSchemas);
2,280!
167
    pMeta = taosHashIterate(pMnode->infosMeta, pMeta);
2,280✔
168
  }
169

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