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

taosdata / TDengine / #4380

25 Jun 2025 06:58AM UTC coverage: 62.307% (-0.09%) from 62.393%
#4380

push

travis-ci

web-flow
feat(mqtt): mqtt subscription (#30127)

* feat(mqtt): Initial commit for mqtt

* chore(xnode/mnd): xnode message handlers for mnode

* chore(mnd/xnode): mnode part for xnode

* chore(xnode/translater): fix show commands

* fix(ast/creater): fix xnode create option

* fix(xnode/ci): fix ci & doc's error codes

* chore(xnode/sql): make create/drop/show work properly

* fix(xnode/sql): commit new files

* fix(xnode/sql): commit cmake files

* fix: fix testing cases

* fix(xnode/tsc): fix tokens

* fix(ast/anode): fix anode update decl.

* fix(xnode/error): fix xnode error codes

* fix: xnode make/destroy

* chore: xnode with option & dnode id

* chore: use taosmqtt for xnode

* chore: new error code for xnode launching

* chore(xnode): new error code

* chore: header for _xnode_mgmt_mqtt

* chore: source for _xnode_mgmt_mqtt

* chore: remove test directory from cmake

* chore: remove taosmqtt for ci to compile

* chore: remove taosudf header from xnode

* chore: new window macro

* chore: remove xnode mgmt mqtt for windows compilation

* Revert "chore: remove xnode mgmt mqtt for windows compilation"

This reverts commit 197e1640c.

* chore: cleanup code

* chore: xnode mgmt comment windows part out

* chore: mgmt/mqtt, move uv head toppest

* xnode/mnode: create xnode once per dnode

* fix(xnode/systable/test): fix column count

* xnode/sdb: renumber sdb type for xnode to make start/stop order correct

* xnode/mqtt: new param mqttPort

* fix SXnode's struct type

* transfer dnode id to mqtt subscription

* tmqtt: remove uv_a linking

* tmqtt/tools: sources for tools

* tools: fix windows compilation

* tools/producer: fix windows sleep param

* tools/producer: fix uninited var rc

* make tools only for linux

* test/mnodes: wail 1 or 2 seconds for offline to be leader

* update topic producer tool for geometry data type testing

* format tool sql statements

* show xnodes' ep

* make shell auto complete xnodes

* use usleep... (continued)

156642 of 320746 branches covered (48.84%)

Branch coverage included in aggregate %.

61 of 1020 new or added lines in 21 files covered. (5.98%)

1736 existing lines in 172 files now uncovered.

242538 of 319922 relevant lines covered (75.81%)

6277604.48 hits per line

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

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

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

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

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

59
  if (strncasecmp(name, TSDB_INS_TABLE_DNODES, len) == 0) {
15,547✔
60
    type = TSDB_MGMT_TABLE_DNODE;
770✔
61
  } else if (strncasecmp(name, TSDB_INS_TABLE_MNODES, len) == 0) {
14,777✔
62
    type = TSDB_MGMT_TABLE_MNODE;
164✔
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) {
14,613✔
68
    type = TSDB_MGMT_TABLE_QNODE;
22✔
69
  } else if (strncasecmp(name, TSDB_INS_TABLE_SNODES, len) == 0) {
14,591✔
70
    type = TSDB_MGMT_TABLE_SNODE;
17✔
71
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES, len) == 0) {
14,574✔
72
    type = TSDB_MGMT_TABLE_ANODE;
4✔
73
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES_FULL, len) == 0) {
14,570✔
74
    type = TSDB_MGMT_TABLE_ANODE_FULL;
1✔
75
  } else if (strncasecmp(name, TSDB_INS_TABLE_BNODES, len) == 0) {
14,569!
NEW
76
    type = TSDB_MGMT_TABLE_BNODE;
×
77
  } else if (strncasecmp(name, TSDB_INS_TABLE_ARBGROUPS, len) == 0) {
14,569!
78
    type = TSDB_MGMT_TABLE_ARBGROUP;
×
79
  } else if (strncasecmp(name, TSDB_INS_TABLE_CLUSTER, len) == 0) {
14,569✔
80
    type = TSDB_MGMT_TABLE_CLUSTER;
12✔
81
  } else if (strncasecmp(name, TSDB_INS_TABLE_DATABASES, len) == 0) {
14,557✔
82
    type = TSDB_MGMT_TABLE_DB;
1,081✔
83
  } else if (strncasecmp(name, TSDB_INS_TABLE_FUNCTIONS, len) == 0) {
13,476✔
84
    type = TSDB_MGMT_TABLE_FUNC;
32✔
85
  } else if (strncasecmp(name, TSDB_INS_TABLE_INDEXES, len) == 0) {
13,444✔
86
    type = TSDB_MGMT_TABLE_INDEX;
38✔
87
  } else if (strncasecmp(name, TSDB_INS_TABLE_STABLES, len) == 0) {
13,406✔
88
    type = TSDB_MGMT_TABLE_STB;
944✔
89
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLES, len) == 0) {
12,462!
90
    type = TSDB_MGMT_TABLE_TABLE;
×
91
  } else if (strncasecmp(name, TSDB_INS_TABLE_TAGS, len) == 0) {
12,462!
92
    type = TSDB_MGMT_TABLE_TAG;
×
93
  } else if (strncasecmp(name, TSDB_INS_TABLE_COLS, len) == 0) {
12,462✔
94
    type = TSDB_MGMT_TABLE_COL;
6,832✔
95
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLE_DISTRIBUTED, len) == 0) {
5,630!
96
    //    type = TSDB_MGMT_TABLE_DIST;
97
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS, len) == 0) {
5,630✔
98
    type = TSDB_MGMT_TABLE_USER;
40✔
99
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS_FULL, len) == 0) {
5,590!
100
    type = TSDB_MGMT_TABLE_USER_FULL;
×
101
  } else if (strncasecmp(name, TSDB_INS_TABLE_LICENCES, len) == 0) {
5,590✔
102
    type = TSDB_MGMT_TABLE_GRANTS;
97✔
103
  } else if (strncasecmp(name, TSDB_INS_TABLE_VGROUPS, len) == 0) {
5,493✔
104
    type = TSDB_MGMT_TABLE_VGROUP;
655✔
105
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONSUMERS, len) == 0) {
4,838✔
106
    type = TSDB_MGMT_TABLE_CONSUMERS;
90✔
107
  } else if (strncasecmp(name, TSDB_INS_TABLE_SUBSCRIPTIONS, len) == 0) {
4,748✔
108
    type = TSDB_MGMT_TABLE_SUBSCRIPTIONS;
90✔
109
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_TRANS, len) == 0) {
4,658✔
110
    type = TSDB_MGMT_TABLE_TRANS;
115✔
111
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_SMAS, len) == 0) {
4,543!
112
    type = TSDB_MGMT_TABLE_SMAS;
×
113
  } else if (strncasecmp(name, TSDB_INS_TABLE_CONFIGS, len) == 0) {
4,543✔
114
    type = TSDB_MGMT_TABLE_CONFIGS;
7✔
115
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONNECTIONS, len) == 0) {
4,536✔
116
    type = TSDB_MGMT_TABLE_CONNS;
42✔
117
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_QUERIES, len) == 0) {
4,494✔
118
    type = TSDB_MGMT_TABLE_QUERIES;
16✔
119
  } else if (strncasecmp(name, TSDB_INS_TABLE_VNODES, len) == 0) {
4,478✔
120
    type = TSDB_MGMT_TABLE_VNODES;
124✔
121
  } else if (strncasecmp(name, TSDB_INS_TABLE_TOPICS, len) == 0) {
4,354✔
122
    type = TSDB_MGMT_TABLE_TOPICS;
45✔
123
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAMS, len) == 0) {
4,309✔
124
    type = TSDB_MGMT_TABLE_STREAMS;
231✔
125
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_APPS, len) == 0) {
4,078✔
126
    type = TSDB_MGMT_TABLE_APPS;
16✔
127
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAM_TASKS, len) == 0) {
4,062✔
128
    type = TSDB_MGMT_TABLE_STREAM_TASKS;
3,806✔
129
  } else if (strncasecmp(name, TSDB_INS_TABLE_USER_PRIVILEGES, len) == 0) {
256✔
130
    type = TSDB_MGMT_TABLE_PRIVILEGES;
21✔
131
  } else if (strncasecmp(name, TSDB_INS_TABLE_VIEWS, len) == 0) {
235✔
132
    type = TSDB_MGMT_TABLE_VIEWS;
55✔
133
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACTS, len) == 0) {
180✔
134
    type = TSDB_MGMT_TABLE_COMPACT;
73✔
135
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACT_DETAILS, len) == 0) {
107!
UNCOV
136
    type = TSDB_MGMT_TABLE_COMPACT_DETAIL;
×
137
  } else if (strncasecmp(name, TSDB_INS_TABLE_TRANSACTION_DETAILS, len) == 0) {
107!
138
    type = TSDB_MGMT_TABLE_TRANSACTION_DETAIL;
×
139
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_FULL, len) == 0) {
107✔
140
    type = TSDB_MGMT_TABLE_GRANTS_FULL;
77✔
141
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_LOGS, len) == 0) {
30✔
142
    type = TSDB_MGMT_TABLE_GRANTS_LOGS;
11✔
143
  } else if (strncasecmp(name, TSDB_INS_TABLE_MACHINES, len) == 0) {
19✔
144
    type = TSDB_MGMT_TABLE_MACHINES;
9✔
145
  } else if (strncasecmp(name, TSDB_INS_TABLE_ENCRYPTIONS, len) == 0) {
10✔
146
    type = TSDB_MGMT_TABLE_ENCRYPTIONS;
4✔
147
  } else if (strncasecmp(name, TSDB_INS_TABLE_TSMAS, len) == 0) {
6!
148
    type = TSDB_MGMT_TABLE_TSMAS;
6✔
UNCOV
149
  } else if (strncasecmp(name, TSDB_INS_DISK_USAGE, len) == 0) {
×
150
    type = TSDB_MGMT_TABLE_USAGE;
×
UNCOV
151
  } else if (strncasecmp(name, TSDB_INS_TABLE_FILESETS, len) == 0) {
×
152
    type = TSDB_MGMT_TABLE_FILESETS;
×
153
  } else {
UNCOV
154
    mError("invalid show name:%s len:%d", name, len);
×
155
  }
156

157
  return type;
15,547✔
158
}
159

160
static SShowObj *mndCreateShowObj(SMnode *pMnode, SRetrieveTableReq *pReq) {
15,547✔
161
  SShowMgmt *pMgmt = &pMnode->showMgmt;
15,547✔
162

163
  int64_t showId = atomic_add_fetch_64(&pMgmt->showId, 1);
15,547✔
164
  if (showId == 0) atomic_add_fetch_64(&pMgmt->showId, 1);
15,547!
165

166
  int32_t size = sizeof(SShowObj);
15,547✔
167

168
  SShowObj showObj = {0};
15,547✔
169

170
  showObj.id = showId;
15,547✔
171
  showObj.pMnode = pMnode;
15,547✔
172
  showObj.type = convertToRetrieveType(pReq->tb, tListLen(pReq->tb));
15,547✔
173
  (void)memcpy(showObj.db, pReq->db, TSDB_DB_FNAME_LEN);
15,547✔
174
  tstrncpy(showObj.filterTb, pReq->filterTb, TSDB_TABLE_NAME_LEN);
15,547✔
175

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

184
  mTrace("show:0x%" PRIx64 ", is created, data:%p", showId, pShow);
15,547✔
185
  return pShow;
15,547✔
186
}
187

188
static void mndFreeShowObj(SShowObj *pShow) {
15,547✔
189
  SMnode    *pMnode = pShow->pMnode;
15,547✔
190
  SShowMgmt *pMgmt = &pMnode->showMgmt;
15,547✔
191

192
  ShowFreeIterFp freeFp = pMgmt->freeIterFps[pShow->type];
15,547✔
193
  if (freeFp != NULL) {
15,547✔
194
    if (pShow->pIter != NULL) {
15,384✔
195
      mTrace("show:0x%" PRIx64 ", is destroying, data:%p, pIter:%p, ", pShow->id, pShow, pShow->pIter);
1!
196

197
      (*freeFp)(pMnode, pShow->pIter);
1✔
198

199
      pShow->pIter = NULL;
1✔
200
    }
201
  }
202

203
  mTrace("show:0x%" PRIx64 ", is destroyed, data:%p", pShow->id, pShow);
15,547✔
204
}
15,547✔
205

206
static SShowObj *mndAcquireShowObj(SMnode *pMnode, int64_t showId) {
82✔
207
  SShowMgmt *pMgmt = &pMnode->showMgmt;
82✔
208

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

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

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

223
  // A bug in tcache.c
224
  forceRemove = 0;
15,625✔
225

226
  SMnode    *pMnode = pShow->pMnode;
15,625✔
227
  SShowMgmt *pMgmt = &pMnode->showMgmt;
15,625✔
228
  taosCacheRelease(pMgmt->cache, (void **)(&pShow), forceRemove);
15,625✔
229
}
230

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

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

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

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

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

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

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

307
  int32_t numOfCols = pShow->pMeta->numOfColumns;
15,625✔
308

309
  SSDataBlock *pBlock = NULL;
15,625✔
310
  code = createDataBlock(&pBlock);
15,625✔
311
  if (code) {
15,625!
UNCOV
312
    TAOS_RETURN(code);
×
313
  }
314

315
  for (int32_t i = 0; i < numOfCols; ++i) {
265,199✔
316
    SColumnInfoData idata = {0};
249,574✔
317

318
    SSchema *p = &pShow->pMeta->pSchemas[i];
249,574✔
319

320
    idata.info.bytes = p->bytes;
249,574✔
321
    idata.info.type = p->type;
249,574✔
322
    idata.info.colId = p->colId;
249,574✔
323
    TAOS_CHECK_RETURN(blockDataAppendColInfo(pBlock, &idata));
249,574!
324
  }
325

326
  TAOS_CHECK_RETURN(blockDataEnsureCapacity(pBlock, rowsToRead));
15,625!
327

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

341
    pBlock->info.rows = rowsRead;
15,620✔
342
    mDebug("show:0x%" PRIx64 ", stop retrieve data, rowsRead:%d numOfRows:%d", pShow->id, rowsRead, pShow->numOfRows);
15,620✔
343
  }
344

345
  size_t dataEncodeBufSize = blockGetEncodeSize(pBlock);
15,620✔
346
  size = sizeof(SRetrieveMetaTableRsp) + sizeof(int32_t) + sizeof(SSysTableSchema) * pShow->pMeta->numOfColumns +
15,620✔
347
         dataEncodeBufSize;
348

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

356
  pRsp->handle = htobe64(pShow->id);
15,620✔
357

358
  if (rowsRead > 0) {
15,620✔
359
    char    *pStart = pRsp->data;
15,200✔
360
    SSchema *ps = pShow->pMeta->pSchemas;
15,200✔
361

362
    *(int32_t *)pStart = htonl(pShow->pMeta->numOfColumns);
15,200✔
363
    pStart += sizeof(int32_t);  // number of columns
15,200✔
364

365
    for (int32_t i = 0; i < pShow->pMeta->numOfColumns; ++i) {
259,519✔
366
      SSysTableSchema *pSchema = (SSysTableSchema *)pStart;
244,319✔
367
      pSchema->bytes = htonl(ps[i].bytes);
244,319✔
368
      pSchema->colId = htons(ps[i].colId);
244,319✔
369
      pSchema->type = ps[i].type;
244,319✔
370

371
      pStart += sizeof(SSysTableSchema);
244,319✔
372
    }
373

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

382
  pRsp->numOfRows = htonl(rowsRead);
15,620✔
383
  pRsp->precision = TSDB_TIME_PRECISION_MILLI;  // millisecond time precision
15,620✔
384
  pReq->info.rsp = pRsp;
15,620✔
385
  pReq->info.rspLen = size;
15,620✔
386

387
  if (rowsRead == 0 || mndCheckRetrieveFinished(pShow)) {
15,620✔
388
    pRsp->completed = 1;
15,537✔
389
    mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
15,537✔
390
    mndReleaseShowObj(pShow, true);
15,537✔
391
  } else {
392
    mDebug("show:0x%" PRIx64 ", retrieve not completed yet", pShow->id);
83!
393
    mndReleaseShowObj(pShow, false);
83✔
394
  }
395

396
  blockDataDestroy(pBlock);
15,620✔
397
  return TSDB_CODE_SUCCESS;
15,620✔
398
_exit:
×
399
  mndReleaseShowObj(pShow, false);
×
400
  blockDataDestroy(pBlock);
×
401
  if (pRsp) {
×
402
    rpcFreeCont(pRsp);
×
403
  }
404
  return code;
×
405
}
406

407
static bool mndCheckRetrieveFinished(SShowObj *pShow) {
30,825✔
408
  if (pShow->pIter == NULL && pShow->numOfRows != 0) {
30,825✔
409
    return true;
15,117✔
410
  }
411
  return false;
15,708✔
412
}
413

414
void mndAddShowRetrieveHandle(SMnode *pMnode, EShowType showType, ShowRetrieveFp fp) {
79,248✔
415
  SShowMgmt *pMgmt = &pMnode->showMgmt;
79,248✔
416
  pMgmt->retrieveFps[showType] = fp;
79,248✔
417
}
79,248✔
418

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