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

taosdata / TDengine / #4898

26 Dec 2025 09:58AM UTC coverage: 65.061% (-0.7%) from 65.717%
#4898

push

travis-ci

web-flow
feat: support encryption of configuration files, data files and metadata files (#33801)

350 of 1333 new or added lines in 31 files covered. (26.26%)

2796 existing lines in 159 files now uncovered.

184024 of 282850 relevant lines covered (65.06%)

113940470.33 hits per line

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

81.85
/source/dnode/mnode/impl/src/mndShow.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 "mndShow.h"
18
#include "mndPrivilege.h"
19
#include "mndUser.h"
20
#include "systable.h"
21

22
#define SHOW_STEP_SIZE            100
23
#define SHOW_COLS_STEP_SIZE       4096
24
#define SHOW_PRIVILEGES_STEP_SIZE 2048
25

26
static SShowObj *mndCreateShowObj(SMnode *pMnode, SRetrieveTableReq *pReq);
27
static void      mndFreeShowObj(SShowObj *pShow);
28
static SShowObj *mndAcquireShowObj(SMnode *pMnode, int64_t showId);
29
static void      mndReleaseShowObj(SShowObj *pShow, bool forceRemove);
30
static bool      mndCheckRetrieveFinished(SShowObj *pShow);
31
static int32_t   mndProcessRetrieveSysTableReq(SRpcMsg *pReq);
32

33
int32_t mndInitShow(SMnode *pMnode) {
401,246✔
34
  int32_t    code = 0;
401,246✔
35
  SShowMgmt *pMgmt = &pMnode->showMgmt;
401,246✔
36

37
  pMgmt->cache = taosCacheInit(TSDB_DATA_TYPE_INT, 5000, true, (__cache_free_fn_t)mndFreeShowObj, "show");
401,246✔
38
  if (pMgmt->cache == NULL) {
401,246✔
39
    code = TSDB_CODE_OUT_OF_MEMORY;
×
40
    mError("failed to alloc show cache since %s", tstrerror(code));
×
41
    TAOS_RETURN(code);
×
42
  }
43

44
  mndSetMsgHandle(pMnode, TDMT_MND_SYSTABLE_RETRIEVE, mndProcessRetrieveSysTableReq);
401,246✔
45
  TAOS_RETURN(code);
401,246✔
46
}
47

48
void mndCleanupShow(SMnode *pMnode) {
401,182✔
49
  SShowMgmt *pMgmt = &pMnode->showMgmt;
401,182✔
50
  if (pMgmt->cache != NULL) {
401,182✔
51
    taosCacheCleanup(pMgmt->cache);
401,182✔
52
    pMgmt->cache = NULL;
401,182✔
53
  }
54
}
401,182✔
55

56
static int32_t convertToRetrieveType(char *name, int32_t len) {
4,302,376✔
57
  int32_t type = -1;
4,302,376✔
58

59
  if (strncasecmp(name, TSDB_INS_TABLE_DNODES, len) == 0) {
4,302,376✔
60
    type = TSDB_MGMT_TABLE_DNODE;
716,447✔
61
  } else if (strncasecmp(name, TSDB_INS_TABLE_MNODES, len) == 0) {
3,585,929✔
62
    type = TSDB_MGMT_TABLE_MNODE;
302,095✔
63
    /*
64
      } else if (strncasecmp(name, TSDB_INS_TABLE_MODULES, len) == 0) {
65
        type = TSDB_MGMT_TABLE_MODULE;
66
    */
67
  } else if (strncasecmp(name, TSDB_INS_TABLE_QNODES, len) == 0) {
3,283,834✔
68
    type = TSDB_MGMT_TABLE_QNODE;
3,540✔
69
  } else if (strncasecmp(name, TSDB_INS_TABLE_SNODES, len) == 0) {
3,280,294✔
70
    type = TSDB_MGMT_TABLE_SNODE;
95,174✔
71
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES, len) == 0) {
3,185,120✔
72
    type = TSDB_MGMT_TABLE_ANODE;
160✔
73
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES_FULL, len) == 0) {
3,184,960✔
74
    type = TSDB_MGMT_TABLE_ANODE_FULL;
×
75
  } else if (strncasecmp(name, TSDB_INS_TABLE_BNODES, len) == 0) {
3,184,960✔
76
    type = TSDB_MGMT_TABLE_BNODE;
71,109✔
77
  } else if (strncasecmp(name, TSDB_INS_TABLE_ARBGROUPS, len) == 0) {
3,113,851✔
78
    type = TSDB_MGMT_TABLE_ARBGROUP;
×
79
  } else if (strncasecmp(name, TSDB_INS_TABLE_CLUSTER, len) == 0) {
3,113,851✔
80
    type = TSDB_MGMT_TABLE_CLUSTER;
1,608✔
81
  } else if (strncasecmp(name, TSDB_INS_TABLE_DATABASES, len) == 0) {
3,112,243✔
82
    type = TSDB_MGMT_TABLE_DB;
436,927✔
83
  } else if (strncasecmp(name, TSDB_INS_TABLE_FUNCTIONS, len) == 0) {
2,675,316✔
84
    type = TSDB_MGMT_TABLE_FUNC;
5,876✔
85
  } else if (strncasecmp(name, TSDB_INS_TABLE_INDEXES, len) == 0) {
2,669,440✔
86
    type = TSDB_MGMT_TABLE_INDEX;
6,708✔
87
  } else if (strncasecmp(name, TSDB_INS_TABLE_STABLES, len) == 0) {
2,662,732✔
88
    type = TSDB_MGMT_TABLE_STB;
253,218✔
89
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLES, len) == 0) {
2,409,514✔
90
    type = TSDB_MGMT_TABLE_TABLE;
×
91
  } else if (strncasecmp(name, TSDB_INS_TABLE_TAGS, len) == 0) {
2,409,514✔
92
    type = TSDB_MGMT_TABLE_TAG;
×
93
  } else if (strncasecmp(name, TSDB_INS_TABLE_COLS, len) == 0) {
2,409,514✔
94
    type = TSDB_MGMT_TABLE_COL;
866,983✔
95
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLE_DISTRIBUTED, len) == 0) {
1,542,531✔
96
    //    type = TSDB_MGMT_TABLE_DIST;
97
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS, len) == 0) {
1,542,531✔
98
    type = TSDB_MGMT_TABLE_USER;
8,913✔
99
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS_FULL, len) == 0) {
1,533,618✔
100
    type = TSDB_MGMT_TABLE_USER_FULL;
×
101
  } else if (strncasecmp(name, TSDB_INS_TABLE_TOKENS, len) == 0) {
1,533,618✔
102
    type = TSDB_MGMT_TABLE_TOKEN;
×
103
  } else if (strncasecmp(name, TSDB_INS_TABLE_LICENCES, len) == 0) {
1,533,618✔
104
    type = TSDB_MGMT_TABLE_GRANTS;
1,878✔
105
  } else if (strncasecmp(name, TSDB_INS_TABLE_VGROUPS, len) == 0) {
1,531,740✔
106
    type = TSDB_MGMT_TABLE_VGROUP;
241,117✔
107
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONSUMERS, len) == 0) {
1,290,623✔
108
    type = TSDB_MGMT_TABLE_CONSUMERS;
15,152✔
109
  } else if (strncasecmp(name, TSDB_INS_TABLE_SUBSCRIPTIONS, len) == 0) {
1,275,471✔
110
    type = TSDB_MGMT_TABLE_SUBSCRIPTIONS;
22,991✔
111
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_TRANS, len) == 0) {
1,252,480✔
112
    type = TSDB_MGMT_TABLE_TRANS;
335,205✔
113
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_SMAS, len) == 0) {
917,275✔
114
    type = TSDB_MGMT_TABLE_SMAS;
×
115
  } else if (strncasecmp(name, TSDB_INS_TABLE_CONFIGS, len) == 0) {
917,275✔
116
    type = TSDB_MGMT_TABLE_CONFIGS;
1,120✔
117
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONNECTIONS, len) == 0) {
916,155✔
118
    type = TSDB_MGMT_TABLE_CONNS;
11,215✔
119
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_QUERIES, len) == 0) {
904,940✔
120
    type = TSDB_MGMT_TABLE_QUERIES;
2,708✔
121
  } else if (strncasecmp(name, TSDB_INS_TABLE_VNODES, len) == 0) {
902,232✔
122
    type = TSDB_MGMT_TABLE_VNODES;
12,381✔
123
  } else if (strncasecmp(name, TSDB_INS_TABLE_TOPICS, len) == 0) {
889,851✔
124
    type = TSDB_MGMT_TABLE_TOPICS;
17,332✔
125
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAMS, len) == 0) {
872,519✔
126
    type = TSDB_MGMT_TABLE_STREAMS;
208,073✔
127
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_APPS, len) == 0) {
664,446✔
128
    type = TSDB_MGMT_TABLE_APPS;
2,727✔
129
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_INSTANCES, len) == 0) {
661,719✔
130
    type = TSDB_MGMT_TABLE_INSTANCE;
×
131
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAM_TASKS, len) == 0) {
661,719✔
132
    type = TSDB_MGMT_TABLE_STREAM_TASKS;
168,727✔
133
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAM_RECALCULATES, len) == 0) {
492,992✔
134
    type = TSDB_MGMT_TABLE_STREAM_RECALCULATES;
245✔
135
  } else if (strncasecmp(name, TSDB_INS_TABLE_USER_PRIVILEGES, len) == 0) {
492,747✔
136
    type = TSDB_MGMT_TABLE_PRIVILEGES;
11,263✔
137
  } else if (strncasecmp(name, TSDB_INS_TABLE_VIEWS, len) == 0) {
481,484✔
138
    type = TSDB_MGMT_TABLE_VIEWS;
24,940✔
139
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACTS, len) == 0) {
456,544✔
140
    type = TSDB_MGMT_TABLE_COMPACT;
349,324✔
141
  } else if (strncasecmp(name, TSDB_INS_TABLE_ENCRYPT_ALGORITHMS, len) == 0) {
107,220✔
142
    type = TSDB_MGMT_TABLE_ENCRYPT_ALGORITHMS;
×
143
  } else if (strncasecmp(name, TSDB_INS_TABLE_ENCRYPT_STATUS, len) == 0) {
107,220✔
NEW
144
    type = TSDB_MGMT_TABLE_ENCRYPT_STATUS;
×
145
  } else if (strncasecmp(name, TSDB_INS_TABLE_SCANS, len) == 0) {
107,220✔
146
    type = TSDB_MGMT_TABLE_SCAN;
1,525✔
147
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACT_DETAILS, len) == 0) {
105,695✔
148
    type = TSDB_MGMT_TABLE_COMPACT_DETAIL;
32,326✔
149
  } else if (strncasecmp(name, TSDB_INS_TABLE_SCAN_DETAILS, len) == 0) {
73,369✔
150
    type = TSDB_MGMT_TABLE_SCAN_DETAIL;
2,440✔
151
  } else if (strncasecmp(name, TSDB_INS_TABLE_SSMIGRATES, len) == 0) {
70,929✔
152
    type = TSDB_MGMT_TABLE_SSMIGRATE;
×
153
  } else if (strncasecmp(name, TSDB_INS_TABLE_TRANSACTION_DETAILS, len) == 0) {
70,929✔
154
    type = TSDB_MGMT_TABLE_TRANSACTION_DETAIL;
439✔
155
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_FULL, len) == 0) {
70,490✔
156
    type = TSDB_MGMT_TABLE_GRANTS_FULL;
1,101✔
157
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_LOGS, len) == 0) {
69,389✔
158
    type = TSDB_MGMT_TABLE_GRANTS_LOGS;
1,101✔
159
  } else if (strncasecmp(name, TSDB_INS_TABLE_MACHINES, len) == 0) {
68,288✔
160
    type = TSDB_MGMT_TABLE_MACHINES;
1,263✔
161
  } else if (strncasecmp(name, TSDB_INS_TABLE_ENCRYPTIONS, len) == 0) {
67,025✔
162
    type = TSDB_MGMT_TABLE_ENCRYPTIONS;
162✔
163
  } else if (strncasecmp(name, TSDB_INS_TABLE_TSMAS, len) == 0) {
66,863✔
164
    type = TSDB_MGMT_TABLE_TSMAS;
×
165
  } else if (strncasecmp(name, TSDB_INS_DISK_USAGE, len) == 0) {
66,863✔
166
    type = TSDB_MGMT_TABLE_USAGE;
×
167
  } else if (strncasecmp(name, TSDB_INS_TABLE_FILESETS, len) == 0) {
66,863✔
168
    type = TSDB_MGMT_TABLE_FILESETS;
×
169
  } else if (strncasecmp(name, TSDB_INS_TABLE_VC_COLS, len) == 0) {
66,863✔
170
    type = TSDB_MGMT_TABLE_VC_COL;
×
171
  } else if (strncasecmp(name, TSDB_INS_TABLE_MOUNTS, len) == 0) {
66,863✔
172
    type = TSDB_MGMT_TABLE_MOUNT;
6,190✔
173
  } else if (strncasecmp(name, TSDB_INS_TABLE_RSMAS, len) == 0) {
60,673✔
174
    type = TSDB_MGMT_TABLE_RSMA;
16,082✔
175
  } else if (strncasecmp(name, TSDB_INS_TABLE_RETENTIONS, len) == 0) {
44,591✔
176
    type = TSDB_MGMT_TABLE_RETENTION;
42,398✔
177
  } else if (strncasecmp(name, TSDB_INS_TABLE_RETENTION_DETAILS, len) == 0) {
2,193✔
178
    type = TSDB_MGMT_TABLE_RETENTION_DETAIL;
2,193✔
179
  } else {
180
    mError("invalid show name:%s len:%d", name, len);
×
181
  }
182

183
  return type;
4,302,376✔
184
}
185

186
static SShowObj *mndCreateShowObj(SMnode *pMnode, SRetrieveTableReq *pReq) {
4,302,376✔
187
  SShowMgmt *pMgmt = &pMnode->showMgmt;
4,302,376✔
188

189
  int64_t showId = atomic_add_fetch_64(&pMgmt->showId, 1);
4,302,376✔
190
  if (showId == 0) atomic_add_fetch_64(&pMgmt->showId, 1);
4,302,376✔
191

192
  int32_t size = sizeof(SShowObj);
4,302,376✔
193

194
  SShowObj showObj = {0};
4,302,376✔
195

196
  showObj.id = showId;
4,302,376✔
197
  showObj.pMnode = pMnode;
4,302,376✔
198
  showObj.type = convertToRetrieveType(pReq->tb, tListLen(pReq->tb));
4,302,376✔
199
  (void)memcpy(showObj.db, pReq->db, TSDB_DB_FNAME_LEN);
4,302,376✔
200
  tstrncpy(showObj.filterTb, pReq->filterTb, TSDB_TABLE_NAME_LEN);
4,302,376✔
201

202
  int32_t   keepTime = tsShellActivityTimer * 6 * 1000;
4,302,376✔
203
  SShowObj *pShow = taosCachePut(pMgmt->cache, &showId, sizeof(int64_t), &showObj, size, keepTime);
4,302,376✔
204
  if (pShow == NULL) {
4,302,376✔
205
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
206
    mError("show:0x%" PRIx64 ", failed to put into cache since %s", showId, terrstr());
×
207
    return NULL;
×
208
  }
209

210
  mTrace("show:0x%" PRIx64 ", is created, data:%p", showId, pShow);
4,302,376✔
211
  return pShow;
4,302,376✔
212
}
213

214
static void mndFreeShowObj(SShowObj *pShow) {
4,302,376✔
215
  SMnode    *pMnode = pShow->pMnode;
4,302,376✔
216
  SShowMgmt *pMgmt = &pMnode->showMgmt;
4,302,376✔
217

218
  ShowFreeIterFp freeFp = pMgmt->freeIterFps[pShow->type];
4,302,376✔
219
  if (freeFp != NULL) {
4,302,376✔
220
    if (pShow->pIter != NULL) {
3,891,138✔
221
      mTrace("show:0x%" PRIx64 ", is destroying, data:%p, pIter:%p, ", pShow->id, pShow, pShow->pIter);
141✔
222

223
      (*freeFp)(pMnode, pShow->pIter);
141✔
224

225
      pShow->pIter = NULL;
141✔
226
    }
227
  }
228

229
  mTrace("show:0x%" PRIx64 ", is destroyed, data:%p", pShow->id, pShow);
4,302,376✔
230
}
4,302,376✔
231

232
static SShowObj *mndAcquireShowObj(SMnode *pMnode, int64_t showId) {
96,335✔
233
  SShowMgmt *pMgmt = &pMnode->showMgmt;
96,335✔
234

235
  SShowObj *pShow = taosCacheAcquireByKey(pMgmt->cache, &showId, sizeof(showId));
96,335✔
236
  if (pShow == NULL) {
96,335✔
237
    mError("show:0x%" PRIx64 ", already destroyed", showId);
×
238
    return NULL;
×
239
  }
240

241
  mTrace("show:0x%" PRIx64 ", acquired from cache, data:%p", pShow->id, pShow);
96,335✔
242
  return pShow;
96,335✔
243
}
244

245
static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove) {
4,397,753✔
246
  if (pShow == NULL) return;
4,397,753✔
247
  mTrace("show:0x%" PRIx64 ", released from cache, data:%p force:%d", pShow->id, pShow, forceRemove);
4,397,753✔
248

249
  // A bug in tcache.c
250
  forceRemove = 0;
4,397,753✔
251

252
  SMnode    *pMnode = pShow->pMnode;
4,397,753✔
253
  SShowMgmt *pMgmt = &pMnode->showMgmt;
4,397,753✔
254
  taosCacheRelease(pMgmt->cache, (void **)(&pShow), forceRemove);
4,397,753✔
255
}
256

257
static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) {
4,398,711✔
258
  int32_t    code = 0;
4,398,711✔
259
  SMnode    *pMnode = pReq->info.node;
4,398,711✔
260
  SShowMgmt *pMgmt = &pMnode->showMgmt;
4,398,711✔
261
  SShowObj  *pShow = NULL;
4,398,711✔
262
  int32_t    rowsToRead = SHOW_STEP_SIZE;
4,398,711✔
263
  int32_t    size = 0;
4,398,711✔
264
  int32_t    rowsRead = 0;
4,398,711✔
265
  mDebug("mndProcessRetrieveSysTableReq start");
4,398,711✔
266
  SRetrieveTableReq retrieveReq = {0};
4,398,711✔
267
  TAOS_CHECK_RETURN(tDeserializeSRetrieveTableReq(pReq->pCont, pReq->contLen, &retrieveReq));
4,398,711✔
268

269
  mDebug("process to retrieve systable req db:%s, tb:%s, compactId:%" PRId64, retrieveReq.db, retrieveReq.tb,
4,398,711✔
270
         retrieveReq.compactId);
271

272
  if (retrieveReq.showId == 0) {
4,398,711✔
273
    STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, retrieveReq.tb, strlen(retrieveReq.tb));
4,302,376✔
274
    if (pMeta == NULL) {
4,302,376✔
275
      pMeta = taosHashGet(pMnode->perfsMeta, retrieveReq.tb, strlen(retrieveReq.tb));
367,007✔
276
      if (pMeta == NULL) {
367,007✔
277
        code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
×
278
        mError("failed to process show-retrieve req:%p since %s", pShow, tstrerror(code));
×
279
        TAOS_RETURN(code);
×
280
      }
281
    }
282

283
    pShow = mndCreateShowObj(pMnode, &retrieveReq);
4,302,376✔
284
    if (pShow == NULL) {
4,302,376✔
285
      code = terrno;
×
286
      mError("failed to process show-meta req since %s", tstrerror(code));
×
287
      TAOS_RETURN(code);
×
288
    }
289

290
    pShow->pMeta = pMeta;
4,302,376✔
291
    pShow->numOfColumns = pShow->pMeta->numOfColumns;
4,302,376✔
292
  } else {
293
    pShow = mndAcquireShowObj(pMnode, retrieveReq.showId);
96,335✔
294
    if (pShow == NULL) {
96,335✔
295
      code = TSDB_CODE_MND_INVALID_SHOWOBJ;
×
296
      mError("failed to process show-retrieve req:%p since %s", pShow, tstrerror(code));
×
297
      TAOS_RETURN(code);
×
298
    }
299
  }
300

301
  if (pShow->type == TSDB_MGMT_TABLE_COL) {  // expend capacity for ins_columns
4,398,711✔
302
    rowsToRead = SHOW_COLS_STEP_SIZE;
870,367✔
303
  } else if (pShow->type == TSDB_MGMT_TABLE_PRIVILEGES) {
3,528,344✔
304
    rowsToRead = SHOW_PRIVILEGES_STEP_SIZE;
11,263✔
305
  }
306
  ShowRetrieveFp retrieveFp = pMgmt->retrieveFps[pShow->type];
4,398,711✔
307
  if (retrieveFp == NULL) {
4,398,711✔
308
    mndReleaseShowObj(pShow, false);
×
309
    code = TSDB_CODE_MSG_NOT_PROCESSED;
×
310
    mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, tstrerror(code));
×
311
    TAOS_RETURN(code);
×
312
  }
313

314
  mDebug("show:0x%" PRIx64 ", start retrieve data, type:%d", pShow->id, pShow->type);
4,398,711✔
315
  if (retrieveReq.user[0] != 0) {
4,398,711✔
316
    (void)memcpy(pReq->info.conn.user, retrieveReq.user, TSDB_USER_LEN);
4,398,711✔
317
  } else {
318
    (void)memcpy(pReq->info.conn.user, TSDB_DEFAULT_USER, strlen(TSDB_DEFAULT_USER) + 1);
×
319
  }
320
  code = -1;
4,398,711✔
321
  if (retrieveReq.db[0] &&
5,994,298✔
322
      (code = mndCheckShowPrivilege(pMnode, RPC_MSG_USER(pReq), RPC_MSG_TOKEN(pReq), pShow->type, retrieveReq.db)) != 0) {
1,595,587✔
323
    TAOS_RETURN(code);
958✔
324
  }
325
  if (pShow->type == TSDB_MGMT_TABLE_USER_FULL) {
4,397,753✔
326
    if (strcmp(RPC_MSG_USER(pReq), "root") != 0) {
×
327
      mError("The operation is not permitted, user:%s, pShow->type:%d", RPC_MSG_USER(pReq), pShow->type);
×
328
      code = TSDB_CODE_MND_NO_RIGHTS;
×
329
      TAOS_RETURN(code);
×
330
    }
331
  }
332

333
  int32_t numOfCols = pShow->pMeta->numOfColumns;
4,397,753✔
334

335
  SSDataBlock *pBlock = NULL;
4,397,753✔
336
  code = createDataBlock(&pBlock);
4,397,753✔
337
  if (code) {
4,397,753✔
338
    TAOS_RETURN(code);
×
339
  }
340

341
  for (int32_t i = 0; i < numOfCols; ++i) {
60,118,590✔
342
    SColumnInfoData idata = {0};
55,720,837✔
343

344
    SSchema *p = &pShow->pMeta->pSchemas[i];
55,720,837✔
345

346
    idata.info.bytes = p->bytes;
55,720,837✔
347
    idata.info.type = p->type;
55,720,837✔
348
    idata.info.colId = p->colId;
55,720,837✔
349
    TAOS_CHECK_RETURN(blockDataAppendColInfo(pBlock, &idata));
55,720,837✔
350
  }
351

352
  TAOS_CHECK_RETURN(blockDataEnsureCapacity(pBlock, rowsToRead));
4,397,753✔
353

354
  if (mndCheckRetrieveFinished(pShow)) {
4,397,753✔
355
    mDebug("show:0x%" PRIx64 ", read finished, numOfRows:%d", pShow->id, pShow->numOfRows);
×
356
    rowsRead = 0;
×
357
  } else {
358
    rowsRead = (*retrieveFp)(pReq, pShow, pBlock, rowsToRead);
4,397,753✔
359
    if (rowsRead < 0) {
4,397,753✔
360
      code = rowsRead;
1,783✔
361
      mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
1,783✔
362
      mndReleaseShowObj(pShow, true);
1,783✔
363
      blockDataDestroy(pBlock);
1,783✔
364
      TAOS_RETURN(code);
1,783✔
365
    }
366

367
    pBlock->info.rows = rowsRead;
4,395,970✔
368
    mDebug("show:0x%" PRIx64 ", stop retrieve data, rowsRead:%d numOfRows:%d", pShow->id, rowsRead, pShow->numOfRows);
4,395,970✔
369
  }
370

371
  size_t dataEncodeBufSize = blockGetEncodeSize(pBlock);
4,395,970✔
372
  size = sizeof(SRetrieveMetaTableRsp) + sizeof(int32_t) + sizeof(SSysTableSchema) * pShow->pMeta->numOfColumns +
4,395,970✔
373
         dataEncodeBufSize;
374

375
  SRetrieveMetaTableRsp *pRsp = rpcMallocCont(size);
4,395,970✔
376
  if (pRsp == NULL) {
4,395,970✔
377
    mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, tstrerror(terrno));
×
378
    code = terrno;
×
379
    goto _exit;
×
380
  }
381

382
  pRsp->handle = htobe64(pShow->id);
4,395,970✔
383

384
  if (rowsRead > 0) {
4,395,970✔
385
    char    *pStart = pRsp->data;
4,142,175✔
386
    SSchema *ps = pShow->pMeta->pSchemas;
4,142,175✔
387

388
    *(int32_t *)pStart = htonl(pShow->pMeta->numOfColumns);
4,142,175✔
389
    pStart += sizeof(int32_t);  // number of columns
4,142,175✔
390

391
    for (int32_t i = 0; i < pShow->pMeta->numOfColumns; ++i) {
57,487,527✔
392
      SSysTableSchema *pSchema = (SSysTableSchema *)pStart;
53,345,352✔
393
      pSchema->bytes = htonl(ps[i].bytes);
53,345,352✔
394
      pSchema->colId = htons(ps[i].colId);
53,345,352✔
395
      pSchema->type = ps[i].type;
53,345,352✔
396

397
      pStart += sizeof(SSysTableSchema);
53,345,352✔
398
    }
399

400
    int32_t len = blockEncode(pBlock, pStart, dataEncodeBufSize, pShow->pMeta->numOfColumns);
4,142,175✔
401
    if (len < 0) {
4,142,175✔
402
      mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, tstrerror(terrno));
×
403
      code = terrno;
×
404
      return code;
×
405
    }
406
  }
407

408
  pRsp->numOfRows = htonl(rowsRead);
4,395,970✔
409
  pRsp->precision = TSDB_TIME_PRECISION_MILLI;  // millisecond time precision
4,395,970✔
410
  pReq->info.rsp = pRsp;
4,395,970✔
411
  pReq->info.rspLen = size;
4,395,970✔
412

413
  if (rowsRead == 0 || mndCheckRetrieveFinished(pShow)) {
4,395,970✔
414
    pRsp->completed = 1;
4,299,494✔
415
    mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
4,299,494✔
416
    mndReleaseShowObj(pShow, true);
4,299,494✔
417
  } else {
418
    mDebug("show:0x%" PRIx64 ", retrieve not completed yet", pShow->id);
96,476✔
419
    mndReleaseShowObj(pShow, false);
96,476✔
420
  }
421

422
  blockDataDestroy(pBlock);
4,395,970✔
423
  return TSDB_CODE_SUCCESS;
4,395,970✔
424
_exit:
×
425
  mndReleaseShowObj(pShow, false);
×
426
  blockDataDestroy(pBlock);
×
427
  if (pRsp) {
×
428
    rpcFreeCont(pRsp);
×
429
  }
430
  return code;
×
431
}
432

433
static bool mndCheckRetrieveFinished(SShowObj *pShow) {
8,539,928✔
434
  if (pShow->pIter == NULL && pShow->numOfRows != 0) {
8,539,928✔
435
    return true;
4,045,699✔
436
  }
437
  return false;
4,494,229✔
438
}
439

440
void mndAddShowRetrieveHandle(SMnode *pMnode, EShowType showType, ShowRetrieveFp fp) {
20,463,546✔
441
  SShowMgmt *pMgmt = &pMnode->showMgmt;
20,463,546✔
442
  pMgmt->retrieveFps[showType] = fp;
20,463,546✔
443
}
20,463,546✔
444

445
void mndAddShowFreeIterHandle(SMnode *pMnode, EShowType showType, ShowFreeIterFp fp) {
16,451,086✔
446
  SShowMgmt *pMgmt = &pMnode->showMgmt;
16,451,086✔
447
  pMgmt->freeIterFps[showType] = fp;
16,451,086✔
448
}
16,451,086✔
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