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

taosdata / TDengine / #4911

04 Jan 2026 09:05AM UTC coverage: 65.028% (-0.8%) from 65.864%
#4911

push

travis-ci

web-flow
merge: from main to 3.0 branch #34156

1206 of 4524 new or added lines in 22 files covered. (26.66%)

1517 existing lines in 134 files now uncovered.

195276 of 300296 relevant lines covered (65.03%)

116931714.52 hits per line

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

81.54
/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 "mndInt.h"
19
#include "mndPrivilege.h"
20
#include "mndUser.h"
21
#include "systable.h"
22
#include "tmsg.h"
23

24
#define SHOW_STEP_SIZE            100
25
#define SHOW_COLS_STEP_SIZE       4096
26
#define SHOW_PRIVILEGES_STEP_SIZE 2048
27

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

35
int32_t mndInitShow(SMnode *pMnode) {
385,564✔
36
  int32_t    code = 0;
385,564✔
37
  SShowMgmt *pMgmt = &pMnode->showMgmt;
385,564✔
38

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

46
  mndSetMsgHandle(pMnode, TDMT_MND_SYSTABLE_RETRIEVE, mndProcessRetrieveSysTableReq);
385,564✔
47
  TAOS_RETURN(code);
385,564✔
48
}
49

50
void mndCleanupShow(SMnode *pMnode) {
385,502✔
51
  SShowMgmt *pMgmt = &pMnode->showMgmt;
385,502✔
52
  if (pMgmt->cache != NULL) {
385,502✔
53
    taosCacheCleanup(pMgmt->cache);
385,502✔
54
    pMgmt->cache = NULL;
385,502✔
55
  }
56
}
385,502✔
57

58
static int32_t convertToRetrieveType(char *name, int32_t len) {
4,188,976✔
59
  int32_t type = -1;
4,188,976✔
60

61
  if (strncasecmp(name, TSDB_INS_TABLE_DNODES, len) == 0) {
4,188,976✔
62
    type = TSDB_MGMT_TABLE_DNODE;
691,760✔
63
  } else if (strncasecmp(name, TSDB_INS_TABLE_MNODES, len) == 0) {
3,497,216✔
64
    type = TSDB_MGMT_TABLE_MNODE;
290,910✔
65
    /*
66
      } else if (strncasecmp(name, TSDB_INS_TABLE_MODULES, len) == 0) {
67
        type = TSDB_MGMT_TABLE_MODULE;
68
    */
69
  } else if (strncasecmp(name, TSDB_INS_TABLE_QNODES, len) == 0) {
3,206,306✔
70
    type = TSDB_MGMT_TABLE_QNODE;
3,273✔
71
  } else if (strncasecmp(name, TSDB_INS_TABLE_SNODES, len) == 0) {
3,203,033✔
72
    type = TSDB_MGMT_TABLE_SNODE;
93,696✔
73
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES, len) == 0) {
3,109,337✔
74
    type = TSDB_MGMT_TABLE_ANODE;
145✔
75
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES_FULL, len) == 0) {
3,109,192✔
76
    type = TSDB_MGMT_TABLE_ANODE_FULL;
×
77
  } else if (strncasecmp(name, TSDB_INS_TABLE_BNODES, len) == 0) {
3,109,192✔
78
    type = TSDB_MGMT_TABLE_BNODE;
66,515✔
79
  } else if (strncasecmp(name, TSDB_INS_TABLE_XNODES, len) == 0) {
3,042,677✔
80
    type = TSDB_MGMT_TABLE_XNODES;
714✔
81
  } else if (strncasecmp(name, TSDB_INS_TABLE_XNODE_TASKS, len) == 0) {
3,041,963✔
82
    type = TSDB_MGMT_TABLE_XNODE_TASKS;
834✔
83
  } else if (strncasecmp(name, TSDB_INS_TABLE_XNODE_AGENTS, len) == 0) {
3,041,129✔
84
    type = TSDB_MGMT_TABLE_XNODE_AGENTS;
354✔
85
  } else if (strncasecmp(name, TSDB_INS_TABLE_XNODE_JOBS, len) == 0) {
3,040,775✔
86
    type = TSDB_MGMT_TABLE_XNODE_JOBS;
354✔
87
  } else if (strncasecmp(name, TSDB_INS_TABLE_ARBGROUPS, len) == 0) {
3,040,421✔
88
    type = TSDB_MGMT_TABLE_ARBGROUP;
×
89
  } else if (strncasecmp(name, TSDB_INS_TABLE_CLUSTER, len) == 0) {
3,040,421✔
90
    type = TSDB_MGMT_TABLE_CLUSTER;
1,506✔
91
  } else if (strncasecmp(name, TSDB_INS_TABLE_DATABASES, len) == 0) {
3,038,915✔
92
    type = TSDB_MGMT_TABLE_DB;
417,186✔
93
  } else if (strncasecmp(name, TSDB_INS_TABLE_FUNCTIONS, len) == 0) {
2,621,729✔
94
    type = TSDB_MGMT_TABLE_FUNC;
7,429✔
95
  } else if (strncasecmp(name, TSDB_INS_TABLE_INDEXES, len) == 0) {
2,614,300✔
96
    type = TSDB_MGMT_TABLE_INDEX;
5,286✔
97
  } else if (strncasecmp(name, TSDB_INS_TABLE_STABLES, len) == 0) {
2,609,014✔
98
    type = TSDB_MGMT_TABLE_STB;
221,384✔
99
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLES, len) == 0) {
2,387,630✔
100
    type = TSDB_MGMT_TABLE_TABLE;
×
101
  } else if (strncasecmp(name, TSDB_INS_TABLE_TAGS, len) == 0) {
2,387,630✔
102
    type = TSDB_MGMT_TABLE_TAG;
×
103
  } else if (strncasecmp(name, TSDB_INS_TABLE_COLS, len) == 0) {
2,387,630✔
104
    type = TSDB_MGMT_TABLE_COL;
859,411✔
105
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLE_DISTRIBUTED, len) == 0) {
1,528,219✔
106
    //    type = TSDB_MGMT_TABLE_DIST;
107
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS, len) == 0) {
1,528,219✔
108
    type = TSDB_MGMT_TABLE_USER;
7,134✔
109
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS_FULL, len) == 0) {
1,521,085✔
110
    type = TSDB_MGMT_TABLE_USER_FULL;
×
111
  } else if (strncasecmp(name, TSDB_INS_TABLE_TOKENS, len) == 0) {
1,521,085✔
112
    type = TSDB_MGMT_TABLE_TOKEN;
×
113
  } else if (strncasecmp(name, TSDB_INS_TABLE_LICENCES, len) == 0) {
1,521,085✔
114
    type = TSDB_MGMT_TABLE_GRANTS;
1,716✔
115
  } else if (strncasecmp(name, TSDB_INS_TABLE_VGROUPS, len) == 0) {
1,519,369✔
116
    type = TSDB_MGMT_TABLE_VGROUP;
243,456✔
117
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONSUMERS, len) == 0) {
1,275,913✔
118
    type = TSDB_MGMT_TABLE_CONSUMERS;
14,192✔
119
  } else if (strncasecmp(name, TSDB_INS_TABLE_SUBSCRIPTIONS, len) == 0) {
1,261,721✔
120
    type = TSDB_MGMT_TABLE_SUBSCRIPTIONS;
21,739✔
121
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_TRANS, len) == 0) {
1,239,982✔
122
    type = TSDB_MGMT_TABLE_TRANS;
395,176✔
123
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_SMAS, len) == 0) {
844,806✔
124
    type = TSDB_MGMT_TABLE_SMAS;
×
125
  } else if (strncasecmp(name, TSDB_INS_TABLE_CONFIGS, len) == 0) {
844,806✔
126
    type = TSDB_MGMT_TABLE_CONFIGS;
1,015✔
127
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONNECTIONS, len) == 0) {
843,791✔
128
    type = TSDB_MGMT_TABLE_CONNS;
3,154✔
129
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_QUERIES, len) == 0) {
840,637✔
130
    type = TSDB_MGMT_TABLE_QUERIES;
2,516✔
131
  } else if (strncasecmp(name, TSDB_INS_TABLE_VNODES, len) == 0) {
838,121✔
132
    type = TSDB_MGMT_TABLE_VNODES;
13,334✔
133
  } else if (strncasecmp(name, TSDB_INS_TABLE_TOPICS, len) == 0) {
824,787✔
134
    type = TSDB_MGMT_TABLE_TOPICS;
16,435✔
135
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAMS, len) == 0) {
808,352✔
136
    type = TSDB_MGMT_TABLE_STREAMS;
197,711✔
137
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_APPS, len) == 0) {
610,641✔
138
    type = TSDB_MGMT_TABLE_APPS;
2,508✔
139
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_INSTANCES, len) == 0) {
608,133✔
140
    type = TSDB_MGMT_TABLE_INSTANCE;
×
141
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAM_TASKS, len) == 0) {
608,133✔
142
    type = TSDB_MGMT_TABLE_STREAM_TASKS;
157,045✔
143
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAM_RECALCULATES, len) == 0) {
451,088✔
144
    type = TSDB_MGMT_TABLE_STREAM_RECALCULATES;
233✔
145
  } else if (strncasecmp(name, TSDB_INS_TABLE_USER_PRIVILEGES, len) == 0) {
450,855✔
146
    type = TSDB_MGMT_TABLE_PRIVILEGES;
4,811✔
147
  } else if (strncasecmp(name, TSDB_INS_TABLE_VIEWS, len) == 0) {
446,044✔
148
    type = TSDB_MGMT_TABLE_VIEWS;
1,914✔
149
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACTS, len) == 0) {
444,130✔
150
    type = TSDB_MGMT_TABLE_COMPACT;
341,417✔
151
  } else if (strncasecmp(name, TSDB_INS_TABLE_ENCRYPT_ALGORITHMS, len) == 0) {
102,713✔
152
    type = TSDB_MGMT_TABLE_ENCRYPT_ALGORITHMS;
×
153
  } else if (strncasecmp(name, TSDB_INS_TABLE_ENCRYPT_STATUS, len) == 0) {
102,713✔
154
    type = TSDB_MGMT_TABLE_ENCRYPT_STATUS;
×
155
  } else if (strncasecmp(name, TSDB_INS_TABLE_SCANS, len) == 0) {
102,713✔
156
    type = TSDB_MGMT_TABLE_SCAN;
1,980✔
157
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACT_DETAILS, len) == 0) {
100,733✔
158
    type = TSDB_MGMT_TABLE_COMPACT_DETAIL;
31,267✔
159
  } else if (strncasecmp(name, TSDB_INS_TABLE_SCAN_DETAILS, len) == 0) {
69,466✔
160
    type = TSDB_MGMT_TABLE_SCAN_DETAIL;
1,760✔
161
  } else if (strncasecmp(name, TSDB_INS_TABLE_SSMIGRATES, len) == 0) {
67,706✔
162
    type = TSDB_MGMT_TABLE_SSMIGRATE;
×
163
  } else if (strncasecmp(name, TSDB_INS_TABLE_TRANSACTION_DETAILS, len) == 0) {
67,706✔
164
    type = TSDB_MGMT_TABLE_TRANSACTION_DETAIL;
414✔
165
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_FULL, len) == 0) {
67,292✔
166
    type = TSDB_MGMT_TABLE_GRANTS_FULL;
1,007✔
167
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_LOGS, len) == 0) {
66,285✔
168
    type = TSDB_MGMT_TABLE_GRANTS_LOGS;
1,007✔
169
  } else if (strncasecmp(name, TSDB_INS_TABLE_MACHINES, len) == 0) {
65,278✔
170
    type = TSDB_MGMT_TABLE_MACHINES;
1,166✔
171
  } else if (strncasecmp(name, TSDB_INS_TABLE_ENCRYPTIONS, len) == 0) {
64,112✔
172
    type = TSDB_MGMT_TABLE_ENCRYPTIONS;
152✔
173
  } else if (strncasecmp(name, TSDB_INS_TABLE_TSMAS, len) == 0) {
63,960✔
174
    type = TSDB_MGMT_TABLE_TSMAS;
×
175
  } else if (strncasecmp(name, TSDB_INS_DISK_USAGE, len) == 0) {
63,960✔
176
    type = TSDB_MGMT_TABLE_USAGE;
×
177
  } else if (strncasecmp(name, TSDB_INS_TABLE_FILESETS, len) == 0) {
63,960✔
178
    type = TSDB_MGMT_TABLE_FILESETS;
×
179
  } else if (strncasecmp(name, TSDB_INS_TABLE_VC_COLS, len) == 0) {
63,960✔
180
    type = TSDB_MGMT_TABLE_VC_COL;
×
181
  } else if (strncasecmp(name, TSDB_INS_TABLE_MOUNTS, len) == 0) {
63,960✔
182
    type = TSDB_MGMT_TABLE_MOUNT;
5,661✔
183
  } else if (strncasecmp(name, TSDB_INS_TABLE_RSMAS, len) == 0) {
58,299✔
184
    type = TSDB_MGMT_TABLE_RSMA;
15,598✔
185
  } else if (strncasecmp(name, TSDB_INS_TABLE_RETENTIONS, len) == 0) {
42,701✔
186
    type = TSDB_MGMT_TABLE_RETENTION;
39,704✔
187
  } else if (strncasecmp(name, TSDB_INS_TABLE_RETENTION_DETAILS, len) == 0) {
2,997✔
188
    type = TSDB_MGMT_TABLE_RETENTION_DETAIL;
2,127✔
189
  } else if (strncasecmp(name, TSDB_INS_TABLE_ROLES, len) == 0) {
870✔
190
    type = TSDB_MGMT_TABLE_ROLE;
145✔
191
  } else if (strncasecmp(name, TSDB_INS_TABLE_ROLE_PRIVILEGES, len) == 0) {
725✔
192
    type = TSDB_MGMT_TABLE_ROLE_PRIVILEGES;
725✔
193
  } else if (strncasecmp(name, TSDB_INS_TABLE_ROLE_COL_PRIVILEGES, len) == 0) {
×
194
    type = TSDB_MGMT_TABLE_ROLE_COL_PRIVILEGES;
×
195
  } else {
196
    mError("invalid show name:%s len:%d", name, len);
×
197
  }
198

199
  return type;
4,188,976✔
200
}
201

202
static SShowObj *mndCreateShowObj(SMnode *pMnode, SRetrieveTableReq *pReq) {
4,188,976✔
203
  SShowMgmt *pMgmt = &pMnode->showMgmt;
4,188,976✔
204

205
  int64_t showId = atomic_add_fetch_64(&pMgmt->showId, 1);
4,188,976✔
206
  if (showId == 0) atomic_add_fetch_64(&pMgmt->showId, 1);
4,188,976✔
207

208
  int32_t size = sizeof(SShowObj);
4,188,976✔
209

210
  SShowObj showObj = {0};
4,188,976✔
211

212
  showObj.id = showId;
4,188,976✔
213
  showObj.pMnode = pMnode;
4,188,976✔
214
  showObj.type = convertToRetrieveType(pReq->tb, tListLen(pReq->tb));
4,188,976✔
215
  (void)memcpy(showObj.db, pReq->db, TSDB_DB_FNAME_LEN);
4,188,976✔
216
  tstrncpy(showObj.filterTb, pReq->filterTb, TSDB_TABLE_NAME_LEN);
4,188,976✔
217

218
  int32_t   keepTime = tsShellActivityTimer * 6 * 1000;
4,188,976✔
219
  SShowObj *pShow = taosCachePut(pMgmt->cache, &showId, sizeof(int64_t), &showObj, size, keepTime);
4,188,976✔
220
  if (pShow == NULL) {
4,188,976✔
221
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
222
    mError("show:0x%" PRIx64 ", failed to put into cache since %s", showId, terrstr());
×
223
    return NULL;
×
224
  }
225

226
  mTrace("show:0x%" PRIx64 ", is created, data:%p", showId, pShow);
4,188,976✔
227
  return pShow;
4,188,976✔
228
}
229

230
static void mndFreeShowObj(SShowObj *pShow) {
4,188,976✔
231
  SMnode    *pMnode = pShow->pMnode;
4,188,976✔
232
  SShowMgmt *pMgmt = &pMnode->showMgmt;
4,188,976✔
233

234
  ShowFreeIterFp freeFp = pMgmt->freeIterFps[pShow->type];
4,188,976✔
235
  if (freeFp != NULL) {
4,188,976✔
236
    if (pShow->pIter != NULL) {
3,790,399✔
237
      mTrace("show:0x%" PRIx64 ", is destroying, data:%p, pIter:%p, ", pShow->id, pShow, pShow->pIter);
725✔
238

239
      (*freeFp)(pMnode, pShow->pIter);
725✔
240

241
      pShow->pIter = NULL;
725✔
242
    }
243
  }
244

245
  mTrace("show:0x%" PRIx64 ", is destroyed, data:%p", pShow->id, pShow);
4,188,976✔
246
}
4,188,976✔
247

248
static SShowObj *mndAcquireShowObj(SMnode *pMnode, int64_t showId) {
3,702✔
249
  SShowMgmt *pMgmt = &pMnode->showMgmt;
3,702✔
250

251
  SShowObj *pShow = taosCacheAcquireByKey(pMgmt->cache, &showId, sizeof(showId));
3,702✔
252
  if (pShow == NULL) {
3,702✔
253
    mError("show:0x%" PRIx64 ", already destroyed", showId);
×
254
    return NULL;
×
255
  }
256

257
  mTrace("show:0x%" PRIx64 ", acquired from cache, data:%p", pShow->id, pShow);
3,702✔
258
  return pShow;
3,702✔
259
}
260

261
static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove) {
4,192,678✔
262
  if (pShow == NULL) return;
4,192,678✔
263
  mTrace("show:0x%" PRIx64 ", released from cache, data:%p force:%d", pShow->id, pShow, forceRemove);
4,192,678✔
264

265
  // A bug in tcache.c
266
  forceRemove = 0;
4,192,678✔
267

268
  SMnode    *pMnode = pShow->pMnode;
4,192,678✔
269
  SShowMgmt *pMgmt = &pMnode->showMgmt;
4,192,678✔
270
  taosCacheRelease(pMgmt->cache, (void **)(&pShow), forceRemove);
4,192,678✔
271
}
272

273
static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) {
4,192,678✔
274
  int32_t    code = 0;
4,192,678✔
275
  SMnode    *pMnode = pReq->info.node;
4,192,678✔
276
  SShowMgmt *pMgmt = &pMnode->showMgmt;
4,192,678✔
277
  SShowObj  *pShow = NULL;
4,192,678✔
278
  int32_t    rowsToRead = SHOW_STEP_SIZE;
4,192,678✔
279
  int32_t    size = 0;
4,192,678✔
280
  int32_t    rowsRead = 0;
4,192,678✔
281
  mDebug("mndProcessRetrieveSysTableReq start");
4,192,678✔
282
  SRetrieveTableReq retrieveReq = {0};
4,192,678✔
283
  TAOS_CHECK_RETURN(tDeserializeSRetrieveTableReq(pReq->pCont, pReq->contLen, &retrieveReq));
4,192,678✔
284

285
  mDebug("process to retrieve systable req db:%s, tb:%s, compactId:%" PRId64, retrieveReq.db, retrieveReq.tb,
4,192,678✔
286
         retrieveReq.compactId);
287

288
  if (retrieveReq.showId == 0) {
4,192,678✔
289
    STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, retrieveReq.tb, strlen(retrieveReq.tb));
4,188,976✔
290
    if (pMeta == NULL) {
4,188,976✔
291
      pMeta = taosHashGet(pMnode->perfsMeta, retrieveReq.tb, strlen(retrieveReq.tb));
417,546✔
292
      if (pMeta == NULL) {
417,546✔
293
        code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
×
294
        mError("failed to process show-retrieve req:%p since %s", pShow, tstrerror(code));
×
295
        TAOS_RETURN(code);
×
296
      }
297
    }
298

299
    pShow = mndCreateShowObj(pMnode, &retrieveReq);
4,188,976✔
300
    if (pShow == NULL) {
4,188,976✔
301
      code = terrno;
×
302
      mError("failed to process show-meta req since %s", tstrerror(code));
×
303
      TAOS_RETURN(code);
×
304
    }
305

306
    pShow->pMeta = pMeta;
4,188,976✔
307
    pShow->numOfColumns = pShow->pMeta->numOfColumns;
4,188,976✔
308
  } else {
309
    pShow = mndAcquireShowObj(pMnode, retrieveReq.showId);
3,702✔
310
    if (pShow == NULL) {
3,702✔
311
      code = TSDB_CODE_MND_INVALID_SHOWOBJ;
×
312
      mError("failed to process show-retrieve req:%p since %s", pShow, tstrerror(code));
×
313
      TAOS_RETURN(code);
×
314
    }
315
  }
316

317
  // expend capacity for ins_columns and privileges
318
  if (pShow->type == TSDB_MGMT_TABLE_COL || TSDB_MGMT_TABLE_PRIVILEGES ||
319
      pShow->type == TSDB_MGMT_TABLE_ROLE_COL_PRIVILEGES || pShow->type == TSDB_MGMT_TABLE_ROLE_PRIVILEGES) {
320
    rowsToRead = SHOW_COLS_STEP_SIZE;
4,192,204✔
321
  }
322
  ShowRetrieveFp retrieveFp = pMgmt->retrieveFps[pShow->type];
4,192,204✔
323
  if (retrieveFp == NULL) {
4,192,678✔
324
    mndReleaseShowObj(pShow, false);
×
325
    code = TSDB_CODE_MSG_NOT_PROCESSED;
×
NEW
326
    mError("show:0x%" PRIx64 ", failed to retrieve data since %s: retrieveFp is NULL", pShow->id, tstrerror(code));
×
327
    TAOS_RETURN(code);
×
328
  }
329

330
  mDebug("show:0x%" PRIx64 ", start retrieve data, type:%d", pShow->id, pShow->type);
4,192,678✔
331
  if (retrieveReq.user[0] != 0) {
4,192,678✔
332
    (void)memcpy(RPC_MSG_USER(pReq), retrieveReq.user, TSDB_USER_LEN);
4,192,678✔
333
  } else {
334
    (void)memcpy(RPC_MSG_USER(pReq), TSDB_DEFAULT_USER, strlen(TSDB_DEFAULT_USER) + 1);
×
335
  }
336
  code = -1;
4,192,678✔
337
  if (retrieveReq.db[0] &&
5,785,121✔
338
      (code = mndCheckShowPrivilege(pMnode, RPC_MSG_USER(pReq), RPC_MSG_TOKEN(pReq), pShow->type, retrieveReq.db)) != 0) {
1,592,443✔
339
    TAOS_RETURN(code);
×
340
  }
341
  if (pShow->type == TSDB_MGMT_TABLE_USER_FULL) {
4,192,678✔
342
    if (strcmp(RPC_MSG_USER(pReq), "root") != 0) {
×
343
      mError("The operation is not permitted, user:%s, pShow->type:%d", RPC_MSG_USER(pReq), pShow->type);
×
344
      code = TSDB_CODE_MND_NO_RIGHTS;
×
345
      TAOS_RETURN(code);
×
346
    }
347
  }
348

349
  int32_t numOfCols = pShow->pMeta->numOfColumns;
4,192,678✔
350

351
  SSDataBlock *pBlock = NULL;
4,192,678✔
352
  code = createDataBlock(&pBlock);
4,192,678✔
353
  if (code) {
4,192,678✔
354
    TAOS_RETURN(code);
×
355
  }
356

357
  for (int32_t i = 0; i < numOfCols; ++i) {
57,720,391✔
358
    SColumnInfoData idata = {0};
53,527,713✔
359

360
    SSchema *p = &pShow->pMeta->pSchemas[i];
53,527,713✔
361

362
    idata.info.bytes = p->bytes;
53,527,713✔
363
    idata.info.type = p->type;
53,527,713✔
364
    idata.info.colId = p->colId;
53,527,713✔
365
    TAOS_CHECK_RETURN(blockDataAppendColInfo(pBlock, &idata));
53,527,713✔
366
  }
367

368
  TAOS_CHECK_RETURN(blockDataEnsureCapacity(pBlock, rowsToRead));
4,192,678✔
369

370
  if (mndCheckRetrieveFinished(pShow)) {
4,192,678✔
371
    mDebug("show:0x%" PRIx64 ", read finished, numOfRows:%d", pShow->id, pShow->numOfRows);
×
372
    rowsRead = 0;
×
373
  } else {
374
    rowsRead = (*retrieveFp)(pReq, pShow, pBlock, rowsToRead);
4,192,678✔
375
    if (rowsRead < 0) {
4,192,678✔
376
      code = rowsRead;
910✔
377
      mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
910✔
378
      mndReleaseShowObj(pShow, true);
910✔
379
      blockDataDestroy(pBlock);
910✔
380
      TAOS_RETURN(code);
910✔
381
    }
382

383
    pBlock->info.rows = rowsRead;
4,191,768✔
384
    mDebug("show:0x%" PRIx64 ", stop retrieve data, rowsRead:%d numOfRows:%d", pShow->id, rowsRead, pShow->numOfRows);
4,191,768✔
385
  }
386

387
  size_t dataEncodeBufSize = blockGetEncodeSize(pBlock);
4,191,768✔
388
  size = sizeof(SRetrieveMetaTableRsp) + sizeof(int32_t) + sizeof(SSysTableSchema) * pShow->pMeta->numOfColumns +
4,191,768✔
389
         dataEncodeBufSize;
390

391
  SRetrieveMetaTableRsp *pRsp = rpcMallocCont(size);
4,191,768✔
392
  if (pRsp == NULL) {
4,191,768✔
NEW
393
    mError("show:0x%" PRIx64 ", failed to retrieve data since %s: pRsp is NULL", pShow->id, tstrerror(terrno));
×
394
    code = terrno;
×
395
    goto _exit;
×
396
  }
397

398
  pRsp->handle = htobe64(pShow->id);
4,191,768✔
399

400
  if (rowsRead > 0) {
4,191,768✔
401
    char    *pStart = pRsp->data;
3,946,054✔
402
    SSchema *ps = pShow->pMeta->pSchemas;
3,946,054✔
403

404
    *(int32_t *)pStart = htonl(pShow->pMeta->numOfColumns);
3,946,054✔
405
    pStart += sizeof(int32_t);  // number of columns
3,946,054✔
406

407
    for (int32_t i = 0; i < pShow->pMeta->numOfColumns; ++i) {
55,133,344✔
408
      SSysTableSchema *pSchema = (SSysTableSchema *)pStart;
51,187,290✔
409
      pSchema->bytes = htonl(ps[i].bytes);
51,187,290✔
410
      pSchema->colId = htons(ps[i].colId);
51,187,290✔
411
      pSchema->type = ps[i].type;
51,187,290✔
412

413
      pStart += sizeof(SSysTableSchema);
51,187,290✔
414
    }
415

416
    int32_t len = blockEncode(pBlock, pStart, dataEncodeBufSize, pShow->pMeta->numOfColumns);
3,946,054✔
417
    if (len < 0) {
3,946,054✔
NEW
418
      mError("show:0x%" PRIx64 ", failed to retrieve data since %s: block len(%d) < 0", pShow->id, tstrerror(terrno),
×
419
             len);
420
      code = terrno;
×
421
      return code;
×
422
    }
423
  }
424

425
  pRsp->numOfRows = htonl(rowsRead);
4,191,768✔
426
  pRsp->precision = TSDB_TIME_PRECISION_MILLI;  // millisecond time precision
4,191,768✔
427
  pReq->info.rsp = pRsp;
4,191,768✔
428
  pReq->info.rspLen = size;
4,191,768✔
429

430
  if (rowsRead == 0 || mndCheckRetrieveFinished(pShow)) {
4,191,768✔
431
    pRsp->completed = 1;
4,188,066✔
432
    mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
4,188,066✔
433
    mndReleaseShowObj(pShow, true);
4,188,066✔
434
  } else {
435
    mDebug("show:0x%" PRIx64 ", retrieve not completed yet", pShow->id);
3,702✔
436
    mndReleaseShowObj(pShow, false);
3,702✔
437
  }
438

439
  blockDataDestroy(pBlock);
4,191,768✔
440
  return TSDB_CODE_SUCCESS;
4,191,768✔
441
_exit:
×
442
  mndReleaseShowObj(pShow, false);
×
443
  blockDataDestroy(pBlock);
×
444
  if (pRsp) {
×
445
    rpcFreeCont(pRsp);
×
446
  }
447
  return code;
×
448
}
449

450
static bool mndCheckRetrieveFinished(SShowObj *pShow) {
8,138,732✔
451
  if (pShow->pIter == NULL && pShow->numOfRows != 0) {
8,138,732✔
452
    return true;
3,942,352✔
453
  }
454
  return false;
4,196,380✔
455
}
456

457
void mndAddShowRetrieveHandle(SMnode *pMnode, EShowType showType, ShowRetrieveFp fp) {
22,362,712✔
458
  SShowMgmt *pMgmt = &pMnode->showMgmt;
22,362,712✔
459
  pMgmt->retrieveFps[showType] = fp;
22,362,712✔
460
}
22,362,712✔
461

462
void mndAddShowFreeIterHandle(SMnode *pMnode, EShowType showType, ShowFreeIterFp fp) {
19,278,200✔
463
  SShowMgmt *pMgmt = &pMnode->showMgmt;
19,278,200✔
464
  pMgmt->freeIterFps[showType] = fp;
19,278,200✔
465
}
19,278,200✔
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