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

taosdata / TDengine / #4873

04 Dec 2025 01:55AM UTC coverage: 64.558% (-0.1%) from 64.678%
#4873

push

travis-ci

guanshengliang
Merge branch '3.0' into cover/3.0

719 of 2219 new or added lines in 36 files covered. (32.4%)

6363 existing lines in 135 files now uncovered.

159381 of 246882 relevant lines covered (64.56%)

108937395.15 hits per line

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

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

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

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

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

59
  if (strncasecmp(name, TSDB_INS_TABLE_DNODES, len) == 0) {
5,410,785✔
60
    type = TSDB_MGMT_TABLE_DNODE;
884,449✔
61
  } else if (strncasecmp(name, TSDB_INS_TABLE_MNODES, len) == 0) {
4,526,336✔
62
    type = TSDB_MGMT_TABLE_MNODE;
358,259✔
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) {
4,168,077✔
68
    type = TSDB_MGMT_TABLE_QNODE;
8,047✔
69
  } else if (strncasecmp(name, TSDB_INS_TABLE_SNODES, len) == 0) {
4,160,030✔
70
    type = TSDB_MGMT_TABLE_SNODE;
161,825✔
71
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES, len) == 0) {
3,998,205✔
72
    type = TSDB_MGMT_TABLE_ANODE;
357✔
73
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES_FULL, len) == 0) {
3,997,848✔
74
    type = TSDB_MGMT_TABLE_ANODE_FULL;
×
75
  } else if (strncasecmp(name, TSDB_INS_TABLE_BNODES, len) == 0) {
3,997,848✔
76
    type = TSDB_MGMT_TABLE_BNODE;
122,217✔
77
  } else if (strncasecmp(name, TSDB_INS_TABLE_ARBGROUPS, len) == 0) {
3,875,631✔
78
    type = TSDB_MGMT_TABLE_ARBGROUP;
×
79
  } else if (strncasecmp(name, TSDB_INS_TABLE_CLUSTER, len) == 0) {
3,875,631✔
80
    type = TSDB_MGMT_TABLE_CLUSTER;
3,578✔
81
  } else if (strncasecmp(name, TSDB_INS_TABLE_DATABASES, len) == 0) {
3,872,053✔
82
    type = TSDB_MGMT_TABLE_DB;
616,717✔
83
  } else if (strncasecmp(name, TSDB_INS_TABLE_FUNCTIONS, len) == 0) {
3,255,336✔
84
    type = TSDB_MGMT_TABLE_FUNC;
12,619✔
85
  } else if (strncasecmp(name, TSDB_INS_TABLE_INDEXES, len) == 0) {
3,242,717✔
86
    type = TSDB_MGMT_TABLE_INDEX;
14,332✔
87
  } else if (strncasecmp(name, TSDB_INS_TABLE_STABLES, len) == 0) {
3,228,385✔
88
    type = TSDB_MGMT_TABLE_STB;
344,375✔
89
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLES, len) == 0) {
2,884,010✔
90
    type = TSDB_MGMT_TABLE_TABLE;
×
91
  } else if (strncasecmp(name, TSDB_INS_TABLE_TAGS, len) == 0) {
2,884,010✔
92
    type = TSDB_MGMT_TABLE_TAG;
×
93
  } else if (strncasecmp(name, TSDB_INS_TABLE_COLS, len) == 0) {
2,884,010✔
94
    type = TSDB_MGMT_TABLE_COL;
531,528✔
95
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLE_DISTRIBUTED, len) == 0) {
2,352,482✔
96
    //    type = TSDB_MGMT_TABLE_DIST;
97
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS, len) == 0) {
2,352,482✔
98
    type = TSDB_MGMT_TABLE_USER;
20,398✔
99
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS_FULL, len) == 0) {
2,332,084✔
100
    type = TSDB_MGMT_TABLE_USER_FULL;
×
101
  } else if (strncasecmp(name, TSDB_INS_TABLE_LICENCES, len) == 0) {
2,332,084✔
102
    type = TSDB_MGMT_TABLE_GRANTS;
4,218✔
103
  } else if (strncasecmp(name, TSDB_INS_TABLE_VGROUPS, len) == 0) {
2,327,866✔
104
    type = TSDB_MGMT_TABLE_VGROUP;
313,787✔
105
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONSUMERS, len) == 0) {
2,014,079✔
106
    type = TSDB_MGMT_TABLE_CONSUMERS;
9,282✔
107
  } else if (strncasecmp(name, TSDB_INS_TABLE_SUBSCRIPTIONS, len) == 0) {
2,004,797✔
108
    type = TSDB_MGMT_TABLE_SUBSCRIPTIONS;
10,639✔
109
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_TRANS, len) == 0) {
1,994,158✔
110
    type = TSDB_MGMT_TABLE_TRANS;
659,416✔
111
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_SMAS, len) == 0) {
1,334,742✔
112
    type = TSDB_MGMT_TABLE_SMAS;
×
113
  } else if (strncasecmp(name, TSDB_INS_TABLE_CONFIGS, len) == 0) {
1,334,742✔
114
    type = TSDB_MGMT_TABLE_CONFIGS;
2,499✔
115
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONNECTIONS, len) == 0) {
1,332,243✔
116
    type = TSDB_MGMT_TABLE_CONNS;
16,604✔
117
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_QUERIES, len) == 0) {
1,315,639✔
118
    type = TSDB_MGMT_TABLE_QUERIES;
6,160✔
119
  } else if (strncasecmp(name, TSDB_INS_TABLE_VNODES, len) == 0) {
1,309,479✔
120
    type = TSDB_MGMT_TABLE_VNODES;
1,247✔
121
  } else if (strncasecmp(name, TSDB_INS_TABLE_TOPICS, len) == 0) {
1,308,232✔
122
    type = TSDB_MGMT_TABLE_TOPICS;
25,913✔
123
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAMS, len) == 0) {
1,282,319✔
124
    type = TSDB_MGMT_TABLE_STREAMS;
347,021✔
125
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_APPS, len) == 0) {
935,298✔
126
    type = TSDB_MGMT_TABLE_APPS;
5,716✔
127
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_INSTANCES, len) == 0) {
929,582✔
NEW
128
    type = TSDB_MGMT_TABLE_INSTANCE;
×
129
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAM_TASKS, len) == 0) {
929,582✔
130
    type = TSDB_MGMT_TABLE_STREAM_TASKS;
325,486✔
131
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAM_RECALCULATES, len) == 0) {
604,096✔
132
    type = TSDB_MGMT_TABLE_STREAM_RECALCULATES;
426✔
133
  } else if (strncasecmp(name, TSDB_INS_TABLE_USER_PRIVILEGES, len) == 0) {
603,670✔
134
    type = TSDB_MGMT_TABLE_PRIVILEGES;
26,464✔
135
  } else if (strncasecmp(name, TSDB_INS_TABLE_VIEWS, len) == 0) {
577,206✔
136
    type = TSDB_MGMT_TABLE_VIEWS;
32,333✔
137
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACTS, len) == 0) {
544,873✔
138
    type = TSDB_MGMT_TABLE_COMPACT;
360,267✔
139
  } else if (strncasecmp(name, TSDB_INS_TABLE_SCANS, len) == 0) {
184,606✔
140
    type = TSDB_MGMT_TABLE_SCAN;
3,658✔
141
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACT_DETAILS, len) == 0) {
180,948✔
142
    type = TSDB_MGMT_TABLE_COMPACT_DETAIL;
27,947✔
143
  } else if (strncasecmp(name, TSDB_INS_TABLE_SCAN_DETAILS, len) == 0) {
153,001✔
144
    type = TSDB_MGMT_TABLE_SCAN_DETAIL;
3,540✔
145
  } else if (strncasecmp(name, TSDB_INS_TABLE_SSMIGRATES, len) == 0) {
149,461✔
UNCOV
146
    type = TSDB_MGMT_TABLE_SSMIGRATE;
×
147
  } else if (strncasecmp(name, TSDB_INS_TABLE_TRANSACTION_DETAILS, len) == 0) {
149,461✔
148
    type = TSDB_MGMT_TABLE_TRANSACTION_DETAIL;
1,029✔
149
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_FULL, len) == 0) {
148,432✔
150
    type = TSDB_MGMT_TABLE_GRANTS_FULL;
2,259✔
151
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_LOGS, len) == 0) {
146,173✔
152
    type = TSDB_MGMT_TABLE_GRANTS_LOGS;
2,259✔
153
  } else if (strncasecmp(name, TSDB_INS_TABLE_MACHINES, len) == 0) {
143,914✔
154
    type = TSDB_MGMT_TABLE_MACHINES;
2,618✔
155
  } else if (strncasecmp(name, TSDB_INS_TABLE_ENCRYPTIONS, len) == 0) {
141,296✔
156
    type = TSDB_MGMT_TABLE_ENCRYPTIONS;
827✔
157
  } else if (strncasecmp(name, TSDB_INS_TABLE_TSMAS, len) == 0) {
140,469✔
UNCOV
158
    type = TSDB_MGMT_TABLE_TSMAS;
×
159
  } else if (strncasecmp(name, TSDB_INS_DISK_USAGE, len) == 0) {
140,469✔
160
    type = TSDB_MGMT_TABLE_USAGE;
×
161
  } else if (strncasecmp(name, TSDB_INS_TABLE_FILESETS, len) == 0) {
140,469✔
162
    type = TSDB_MGMT_TABLE_FILESETS;
×
163
  } else if (strncasecmp(name, TSDB_INS_TABLE_VC_COLS, len) == 0) {
140,469✔
164
    type = TSDB_MGMT_TABLE_VC_COL;
×
165
  } else if (strncasecmp(name, TSDB_INS_TABLE_MOUNTS, len) == 0) {
140,469✔
166
    type = TSDB_MGMT_TABLE_MOUNT;
15,405✔
167
  } else if (strncasecmp(name, TSDB_INS_TABLE_RSMAS, len) == 0) {
125,064✔
168
    type = TSDB_MGMT_TABLE_RSMA;
33,968✔
169
  } else if (strncasecmp(name, TSDB_INS_TABLE_RETENTIONS, len) == 0) {
91,096✔
170
    type = TSDB_MGMT_TABLE_RETENTION;
86,464✔
171
  } else if (strncasecmp(name, TSDB_INS_TABLE_RETENTION_DETAILS, len) == 0) {
4,632✔
172
    type = TSDB_MGMT_TABLE_RETENTION_DETAIL;
4,632✔
173
  } else {
UNCOV
174
    mError("invalid show name:%s len:%d", name, len);
×
175
  }
176

177
  return type;
5,410,785✔
178
}
179

180
static SShowObj *mndCreateShowObj(SMnode *pMnode, SRetrieveTableReq *pReq) {
5,410,785✔
181
  SShowMgmt *pMgmt = &pMnode->showMgmt;
5,410,785✔
182

183
  int64_t showId = atomic_add_fetch_64(&pMgmt->showId, 1);
5,410,785✔
184
  if (showId == 0) atomic_add_fetch_64(&pMgmt->showId, 1);
5,410,785✔
185

186
  int32_t size = sizeof(SShowObj);
5,410,785✔
187

188
  SShowObj showObj = {0};
5,410,785✔
189

190
  showObj.id = showId;
5,410,785✔
191
  showObj.pMnode = pMnode;
5,410,785✔
192
  showObj.type = convertToRetrieveType(pReq->tb, tListLen(pReq->tb));
5,410,785✔
193
  (void)memcpy(showObj.db, pReq->db, TSDB_DB_FNAME_LEN);
5,410,785✔
194
  tstrncpy(showObj.filterTb, pReq->filterTb, TSDB_TABLE_NAME_LEN);
5,410,785✔
195

196
  int32_t   keepTime = tsShellActivityTimer * 6 * 1000;
5,410,785✔
197
  SShowObj *pShow = taosCachePut(pMgmt->cache, &showId, sizeof(int64_t), &showObj, size, keepTime);
5,410,785✔
198
  if (pShow == NULL) {
5,410,583✔
UNCOV
199
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
UNCOV
200
    mError("show:0x%" PRIx64 ", failed to put into cache since %s", showId, terrstr());
×
201
    return NULL;
×
202
  }
203

204
  mTrace("show:0x%" PRIx64 ", is created, data:%p", showId, pShow);
5,410,583✔
205
  return pShow;
5,410,785✔
206
}
207

208
static void mndFreeShowObj(SShowObj *pShow) {
5,410,785✔
209
  SMnode    *pMnode = pShow->pMnode;
5,410,785✔
210
  SShowMgmt *pMgmt = &pMnode->showMgmt;
5,410,785✔
211

212
  ShowFreeIterFp freeFp = pMgmt->freeIterFps[pShow->type];
5,410,785✔
213
  if (freeFp != NULL) {
5,410,785✔
214
    if (pShow->pIter != NULL) {
4,999,073✔
215
      mTrace("show:0x%" PRIx64 ", is destroying, data:%p, pIter:%p, ", pShow->id, pShow, pShow->pIter);
117✔
216

217
      (*freeFp)(pMnode, pShow->pIter);
117✔
218

219
      pShow->pIter = NULL;
117✔
220
    }
221
  }
222

223
  mTrace("show:0x%" PRIx64 ", is destroyed, data:%p", pShow->id, pShow);
5,410,785✔
224
}
5,410,785✔
225

226
static SShowObj *mndAcquireShowObj(SMnode *pMnode, int64_t showId) {
133,256✔
227
  SShowMgmt *pMgmt = &pMnode->showMgmt;
133,256✔
228

229
  SShowObj *pShow = taosCacheAcquireByKey(pMgmt->cache, &showId, sizeof(showId));
133,256✔
230
  if (pShow == NULL) {
133,256✔
UNCOV
231
    mError("show:0x%" PRIx64 ", already destroyed", showId);
×
UNCOV
232
    return NULL;
×
233
  }
234

235
  mTrace("show:0x%" PRIx64 ", acquired from cache, data:%p", pShow->id, pShow);
133,256✔
236
  return pShow;
133,256✔
237
}
238

239
static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove) {
5,541,911✔
240
  if (pShow == NULL) return;
5,541,911✔
241
  mTrace("show:0x%" PRIx64 ", released from cache, data:%p force:%d", pShow->id, pShow, forceRemove);
5,541,911✔
242

243
  // A bug in tcache.c
244
  forceRemove = 0;
5,541,911✔
245

246
  SMnode    *pMnode = pShow->pMnode;
5,541,911✔
247
  SShowMgmt *pMgmt = &pMnode->showMgmt;
5,541,911✔
248
  taosCacheRelease(pMgmt->cache, (void **)(&pShow), forceRemove);
5,541,911✔
249
}
250

251
static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) {
5,544,041✔
252
  int32_t    code = 0;
5,544,041✔
253
  SMnode    *pMnode = pReq->info.node;
5,544,041✔
254
  SShowMgmt *pMgmt = &pMnode->showMgmt;
5,544,041✔
255
  SShowObj  *pShow = NULL;
5,544,041✔
256
  int32_t    rowsToRead = SHOW_STEP_SIZE;
5,544,041✔
257
  int32_t    size = 0;
5,544,041✔
258
  int32_t    rowsRead = 0;
5,544,041✔
259
  mDebug("mndProcessRetrieveSysTableReq start");
5,544,041✔
260
  SRetrieveTableReq retrieveReq = {0};
5,544,041✔
261
  TAOS_CHECK_RETURN(tDeserializeSRetrieveTableReq(pReq->pCont, pReq->contLen, &retrieveReq));
5,544,041✔
262

263
  mDebug("process to retrieve systable req db:%s, tb:%s, compactId:%" PRId64, retrieveReq.db, retrieveReq.tb,
5,544,041✔
264
         retrieveReq.compactId);
265

266
  if (retrieveReq.showId == 0) {
5,544,041✔
267
    STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, retrieveReq.tb, strlen(retrieveReq.tb));
5,410,785✔
268
    if (pMeta == NULL) {
5,410,785✔
269
      pMeta = taosHashGet(pMnode->perfsMeta, retrieveReq.tb, strlen(retrieveReq.tb));
697,178✔
270
      if (pMeta == NULL) {
697,178✔
UNCOV
271
        code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
×
UNCOV
272
        mError("failed to process show-retrieve req:%p since %s", pShow, tstrerror(code));
×
273
        TAOS_RETURN(code);
×
274
      }
275
    }
276

277
    pShow = mndCreateShowObj(pMnode, &retrieveReq);
5,410,785✔
278
    if (pShow == NULL) {
5,410,785✔
UNCOV
279
      code = terrno;
×
UNCOV
280
      mError("failed to process show-meta req since %s", tstrerror(code));
×
281
      TAOS_RETURN(code);
×
282
    }
283

284
    pShow->pMeta = pMeta;
5,410,785✔
285
    pShow->numOfColumns = pShow->pMeta->numOfColumns;
5,410,785✔
286
  } else {
287
    pShow = mndAcquireShowObj(pMnode, retrieveReq.showId);
133,256✔
288
    if (pShow == NULL) {
133,256✔
UNCOV
289
      code = TSDB_CODE_MND_INVALID_SHOWOBJ;
×
UNCOV
290
      mError("failed to process show-retrieve req:%p since %s", pShow, tstrerror(code));
×
291
      TAOS_RETURN(code);
×
292
    }
293
  }
294

295
  if (pShow->type == TSDB_MGMT_TABLE_COL) {  // expend capacity for ins_columns
5,544,041✔
296
    rowsToRead = SHOW_COLS_STEP_SIZE;
534,134✔
297
  } else if (pShow->type == TSDB_MGMT_TABLE_PRIVILEGES) {
5,009,705✔
298
    rowsToRead = SHOW_PRIVILEGES_STEP_SIZE;
26,464✔
299
  }
300
  ShowRetrieveFp retrieveFp = pMgmt->retrieveFps[pShow->type];
5,543,839✔
301
  if (retrieveFp == NULL) {
5,544,041✔
UNCOV
302
    mndReleaseShowObj(pShow, false);
×
UNCOV
303
    code = TSDB_CODE_MSG_NOT_PROCESSED;
×
304
    mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, tstrerror(code));
×
305
    TAOS_RETURN(code);
×
306
  }
307

308
  mDebug("show:0x%" PRIx64 ", start retrieve data, type:%d", pShow->id, pShow->type);
5,544,041✔
309
  if (retrieveReq.user[0] != 0) {
5,544,041✔
310
    (void)memcpy(pReq->info.conn.user, retrieveReq.user, TSDB_USER_LEN);
5,544,041✔
311
  } else {
UNCOV
312
    (void)memcpy(pReq->info.conn.user, TSDB_DEFAULT_USER, strlen(TSDB_DEFAULT_USER) + 1);
×
313
  }
314
  code = -1;
5,544,041✔
315
  if (retrieveReq.db[0] &&
7,837,668✔
316
      (code = mndCheckShowPrivilege(pMnode, pReq->info.conn.user, pShow->type, retrieveReq.db)) != 0) {
2,293,627✔
317
    TAOS_RETURN(code);
2,130✔
318
  }
319
  if (pShow->type == TSDB_MGMT_TABLE_USER_FULL) {
5,541,911✔
UNCOV
320
    if (strcmp(pReq->info.conn.user, "root") != 0) {
×
UNCOV
321
      mError("The operation is not permitted, user:%s, pShow->type:%d", pReq->info.conn.user, pShow->type);
×
322
      code = TSDB_CODE_MND_NO_RIGHTS;
×
323
      TAOS_RETURN(code);
×
324
    }
325
  }
326

327
  int32_t numOfCols = pShow->pMeta->numOfColumns;
5,541,911✔
328

329
  SSDataBlock *pBlock = NULL;
5,541,911✔
330
  code = createDataBlock(&pBlock);
5,541,911✔
331
  if (code) {
5,541,911✔
UNCOV
332
    TAOS_RETURN(code);
×
333
  }
334

335
  for (int32_t i = 0; i < numOfCols; ++i) {
76,625,544✔
336
    SColumnInfoData idata = {0};
71,083,431✔
337

338
    SSchema *p = &pShow->pMeta->pSchemas[i];
71,083,431✔
339

340
    idata.info.bytes = p->bytes;
71,083,431✔
341
    idata.info.type = p->type;
71,083,431✔
342
    idata.info.colId = p->colId;
71,083,633✔
343
    TAOS_CHECK_RETURN(blockDataAppendColInfo(pBlock, &idata));
71,083,633✔
344
  }
345

346
  TAOS_CHECK_RETURN(blockDataEnsureCapacity(pBlock, rowsToRead));
5,542,113✔
347

348
  if (mndCheckRetrieveFinished(pShow)) {
5,541,911✔
UNCOV
349
    mDebug("show:0x%" PRIx64 ", read finished, numOfRows:%d", pShow->id, pShow->numOfRows);
×
UNCOV
350
    rowsRead = 0;
×
351
  } else {
352
    rowsRead = (*retrieveFp)(pReq, pShow, pBlock, rowsToRead);
5,541,911✔
353
    if (rowsRead < 0) {
5,541,911✔
354
      code = rowsRead;
5,077✔
355
      mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
5,077✔
356
      mndReleaseShowObj(pShow, true);
5,077✔
357
      blockDataDestroy(pBlock);
5,077✔
358
      TAOS_RETURN(code);
5,077✔
359
    }
360

361
    pBlock->info.rows = rowsRead;
5,536,834✔
362
    mDebug("show:0x%" PRIx64 ", stop retrieve data, rowsRead:%d numOfRows:%d", pShow->id, rowsRead, pShow->numOfRows);
5,536,834✔
363
  }
364

365
  size_t dataEncodeBufSize = blockGetEncodeSize(pBlock);
5,536,834✔
366
  size = sizeof(SRetrieveMetaTableRsp) + sizeof(int32_t) + sizeof(SSysTableSchema) * pShow->pMeta->numOfColumns +
5,536,834✔
367
         dataEncodeBufSize;
368

369
  SRetrieveMetaTableRsp *pRsp = rpcMallocCont(size);
5,536,834✔
370
  if (pRsp == NULL) {
5,536,834✔
UNCOV
371
    mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, tstrerror(terrno));
×
UNCOV
372
    code = terrno;
×
373
    goto _exit;
×
374
  }
375

376
  pRsp->handle = htobe64(pShow->id);
5,536,834✔
377

378
  if (rowsRead > 0) {
5,536,834✔
379
    char    *pStart = pRsp->data;
5,192,877✔
380
    SSchema *ps = pShow->pMeta->pSchemas;
5,192,877✔
381

382
    *(int32_t *)pStart = htonl(pShow->pMeta->numOfColumns);
5,192,877✔
383
    pStart += sizeof(int32_t);  // number of columns
5,192,877✔
384

385
    for (int32_t i = 0; i < pShow->pMeta->numOfColumns; ++i) {
73,060,039✔
386
      SSysTableSchema *pSchema = (SSysTableSchema *)pStart;
67,867,162✔
387
      pSchema->bytes = htonl(ps[i].bytes);
67,867,162✔
388
      pSchema->colId = htons(ps[i].colId);
67,867,162✔
389
      pSchema->type = ps[i].type;
67,867,162✔
390

391
      pStart += sizeof(SSysTableSchema);
67,867,162✔
392
    }
393

394
    int32_t len = blockEncode(pBlock, pStart, dataEncodeBufSize, pShow->pMeta->numOfColumns);
5,192,877✔
395
    if (len < 0) {
5,192,877✔
UNCOV
396
      mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, tstrerror(terrno));
×
UNCOV
397
      code = terrno;
×
398
      return code;
×
399
    }
400
  }
401

402
  pRsp->numOfRows = htonl(rowsRead);
5,536,834✔
403
  pRsp->precision = TSDB_TIME_PRECISION_MILLI;  // millisecond time precision
5,536,834✔
404
  pReq->info.rsp = pRsp;
5,536,834✔
405
  pReq->info.rspLen = size;
5,536,834✔
406

407
  if (rowsRead == 0 || mndCheckRetrieveFinished(pShow)) {
5,536,834✔
408
    pRsp->completed = 1;
5,403,461✔
409
    mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
5,403,461✔
410
    mndReleaseShowObj(pShow, true);
5,403,461✔
411
  } else {
412
    mDebug("show:0x%" PRIx64 ", retrieve not completed yet", pShow->id);
133,373✔
413
    mndReleaseShowObj(pShow, false);
133,373✔
414
  }
415

416
  blockDataDestroy(pBlock);
5,536,834✔
417
  return TSDB_CODE_SUCCESS;
5,536,834✔
UNCOV
418
_exit:
×
UNCOV
419
  mndReleaseShowObj(pShow, false);
×
420
  blockDataDestroy(pBlock);
×
421
  if (pRsp) {
×
422
    rpcFreeCont(pRsp);
×
423
  }
424
  return code;
×
425
}
426

427
static bool mndCheckRetrieveFinished(SShowObj *pShow) {
10,734,788✔
428
  if (pShow->pIter == NULL && pShow->numOfRows != 0) {
10,734,788✔
429
    return true;
5,059,504✔
430
  }
431
  return false;
5,675,284✔
432
}
433

434
void mndAddShowRetrieveHandle(SMnode *pMnode, EShowType showType, ShowRetrieveFp fp) {
23,538,768✔
435
  SShowMgmt *pMgmt = &pMnode->showMgmt;
23,538,768✔
436
  pMgmt->retrieveFps[showType] = fp;
23,538,768✔
437
}
23,538,768✔
438

439
void mndAddShowFreeIterHandle(SMnode *pMnode, EShowType showType, ShowFreeIterFp fp) {
19,615,640✔
440
  SShowMgmt *pMgmt = &pMnode->showMgmt;
19,615,640✔
441
  pMgmt->freeIterFps[showType] = fp;
19,615,640✔
442
}
19,615,640✔
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