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

taosdata / TDengine / #4986

15 Mar 2026 08:32AM UTC coverage: 37.305% (-31.3%) from 68.601%
#4986

push

travis-ci

tomchon
test: keep docs and unit test

125478 of 336361 relevant lines covered (37.3%)

1134847.06 hits per line

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

53.7
/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

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

34
int32_t mndInitShow(SMnode *pMnode) {
16✔
35
  int32_t    code = 0;
16✔
36
  SShowMgmt *pMgmt = &pMnode->showMgmt;
16✔
37

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

45
  mndSetMsgHandle(pMnode, TDMT_MND_SYSTABLE_RETRIEVE, mndProcessRetrieveSysTableReq);
16✔
46
  TAOS_RETURN(code);
16✔
47
}
48

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

57
static int32_t convertToRetrieveType(char *name, int32_t len) {
44✔
58
  int32_t type = -1;
44✔
59

60
  if (strncasecmp(name, TSDB_INS_TABLE_DNODES, len) == 0) {
44✔
61
    type = TSDB_MGMT_TABLE_DNODE;
×
62
  } else if (strncasecmp(name, TSDB_INS_TABLE_MNODES, len) == 0) {
44✔
63
    type = TSDB_MGMT_TABLE_MNODE;
×
64
    /*
65
      } else if (strncasecmp(name, TSDB_INS_TABLE_MODULES, len) == 0) {
66
        type = TSDB_MGMT_TABLE_MODULE;
67
    */
68
  } else if (strncasecmp(name, TSDB_INS_TABLE_QNODES, len) == 0) {
44✔
69
    type = TSDB_MGMT_TABLE_QNODE;
×
70
  } else if (strncasecmp(name, TSDB_INS_TABLE_SNODES, len) == 0) {
44✔
71
    type = TSDB_MGMT_TABLE_SNODE;
×
72
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES, len) == 0) {
44✔
73
    type = TSDB_MGMT_TABLE_ANODE;
×
74
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES_FULL, len) == 0) {
44✔
75
    type = TSDB_MGMT_TABLE_ANODE_FULL;
×
76
  } else if (strncasecmp(name, TSDB_INS_TABLE_BNODES, len) == 0) {
44✔
77
    type = TSDB_MGMT_TABLE_BNODE;
×
78
  } else if (strncasecmp(name, TSDB_INS_TABLE_XNODES, len) == 0) {
44✔
79
    type = TSDB_MGMT_TABLE_XNODES;
×
80
  } else if (strncasecmp(name, TSDB_INS_TABLE_XNODE_TASKS, len) == 0) {
44✔
81
    type = TSDB_MGMT_TABLE_XNODE_TASKS;
×
82
  } else if (strncasecmp(name, TSDB_INS_TABLE_XNODE_AGENTS, len) == 0) {
44✔
83
    type = TSDB_MGMT_TABLE_XNODE_AGENTS;
×
84
  } else if (strncasecmp(name, TSDB_INS_TABLE_XNODE_JOBS, len) == 0) {
44✔
85
    type = TSDB_MGMT_TABLE_XNODE_JOBS;
×
86
  } else if (strncasecmp(name, TSDB_INS_TABLE_ARBGROUPS, len) == 0) {
44✔
87
    type = TSDB_MGMT_TABLE_ARBGROUP;
×
88
  } else if (strncasecmp(name, TSDB_INS_TABLE_CLUSTER, len) == 0) {
44✔
89
    type = TSDB_MGMT_TABLE_CLUSTER;
2✔
90
  } else if (strncasecmp(name, TSDB_INS_TABLE_DATABASES, len) == 0) {
42✔
91
    type = TSDB_MGMT_TABLE_DB;
×
92
  } else if (strncasecmp(name, TSDB_INS_TABLE_FUNCTIONS, len) == 0) {
42✔
93
    type = TSDB_MGMT_TABLE_FUNC;
10✔
94
  } else if (strncasecmp(name, TSDB_INS_TABLE_INDEXES, len) == 0) {
32✔
95
    type = TSDB_MGMT_TABLE_INDEX;
×
96
  } else if (strncasecmp(name, TSDB_INS_TABLE_STABLES, len) == 0) {
32✔
97
    type = TSDB_MGMT_TABLE_STB;
26✔
98
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLES, len) == 0) {
6✔
99
    type = TSDB_MGMT_TABLE_TABLE;
×
100
  } else if (strncasecmp(name, TSDB_INS_TABLE_TAGS, len) == 0) {
6✔
101
    type = TSDB_MGMT_TABLE_TAG;
×
102
  } else if (strncasecmp(name, TSDB_INS_TABLE_COLS, len) == 0) {
6✔
103
    type = TSDB_MGMT_TABLE_COL;
×
104
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLE_DISTRIBUTED, len) == 0) {
6✔
105
    //    type = TSDB_MGMT_TABLE_DIST;
106
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS, len) == 0) {
6✔
107
    type = TSDB_MGMT_TABLE_USER;
×
108
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS_FULL, len) == 0) {
6✔
109
    type = TSDB_MGMT_TABLE_USER_FULL;
×
110
  } else if (strncasecmp(name, TSDB_INS_TABLE_TOKENS, len) == 0) {
6✔
111
    type = TSDB_MGMT_TABLE_TOKEN;
×
112
  } else if (strncasecmp(name, TSDB_INS_TABLE_LICENCES, len) == 0) {
6✔
113
    type = TSDB_MGMT_TABLE_GRANTS;
×
114
  } else if (strncasecmp(name, TSDB_INS_TABLE_VGROUPS, len) == 0) {
6✔
115
    type = TSDB_MGMT_TABLE_VGROUP;
×
116
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONSUMERS, len) == 0) {
6✔
117
    type = TSDB_MGMT_TABLE_CONSUMERS;
×
118
  } else if (strncasecmp(name, TSDB_INS_TABLE_SUBSCRIPTIONS, len) == 0) {
6✔
119
    type = TSDB_MGMT_TABLE_SUBSCRIPTIONS;
×
120
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_TRANS, len) == 0) {
6✔
121
    type = TSDB_MGMT_TABLE_TRANS;
×
122
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_SMAS, len) == 0) {
6✔
123
    type = TSDB_MGMT_TABLE_SMAS;
×
124
  } else if (strncasecmp(name, TSDB_INS_TABLE_CONFIGS, len) == 0) {
6✔
125
    type = TSDB_MGMT_TABLE_CONFIGS;
×
126
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONNECTIONS, len) == 0) {
6✔
127
    type = TSDB_MGMT_TABLE_CONNS;
4✔
128
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_QUERIES, len) == 0) {
2✔
129
    type = TSDB_MGMT_TABLE_QUERIES;
2✔
130
  } else if (strncasecmp(name, TSDB_INS_TABLE_VNODES, len) == 0) {
×
131
    type = TSDB_MGMT_TABLE_VNODES;
×
132
  } else if (strncasecmp(name, TSDB_INS_TABLE_TOPICS, len) == 0) {
×
133
    type = TSDB_MGMT_TABLE_TOPICS;
×
134
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAMS, len) == 0) {
×
135
    type = TSDB_MGMT_TABLE_STREAMS;
×
136
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_APPS, len) == 0) {
×
137
    type = TSDB_MGMT_TABLE_APPS;
×
138
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_INSTANCES, len) == 0) {
×
139
    type = TSDB_MGMT_TABLE_INSTANCE;
×
140
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAM_TASKS, len) == 0) {
×
141
    type = TSDB_MGMT_TABLE_STREAM_TASKS;
×
142
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAM_RECALCULATES, len) == 0) {
×
143
    type = TSDB_MGMT_TABLE_STREAM_RECALCULATES;
×
144
  } else if (strncasecmp(name, TSDB_INS_TABLE_USER_PRIVILEGES, len) == 0) {
×
145
    type = TSDB_MGMT_TABLE_PRIVILEGES;
×
146
  } else if (strncasecmp(name, TSDB_INS_TABLE_VIEWS, len) == 0) {
×
147
    type = TSDB_MGMT_TABLE_VIEWS;
×
148
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACTS, len) == 0) {
×
149
    type = TSDB_MGMT_TABLE_COMPACT;
×
150
  } else if (strncasecmp(name, TSDB_INS_TABLE_ENCRYPT_ALGORITHMS, len) == 0) {
×
151
    type = TSDB_MGMT_TABLE_ENCRYPT_ALGORITHMS;
×
152
  } else if (strncasecmp(name, TSDB_INS_TABLE_ENCRYPT_STATUS, len) == 0) {
×
153
    type = TSDB_MGMT_TABLE_ENCRYPT_STATUS;
×
154
  } else if (strncasecmp(name, TSDB_INS_TABLE_SCANS, len) == 0) {
×
155
    type = TSDB_MGMT_TABLE_SCAN;
×
156
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACT_DETAILS, len) == 0) {
×
157
    type = TSDB_MGMT_TABLE_COMPACT_DETAIL;
×
158
  } else if (strncasecmp(name, TSDB_INS_TABLE_SCAN_DETAILS, len) == 0) {
×
159
    type = TSDB_MGMT_TABLE_SCAN_DETAIL;
×
160
  } else if (strncasecmp(name, TSDB_INS_TABLE_SSMIGRATES, len) == 0) {
×
161
    type = TSDB_MGMT_TABLE_SSMIGRATE;
×
162
  } else if (strncasecmp(name, TSDB_INS_TABLE_TRANSACTION_DETAILS, len) == 0) {
×
163
    type = TSDB_MGMT_TABLE_TRANSACTION_DETAIL;
×
164
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_FULL, len) == 0) {
×
165
    type = TSDB_MGMT_TABLE_GRANTS_FULL;
×
166
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_LOGS, len) == 0) {
×
167
    type = TSDB_MGMT_TABLE_GRANTS_LOGS;
×
168
  } else if (strncasecmp(name, TSDB_INS_TABLE_MACHINES, len) == 0) {
×
169
    type = TSDB_MGMT_TABLE_MACHINES;
×
170
  } else if (strncasecmp(name, TSDB_INS_TABLE_ENCRYPTIONS, len) == 0) {
×
171
    type = TSDB_MGMT_TABLE_ENCRYPTIONS;
×
172
  } else if (strncasecmp(name, TSDB_INS_TABLE_TSMAS, len) == 0) {
×
173
    type = TSDB_MGMT_TABLE_TSMAS;
×
174
  } else if (strncasecmp(name, TSDB_INS_DISK_USAGE, len) == 0) {
×
175
    type = TSDB_MGMT_TABLE_USAGE;
×
176
  } else if (strncasecmp(name, TSDB_INS_TABLE_FILESETS, len) == 0) {
×
177
    type = TSDB_MGMT_TABLE_FILESETS;
×
178
  } else if (strncasecmp(name, TSDB_INS_TABLE_VC_COLS, len) == 0) {
×
179
    type = TSDB_MGMT_TABLE_VC_COL;
×
180
  } else if (strncasecmp(name, TSDB_INS_TABLE_MOUNTS, len) == 0) {
×
181
    type = TSDB_MGMT_TABLE_MOUNT;
×
182
  } else if (strncasecmp(name, TSDB_INS_TABLE_RSMAS, len) == 0) {
×
183
    type = TSDB_MGMT_TABLE_RSMA;
×
184
  } else if (strncasecmp(name, TSDB_INS_TABLE_RETENTIONS, len) == 0) {
×
185
    type = TSDB_MGMT_TABLE_RETENTION;
×
186
  } else if (strncasecmp(name, TSDB_INS_TABLE_RETENTION_DETAILS, len) == 0) {
×
187
    type = TSDB_MGMT_TABLE_RETENTION_DETAIL;
×
188
  } else if (strncasecmp(name, TSDB_INS_TABLE_ROLES, len) == 0) {
×
189
    type = TSDB_MGMT_TABLE_ROLE;
×
190
  } else if (strncasecmp(name, TSDB_INS_TABLE_ROLE_PRIVILEGES, len) == 0) {
×
191
    type = TSDB_MGMT_TABLE_ROLE_PRIVILEGES;
×
192
  } else if (strncasecmp(name, TSDB_INS_TABLE_ROLE_COL_PRIVILEGES, len) == 0) {
×
193
    type = TSDB_MGMT_TABLE_ROLE_COL_PRIVILEGES;
×
194
  } else {
195
    mError("invalid show name:%s len:%d", name, len);
×
196
  }
197

198
  return type;
44✔
199
}
200

201
static SShowObj *mndCreateShowObj(SMnode *pMnode, SRetrieveTableReq *pReq) {
44✔
202
  SShowMgmt *pMgmt = &pMnode->showMgmt;
44✔
203

204
  int64_t showId = atomic_add_fetch_64(&pMgmt->showId, 1);
44✔
205
  if (showId == 0) atomic_add_fetch_64(&pMgmt->showId, 1);
44✔
206

207
  int32_t size = sizeof(SShowObj);
44✔
208

209
  SShowObj showObj = {0};
44✔
210

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

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

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

229
static void mndFreeShowObj(SShowObj *pShow) {
44✔
230
  SMnode    *pMnode = pShow->pMnode;
44✔
231
  SShowMgmt *pMgmt = &pMnode->showMgmt;
44✔
232

233
  ShowFreeIterFp freeFp = pMgmt->freeIterFps[pShow->type];
44✔
234
  if (freeFp != NULL) {
44✔
235
    if (pShow->pIter != NULL) {
44✔
236
      mTrace("show:0x%" PRIx64 ", is destroying, data:%p, pIter:%p, ", pShow->id, pShow, pShow->pIter);
×
237

238
      (*freeFp)(pMnode, pShow->pIter);
×
239

240
      pShow->pIter = NULL;
×
241
    }
242
  }
243

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

247
static SShowObj *mndAcquireShowObj(SMnode *pMnode, int64_t showId) {
×
248
  SShowMgmt *pMgmt = &pMnode->showMgmt;
×
249

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

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

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

264
  // A bug in tcache.c
265
  forceRemove = 0;
44✔
266

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

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

284
  mDebug("process to retrieve systable req db:%s, tb:%s, compactId:%" PRId64, retrieveReq.db, retrieveReq.tb,
44✔
285
         retrieveReq.compactId);
286

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

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

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

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

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

352
  int32_t numOfCols = pShow->pMeta->numOfColumns;
44✔
353

354
  SSDataBlock *pBlock = NULL;
44✔
355
  code = createDataBlock(&pBlock);
44✔
356
  if (code) {
44✔
357
    TAOS_RETURN(code);
×
358
  }
359

360
  for (int32_t i = 0; i < numOfCols; ++i) {
604✔
361
    SColumnInfoData idata = {0};
560✔
362

363
    SSchema *p = &pShow->pMeta->pSchemas[i];
560✔
364

365
    idata.info.bytes = p->bytes;
560✔
366
    idata.info.type = p->type;
560✔
367
    idata.info.colId = p->colId;
560✔
368
    TAOS_CHECK_RETURN(blockDataAppendColInfo(pBlock, &idata));
560✔
369
  }
370

371
  TAOS_CHECK_RETURN(blockDataEnsureCapacity(pBlock, rowsToRead));
44✔
372

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

386
    pBlock->info.rows = rowsRead;
44✔
387
    mDebug("show:0x%" PRIx64 ", stop retrieve data, rowsRead:%d numOfRows:%d", pShow->id, rowsRead, pShow->numOfRows);
44✔
388
  }
389

390
  size_t dataEncodeBufSize = blockGetEncodeSize(pBlock);
44✔
391
  size = sizeof(SRetrieveMetaTableRsp) + sizeof(int32_t) + sizeof(SSysTableSchema) * pShow->pMeta->numOfColumns +
44✔
392
         dataEncodeBufSize;
393

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

401
  pRsp->handle = htobe64(pShow->id);
44✔
402

403
  if (rowsRead > 0) {
44✔
404
    char    *pStart = pRsp->data;
36✔
405
    SSchema *ps = pShow->pMeta->pSchemas;
36✔
406

407
    *(int32_t *)pStart = htonl(pShow->pMeta->numOfColumns);
36✔
408
    pStart += sizeof(int32_t);  // number of columns
36✔
409

410
    for (int32_t i = 0; i < pShow->pMeta->numOfColumns; ++i) {
488✔
411
      SSysTableSchema *pSchema = (SSysTableSchema *)pStart;
452✔
412
      pSchema->bytes = htonl(ps[i].bytes);
452✔
413
      pSchema->colId = htons(ps[i].colId);
452✔
414
      pSchema->type = ps[i].type;
452✔
415

416
      pStart += sizeof(SSysTableSchema);
452✔
417
    }
418

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

428
  pRsp->numOfRows = htonl(rowsRead);
44✔
429
  pRsp->precision = TSDB_TIME_PRECISION_MILLI;  // millisecond time precision
44✔
430
  pReq->info.rsp = pRsp;
44✔
431
  pReq->info.rspLen = size;
44✔
432

433
  if (rowsRead == 0 || mndCheckRetrieveFinished(pShow)) {
44✔
434
    pRsp->completed = 1;
44✔
435
    mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
44✔
436
    mndReleaseShowObj(pShow, true);
44✔
437
  } else {
438
    mDebug("show:0x%" PRIx64 ", retrieve not completed yet", pShow->id);
×
439
    mndReleaseShowObj(pShow, false);
×
440
  }
441

442
  blockDataDestroy(pBlock);
44✔
443
  return TSDB_CODE_SUCCESS;
44✔
444
_exit:
×
445
  mndReleaseShowObj(pShow, false);
×
446
  blockDataDestroy(pBlock);
×
447
  if (pRsp) {
×
448
    rpcFreeCont(pRsp);
×
449
  }
450
  return code;
×
451
}
452

453
static bool mndCheckRetrieveFinished(SShowObj *pShow) {
80✔
454
  if (pShow->pIter == NULL && pShow->numOfRows != 0) {
80✔
455
    return true;
36✔
456
  }
457
  return false;
44✔
458
}
459

460
void mndAddShowRetrieveHandle(SMnode *pMnode, EShowType showType, ShowRetrieveFp fp) {
928✔
461
  SShowMgmt *pMgmt = &pMnode->showMgmt;
928✔
462
  pMgmt->retrieveFps[showType] = fp;
928✔
463
}
928✔
464

465
void mndAddShowFreeIterHandle(SMnode *pMnode, EShowType showType, ShowFreeIterFp fp) {
800✔
466
  SShowMgmt *pMgmt = &pMnode->showMgmt;
800✔
467
  pMgmt->freeIterFps[showType] = fp;
800✔
468
}
800✔
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