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

taosdata / TDengine / #4488

12 Jul 2025 07:47AM UTC coverage: 62.207% (-0.7%) from 62.948%
#4488

push

travis-ci

web-flow
docs: update stream docs (#31822)

157961 of 324087 branches covered (48.74%)

Branch coverage included in aggregate %.

244465 of 322830 relevant lines covered (75.73%)

6561668.76 hits per line

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

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

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

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

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

59
  if (strncasecmp(name, TSDB_INS_TABLE_DNODES, len) == 0) {
18,235✔
60
    type = TSDB_MGMT_TABLE_DNODE;
1,857✔
61
  } else if (strncasecmp(name, TSDB_INS_TABLE_MNODES, len) == 0) {
16,378✔
62
    type = TSDB_MGMT_TABLE_MNODE;
548✔
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) {
15,830✔
68
    type = TSDB_MGMT_TABLE_QNODE;
34✔
69
  } else if (strncasecmp(name, TSDB_INS_TABLE_SNODES, len) == 0) {
15,796✔
70
    type = TSDB_MGMT_TABLE_SNODE;
26✔
71
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES, len) == 0) {
15,770✔
72
    type = TSDB_MGMT_TABLE_ANODE;
4✔
73
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES_FULL, len) == 0) {
15,766✔
74
    type = TSDB_MGMT_TABLE_ANODE_FULL;
1✔
75
  } else if (strncasecmp(name, TSDB_INS_TABLE_BNODES, len) == 0) {
15,765✔
76
    type = TSDB_MGMT_TABLE_BNODE;
278✔
77
  } else if (strncasecmp(name, TSDB_INS_TABLE_ARBGROUPS, len) == 0) {
15,487!
78
    type = TSDB_MGMT_TABLE_ARBGROUP;
×
79
  } else if (strncasecmp(name, TSDB_INS_TABLE_CLUSTER, len) == 0) {
15,487✔
80
    type = TSDB_MGMT_TABLE_CLUSTER;
12✔
81
  } else if (strncasecmp(name, TSDB_INS_TABLE_DATABASES, len) == 0) {
15,475✔
82
    type = TSDB_MGMT_TABLE_DB;
1,270✔
83
  } else if (strncasecmp(name, TSDB_INS_TABLE_FUNCTIONS, len) == 0) {
14,205✔
84
    type = TSDB_MGMT_TABLE_FUNC;
34✔
85
  } else if (strncasecmp(name, TSDB_INS_TABLE_INDEXES, len) == 0) {
14,171✔
86
    type = TSDB_MGMT_TABLE_INDEX;
387✔
87
  } else if (strncasecmp(name, TSDB_INS_TABLE_STABLES, len) == 0) {
13,784✔
88
    type = TSDB_MGMT_TABLE_STB;
1,032✔
89
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLES, len) == 0) {
12,752!
90
    type = TSDB_MGMT_TABLE_TABLE;
×
91
  } else if (strncasecmp(name, TSDB_INS_TABLE_TAGS, len) == 0) {
12,752!
92
    type = TSDB_MGMT_TABLE_TAG;
×
93
  } else if (strncasecmp(name, TSDB_INS_TABLE_COLS, len) == 0) {
12,752✔
94
    type = TSDB_MGMT_TABLE_COL;
6,833✔
95
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLE_DISTRIBUTED, len) == 0) {
5,919!
96
    //    type = TSDB_MGMT_TABLE_DIST;
97
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS, len) == 0) {
5,919✔
98
    type = TSDB_MGMT_TABLE_USER;
61✔
99
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS_FULL, len) == 0) {
5,858!
100
    type = TSDB_MGMT_TABLE_USER_FULL;
×
101
  } else if (strncasecmp(name, TSDB_INS_TABLE_LICENCES, len) == 0) {
5,858✔
102
    type = TSDB_MGMT_TABLE_GRANTS;
97✔
103
  } else if (strncasecmp(name, TSDB_INS_TABLE_VGROUPS, len) == 0) {
5,761✔
104
    type = TSDB_MGMT_TABLE_VGROUP;
792✔
105
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONSUMERS, len) == 0) {
4,969✔
106
    type = TSDB_MGMT_TABLE_CONSUMERS;
92✔
107
  } else if (strncasecmp(name, TSDB_INS_TABLE_SUBSCRIPTIONS, len) == 0) {
4,877✔
108
    type = TSDB_MGMT_TABLE_SUBSCRIPTIONS;
89✔
109
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_TRANS, len) == 0) {
4,788✔
110
    type = TSDB_MGMT_TABLE_TRANS;
186✔
111
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_SMAS, len) == 0) {
4,602!
112
    type = TSDB_MGMT_TABLE_SMAS;
×
113
  } else if (strncasecmp(name, TSDB_INS_TABLE_CONFIGS, len) == 0) {
4,602✔
114
    type = TSDB_MGMT_TABLE_CONFIGS;
7✔
115
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONNECTIONS, len) == 0) {
4,595✔
116
    type = TSDB_MGMT_TABLE_CONNS;
50✔
117
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_QUERIES, len) == 0) {
4,545✔
118
    type = TSDB_MGMT_TABLE_QUERIES;
16✔
119
  } else if (strncasecmp(name, TSDB_INS_TABLE_VNODES, len) == 0) {
4,529✔
120
    type = TSDB_MGMT_TABLE_VNODES;
111✔
121
  } else if (strncasecmp(name, TSDB_INS_TABLE_TOPICS, len) == 0) {
4,418✔
122
    type = TSDB_MGMT_TABLE_TOPICS;
84✔
123
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAMS, len) == 0) {
4,334✔
124
    type = TSDB_MGMT_TABLE_STREAMS;
233✔
125
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_APPS, len) == 0) {
4,101✔
126
    type = TSDB_MGMT_TABLE_APPS;
16✔
127
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAM_TASKS, len) == 0) {
4,085✔
128
    type = TSDB_MGMT_TABLE_STREAM_TASKS;
3,808✔
129
  } else if (strncasecmp(name, TSDB_INS_TABLE_USER_PRIVILEGES, len) == 0) {
277✔
130
    type = TSDB_MGMT_TABLE_PRIVILEGES;
23✔
131
  } else if (strncasecmp(name, TSDB_INS_TABLE_VIEWS, len) == 0) {
254✔
132
    type = TSDB_MGMT_TABLE_VIEWS;
73✔
133
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACTS, len) == 0) {
181✔
134
    type = TSDB_MGMT_TABLE_COMPACT;
71✔
135
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACT_DETAILS, len) == 0) {
110!
136
    type = TSDB_MGMT_TABLE_COMPACT_DETAIL;
×
137
  } else if (strncasecmp(name, TSDB_INS_TABLE_TRANSACTION_DETAILS, len) == 0) {
110!
138
    type = TSDB_MGMT_TABLE_TRANSACTION_DETAIL;
×
139
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_FULL, len) == 0) {
110✔
140
    type = TSDB_MGMT_TABLE_GRANTS_FULL;
79✔
141
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_LOGS, len) == 0) {
31✔
142
    type = TSDB_MGMT_TABLE_GRANTS_LOGS;
11✔
143
  } else if (strncasecmp(name, TSDB_INS_TABLE_MACHINES, len) == 0) {
20✔
144
    type = TSDB_MGMT_TABLE_MACHINES;
9✔
145
  } else if (strncasecmp(name, TSDB_INS_TABLE_ENCRYPTIONS, len) == 0) {
11✔
146
    type = TSDB_MGMT_TABLE_ENCRYPTIONS;
5✔
147
  } else if (strncasecmp(name, TSDB_INS_TABLE_TSMAS, len) == 0) {
6!
148
    type = TSDB_MGMT_TABLE_TSMAS;
6✔
149
  } else if (strncasecmp(name, TSDB_INS_DISK_USAGE, len) == 0) {
×
150
    type = TSDB_MGMT_TABLE_USAGE;
×
151
  } else if (strncasecmp(name, TSDB_INS_TABLE_FILESETS, len) == 0) {
×
152
    type = TSDB_MGMT_TABLE_FILESETS;
×
153
  } else if (strncasecmp(name, TSDB_INS_TABLE_MOUNTS, len) == 0) {
×
154
    type = TSDB_MGMT_TABLE_MOUNT;
×
155
  } else {
156
    mError("invalid show name:%s len:%d", name, len);
×
157
  }
158

159
  return type;
18,235✔
160
}
161

162
static SShowObj *mndCreateShowObj(SMnode *pMnode, SRetrieveTableReq *pReq) {
18,234✔
163
  SShowMgmt *pMgmt = &pMnode->showMgmt;
18,234✔
164

165
  int64_t showId = atomic_add_fetch_64(&pMgmt->showId, 1);
18,234✔
166
  if (showId == 0) atomic_add_fetch_64(&pMgmt->showId, 1);
18,235!
167

168
  int32_t size = sizeof(SShowObj);
18,235✔
169

170
  SShowObj showObj = {0};
18,235✔
171

172
  showObj.id = showId;
18,235✔
173
  showObj.pMnode = pMnode;
18,235✔
174
  showObj.type = convertToRetrieveType(pReq->tb, tListLen(pReq->tb));
18,235✔
175
  (void)memcpy(showObj.db, pReq->db, TSDB_DB_FNAME_LEN);
18,235✔
176
  tstrncpy(showObj.filterTb, pReq->filterTb, TSDB_TABLE_NAME_LEN);
18,235✔
177

178
  int32_t   keepTime = tsShellActivityTimer * 6 * 1000;
18,235✔
179
  SShowObj *pShow = taosCachePut(pMgmt->cache, &showId, sizeof(int64_t), &showObj, size, keepTime);
18,235✔
180
  if (pShow == NULL) {
18,235!
181
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
182
    mError("show:0x%" PRIx64 ", failed to put into cache since %s", showId, terrstr());
×
183
    return NULL;
×
184
  }
185

186
  mTrace("show:0x%" PRIx64 ", is created, data:%p", showId, pShow);
18,235✔
187
  return pShow;
18,235✔
188
}
189

190
static void mndFreeShowObj(SShowObj *pShow) {
18,235✔
191
  SMnode    *pMnode = pShow->pMnode;
18,235✔
192
  SShowMgmt *pMgmt = &pMnode->showMgmt;
18,235✔
193

194
  ShowFreeIterFp freeFp = pMgmt->freeIterFps[pShow->type];
18,235✔
195
  if (freeFp != NULL) {
18,235✔
196
    if (pShow->pIter != NULL) {
18,075✔
197
      mTrace("show:0x%" PRIx64 ", is destroying, data:%p, pIter:%p, ", pShow->id, pShow, pShow->pIter);
1!
198

199
      (*freeFp)(pMnode, pShow->pIter);
1✔
200

201
      pShow->pIter = NULL;
1✔
202
    }
203
  }
204

205
  mTrace("show:0x%" PRIx64 ", is destroyed, data:%p", pShow->id, pShow);
18,235✔
206
}
18,235✔
207

208
static SShowObj *mndAcquireShowObj(SMnode *pMnode, int64_t showId) {
86✔
209
  SShowMgmt *pMgmt = &pMnode->showMgmt;
86✔
210

211
  SShowObj *pShow = taosCacheAcquireByKey(pMgmt->cache, &showId, sizeof(showId));
86✔
212
  if (pShow == NULL) {
86!
213
    mError("show:0x%" PRIx64 ", already destroyed", showId);
×
214
    return NULL;
×
215
  }
216

217
  mTrace("show:0x%" PRIx64 ", acquired from cache, data:%p", pShow->id, pShow);
86!
218
  return pShow;
86✔
219
}
220

221
static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove) {
18,317✔
222
  if (pShow == NULL) return;
18,317!
223
  mTrace("show:0x%" PRIx64 ", released from cache, data:%p force:%d", pShow->id, pShow, forceRemove);
18,317✔
224

225
  // A bug in tcache.c
226
  forceRemove = 0;
18,317✔
227

228
  SMnode    *pMnode = pShow->pMnode;
18,317✔
229
  SShowMgmt *pMgmt = &pMnode->showMgmt;
18,317✔
230
  taosCacheRelease(pMgmt->cache, (void **)(&pShow), forceRemove);
18,317✔
231
}
232

233
static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) {
18,323✔
234
  int32_t    code = 0;
18,323✔
235
  SMnode    *pMnode = pReq->info.node;
18,323✔
236
  SShowMgmt *pMgmt = &pMnode->showMgmt;
18,323✔
237
  SShowObj  *pShow = NULL;
18,323✔
238
  int32_t    rowsToRead = SHOW_STEP_SIZE;
18,323✔
239
  int32_t    size = 0;
18,323✔
240
  int32_t    rowsRead = 0;
18,323✔
241
  mDebug("mndProcessRetrieveSysTableReq start");
18,323✔
242
  SRetrieveTableReq retrieveReq = {0};
18,323✔
243
  TAOS_CHECK_RETURN(tDeserializeSRetrieveTableReq(pReq->pCont, pReq->contLen, &retrieveReq));
18,323✔
244

245
  mDebug("process to retrieve systable req db:%s, tb:%s, compactId:%" PRId64, retrieveReq.db, retrieveReq.tb,
18,321✔
246
         retrieveReq.compactId);
247

248
  if (retrieveReq.showId == 0) {
18,321✔
249
    STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, retrieveReq.tb, strlen(retrieveReq.tb));
18,235✔
250
    if (pMeta == NULL) {
18,235✔
251
      pMeta = taosHashGet(pMnode->perfsMeta, retrieveReq.tb, strlen(retrieveReq.tb));
360✔
252
      if (pMeta == NULL) {
360!
253
        code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
×
254
        mError("failed to process show-retrieve req:%p since %s", pShow, tstrerror(code));
×
255
        TAOS_RETURN(code);
×
256
      }
257
    }
258

259
    pShow = mndCreateShowObj(pMnode, &retrieveReq);
18,235✔
260
    if (pShow == NULL) {
18,235!
261
      code = terrno;
×
262
      mError("failed to process show-meta req since %s", tstrerror(code));
×
263
      TAOS_RETURN(code);
×
264
    }
265

266
    pShow->pMeta = pMeta;
18,235✔
267
    pShow->numOfColumns = pShow->pMeta->numOfColumns;
18,235✔
268
  } else {
269
    pShow = mndAcquireShowObj(pMnode, retrieveReq.showId);
86✔
270
    if (pShow == NULL) {
86!
271
      code = TSDB_CODE_MND_INVALID_SHOWOBJ;
×
272
      mError("failed to process show-retrieve req:%p since %s", pShow, tstrerror(code));
×
273
      TAOS_RETURN(code);
×
274
    }
275
  }
276

277
  if (pShow->type == TSDB_MGMT_TABLE_COL) {  // expend capacity for ins_columns
18,321✔
278
    rowsToRead = SHOW_COLS_STEP_SIZE;
6,857✔
279
  } else if (pShow->type == TSDB_MGMT_TABLE_PRIVILEGES) {
11,464✔
280
    rowsToRead = SHOW_PRIVILEGES_STEP_SIZE;
23✔
281
  }
282
  ShowRetrieveFp retrieveFp = pMgmt->retrieveFps[pShow->type];
18,321✔
283
  if (retrieveFp == NULL) {
18,321!
284
    mndReleaseShowObj(pShow, false);
×
285
    code = TSDB_CODE_MSG_NOT_PROCESSED;
×
286
    mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, tstrerror(code));
×
287
    TAOS_RETURN(code);
×
288
  }
289

290
  mDebug("show:0x%" PRIx64 ", start retrieve data, type:%d", pShow->id, pShow->type);
18,321✔
291
  if (retrieveReq.user[0] != 0) {
18,321✔
292
    (void)memcpy(pReq->info.conn.user, retrieveReq.user, TSDB_USER_LEN);
18,299✔
293
  } else {
294
    (void)memcpy(pReq->info.conn.user, TSDB_DEFAULT_USER, strlen(TSDB_DEFAULT_USER) + 1);
22✔
295
  }
296
  code = -1;
18,321✔
297
  if (retrieveReq.db[0] &&
22,152✔
298
      (code = mndCheckShowPrivilege(pMnode, pReq->info.conn.user, pShow->type, retrieveReq.db)) != 0) {
3,831✔
299
    TAOS_RETURN(code);
4✔
300
  }
301
  if (pShow->type == TSDB_MGMT_TABLE_USER_FULL) {
18,317!
302
    if (strcmp(pReq->info.conn.user, "root") != 0) {
×
303
      mError("The operation is not permitted, user:%s, pShow->type:%d", pReq->info.conn.user, pShow->type);
×
304
      code = TSDB_CODE_MND_NO_RIGHTS;
×
305
      TAOS_RETURN(code);
×
306
    }
307
  }
308

309
  int32_t numOfCols = pShow->pMeta->numOfColumns;
18,317✔
310

311
  SSDataBlock *pBlock = NULL;
18,317✔
312
  code = createDataBlock(&pBlock);
18,317✔
313
  if (code) {
18,317!
314
    TAOS_RETURN(code);
×
315
  }
316

317
  for (int32_t i = 0; i < numOfCols; ++i) {
296,387✔
318
    SColumnInfoData idata = {0};
278,069✔
319

320
    SSchema *p = &pShow->pMeta->pSchemas[i];
278,069✔
321

322
    idata.info.bytes = p->bytes;
278,069✔
323
    idata.info.type = p->type;
278,069✔
324
    idata.info.colId = p->colId;
278,069✔
325
    TAOS_CHECK_RETURN(blockDataAppendColInfo(pBlock, &idata));
278,069!
326
  }
327

328
  TAOS_CHECK_RETURN(blockDataEnsureCapacity(pBlock, rowsToRead));
18,318!
329

330
  if (mndCheckRetrieveFinished(pShow)) {
18,317!
331
    mDebug("show:0x%" PRIx64 ", read finished, numOfRows:%d", pShow->id, pShow->numOfRows);
×
332
    rowsRead = 0;
×
333
  } else {
334
    rowsRead = (*retrieveFp)(pReq, pShow, pBlock, rowsToRead);
18,317✔
335
    if (rowsRead < 0) {
18,317✔
336
      code = rowsRead;
7✔
337
      mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
7!
338
      mndReleaseShowObj(pShow, true);
7✔
339
      blockDataDestroy(pBlock);
7✔
340
      TAOS_RETURN(code);
7✔
341
    }
342

343
    pBlock->info.rows = rowsRead;
18,310✔
344
    mDebug("show:0x%" PRIx64 ", stop retrieve data, rowsRead:%d numOfRows:%d", pShow->id, rowsRead, pShow->numOfRows);
18,310✔
345
  }
346

347
  size_t dataEncodeBufSize = blockGetEncodeSize(pBlock);
18,310✔
348
  size = sizeof(SRetrieveMetaTableRsp) + sizeof(int32_t) + sizeof(SSysTableSchema) * pShow->pMeta->numOfColumns +
18,310✔
349
         dataEncodeBufSize;
350

351
  SRetrieveMetaTableRsp *pRsp = rpcMallocCont(size);
18,310✔
352
  if (pRsp == NULL) {
18,310!
353
    mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, tstrerror(code));
×
354
    code = terrno;
×
355
    goto _exit;
×
356
  }
357

358
  pRsp->handle = htobe64(pShow->id);
18,310✔
359

360
  if (rowsRead > 0) {
18,310✔
361
    char    *pStart = pRsp->data;
17,819✔
362
    SSchema *ps = pShow->pMeta->pSchemas;
17,819✔
363

364
    *(int32_t *)pStart = htonl(pShow->pMeta->numOfColumns);
17,819✔
365
    pStart += sizeof(int32_t);  // number of columns
17,819✔
366

367
    for (int32_t i = 0; i < pShow->pMeta->numOfColumns; ++i) {
290,126✔
368
      SSysTableSchema *pSchema = (SSysTableSchema *)pStart;
272,307✔
369
      pSchema->bytes = htonl(ps[i].bytes);
272,307✔
370
      pSchema->colId = htons(ps[i].colId);
272,307✔
371
      pSchema->type = ps[i].type;
272,307✔
372

373
      pStart += sizeof(SSysTableSchema);
272,307✔
374
    }
375

376
    int32_t len = blockEncode(pBlock, pStart, dataEncodeBufSize, pShow->pMeta->numOfColumns);
17,819✔
377
    if (len < 0) {
17,819!
378
      mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, tstrerror(code));
×
379
      code = terrno;
×
380
      return code;
×
381
    }
382
  }
383

384
  pRsp->numOfRows = htonl(rowsRead);
18,310✔
385
  pRsp->precision = TSDB_TIME_PRECISION_MILLI;  // millisecond time precision
18,310✔
386
  pReq->info.rsp = pRsp;
18,310✔
387
  pReq->info.rspLen = size;
18,310✔
388

389
  if (rowsRead == 0 || mndCheckRetrieveFinished(pShow)) {
18,310✔
390
    pRsp->completed = 1;
18,223✔
391
    mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
18,223✔
392
    mndReleaseShowObj(pShow, true);
18,223✔
393
  } else {
394
    mDebug("show:0x%" PRIx64 ", retrieve not completed yet", pShow->id);
87!
395
    mndReleaseShowObj(pShow, false);
87✔
396
  }
397

398
  blockDataDestroy(pBlock);
18,310✔
399
  return TSDB_CODE_SUCCESS;
18,310✔
400
_exit:
×
401
  mndReleaseShowObj(pShow, false);
×
402
  blockDataDestroy(pBlock);
×
403
  if (pRsp) {
×
404
    rpcFreeCont(pRsp);
×
405
  }
406
  return code;
×
407
}
408

409
static bool mndCheckRetrieveFinished(SShowObj *pShow) {
36,136✔
410
  if (pShow->pIter == NULL && pShow->numOfRows != 0) {
36,136✔
411
    return true;
17,732✔
412
  }
413
  return false;
18,404✔
414
}
415

416
void mndAddShowRetrieveHandle(SMnode *pMnode, EShowType showType, ShowRetrieveFp fp) {
98,680✔
417
  SShowMgmt *pMgmt = &pMnode->showMgmt;
98,680✔
418
  pMgmt->retrieveFps[showType] = fp;
98,680✔
419
}
98,680✔
420

421
void mndAddShowFreeIterHandle(SMnode *pMnode, EShowType showType, ShowFreeIterFp fp) {
91,279✔
422
  SShowMgmt *pMgmt = &pMnode->showMgmt;
91,279✔
423
  pMgmt->freeIterFps[showType] = fp;
91,279✔
424
}
91,279✔
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