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

taosdata / TDengine / #4541

19 Jul 2025 01:13AM UTC coverage: 56.753% (-1.6%) from 58.31%
#4541

push

travis-ci

web-flow
fix: subquery memleak (#32024)

124299 of 282344 branches covered (44.02%)

Branch coverage included in aggregate %.

181106 of 255787 relevant lines covered (70.8%)

24937406.43 hits per line

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

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

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

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

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

59
  if (strncasecmp(name, TSDB_INS_TABLE_DNODES, len) == 0) {
422,058✔
60
    type = TSDB_MGMT_TABLE_DNODE;
15,069✔
61
  } else if (strncasecmp(name, TSDB_INS_TABLE_MNODES, len) == 0) {
406,989✔
62
    type = TSDB_MGMT_TABLE_MNODE;
9,278✔
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) {
397,711✔
68
    type = TSDB_MGMT_TABLE_QNODE;
4,358✔
69
  } else if (strncasecmp(name, TSDB_INS_TABLE_SNODES, len) == 0) {
393,353✔
70
    type = TSDB_MGMT_TABLE_SNODE;
7,220✔
71
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES, len) == 0) {
386,133✔
72
    type = TSDB_MGMT_TABLE_ANODE;
4✔
73
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES_FULL, len) == 0) {
386,129✔
74
    type = TSDB_MGMT_TABLE_ANODE_FULL;
1✔
75
  } else if (strncasecmp(name, TSDB_INS_TABLE_BNODES, len) == 0) {
386,128✔
76
    type = TSDB_MGMT_TABLE_BNODE;
278✔
77
  } else if (strncasecmp(name, TSDB_INS_TABLE_ARBGROUPS, len) == 0) {
385,850!
78
    type = TSDB_MGMT_TABLE_ARBGROUP;
×
79
  } else if (strncasecmp(name, TSDB_INS_TABLE_CLUSTER, len) == 0) {
385,850✔
80
    type = TSDB_MGMT_TABLE_CLUSTER;
8,638✔
81
  } else if (strncasecmp(name, TSDB_INS_TABLE_DATABASES, len) == 0) {
377,212✔
82
    type = TSDB_MGMT_TABLE_DB;
54,294✔
83
  } else if (strncasecmp(name, TSDB_INS_TABLE_FUNCTIONS, len) == 0) {
322,918✔
84
    type = TSDB_MGMT_TABLE_FUNC;
14,411✔
85
  } else if (strncasecmp(name, TSDB_INS_TABLE_INDEXES, len) == 0) {
308,507✔
86
    type = TSDB_MGMT_TABLE_INDEX;
13,500✔
87
  } else if (strncasecmp(name, TSDB_INS_TABLE_STABLES, len) == 0) {
295,007✔
88
    type = TSDB_MGMT_TABLE_STB;
20,106✔
89
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLES, len) == 0) {
274,901!
90
    type = TSDB_MGMT_TABLE_TABLE;
×
91
  } else if (strncasecmp(name, TSDB_INS_TABLE_TAGS, len) == 0) {
274,901!
92
    type = TSDB_MGMT_TABLE_TAG;
×
93
  } else if (strncasecmp(name, TSDB_INS_TABLE_COLS, len) == 0) {
274,901✔
94
    type = TSDB_MGMT_TABLE_COL;
21,311✔
95
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLE_DISTRIBUTED, len) == 0) {
253,590✔
96
    //    type = TSDB_MGMT_TABLE_DIST;
97
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS, len) == 0) {
253,588✔
98
    type = TSDB_MGMT_TABLE_USER;
10,126✔
99
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS_FULL, len) == 0) {
243,462!
100
    type = TSDB_MGMT_TABLE_USER_FULL;
×
101
  } else if (strncasecmp(name, TSDB_INS_TABLE_LICENCES, len) == 0) {
243,462✔
102
    type = TSDB_MGMT_TABLE_GRANTS;
14,376✔
103
  } else if (strncasecmp(name, TSDB_INS_TABLE_VGROUPS, len) == 0) {
229,086✔
104
    type = TSDB_MGMT_TABLE_VGROUP;
28,174✔
105
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONSUMERS, len) == 0) {
200,912✔
106
    type = TSDB_MGMT_TABLE_CONSUMERS;
17,320✔
107
  } else if (strncasecmp(name, TSDB_INS_TABLE_SUBSCRIPTIONS, len) == 0) {
183,592✔
108
    type = TSDB_MGMT_TABLE_SUBSCRIPTIONS;
11,585✔
109
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_TRANS, len) == 0) {
172,007✔
110
    type = TSDB_MGMT_TABLE_TRANS;
14,603✔
111
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_SMAS, len) == 0) {
157,404!
112
    type = TSDB_MGMT_TABLE_SMAS;
×
113
  } else if (strncasecmp(name, TSDB_INS_TABLE_CONFIGS, len) == 0) {
157,404✔
114
    type = TSDB_MGMT_TABLE_CONFIGS;
2,883✔
115
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONNECTIONS, len) == 0) {
154,521✔
116
    type = TSDB_MGMT_TABLE_CONNS;
12,988✔
117
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_QUERIES, len) == 0) {
141,533✔
118
    type = TSDB_MGMT_TABLE_QUERIES;
22,990✔
119
  } else if (strncasecmp(name, TSDB_INS_TABLE_VNODES, len) == 0) {
118,543✔
120
    type = TSDB_MGMT_TABLE_VNODES;
15,957✔
121
  } else if (strncasecmp(name, TSDB_INS_TABLE_TOPICS, len) == 0) {
102,586✔
122
    type = TSDB_MGMT_TABLE_TOPICS;
10,131✔
123
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAMS, len) == 0) {
92,455✔
124
    type = TSDB_MGMT_TABLE_STREAMS;
12,956✔
125
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_APPS, len) == 0) {
79,499✔
126
    type = TSDB_MGMT_TABLE_APPS;
21,564✔
127
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAM_TASKS, len) == 0) {
57,935✔
128
    type = TSDB_MGMT_TABLE_STREAM_TASKS;
20,112✔
129
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAM_RECALCULATES, len) == 0) {
37,823!
130
    type = TSDB_MGMT_TABLE_STREAM_RECALCULATES;
×
131
  } else if (strncasecmp(name, TSDB_INS_TABLE_USER_PRIVILEGES, len) == 0) {
37,823✔
132
    type = TSDB_MGMT_TABLE_PRIVILEGES;
8,641✔
133
  } else if (strncasecmp(name, TSDB_INS_TABLE_VIEWS, len) == 0) {
29,182✔
134
    type = TSDB_MGMT_TABLE_VIEWS;
13,030✔
135
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACTS, len) == 0) {
16,152✔
136
    type = TSDB_MGMT_TABLE_COMPACT;
4,376✔
137
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACT_DETAILS, len) == 0) {
11,776✔
138
    type = TSDB_MGMT_TABLE_COMPACT_DETAIL;
11,475✔
139
  } else if (strncasecmp(name, TSDB_INS_TABLE_TRANSACTION_DETAILS, len) == 0) {
301!
140
    type = TSDB_MGMT_TABLE_TRANSACTION_DETAIL;
×
141
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_FULL, len) == 0) {
301✔
142
    type = TSDB_MGMT_TABLE_GRANTS_FULL;
7✔
143
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_LOGS, len) == 0) {
294✔
144
    type = TSDB_MGMT_TABLE_GRANTS_LOGS;
7✔
145
  } else if (strncasecmp(name, TSDB_INS_TABLE_MACHINES, len) == 0) {
287✔
146
    type = TSDB_MGMT_TABLE_MACHINES;
7✔
147
  } else if (strncasecmp(name, TSDB_INS_TABLE_ENCRYPTIONS, len) == 0) {
280✔
148
    type = TSDB_MGMT_TABLE_ENCRYPTIONS;
5✔
149
  } else if (strncasecmp(name, TSDB_INS_TABLE_TSMAS, len) == 0) {
275!
150
    type = TSDB_MGMT_TABLE_TSMAS;
×
151
  } else if (strncasecmp(name, TSDB_INS_DISK_USAGE, len) == 0) {
275!
152
    type = TSDB_MGMT_TABLE_USAGE;
×
153
  } else if (strncasecmp(name, TSDB_INS_TABLE_FILESETS, len) == 0) {
275!
154
    type = TSDB_MGMT_TABLE_FILESETS;
×
155
  } else if (strncasecmp(name, TSDB_INS_TABLE_VC_COLS, len) == 0) {
275!
156
    type = TSDB_MGMT_TABLE_VC_COL;
×
157
  } else if (strncasecmp(name, TSDB_INS_TABLE_MOUNTS, len) == 0) {
275!
158
    type = TSDB_MGMT_TABLE_MOUNT;
×
159
  } else {
160
    mError("invalid show name:%s len:%d", name, len);
275!
161
  }
162

163
  return type;
421,825✔
164
}
165

166
static SShowObj *mndCreateShowObj(SMnode *pMnode, SRetrieveTableReq *pReq) {
421,848✔
167
  SShowMgmt *pMgmt = &pMnode->showMgmt;
421,848✔
168

169
  int64_t showId = atomic_add_fetch_64(&pMgmt->showId, 1);
421,848✔
170
  if (showId == 0) atomic_add_fetch_64(&pMgmt->showId, 1);
422,477!
171

172
  int32_t size = sizeof(SShowObj);
422,477✔
173

174
  SShowObj showObj = {0};
422,477✔
175

176
  showObj.id = showId;
422,477✔
177
  showObj.pMnode = pMnode;
422,477✔
178
  showObj.type = convertToRetrieveType(pReq->tb, tListLen(pReq->tb));
422,477✔
179
  (void)memcpy(showObj.db, pReq->db, TSDB_DB_FNAME_LEN);
421,872✔
180
  tstrncpy(showObj.filterTb, pReq->filterTb, TSDB_TABLE_NAME_LEN);
421,872✔
181

182
  int32_t   keepTime = tsShellActivityTimer * 6 * 1000;
421,872✔
183
  SShowObj *pShow = taosCachePut(pMgmt->cache, &showId, sizeof(int64_t), &showObj, size, keepTime);
421,872✔
184
  if (pShow == NULL) {
422,247!
185
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
186
    mError("show:0x%" PRIx64 ", failed to put into cache since %s", showId, terrstr());
×
187
    return NULL;
×
188
  }
189

190
  mTrace("show:0x%" PRIx64 ", is created, data:%p", showId, pShow);
422,247✔
191
  return pShow;
422,200✔
192
}
193

194
static void mndFreeShowObj(SShowObj *pShow) {
422,721✔
195
  SMnode    *pMnode = pShow->pMnode;
422,721✔
196
  SShowMgmt *pMgmt = &pMnode->showMgmt;
422,721✔
197

198
  ShowFreeIterFp freeFp = pMgmt->freeIterFps[pShow->type];
422,721✔
199
  if (freeFp != NULL) {
422,721✔
200
    if (pShow->pIter != NULL) {
395,203✔
201
      mTrace("show:0x%" PRIx64 ", is destroying, data:%p, pIter:%p, ", pShow->id, pShow, pShow->pIter);
1!
202

203
      (*freeFp)(pMnode, pShow->pIter);
1✔
204

205
      pShow->pIter = NULL;
1✔
206
    }
207
  }
208

209
  mTrace("show:0x%" PRIx64 ", is destroyed, data:%p", pShow->id, pShow);
422,721✔
210
}
422,721✔
211

212
static SShowObj *mndAcquireShowObj(SMnode *pMnode, int64_t showId) {
18,738✔
213
  SShowMgmt *pMgmt = &pMnode->showMgmt;
18,738✔
214

215
  SShowObj *pShow = taosCacheAcquireByKey(pMgmt->cache, &showId, sizeof(showId));
18,738✔
216
  if (pShow == NULL) {
18,748!
217
    mError("show:0x%" PRIx64 ", already destroyed", showId);
×
218
    return NULL;
×
219
  }
220

221
  mTrace("show:0x%" PRIx64 ", acquired from cache, data:%p", pShow->id, pShow);
18,748!
222
  return pShow;
18,748✔
223
}
224

225
static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove) {
440,787✔
226
  if (pShow == NULL) return;
440,787!
227
  mTrace("show:0x%" PRIx64 ", released from cache, data:%p force:%d", pShow->id, pShow, forceRemove);
440,787✔
228

229
  // A bug in tcache.c
230
  forceRemove = 0;
440,787✔
231

232
  SMnode    *pMnode = pShow->pMnode;
440,787✔
233
  SShowMgmt *pMgmt = &pMnode->showMgmt;
440,787✔
234
  taosCacheRelease(pMgmt->cache, (void **)(&pShow), forceRemove);
440,787✔
235
}
236

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

249
  mDebug("process to retrieve systable req db:%s, tb:%s, compactId:%" PRId64, retrieveReq.db, retrieveReq.tb,
441,238✔
250
         retrieveReq.compactId);
251

252
  if (retrieveReq.showId == 0) {
440,941✔
253
    STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, retrieveReq.tb, strlen(retrieveReq.tb));
422,199✔
254
    if (pMeta == NULL) {
422,253✔
255
      pMeta = taosHashGet(pMnode->perfsMeta, retrieveReq.tb, strlen(retrieveReq.tb));
89,575✔
256
      if (pMeta == NULL) {
89,561!
257
        code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
×
258
        mError("failed to process show-retrieve req:%p since %s", pShow, tstrerror(code));
×
259
        TAOS_RETURN(code);
×
260
      }
261
    }
262

263
    pShow = mndCreateShowObj(pMnode, &retrieveReq);
422,239✔
264
    if (pShow == NULL) {
422,133✔
265
      code = terrno;
186✔
266
      mError("failed to process show-meta req since %s", tstrerror(code));
×
267
      TAOS_RETURN(code);
×
268
    }
269

270
    pShow->pMeta = pMeta;
421,947✔
271
    pShow->numOfColumns = pShow->pMeta->numOfColumns;
421,947✔
272
  } else {
273
    pShow = mndAcquireShowObj(pMnode, retrieveReq.showId);
18,742✔
274
    if (pShow == NULL) {
18,743✔
275
      code = TSDB_CODE_MND_INVALID_SHOWOBJ;
52✔
276
      mError("failed to process show-retrieve req:%p since %s", pShow, tstrerror(code));
52!
277
      TAOS_RETURN(code);
52✔
278
    }
279
  }
280

281
  if (pShow->type == TSDB_MGMT_TABLE_COL) {  // expend capacity for ins_columns
440,638✔
282
    rowsToRead = SHOW_COLS_STEP_SIZE;
21,335✔
283
  } else if (pShow->type == TSDB_MGMT_TABLE_PRIVILEGES) {
419,303✔
284
    rowsToRead = SHOW_PRIVILEGES_STEP_SIZE;
8,658✔
285
  }
286
  ShowRetrieveFp retrieveFp = pMgmt->retrieveFps[pShow->type];
440,638✔
287
  if (retrieveFp == NULL) {
440,638!
288
    mndReleaseShowObj(pShow, false);
×
289
    code = TSDB_CODE_MSG_NOT_PROCESSED;
×
290
    mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, tstrerror(code));
×
291
    TAOS_RETURN(code);
×
292
  }
293

294
  mDebug("show:0x%" PRIx64 ", start retrieve data, type:%d", pShow->id, pShow->type);
440,638✔
295
  if (retrieveReq.user[0] != 0) {
440,439✔
296
    (void)memcpy(pReq->info.conn.user, retrieveReq.user, TSDB_USER_LEN);
440,417✔
297
  } else {
298
    (void)memcpy(pReq->info.conn.user, TSDB_DEFAULT_USER, strlen(TSDB_DEFAULT_USER) + 1);
22✔
299
  }
300
  code = -1;
440,439✔
301
  if (retrieveReq.db[0] &&
444,861✔
302
      (code = mndCheckShowPrivilege(pMnode, pReq->info.conn.user, pShow->type, retrieveReq.db)) != 0) {
4,422✔
303
    TAOS_RETURN(code);
4✔
304
  }
305
  if (pShow->type == TSDB_MGMT_TABLE_USER_FULL) {
440,435!
306
    if (strcmp(pReq->info.conn.user, "root") != 0) {
×
307
      mError("The operation is not permitted, user:%s, pShow->type:%d", pReq->info.conn.user, pShow->type);
×
308
      code = TSDB_CODE_MND_NO_RIGHTS;
×
309
      TAOS_RETURN(code);
×
310
    }
311
  }
312

313
  int32_t numOfCols = pShow->pMeta->numOfColumns;
440,435✔
314

315
  SSDataBlock *pBlock = NULL;
440,435✔
316
  code = createDataBlock(&pBlock);
440,435✔
317
  if (code) {
440,805✔
318
    TAOS_RETURN(code);
40✔
319
  }
320

321
  for (int32_t i = 0; i < numOfCols; ++i) {
6,585,467✔
322
    SColumnInfoData idata = {0};
6,144,072✔
323

324
    SSchema *p = &pShow->pMeta->pSchemas[i];
6,144,072✔
325

326
    idata.info.bytes = p->bytes;
6,144,072✔
327
    idata.info.type = p->type;
6,144,072✔
328
    idata.info.colId = p->colId;
6,144,072✔
329
    TAOS_CHECK_RETURN(blockDataAppendColInfo(pBlock, &idata));
6,144,072!
330
  }
331

332
  TAOS_CHECK_RETURN(blockDataEnsureCapacity(pBlock, rowsToRead));
441,395!
333

334
  if (mndCheckRetrieveFinished(pShow)) {
441,071!
335
    mDebug("show:0x%" PRIx64 ", read finished, numOfRows:%d", pShow->id, pShow->numOfRows);
×
336
    rowsRead = 0;
×
337
  } else {
338
    rowsRead = (*retrieveFp)(pReq, pShow, pBlock, rowsToRead);
441,022✔
339
    if (rowsRead < 0) {
441,172✔
340
      code = rowsRead;
8✔
341
      mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
8!
342
      mndReleaseShowObj(pShow, true);
8✔
343
      blockDataDestroy(pBlock);
8✔
344
      TAOS_RETURN(code);
8✔
345
    }
346

347
    pBlock->info.rows = rowsRead;
441,164✔
348
    mDebug("show:0x%" PRIx64 ", stop retrieve data, rowsRead:%d numOfRows:%d", pShow->id, rowsRead, pShow->numOfRows);
441,164✔
349
  }
350

351
  size_t dataEncodeBufSize = blockGetEncodeSize(pBlock);
441,164✔
352
  size = sizeof(SRetrieveMetaTableRsp) + sizeof(int32_t) + sizeof(SSysTableSchema) * pShow->pMeta->numOfColumns +
440,067✔
353
         dataEncodeBufSize;
354

355
  SRetrieveMetaTableRsp *pRsp = rpcMallocCont(size);
440,067✔
356
  if (pRsp == NULL) {
440,990!
357
    mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, tstrerror(terrno));
×
358
    code = terrno;
×
359
    goto _exit;
×
360
  }
361

362
  pRsp->handle = htobe64(pShow->id);
440,990✔
363

364
  if (rowsRead > 0) {
440,936✔
365
    char    *pStart = pRsp->data;
309,600✔
366
    SSchema *ps = pShow->pMeta->pSchemas;
309,600✔
367

368
    *(int32_t *)pStart = htonl(pShow->pMeta->numOfColumns);
309,600✔
369
    pStart += sizeof(int32_t);  // number of columns
309,600✔
370

371
    for (int32_t i = 0; i < pShow->pMeta->numOfColumns; ++i) {
5,199,870✔
372
      SSysTableSchema *pSchema = (SSysTableSchema *)pStart;
4,890,270✔
373
      pSchema->bytes = htonl(ps[i].bytes);
4,890,270✔
374
      pSchema->colId = htons(ps[i].colId);
4,890,270✔
375
      pSchema->type = ps[i].type;
4,890,270✔
376

377
      pStart += sizeof(SSysTableSchema);
4,890,270✔
378
    }
379

380
    int32_t len = blockEncode(pBlock, pStart, dataEncodeBufSize, pShow->pMeta->numOfColumns);
309,600✔
381
    if (len < 0) {
309,643!
382
      mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, tstrerror(terrno));
×
383
      code = terrno;
×
384
      return code;
×
385
    }
386
  }
387

388
  pRsp->numOfRows = htonl(rowsRead);
440,979✔
389
  pRsp->precision = TSDB_TIME_PRECISION_MILLI;  // millisecond time precision
440,979✔
390
  pReq->info.rsp = pRsp;
440,979✔
391
  pReq->info.rspLen = size;
440,979✔
392

393
  if (rowsRead == 0 || mndCheckRetrieveFinished(pShow)) {
440,979✔
394
    pRsp->completed = 1;
422,317✔
395
    mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
422,317✔
396
    mndReleaseShowObj(pShow, true);
422,317✔
397
  } else {
398
    mDebug("show:0x%" PRIx64 ", retrieve not completed yet", pShow->id);
18,731✔
399
    mndReleaseShowObj(pShow, false);
18,731✔
400
  }
401

402
  blockDataDestroy(pBlock);
441,003✔
403
  return TSDB_CODE_SUCCESS;
441,390✔
404
_exit:
×
405
  mndReleaseShowObj(pShow, false);
×
406
  blockDataDestroy(pBlock);
×
407
  if (pRsp) {
×
408
    rpcFreeCont(pRsp);
×
409
  }
410
  return code;
×
411
}
412

413
static bool mndCheckRetrieveFinished(SShowObj *pShow) {
750,488✔
414
  if (pShow->pIter == NULL && pShow->numOfRows != 0) {
750,488✔
415
    return true;
290,808✔
416
  }
417
  return false;
459,680✔
418
}
419

420
void mndAddShowRetrieveHandle(SMnode *pMnode, EShowType showType, ShowRetrieveFp fp) {
104,580✔
421
  SShowMgmt *pMgmt = &pMnode->showMgmt;
104,580✔
422
  pMgmt->retrieveFps[showType] = fp;
104,580✔
423
}
104,580✔
424

425
void mndAddShowFreeIterHandle(SMnode *pMnode, EShowType showType, ShowFreeIterFp fp) {
94,620✔
426
  SShowMgmt *pMgmt = &pMnode->showMgmt;
94,620✔
427
  pMgmt->freeIterFps[showType] = fp;
94,620✔
428
}
94,620✔
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