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

taosdata / TDengine / #4754

25 Sep 2025 05:58AM UTC coverage: 57.946% (-1.0%) from 58.977%
#4754

push

travis-ci

web-flow
enh: taos command line support '-uroot' on windows (#33055)

133189 of 293169 branches covered (45.43%)

Branch coverage included in aggregate %.

201677 of 284720 relevant lines covered (70.83%)

5398749.0 hits per line

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

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

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

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

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

59
  if (strncasecmp(name, TSDB_INS_TABLE_DNODES, len) == 0) {
17,844✔
60
    type = TSDB_MGMT_TABLE_DNODE;
2,472✔
61
  } else if (strncasecmp(name, TSDB_INS_TABLE_MNODES, len) == 0) {
15,372✔
62
    type = TSDB_MGMT_TABLE_MNODE;
1,544✔
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) {
13,828✔
68
    type = TSDB_MGMT_TABLE_QNODE;
23✔
69
  } else if (strncasecmp(name, TSDB_INS_TABLE_SNODES, len) == 0) {
13,805✔
70
    type = TSDB_MGMT_TABLE_SNODE;
382✔
71
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES, len) == 0) {
13,423✔
72
    type = TSDB_MGMT_TABLE_ANODE;
1✔
73
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES_FULL, len) == 0) {
13,422!
74
    type = TSDB_MGMT_TABLE_ANODE_FULL;
×
75
  } else if (strncasecmp(name, TSDB_INS_TABLE_BNODES, len) == 0) {
13,422✔
76
    type = TSDB_MGMT_TABLE_BNODE;
283✔
77
  } else if (strncasecmp(name, TSDB_INS_TABLE_ARBGROUPS, len) == 0) {
13,139✔
78
    type = TSDB_MGMT_TABLE_ARBGROUP;
15✔
79
  } else if (strncasecmp(name, TSDB_INS_TABLE_CLUSTER, len) == 0) {
13,124✔
80
    type = TSDB_MGMT_TABLE_CLUSTER;
13✔
81
  } else if (strncasecmp(name, TSDB_INS_TABLE_DATABASES, len) == 0) {
13,111✔
82
    type = TSDB_MGMT_TABLE_DB;
1,328✔
83
  } else if (strncasecmp(name, TSDB_INS_TABLE_FUNCTIONS, len) == 0) {
11,783✔
84
    type = TSDB_MGMT_TABLE_FUNC;
47✔
85
  } else if (strncasecmp(name, TSDB_INS_TABLE_INDEXES, len) == 0) {
11,736✔
86
    type = TSDB_MGMT_TABLE_INDEX;
41✔
87
  } else if (strncasecmp(name, TSDB_INS_TABLE_STABLES, len) == 0) {
11,695✔
88
    type = TSDB_MGMT_TABLE_STB;
1,096✔
89
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLES, len) == 0) {
10,599!
90
    type = TSDB_MGMT_TABLE_TABLE;
×
91
  } else if (strncasecmp(name, TSDB_INS_TABLE_TAGS, len) == 0) {
10,599!
92
    type = TSDB_MGMT_TABLE_TAG;
×
93
  } else if (strncasecmp(name, TSDB_INS_TABLE_COLS, len) == 0) {
10,599✔
94
    type = TSDB_MGMT_TABLE_COL;
6,880✔
95
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLE_DISTRIBUTED, len) == 0) {
3,719!
96
    //    type = TSDB_MGMT_TABLE_DIST;
97
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS, len) == 0) {
3,719✔
98
    type = TSDB_MGMT_TABLE_USER;
59✔
99
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS_FULL, len) == 0) {
3,660!
100
    type = TSDB_MGMT_TABLE_USER_FULL;
×
101
  } else if (strncasecmp(name, TSDB_INS_TABLE_LICENCES, len) == 0) {
3,660✔
102
    type = TSDB_MGMT_TABLE_GRANTS;
15✔
103
  } else if (strncasecmp(name, TSDB_INS_TABLE_VGROUPS, len) == 0) {
3,645✔
104
    type = TSDB_MGMT_TABLE_VGROUP;
620✔
105
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONSUMERS, len) == 0) {
3,025✔
106
    type = TSDB_MGMT_TABLE_CONSUMERS;
78✔
107
  } else if (strncasecmp(name, TSDB_INS_TABLE_SUBSCRIPTIONS, len) == 0) {
2,947✔
108
    type = TSDB_MGMT_TABLE_SUBSCRIPTIONS;
84✔
109
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_TRANS, len) == 0) {
2,863✔
110
    type = TSDB_MGMT_TABLE_TRANS;
832✔
111
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_SMAS, len) == 0) {
2,031!
112
    type = TSDB_MGMT_TABLE_SMAS;
×
113
  } else if (strncasecmp(name, TSDB_INS_TABLE_CONFIGS, len) == 0) {
2,031✔
114
    type = TSDB_MGMT_TABLE_CONFIGS;
7✔
115
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONNECTIONS, len) == 0) {
2,024✔
116
    type = TSDB_MGMT_TABLE_CONNS;
50✔
117
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_QUERIES, len) == 0) {
1,974✔
118
    type = TSDB_MGMT_TABLE_QUERIES;
21✔
119
  } else if (strncasecmp(name, TSDB_INS_TABLE_VNODES, len) == 0) {
1,953✔
120
    type = TSDB_MGMT_TABLE_VNODES;
63✔
121
  } else if (strncasecmp(name, TSDB_INS_TABLE_TOPICS, len) == 0) {
1,890✔
122
    type = TSDB_MGMT_TABLE_TOPICS;
72✔
123
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAMS, len) == 0) {
1,818✔
124
    type = TSDB_MGMT_TABLE_STREAMS;
615✔
125
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_APPS, len) == 0) {
1,203✔
126
    type = TSDB_MGMT_TABLE_APPS;
16✔
127
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAM_TASKS, len) == 0) {
1,187✔
128
    type = TSDB_MGMT_TABLE_STREAM_TASKS;
317✔
129
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAM_RECALCULATES, len) == 0) {
870✔
130
    type = TSDB_MGMT_TABLE_STREAM_RECALCULATES;
1✔
131
  } else if (strncasecmp(name, TSDB_INS_TABLE_USER_PRIVILEGES, len) == 0) {
869✔
132
    type = TSDB_MGMT_TABLE_PRIVILEGES;
71✔
133
  } else if (strncasecmp(name, TSDB_INS_TABLE_VIEWS, len) == 0) {
798✔
134
    type = TSDB_MGMT_TABLE_VIEWS;
77✔
135
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACTS, len) == 0) {
721✔
136
    type = TSDB_MGMT_TABLE_COMPACT;
607✔
137
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACT_DETAILS, len) == 0) {
114✔
138
    type = TSDB_MGMT_TABLE_COMPACT_DETAIL;
39✔
139
  } else if (strncasecmp(name, TSDB_INS_TABLE_TRANSACTION_DETAILS, len) == 0) {
75!
140
    type = TSDB_MGMT_TABLE_TRANSACTION_DETAIL;
×
141
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_FULL, len) == 0) {
75✔
142
    type = TSDB_MGMT_TABLE_GRANTS_FULL;
7✔
143
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_LOGS, len) == 0) {
68✔
144
    type = TSDB_MGMT_TABLE_GRANTS_LOGS;
7✔
145
  } else if (strncasecmp(name, TSDB_INS_TABLE_MACHINES, len) == 0) {
61✔
146
    type = TSDB_MGMT_TABLE_MACHINES;
8✔
147
  } else if (strncasecmp(name, TSDB_INS_TABLE_ENCRYPTIONS, len) == 0) {
53✔
148
    type = TSDB_MGMT_TABLE_ENCRYPTIONS;
5✔
149
  } else if (strncasecmp(name, TSDB_INS_TABLE_TSMAS, len) == 0) {
48!
150
    type = TSDB_MGMT_TABLE_TSMAS;
×
151
  } else if (strncasecmp(name, TSDB_INS_DISK_USAGE, len) == 0) {
48!
152
    type = TSDB_MGMT_TABLE_USAGE;
×
153
  } else if (strncasecmp(name, TSDB_INS_TABLE_FILESETS, len) == 0) {
48!
154
    type = TSDB_MGMT_TABLE_FILESETS;
×
155
  } else if (strncasecmp(name, TSDB_INS_TABLE_VC_COLS, len) == 0) {
48!
156
    type = TSDB_MGMT_TABLE_VC_COL;
×
157
  } else if (strncasecmp(name, TSDB_INS_TABLE_MOUNTS, len) == 0) {
48!
158
    type = TSDB_MGMT_TABLE_MOUNT;
48✔
159
  } else {
160
    mError("invalid show name:%s len:%d", name, len);
×
161
  }
162

163
  return type;
17,844✔
164
}
165

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

169
  int64_t showId = atomic_add_fetch_64(&pMgmt->showId, 1);
17,844✔
170
  if (showId == 0) atomic_add_fetch_64(&pMgmt->showId, 1);
17,844!
171

172
  int32_t size = sizeof(SShowObj);
17,844✔
173

174
  SShowObj showObj = {0};
17,844✔
175

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

182
  int32_t   keepTime = tsShellActivityTimer * 6 * 1000;
17,844✔
183
  SShowObj *pShow = taosCachePut(pMgmt->cache, &showId, sizeof(int64_t), &showObj, size, keepTime);
17,844✔
184
  if (pShow == NULL) {
17,844!
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);
17,844✔
191
  return pShow;
17,844✔
192
}
193

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

198
  ShowFreeIterFp freeFp = pMgmt->freeIterFps[pShow->type];
17,844✔
199
  if (freeFp != NULL) {
17,844✔
200
    if (pShow->pIter != NULL) {
17,114✔
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);
17,844✔
210
}
17,844✔
211

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

215
  SShowObj *pShow = taosCacheAcquireByKey(pMgmt->cache, &showId, sizeof(showId));
104✔
216
  if (pShow == NULL) {
104!
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);
104!
222
  return pShow;
104✔
223
}
224

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

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

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

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

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

252
  if (retrieveReq.showId == 0) {
17,948✔
253
    STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, retrieveReq.tb, strlen(retrieveReq.tb));
17,844✔
254
    if (pMeta == NULL) {
17,844✔
255
      pMeta = taosHashGet(pMnode->perfsMeta, retrieveReq.tb, strlen(retrieveReq.tb));
997✔
256
      if (pMeta == NULL) {
997!
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);
17,844✔
264
    if (pShow == NULL) {
17,844!
265
      code = terrno;
×
266
      mError("failed to process show-meta req since %s", tstrerror(code));
×
267
      TAOS_RETURN(code);
×
268
    }
269

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

281
  if (pShow->type == TSDB_MGMT_TABLE_COL) {  // expend capacity for ins_columns
17,948✔
282
    rowsToRead = SHOW_COLS_STEP_SIZE;
6,904✔
283
  } else if (pShow->type == TSDB_MGMT_TABLE_PRIVILEGES) {
11,044✔
284
    rowsToRead = SHOW_PRIVILEGES_STEP_SIZE;
71✔
285
  }
286
  ShowRetrieveFp retrieveFp = pMgmt->retrieveFps[pShow->type];
17,948✔
287
  if (retrieveFp == NULL) {
17,948!
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);
17,948✔
295
  if (retrieveReq.user[0] != 0) {
17,948✔
296
    (void)memcpy(pReq->info.conn.user, retrieveReq.user, TSDB_USER_LEN);
17,882✔
297
  } else {
298
    (void)memcpy(pReq->info.conn.user, TSDB_DEFAULT_USER, strlen(TSDB_DEFAULT_USER) + 1);
66✔
299
  }
300
  code = -1;
17,948✔
301
  if (retrieveReq.db[0] &&
24,627✔
302
      (code = mndCheckShowPrivilege(pMnode, pReq->info.conn.user, pShow->type, retrieveReq.db)) != 0) {
6,679✔
303
    TAOS_RETURN(code);
6✔
304
  }
305
  if (pShow->type == TSDB_MGMT_TABLE_USER_FULL) {
17,942!
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;
17,942✔
314

315
  SSDataBlock *pBlock = NULL;
17,942✔
316
  code = createDataBlock(&pBlock);
17,942✔
317
  if (code) {
17,942!
318
    TAOS_RETURN(code);
×
319
  }
320

321
  for (int32_t i = 0; i < numOfCols; ++i) {
231,927✔
322
    SColumnInfoData idata = {0};
213,984✔
323

324
    SSchema *p = &pShow->pMeta->pSchemas[i];
213,984✔
325

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

332
  TAOS_CHECK_RETURN(blockDataEnsureCapacity(pBlock, rowsToRead));
17,943!
333

334
  if (mndCheckRetrieveFinished(pShow)) {
17,942!
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);
17,942✔
339
    if (rowsRead < 0) {
17,942✔
340
      code = rowsRead;
5✔
341
      mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
5!
342
      mndReleaseShowObj(pShow, true);
5✔
343
      blockDataDestroy(pBlock);
5✔
344
      TAOS_RETURN(code);
5✔
345
    }
346

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

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

355
  SRetrieveMetaTableRsp *pRsp = rpcMallocCont(size);
17,937✔
356
  if (pRsp == NULL) {
17,937!
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);
17,937✔
363

364
  if (rowsRead > 0) {
17,937✔
365
    char    *pStart = pRsp->data;
17,247✔
366
    SSchema *ps = pShow->pMeta->pSchemas;
17,247✔
367

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

371
    for (int32_t i = 0; i < pShow->pMeta->numOfColumns; ++i) {
224,410✔
372
      SSysTableSchema *pSchema = (SSysTableSchema *)pStart;
207,163✔
373
      pSchema->bytes = htonl(ps[i].bytes);
207,163✔
374
      pSchema->colId = htons(ps[i].colId);
207,163✔
375
      pSchema->type = ps[i].type;
207,163✔
376

377
      pStart += sizeof(SSysTableSchema);
207,163✔
378
    }
379

380
    int32_t len = blockEncode(pBlock, pStart, dataEncodeBufSize, pShow->pMeta->numOfColumns);
17,247✔
381
    if (len < 0) {
17,247!
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);
17,937✔
389
  pRsp->precision = TSDB_TIME_PRECISION_MILLI;  // millisecond time precision
17,937✔
390
  pReq->info.rsp = pRsp;
17,937✔
391
  pReq->info.rspLen = size;
17,937✔
392

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

402
  blockDataDestroy(pBlock);
17,937✔
403
  return TSDB_CODE_SUCCESS;
17,937✔
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) {
35,189✔
414
  if (pShow->pIter == NULL && pShow->numOfRows != 0) {
35,189✔
415
    return true;
17,142✔
416
  }
417
  return false;
18,047✔
418
}
419

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

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