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

taosdata / TDengine / #4905

29 Dec 2025 02:08PM UTC coverage: 65.423% (-0.3%) from 65.734%
#4905

push

travis-ci

web-flow
enh: sign connect request (#34067)

23 of 29 new or added lines in 4 files covered. (79.31%)

11614 existing lines in 186 files now uncovered.

193476 of 295730 relevant lines covered (65.42%)

115752566.53 hits per line

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

81.07
/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) {
385,429✔
34
  int32_t    code = 0;
385,429✔
35
  SShowMgmt *pMgmt = &pMnode->showMgmt;
385,429✔
36

37
  pMgmt->cache = taosCacheInit(TSDB_DATA_TYPE_INT, 5000, true, (__cache_free_fn_t)mndFreeShowObj, "show");
385,429✔
38
  if (pMgmt->cache == NULL) {
385,429✔
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);
385,429✔
45
  TAOS_RETURN(code);
385,429✔
46
}
47

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

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

59
  if (strncasecmp(name, TSDB_INS_TABLE_DNODES, len) == 0) {
4,174,733✔
60
    type = TSDB_MGMT_TABLE_DNODE;
694,781✔
61
  } else if (strncasecmp(name, TSDB_INS_TABLE_MNODES, len) == 0) {
3,479,952✔
62
    type = TSDB_MGMT_TABLE_MNODE;
290,403✔
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,189,549✔
68
    type = TSDB_MGMT_TABLE_QNODE;
3,371✔
69
  } else if (strncasecmp(name, TSDB_INS_TABLE_SNODES, len) == 0) {
3,186,178✔
70
    type = TSDB_MGMT_TABLE_SNODE;
89,365✔
71
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES, len) == 0) {
3,096,813✔
72
    type = TSDB_MGMT_TABLE_ANODE;
156✔
73
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES_FULL, len) == 0) {
3,096,657✔
74
    type = TSDB_MGMT_TABLE_ANODE_FULL;
×
75
  } else if (strncasecmp(name, TSDB_INS_TABLE_BNODES, len) == 0) {
3,096,657✔
76
    type = TSDB_MGMT_TABLE_BNODE;
67,083✔
77
  } else if (strncasecmp(name, TSDB_INS_TABLE_ARBGROUPS, len) == 0) {
3,029,574✔
78
    type = TSDB_MGMT_TABLE_ARBGROUP;
×
79
  } else if (strncasecmp(name, TSDB_INS_TABLE_CLUSTER, len) == 0) {
3,029,574✔
80
    type = TSDB_MGMT_TABLE_CLUSTER;
1,564✔
81
  } else if (strncasecmp(name, TSDB_INS_TABLE_DATABASES, len) == 0) {
3,028,010✔
82
    type = TSDB_MGMT_TABLE_DB;
416,560✔
83
  } else if (strncasecmp(name, TSDB_INS_TABLE_FUNCTIONS, len) == 0) {
2,611,450✔
84
    type = TSDB_MGMT_TABLE_FUNC;
7,514✔
85
  } else if (strncasecmp(name, TSDB_INS_TABLE_INDEXES, len) == 0) {
2,603,936✔
86
    type = TSDB_MGMT_TABLE_INDEX;
5,400✔
87
  } else if (strncasecmp(name, TSDB_INS_TABLE_STABLES, len) == 0) {
2,598,536✔
88
    type = TSDB_MGMT_TABLE_STB;
240,372✔
89
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLES, len) == 0) {
2,358,164✔
90
    type = TSDB_MGMT_TABLE_TABLE;
×
91
  } else if (strncasecmp(name, TSDB_INS_TABLE_TAGS, len) == 0) {
2,358,164✔
92
    type = TSDB_MGMT_TABLE_TAG;
×
93
  } else if (strncasecmp(name, TSDB_INS_TABLE_COLS, len) == 0) {
2,358,164✔
94
    type = TSDB_MGMT_TABLE_COL;
857,350✔
95
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLE_DISTRIBUTED, len) == 0) {
1,500,814✔
96
    //    type = TSDB_MGMT_TABLE_DIST;
97
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS, len) == 0) {
1,500,814✔
98
    type = TSDB_MGMT_TABLE_USER;
7,294✔
99
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS_FULL, len) == 0) {
1,493,520✔
100
    type = TSDB_MGMT_TABLE_USER_FULL;
×
101
  } else if (strncasecmp(name, TSDB_INS_TABLE_TOKENS, len) == 0) {
1,493,520✔
102
    type = TSDB_MGMT_TABLE_TOKEN;
×
103
  } else if (strncasecmp(name, TSDB_INS_TABLE_LICENCES, len) == 0) {
1,493,520✔
104
    type = TSDB_MGMT_TABLE_GRANTS;
1,774✔
105
  } else if (strncasecmp(name, TSDB_INS_TABLE_VGROUPS, len) == 0) {
1,491,746✔
106
    type = TSDB_MGMT_TABLE_VGROUP;
242,954✔
107
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONSUMERS, len) == 0) {
1,248,792✔
108
    type = TSDB_MGMT_TABLE_CONSUMERS;
14,566✔
109
  } else if (strncasecmp(name, TSDB_INS_TABLE_SUBSCRIPTIONS, len) == 0) {
1,234,226✔
110
    type = TSDB_MGMT_TABLE_SUBSCRIPTIONS;
21,512✔
111
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_TRANS, len) == 0) {
1,212,714✔
112
    type = TSDB_MGMT_TABLE_TRANS;
370,262✔
113
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_SMAS, len) == 0) {
842,452✔
114
    type = TSDB_MGMT_TABLE_SMAS;
×
115
  } else if (strncasecmp(name, TSDB_INS_TABLE_CONFIGS, len) == 0) {
842,452✔
116
    type = TSDB_MGMT_TABLE_CONFIGS;
1,092✔
117
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONNECTIONS, len) == 0) {
841,360✔
118
    type = TSDB_MGMT_TABLE_CONNS;
3,309✔
119
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_QUERIES, len) == 0) {
838,051✔
120
    type = TSDB_MGMT_TABLE_QUERIES;
2,661✔
121
  } else if (strncasecmp(name, TSDB_INS_TABLE_VNODES, len) == 0) {
835,390✔
122
    type = TSDB_MGMT_TABLE_VNODES;
12,565✔
123
  } else if (strncasecmp(name, TSDB_INS_TABLE_TOPICS, len) == 0) {
822,825✔
124
    type = TSDB_MGMT_TABLE_TOPICS;
16,653✔
125
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAMS, len) == 0) {
806,172✔
126
    type = TSDB_MGMT_TABLE_STREAMS;
204,190✔
127
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_APPS, len) == 0) {
601,982✔
128
    type = TSDB_MGMT_TABLE_APPS;
2,655✔
129
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_INSTANCES, len) == 0) {
599,327✔
130
    type = TSDB_MGMT_TABLE_INSTANCE;
×
131
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAM_TASKS, len) == 0) {
599,327✔
132
    type = TSDB_MGMT_TABLE_STREAM_TASKS;
162,976✔
133
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAM_RECALCULATES, len) == 0) {
436,351✔
134
    type = TSDB_MGMT_TABLE_STREAM_RECALCULATES;
233✔
135
  } else if (strncasecmp(name, TSDB_INS_TABLE_USER_PRIVILEGES, len) == 0) {
436,118✔
136
    type = TSDB_MGMT_TABLE_PRIVILEGES;
5,023✔
137
  } else if (strncasecmp(name, TSDB_INS_TABLE_VIEWS, len) == 0) {
431,095✔
138
    type = TSDB_MGMT_TABLE_VIEWS;
2,347✔
139
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACTS, len) == 0) {
428,748✔
140
    type = TSDB_MGMT_TABLE_COMPACT;
327,862✔
141
  } else if (strncasecmp(name, TSDB_INS_TABLE_ENCRYPT_ALGORITHMS, len) == 0) {
100,886✔
142
    type = TSDB_MGMT_TABLE_ENCRYPT_ALGORITHMS;
×
143
  } else if (strncasecmp(name, TSDB_INS_TABLE_ENCRYPT_STATUS, len) == 0) {
100,886✔
144
    type = TSDB_MGMT_TABLE_ENCRYPT_STATUS;
×
145
  } else if (strncasecmp(name, TSDB_INS_TABLE_SCANS, len) == 0) {
100,886✔
146
    type = TSDB_MGMT_TABLE_SCAN;
1,530✔
147
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACT_DETAILS, len) == 0) {
99,356✔
148
    type = TSDB_MGMT_TABLE_COMPACT_DETAIL;
31,133✔
149
  } else if (strncasecmp(name, TSDB_INS_TABLE_SCAN_DETAILS, len) == 0) {
68,223✔
150
    type = TSDB_MGMT_TABLE_SCAN_DETAIL;
1,800✔
151
  } else if (strncasecmp(name, TSDB_INS_TABLE_SSMIGRATES, len) == 0) {
66,423✔
152
    type = TSDB_MGMT_TABLE_SSMIGRATE;
×
153
  } else if (strncasecmp(name, TSDB_INS_TABLE_TRANSACTION_DETAILS, len) == 0) {
66,423✔
154
    type = TSDB_MGMT_TABLE_TRANSACTION_DETAIL;
419✔
155
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_FULL, len) == 0) {
66,004✔
156
    type = TSDB_MGMT_TABLE_GRANTS_FULL;
936✔
157
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_LOGS, len) == 0) {
65,068✔
158
    type = TSDB_MGMT_TABLE_GRANTS_LOGS;
936✔
159
  } else if (strncasecmp(name, TSDB_INS_TABLE_MACHINES, len) == 0) {
64,132✔
160
    type = TSDB_MGMT_TABLE_MACHINES;
1,093✔
161
  } else if (strncasecmp(name, TSDB_INS_TABLE_ENCRYPTIONS, len) == 0) {
63,039✔
162
    type = TSDB_MGMT_TABLE_ENCRYPTIONS;
157✔
163
  } else if (strncasecmp(name, TSDB_INS_TABLE_TSMAS, len) == 0) {
62,882✔
164
    type = TSDB_MGMT_TABLE_TSMAS;
×
165
  } else if (strncasecmp(name, TSDB_INS_DISK_USAGE, len) == 0) {
62,882✔
166
    type = TSDB_MGMT_TABLE_USAGE;
×
167
  } else if (strncasecmp(name, TSDB_INS_TABLE_FILESETS, len) == 0) {
62,882✔
168
    type = TSDB_MGMT_TABLE_FILESETS;
×
169
  } else if (strncasecmp(name, TSDB_INS_TABLE_VC_COLS, len) == 0) {
62,882✔
170
    type = TSDB_MGMT_TABLE_VC_COL;
×
171
  } else if (strncasecmp(name, TSDB_INS_TABLE_MOUNTS, len) == 0) {
62,882✔
172
    type = TSDB_MGMT_TABLE_MOUNT;
5,662✔
173
  } else if (strncasecmp(name, TSDB_INS_TABLE_RSMAS, len) == 0) {
57,220✔
174
    type = TSDB_MGMT_TABLE_RSMA;
15,488✔
175
  } else if (strncasecmp(name, TSDB_INS_TABLE_RETENTIONS, len) == 0) {
41,732✔
176
    type = TSDB_MGMT_TABLE_RETENTION;
38,720✔
177
  } else if (strncasecmp(name, TSDB_INS_TABLE_RETENTION_DETAILS, len) == 0) {
3,012✔
178
    type = TSDB_MGMT_TABLE_RETENTION_DETAIL;
2,112✔
179
  } else if (strncasecmp(name, TSDB_INS_TABLE_ROLES, len) == 0) {
900✔
180
    type = TSDB_MGMT_TABLE_ROLE;
150✔
181
  } else if (strncasecmp(name, TSDB_INS_TABLE_ROLE_PRIVILEGES, len) == 0) {
750✔
182
    type = TSDB_MGMT_TABLE_ROLE_PRIVILEGES;
750✔
UNCOV
183
  } else if (strncasecmp(name, TSDB_INS_TABLE_ROLE_COL_PRIVILEGES, len) == 0) {
×
UNCOV
184
    type = TSDB_MGMT_TABLE_ROLE_COL_PRIVILEGES;
×
185
  } else {
UNCOV
186
    mError("invalid show name:%s len:%d", name, len);
×
187
  }
188

189
  return type;
4,174,733✔
190
}
191

192
static SShowObj *mndCreateShowObj(SMnode *pMnode, SRetrieveTableReq *pReq) {
4,174,733✔
193
  SShowMgmt *pMgmt = &pMnode->showMgmt;
4,174,733✔
194

195
  int64_t showId = atomic_add_fetch_64(&pMgmt->showId, 1);
4,174,733✔
196
  if (showId == 0) atomic_add_fetch_64(&pMgmt->showId, 1);
4,174,733✔
197

198
  int32_t size = sizeof(SShowObj);
4,174,733✔
199

200
  SShowObj showObj = {0};
4,174,733✔
201

202
  showObj.id = showId;
4,174,733✔
203
  showObj.pMnode = pMnode;
4,174,733✔
204
  showObj.type = convertToRetrieveType(pReq->tb, tListLen(pReq->tb));
4,174,733✔
205
  (void)memcpy(showObj.db, pReq->db, TSDB_DB_FNAME_LEN);
4,174,733✔
206
  tstrncpy(showObj.filterTb, pReq->filterTb, TSDB_TABLE_NAME_LEN);
4,174,733✔
207

208
  int32_t   keepTime = tsShellActivityTimer * 6 * 1000;
4,174,733✔
209
  SShowObj *pShow = taosCachePut(pMgmt->cache, &showId, sizeof(int64_t), &showObj, size, keepTime);
4,174,733✔
210
  if (pShow == NULL) {
4,174,259✔
UNCOV
211
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
UNCOV
212
    mError("show:0x%" PRIx64 ", failed to put into cache since %s", showId, terrstr());
×
UNCOV
213
    return NULL;
×
214
  }
215

216
  mTrace("show:0x%" PRIx64 ", is created, data:%p", showId, pShow);
4,174,259✔
217
  return pShow;
4,174,259✔
218
}
219

220
static void mndFreeShowObj(SShowObj *pShow) {
4,174,733✔
221
  SMnode    *pMnode = pShow->pMnode;
4,174,733✔
222
  SShowMgmt *pMgmt = &pMnode->showMgmt;
4,174,733✔
223

224
  ShowFreeIterFp freeFp = pMgmt->freeIterFps[pShow->type];
4,174,733✔
225
  if (freeFp != NULL) {
4,174,733✔
226
    if (pShow->pIter != NULL) {
3,790,477✔
227
      mTrace("show:0x%" PRIx64 ", is destroying, data:%p, pIter:%p, ", pShow->id, pShow, pShow->pIter);
780✔
228

229
      (*freeFp)(pMnode, pShow->pIter);
780✔
230

231
      pShow->pIter = NULL;
780✔
232
    }
233
  }
234

235
  mTrace("show:0x%" PRIx64 ", is destroyed, data:%p", pShow->id, pShow);
4,174,733✔
236
}
4,174,733✔
237

238
static SShowObj *mndAcquireShowObj(SMnode *pMnode, int64_t showId) {
419✔
239
  SShowMgmt *pMgmt = &pMnode->showMgmt;
419✔
240

241
  SShowObj *pShow = taosCacheAcquireByKey(pMgmt->cache, &showId, sizeof(showId));
419✔
242
  if (pShow == NULL) {
419✔
UNCOV
243
    mError("show:0x%" PRIx64 ", already destroyed", showId);
×
UNCOV
244
    return NULL;
×
245
  }
246

247
  mTrace("show:0x%" PRIx64 ", acquired from cache, data:%p", pShow->id, pShow);
419✔
248
  return pShow;
419✔
249
}
250

251
static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove) {
4,175,152✔
252
  if (pShow == NULL) return;
4,175,152✔
253
  mTrace("show:0x%" PRIx64 ", released from cache, data:%p force:%d", pShow->id, pShow, forceRemove);
4,175,152✔
254

255
  // A bug in tcache.c
256
  forceRemove = 0;
4,175,152✔
257

258
  SMnode    *pMnode = pShow->pMnode;
4,175,152✔
259
  SShowMgmt *pMgmt = &pMnode->showMgmt;
4,175,152✔
260
  taosCacheRelease(pMgmt->cache, (void **)(&pShow), forceRemove);
4,175,152✔
261
}
262

263
static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) {
4,175,152✔
264
  int32_t    code = 0;
4,175,152✔
265
  SMnode    *pMnode = pReq->info.node;
4,175,152✔
266
  SShowMgmt *pMgmt = &pMnode->showMgmt;
4,175,152✔
267
  SShowObj  *pShow = NULL;
4,175,152✔
268
  int32_t    rowsToRead = SHOW_STEP_SIZE;
4,175,152✔
269
  int32_t    size = 0;
4,175,152✔
270
  int32_t    rowsRead = 0;
4,175,152✔
271
  mDebug("mndProcessRetrieveSysTableReq start");
4,175,152✔
272
  SRetrieveTableReq retrieveReq = {0};
4,175,152✔
273
  TAOS_CHECK_RETURN(tDeserializeSRetrieveTableReq(pReq->pCont, pReq->contLen, &retrieveReq));
4,175,152✔
274

275
  mDebug("process to retrieve systable req db:%s, tb:%s, compactId:%" PRId64, retrieveReq.db, retrieveReq.tb,
4,175,152✔
276
         retrieveReq.compactId);
277

278
  if (retrieveReq.showId == 0) {
4,175,152✔
279
    STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, retrieveReq.tb, strlen(retrieveReq.tb));
4,174,733✔
280
    if (pMeta == NULL) {
4,174,733✔
281
      pMeta = taosHashGet(pMnode->perfsMeta, retrieveReq.tb, strlen(retrieveReq.tb));
393,453✔
282
      if (pMeta == NULL) {
393,453✔
UNCOV
283
        code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
×
UNCOV
284
        mError("failed to process show-retrieve req:%p since %s", pShow, tstrerror(code));
×
285
        TAOS_RETURN(code);
×
286
      }
287
    }
288

289
    pShow = mndCreateShowObj(pMnode, &retrieveReq);
4,174,733✔
290
    if (pShow == NULL) {
4,174,259✔
UNCOV
291
      code = terrno;
×
UNCOV
292
      mError("failed to process show-meta req since %s", tstrerror(code));
×
UNCOV
293
      TAOS_RETURN(code);
×
294
    }
295

296
    pShow->pMeta = pMeta;
4,174,259✔
297
    pShow->numOfColumns = pShow->pMeta->numOfColumns;
4,174,733✔
298
  } else {
299
    pShow = mndAcquireShowObj(pMnode, retrieveReq.showId);
419✔
300
    if (pShow == NULL) {
419✔
UNCOV
301
      code = TSDB_CODE_MND_INVALID_SHOWOBJ;
×
UNCOV
302
      mError("failed to process show-retrieve req:%p since %s", pShow, tstrerror(code));
×
UNCOV
303
      TAOS_RETURN(code);
×
304
    }
305
  }
306

307
  // expend capacity for ins_columns and privileges
308
  if (pShow->type == TSDB_MGMT_TABLE_COL || TSDB_MGMT_TABLE_PRIVILEGES ||
309
      pShow->type == TSDB_MGMT_TABLE_ROLE_COL_PRIVILEGES || pShow->type == TSDB_MGMT_TABLE_ROLE_PRIVILEGES) {
310
    rowsToRead = SHOW_COLS_STEP_SIZE;
4,175,152✔
311
  }
312
  ShowRetrieveFp retrieveFp = pMgmt->retrieveFps[pShow->type];
4,175,152✔
313
  if (retrieveFp == NULL) {
4,174,678✔
UNCOV
314
    mndReleaseShowObj(pShow, false);
×
UNCOV
315
    code = TSDB_CODE_MSG_NOT_PROCESSED;
×
UNCOV
316
    mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, tstrerror(code));
×
UNCOV
317
    TAOS_RETURN(code);
×
318
  }
319

320
  mDebug("show:0x%" PRIx64 ", start retrieve data, type:%d", pShow->id, pShow->type);
4,174,678✔
321
  if (retrieveReq.user[0] != 0) {
4,175,152✔
322
    (void)memcpy(RPC_MSG_USER(pReq), retrieveReq.user, TSDB_USER_LEN);
4,175,152✔
323
  } else {
UNCOV
324
    (void)memcpy(RPC_MSG_USER(pReq), TSDB_DEFAULT_USER, strlen(TSDB_DEFAULT_USER) + 1);
×
325
  }
326
  code = -1;
4,175,152✔
327
  if (retrieveReq.db[0] &&
5,749,148✔
328
      (code = mndCheckShowPrivilege(pMnode, RPC_MSG_USER(pReq), RPC_MSG_TOKEN(pReq), pShow->type, retrieveReq.db)) != 0) {
1,573,996✔
329
    TAOS_RETURN(code);
×
330
  }
331
  if (pShow->type == TSDB_MGMT_TABLE_USER_FULL) {
4,175,152✔
UNCOV
332
    if (strcmp(RPC_MSG_USER(pReq), "root") != 0) {
×
UNCOV
333
      mError("The operation is not permitted, user:%s, pShow->type:%d", RPC_MSG_USER(pReq), pShow->type);
×
UNCOV
334
      code = TSDB_CODE_MND_NO_RIGHTS;
×
UNCOV
335
      TAOS_RETURN(code);
×
336
    }
337
  }
338

339
  int32_t numOfCols = pShow->pMeta->numOfColumns;
4,175,152✔
340

341
  SSDataBlock *pBlock = NULL;
4,175,152✔
342
  code = createDataBlock(&pBlock);
4,175,152✔
343
  if (code) {
4,175,152✔
UNCOV
344
    TAOS_RETURN(code);
×
345
  }
346

347
  for (int32_t i = 0; i < numOfCols; ++i) {
57,716,233✔
348
    SColumnInfoData idata = {0};
53,541,081✔
349

350
    SSchema *p = &pShow->pMeta->pSchemas[i];
53,541,081✔
351

352
    idata.info.bytes = p->bytes;
53,541,081✔
353
    idata.info.type = p->type;
53,541,081✔
354
    idata.info.colId = p->colId;
53,541,555✔
355
    TAOS_CHECK_RETURN(blockDataAppendColInfo(pBlock, &idata));
53,541,555✔
356
  }
357

358
  TAOS_CHECK_RETURN(blockDataEnsureCapacity(pBlock, rowsToRead));
4,175,152✔
359

360
  if (mndCheckRetrieveFinished(pShow)) {
4,175,152✔
UNCOV
361
    mDebug("show:0x%" PRIx64 ", read finished, numOfRows:%d", pShow->id, pShow->numOfRows);
×
UNCOV
362
    rowsRead = 0;
×
363
  } else {
364
    rowsRead = (*retrieveFp)(pReq, pShow, pBlock, rowsToRead);
4,175,152✔
365
    if (rowsRead < 0) {
4,175,152✔
366
      code = rowsRead;
922✔
367
      mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
922✔
368
      mndReleaseShowObj(pShow, true);
922✔
369
      blockDataDestroy(pBlock);
922✔
370
      TAOS_RETURN(code);
922✔
371
    }
372

373
    pBlock->info.rows = rowsRead;
4,174,230✔
374
    mDebug("show:0x%" PRIx64 ", stop retrieve data, rowsRead:%d numOfRows:%d", pShow->id, rowsRead, pShow->numOfRows);
4,174,230✔
375
  }
376

377
  size_t dataEncodeBufSize = blockGetEncodeSize(pBlock);
4,174,230✔
378
  size = sizeof(SRetrieveMetaTableRsp) + sizeof(int32_t) + sizeof(SSysTableSchema) * pShow->pMeta->numOfColumns +
4,174,230✔
379
         dataEncodeBufSize;
380

381
  SRetrieveMetaTableRsp *pRsp = rpcMallocCont(size);
4,174,230✔
382
  if (pRsp == NULL) {
4,174,230✔
UNCOV
383
    mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, tstrerror(terrno));
×
UNCOV
384
    code = terrno;
×
UNCOV
385
    goto _exit;
×
386
  }
387

388
  pRsp->handle = htobe64(pShow->id);
4,174,230✔
389

390
  if (rowsRead > 0) {
4,174,230✔
391
    char    *pStart = pRsp->data;
3,927,246✔
392
    SSchema *ps = pShow->pMeta->pSchemas;
3,927,246✔
393

394
    *(int32_t *)pStart = htonl(pShow->pMeta->numOfColumns);
3,927,246✔
395
    pStart += sizeof(int32_t);  // number of columns
3,927,246✔
396

397
    for (int32_t i = 0; i < pShow->pMeta->numOfColumns; ++i) {
55,086,170✔
398
      SSysTableSchema *pSchema = (SSysTableSchema *)pStart;
51,158,924✔
399
      pSchema->bytes = htonl(ps[i].bytes);
51,158,924✔
400
      pSchema->colId = htons(ps[i].colId);
51,158,924✔
401
      pSchema->type = ps[i].type;
51,158,924✔
402

403
      pStart += sizeof(SSysTableSchema);
51,158,924✔
404
    }
405

406
    int32_t len = blockEncode(pBlock, pStart, dataEncodeBufSize, pShow->pMeta->numOfColumns);
3,927,246✔
407
    if (len < 0) {
3,927,246✔
UNCOV
408
      mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, tstrerror(terrno));
×
UNCOV
409
      code = terrno;
×
UNCOV
410
      return code;
×
411
    }
412
  }
413

414
  pRsp->numOfRows = htonl(rowsRead);
4,174,230✔
415
  pRsp->precision = TSDB_TIME_PRECISION_MILLI;  // millisecond time precision
4,174,230✔
416
  pReq->info.rsp = pRsp;
4,174,230✔
417
  pReq->info.rspLen = size;
4,174,230✔
418

419
  if (rowsRead == 0 || mndCheckRetrieveFinished(pShow)) {
4,174,230✔
420
    pRsp->completed = 1;
4,173,811✔
421
    mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
4,173,811✔
422
    mndReleaseShowObj(pShow, true);
4,173,811✔
423
  } else {
424
    mDebug("show:0x%" PRIx64 ", retrieve not completed yet", pShow->id);
419✔
425
    mndReleaseShowObj(pShow, false);
419✔
426
  }
427

428
  blockDataDestroy(pBlock);
4,174,230✔
429
  return TSDB_CODE_SUCCESS;
4,174,230✔
430
_exit:
×
UNCOV
431
  mndReleaseShowObj(pShow, false);
×
UNCOV
432
  blockDataDestroy(pBlock);
×
UNCOV
433
  if (pRsp) {
×
UNCOV
434
    rpcFreeCont(pRsp);
×
435
  }
UNCOV
436
  return code;
×
437
}
438

439
static bool mndCheckRetrieveFinished(SShowObj *pShow) {
8,102,398✔
440
  if (pShow->pIter == NULL && pShow->numOfRows != 0) {
8,102,398✔
441
    return true;
3,926,827✔
442
  }
443
  return false;
4,175,571✔
444
}
445

446
void mndAddShowRetrieveHandle(SMnode *pMnode, EShowType showType, ShowRetrieveFp fp) {
20,813,166✔
447
  SShowMgmt *pMgmt = &pMnode->showMgmt;
20,813,166✔
448
  pMgmt->retrieveFps[showType] = fp;
20,813,166✔
449
}
20,813,166✔
450

451
void mndAddShowFreeIterHandle(SMnode *pMnode, EShowType showType, ShowFreeIterFp fp) {
17,729,734✔
452
  SShowMgmt *pMgmt = &pMnode->showMgmt;
17,729,734✔
453
  pMgmt->freeIterFps[showType] = fp;
17,729,734✔
454
}
17,729,734✔
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