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

taosdata / TDengine / #3840

04 Apr 2025 03:35PM UTC coverage: 63.027% (+0.6%) from 62.382%
#3840

push

travis-ci

web-flow
Merge pull request #30653 from taosdata/merge/mainto3.0

merge: from main to 3.0 branch

155471 of 315065 branches covered (49.35%)

Branch coverage included in aggregate %.

241637 of 314991 relevant lines covered (76.71%)

18825079.96 hits per line

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

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

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

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

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

59
  if (strncasecmp(name, TSDB_INS_TABLE_DNODES, len) == 0) {
239,358✔
60
    type = TSDB_MGMT_TABLE_DNODE;
7,467✔
61
  } else if (strncasecmp(name, TSDB_INS_TABLE_MNODES, len) == 0) {
231,891✔
62
    type = TSDB_MGMT_TABLE_MNODE;
4,540✔
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) {
227,351✔
68
    type = TSDB_MGMT_TABLE_QNODE;
2,195✔
69
  } else if (strncasecmp(name, TSDB_INS_TABLE_SNODES, len) == 0) {
225,156✔
70
    type = TSDB_MGMT_TABLE_SNODE;
2,202✔
71
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES, len) == 0) {
222,954✔
72
    type = TSDB_MGMT_TABLE_ANODE;
4✔
73
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES_FULL, len) == 0) {
222,950✔
74
    type = TSDB_MGMT_TABLE_ANODE_FULL;
1✔
75
  } else if (strncasecmp(name, TSDB_INS_TABLE_ARBGROUPS, len) == 0) {
222,949!
76
    type = TSDB_MGMT_TABLE_ARBGROUP;
×
77
  } else if (strncasecmp(name, TSDB_INS_TABLE_CLUSTER, len) == 0) {
222,949✔
78
    type = TSDB_MGMT_TABLE_CLUSTER;
4,327✔
79
  } else if (strncasecmp(name, TSDB_INS_TABLE_DATABASES, len) == 0) {
218,622✔
80
    type = TSDB_MGMT_TABLE_DB;
27,554✔
81
  } else if (strncasecmp(name, TSDB_INS_TABLE_FUNCTIONS, len) == 0) {
191,068✔
82
    type = TSDB_MGMT_TABLE_FUNC;
7,212✔
83
  } else if (strncasecmp(name, TSDB_INS_TABLE_INDEXES, len) == 0) {
183,856✔
84
    type = TSDB_MGMT_TABLE_INDEX;
6,770✔
85
  } else if (strncasecmp(name, TSDB_INS_TABLE_STABLES, len) == 0) {
177,086✔
86
    type = TSDB_MGMT_TABLE_STB;
9,149✔
87
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLES, len) == 0) {
167,937!
88
    type = TSDB_MGMT_TABLE_TABLE;
×
89
  } else if (strncasecmp(name, TSDB_INS_TABLE_TAGS, len) == 0) {
167,937!
90
    type = TSDB_MGMT_TABLE_TAG;
×
91
  } else if (strncasecmp(name, TSDB_INS_TABLE_COLS, len) == 0) {
167,937✔
92
    type = TSDB_MGMT_TABLE_COL;
14,059✔
93
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLE_DISTRIBUTED, len) == 0) {
153,878✔
94
    //    type = TSDB_MGMT_TABLE_DIST;
95
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS, len) == 0) {
153,841✔
96
    type = TSDB_MGMT_TABLE_USER;
5,070✔
97
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS_FULL, len) == 0) {
148,771!
98
    type = TSDB_MGMT_TABLE_USER_FULL;
×
99
  } else if (strncasecmp(name, TSDB_INS_TABLE_LICENCES, len) == 0) {
148,771✔
100
    type = TSDB_MGMT_TABLE_GRANTS;
5,760✔
101
  } else if (strncasecmp(name, TSDB_INS_TABLE_VGROUPS, len) == 0) {
143,011✔
102
    type = TSDB_MGMT_TABLE_VGROUP;
13,559✔
103
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONSUMERS, len) == 0) {
129,452✔
104
    type = TSDB_MGMT_TABLE_CONSUMERS;
8,013✔
105
  } else if (strncasecmp(name, TSDB_INS_TABLE_SUBSCRIPTIONS, len) == 0) {
121,439✔
106
    type = TSDB_MGMT_TABLE_SUBSCRIPTIONS;
5,842✔
107
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_TRANS, len) == 0) {
115,597✔
108
    type = TSDB_MGMT_TABLE_TRANS;
7,469✔
109
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_SMAS, len) == 0) {
108,128!
110
    type = TSDB_MGMT_TABLE_SMAS;
×
111
  } else if (strncasecmp(name, TSDB_INS_TABLE_CONFIGS, len) == 0) {
108,128✔
112
    type = TSDB_MGMT_TABLE_CONFIGS;
1,445✔
113
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONNECTIONS, len) == 0) {
106,683✔
114
    type = TSDB_MGMT_TABLE_CONNS;
6,512✔
115
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_QUERIES, len) == 0) {
100,171✔
116
    type = TSDB_MGMT_TABLE_QUERIES;
11,517✔
117
  } else if (strncasecmp(name, TSDB_INS_TABLE_VNODES, len) == 0) {
88,654✔
118
    type = TSDB_MGMT_TABLE_VNODES;
20,034✔
119
  } else if (strncasecmp(name, TSDB_INS_TABLE_TOPICS, len) == 0) {
68,620✔
120
    type = TSDB_MGMT_TABLE_TOPICS;
5,076✔
121
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAMS, len) == 0) {
63,544✔
122
    type = TSDB_MGMT_TABLE_STREAMS;
11,975✔
123
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_APPS, len) == 0) {
51,569✔
124
    type = TSDB_MGMT_TABLE_APPS;
10,794✔
125
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAM_TASKS, len) == 0) {
40,775✔
126
    type = TSDB_MGMT_TABLE_STREAM_TASKS;
21,838✔
127
  } else if (strncasecmp(name, TSDB_INS_TABLE_USER_PRIVILEGES, len) == 0) {
18,937✔
128
    type = TSDB_MGMT_TABLE_PRIVILEGES;
4,335✔
129
  } else if (strncasecmp(name, TSDB_INS_TABLE_VIEWS, len) == 0) {
14,602✔
130
    type = TSDB_MGMT_TABLE_VIEWS;
6,525✔
131
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACTS, len) == 0) {
8,077✔
132
    type = TSDB_MGMT_TABLE_COMPACT;
2,236✔
133
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACT_DETAILS, len) == 0) {
5,841✔
134
    type = TSDB_MGMT_TABLE_COMPACT_DETAIL;
5,751✔
135
  } else if (strncasecmp(name, TSDB_INS_TABLE_TRANSACTION_DETAILS, len) == 0) {
90!
136
    type = TSDB_MGMT_TABLE_TRANSACTION_DETAIL;
×
137
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_FULL, len) == 0) {
90✔
138
    type = TSDB_MGMT_TABLE_GRANTS_FULL;
6✔
139
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_LOGS, len) == 0) {
84✔
140
    type = TSDB_MGMT_TABLE_GRANTS_LOGS;
6✔
141
  } else if (strncasecmp(name, TSDB_INS_TABLE_MACHINES, len) == 0) {
78✔
142
    type = TSDB_MGMT_TABLE_MACHINES;
6✔
143
  } else if (strncasecmp(name, TSDB_INS_TABLE_ENCRYPTIONS, len) == 0) {
72!
144
    type = TSDB_MGMT_TABLE_ENCRYPTIONS;
×
145
  } else if (strncasecmp(name, TSDB_INS_TABLE_TSMAS, len) == 0) {
72✔
146
    type = TSDB_MGMT_TABLE_TSMAS;
6✔
147
  } else if (strncasecmp(name, TSDB_INS_DISK_USAGE, len) == 0) {
66!
148
    type = TSDB_MGMT_TABLE_USAGE;
×
149
  } else if (strncasecmp(name, TSDB_INS_TABLE_FILESETS, len) == 0) {
66!
150
    type = TSDB_MGMT_TABLE_FILESETS;
×
151
  } else {
152
    mError("invalid show name:%s len:%d", name, len);
66!
153
  }
154

155
  return type;
239,263✔
156
}
157

158
static SShowObj *mndCreateShowObj(SMnode *pMnode, SRetrieveTableReq *pReq) {
239,307✔
159
  SShowMgmt *pMgmt = &pMnode->showMgmt;
239,307✔
160

161
  int64_t showId = atomic_add_fetch_64(&pMgmt->showId, 1);
239,307✔
162
  if (showId == 0) atomic_add_fetch_64(&pMgmt->showId, 1);
239,554!
163

164
  int32_t size = sizeof(SShowObj);
239,554✔
165

166
  SShowObj showObj = {0};
239,554✔
167

168
  showObj.id = showId;
239,554✔
169
  showObj.pMnode = pMnode;
239,554✔
170
  showObj.type = convertToRetrieveType(pReq->tb, tListLen(pReq->tb));
239,554✔
171
  (void)memcpy(showObj.db, pReq->db, TSDB_DB_FNAME_LEN);
239,292✔
172
  tstrncpy(showObj.filterTb, pReq->filterTb, TSDB_TABLE_NAME_LEN);
239,292✔
173

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

182
  mTrace("show:0x%" PRIx64 ", is created, data:%p", showId, pShow);
239,517✔
183
  return pShow;
239,480✔
184
}
185

186
static void mndFreeShowObj(SShowObj *pShow) {
239,599✔
187
  SMnode    *pMnode = pShow->pMnode;
239,599✔
188
  SShowMgmt *pMgmt = &pMnode->showMgmt;
239,599✔
189

190
  ShowFreeIterFp freeFp = pMgmt->freeIterFps[pShow->type];
239,599✔
191
  if (freeFp != NULL) {
239,599✔
192
    if (pShow->pIter != NULL) {
225,748!
193
      mTrace("show:0x%" PRIx64 ", is destroying, data:%p, pIter:%p, ", pShow->id, pShow, pShow->pIter);
×
194

195
      (*freeFp)(pMnode, pShow->pIter);
×
196

197
      pShow->pIter = NULL;
×
198
    }
199
  }
200

201
  mTrace("show:0x%" PRIx64 ", is destroyed, data:%p", pShow->id, pShow);
239,599✔
202
}
239,599✔
203

204
static SShowObj *mndAcquireShowObj(SMnode *pMnode, int64_t showId) {
4,728✔
205
  SShowMgmt *pMgmt = &pMnode->showMgmt;
4,728✔
206

207
  SShowObj *pShow = taosCacheAcquireByKey(pMgmt->cache, &showId, sizeof(showId));
4,728✔
208
  if (pShow == NULL) {
4,730!
209
    mError("show:0x%" PRIx64 ", already destroyed", showId);
×
210
    return NULL;
×
211
  }
212

213
  mTrace("show:0x%" PRIx64 ", acquired from cache, data:%p", pShow->id, pShow);
4,730!
214
  return pShow;
4,730✔
215
}
216

217
static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove) {
244,074✔
218
  if (pShow == NULL) return;
244,074!
219
  mTrace("show:0x%" PRIx64 ", released from cache, data:%p force:%d", pShow->id, pShow, forceRemove);
244,074✔
220

221
  // A bug in tcache.c
222
  forceRemove = 0;
244,074✔
223

224
  SMnode    *pMnode = pShow->pMnode;
244,074✔
225
  SShowMgmt *pMgmt = &pMnode->showMgmt;
244,074✔
226
  taosCacheRelease(pMgmt->cache, (void **)(&pShow), forceRemove);
244,074✔
227
}
228

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

241
  mDebug("process to retrieve systable req db:%s, tb:%s, compactId:%" PRId64, retrieveReq.db, retrieveReq.tb,
244,242✔
242
         retrieveReq.compactId);
243

244
  if (retrieveReq.showId == 0) {
244,269✔
245
    STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, retrieveReq.tb, strlen(retrieveReq.tb));
239,541✔
246
    if (pMeta == NULL) {
239,381✔
247
      pMeta = taosHashGet(pMnode->perfsMeta, retrieveReq.tb, strlen(retrieveReq.tb));
44,330✔
248
      if (pMeta == NULL) {
44,351!
249
        code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
×
250
        mError("failed to process show-retrieve req:%p since %s", pShow, tstrerror(code));
×
251
        TAOS_RETURN(code);
×
252
      }
253
    }
254

255
    pShow = mndCreateShowObj(pMnode, &retrieveReq);
239,402✔
256
    if (pShow == NULL) {
239,425!
257
      code = terrno;
×
258
      mError("failed to process show-meta req since %s", tstrerror(code));
×
259
      TAOS_RETURN(code);
×
260
    }
261

262
    pShow->pMeta = pMeta;
239,437✔
263
    pShow->numOfColumns = pShow->pMeta->numOfColumns;
239,437✔
264
  } else {
265
    pShow = mndAcquireShowObj(pMnode, retrieveReq.showId);
4,728✔
266
    if (pShow == NULL) {
4,728✔
267
      code = TSDB_CODE_MND_INVALID_SHOWOBJ;
41✔
268
      mError("failed to process show-retrieve req:%p since %s", pShow, tstrerror(code));
41!
269
      TAOS_RETURN(code);
41✔
270
    }
271
  }
272

273
  if (pShow->type == TSDB_MGMT_TABLE_COL) {  // expend capacity for ins_columns
244,124✔
274
    rowsToRead = SHOW_COLS_STEP_SIZE;
14,059✔
275
  } else if (pShow->type == TSDB_MGMT_TABLE_PRIVILEGES) {
230,065✔
276
    rowsToRead = SHOW_PRIVILEGES_STEP_SIZE;
4,337✔
277
  }
278
  ShowRetrieveFp retrieveFp = pMgmt->retrieveFps[pShow->type];
244,124✔
279
  if (retrieveFp == NULL) {
244,124!
280
    mndReleaseShowObj(pShow, false);
×
281
    code = TSDB_CODE_MSG_NOT_PROCESSED;
×
282
    mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, tstrerror(code));
×
283
    TAOS_RETURN(code);
×
284
  }
285

286
  mDebug("show:0x%" PRIx64 ", start retrieve data, type:%d", pShow->id, pShow->type);
244,124✔
287
  if (retrieveReq.user[0] != 0) {
244,048✔
288
    (void)memcpy(pReq->info.conn.user, retrieveReq.user, TSDB_USER_LEN);
244,026✔
289
  } else {
290
    (void)memcpy(pReq->info.conn.user, TSDB_DEFAULT_USER, strlen(TSDB_DEFAULT_USER) + 1);
22✔
291
  }
292
  code = -1;
244,048✔
293
  if (retrieveReq.db[0] &&
260,370✔
294
      (code = mndCheckShowPrivilege(pMnode, pReq->info.conn.user, pShow->type, retrieveReq.db)) != 0) {
16,320✔
295
    TAOS_RETURN(code);
4✔
296
  }
297
  if (pShow->type == TSDB_MGMT_TABLE_USER_FULL) {
244,046!
298
    if (strcmp(pReq->info.conn.user, "root") != 0) {
×
299
      mError("The operation is not permitted, user:%s, pShow->type:%d", pReq->info.conn.user, pShow->type);
×
300
      code = TSDB_CODE_MND_NO_RIGHTS;
×
301
      TAOS_RETURN(code);
×
302
    }
303
  }
304

305
  int32_t numOfCols = pShow->pMeta->numOfColumns;
244,046✔
306

307
  SSDataBlock *pBlock = NULL;
244,046✔
308
  code = createDataBlock(&pBlock);
244,046✔
309
  if (code) {
244,082!
310
    TAOS_RETURN(code);
×
311
  }
312

313
  for (int32_t i = 0; i < numOfCols; ++i) {
3,839,966✔
314
    SColumnInfoData idata = {0};
3,595,364✔
315

316
    SSchema *p = &pShow->pMeta->pSchemas[i];
3,595,364✔
317

318
    idata.info.bytes = p->bytes;
3,595,364✔
319
    idata.info.type = p->type;
3,595,364✔
320
    idata.info.colId = p->colId;
3,595,364✔
321
    TAOS_CHECK_RETURN(blockDataAppendColInfo(pBlock, &idata));
3,595,364!
322
  }
323

324
  TAOS_CHECK_RETURN(blockDataEnsureCapacity(pBlock, rowsToRead));
244,602!
325

326
  if (mndCheckRetrieveFinished(pShow)) {
244,185!
327
    mDebug("show:0x%" PRIx64 ", read finished, numOfRows:%d", pShow->id, pShow->numOfRows);
×
328
    rowsRead = 0;
×
329
  } else {
330
    rowsRead = (*retrieveFp)(pReq, pShow, pBlock, rowsToRead);
244,175✔
331
    if (rowsRead < 0) {
244,233✔
332
      code = rowsRead;
3✔
333
      mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
3!
334
      mndReleaseShowObj(pShow, true);
3✔
335
      blockDataDestroy(pBlock);
3✔
336
      TAOS_RETURN(code);
3✔
337
    }
338

339
    pBlock->info.rows = rowsRead;
244,230✔
340
    mDebug("show:0x%" PRIx64 ", stop retrieve data, rowsRead:%d numOfRows:%d", pShow->id, rowsRead, pShow->numOfRows);
244,230✔
341
  }
342

343
  size_t dataEncodeBufSize = blockGetEncodeSize(pBlock);
244,230✔
344
  size = sizeof(SRetrieveMetaTableRsp) + sizeof(int32_t) + sizeof(SSysTableSchema) * pShow->pMeta->numOfColumns +
244,123✔
345
         dataEncodeBufSize;
346

347
  SRetrieveMetaTableRsp *pRsp = rpcMallocCont(size);
244,123✔
348
  if (pRsp == NULL) {
244,174!
349
    mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, tstrerror(code));
×
350
    code = terrno;
×
351
    goto _exit;
×
352
  }
353

354
  pRsp->handle = htobe64(pShow->id);
244,174✔
355

356
  if (rowsRead > 0) {
244,192✔
357
    char    *pStart = pRsp->data;
196,199✔
358
    SSchema *ps = pShow->pMeta->pSchemas;
196,199✔
359

360
    *(int32_t *)pStart = htonl(pShow->pMeta->numOfColumns);
196,199✔
361
    pStart += sizeof(int32_t);  // number of columns
196,199✔
362

363
    for (int32_t i = 0; i < pShow->pMeta->numOfColumns; ++i) {
3,383,630✔
364
      SSysTableSchema *pSchema = (SSysTableSchema *)pStart;
3,187,431✔
365
      pSchema->bytes = htonl(ps[i].bytes);
3,187,431✔
366
      pSchema->colId = htons(ps[i].colId);
3,187,431✔
367
      pSchema->type = ps[i].type;
3,187,431✔
368

369
      pStart += sizeof(SSysTableSchema);
3,187,431✔
370
    }
371

372
    int32_t len = blockEncode(pBlock, pStart, dataEncodeBufSize, pShow->pMeta->numOfColumns);
196,199✔
373
    if (len < 0) {
196,231!
374
      mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, tstrerror(code));
×
375
      code = terrno;
×
376
      return code;
×
377
    }
378
  }
379

380
  pRsp->numOfRows = htonl(rowsRead);
244,224✔
381
  pRsp->precision = TSDB_TIME_PRECISION_MILLI;  // millisecond time precision
244,224✔
382
  pReq->info.rsp = pRsp;
244,224✔
383
  pReq->info.rspLen = size;
244,224✔
384

385
  if (rowsRead == 0 || mndCheckRetrieveFinished(pShow)) {
244,224✔
386
    pRsp->completed = 1;
239,533✔
387
    mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
239,533✔
388
    mndReleaseShowObj(pShow, true);
239,533✔
389
  } else {
390
    mDebug("show:0x%" PRIx64 ", retrieve not completed yet", pShow->id);
4,729✔
391
    mndReleaseShowObj(pShow, false);
4,729✔
392
  }
393

394
  blockDataDestroy(pBlock);
244,204✔
395
  return TSDB_CODE_SUCCESS;
244,258✔
396
_exit:
×
397
  mndReleaseShowObj(pShow, false);
×
398
  blockDataDestroy(pBlock);
×
399
  if (pRsp) {
×
400
    rpcFreeCont(pRsp);
×
401
  }
402
  return code;
×
403
}
404

405
static bool mndCheckRetrieveFinished(SShowObj *pShow) {
440,313✔
406
  if (pShow->pIter == NULL && pShow->numOfRows != 0) {
440,313✔
407
    return true;
191,464✔
408
  }
409
  return false;
248,849✔
410
}
411

412
void mndAddShowRetrieveHandle(SMnode *pMnode, EShowType showType, ShowRetrieveFp fp) {
67,070✔
413
  SShowMgmt *pMgmt = &pMnode->showMgmt;
67,070✔
414
  pMgmt->retrieveFps[showType] = fp;
67,070✔
415
}
67,070✔
416

417
void mndAddShowFreeIterHandle(SMnode *pMnode, EShowType showType, ShowFreeIterFp fp) {
61,775✔
418
  SShowMgmt *pMgmt = &pMnode->showMgmt;
61,775✔
419
  pMgmt->freeIterFps[showType] = fp;
61,775✔
420
}
61,775✔
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