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

taosdata / TDengine / #4884

14 Dec 2025 03:48AM UTC coverage: 60.617% (-4.1%) from 64.74%
#4884

push

travis-ci

web-flow
test: update coverage workflow time (#33918)

156854 of 258761 relevant lines covered (60.62%)

75258957.81 hits per line

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

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

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

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

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

59
  if (strncasecmp(name, TSDB_INS_TABLE_DNODES, len) == 0) {
2,371,786✔
60
    type = TSDB_MGMT_TABLE_DNODE;
468,520✔
61
  } else if (strncasecmp(name, TSDB_INS_TABLE_MNODES, len) == 0) {
1,903,266✔
62
    type = TSDB_MGMT_TABLE_MNODE;
172,754✔
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) {
1,730,512✔
68
    type = TSDB_MGMT_TABLE_QNODE;
4,495✔
69
  } else if (strncasecmp(name, TSDB_INS_TABLE_SNODES, len) == 0) {
1,726,017✔
70
    type = TSDB_MGMT_TABLE_SNODE;
2,972✔
71
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES, len) == 0) {
1,723,045✔
72
    type = TSDB_MGMT_TABLE_ANODE;
201✔
73
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES_FULL, len) == 0) {
1,722,844✔
74
    type = TSDB_MGMT_TABLE_ANODE_FULL;
×
75
  } else if (strncasecmp(name, TSDB_INS_TABLE_BNODES, len) == 0) {
1,722,844✔
76
    type = TSDB_MGMT_TABLE_BNODE;
61,222✔
77
  } else if (strncasecmp(name, TSDB_INS_TABLE_ARBGROUPS, len) == 0) {
1,661,622✔
78
    type = TSDB_MGMT_TABLE_ARBGROUP;
×
79
  } else if (strncasecmp(name, TSDB_INS_TABLE_CLUSTER, len) == 0) {
1,661,622✔
80
    type = TSDB_MGMT_TABLE_CLUSTER;
2,042✔
81
  } else if (strncasecmp(name, TSDB_INS_TABLE_DATABASES, len) == 0) {
1,659,580✔
82
    type = TSDB_MGMT_TABLE_DB;
349,066✔
83
  } else if (strncasecmp(name, TSDB_INS_TABLE_FUNCTIONS, len) == 0) {
1,310,514✔
84
    type = TSDB_MGMT_TABLE_FUNC;
6,898✔
85
  } else if (strncasecmp(name, TSDB_INS_TABLE_INDEXES, len) == 0) {
1,303,616✔
86
    type = TSDB_MGMT_TABLE_INDEX;
7,923✔
87
  } else if (strncasecmp(name, TSDB_INS_TABLE_STABLES, len) == 0) {
1,295,693✔
88
    type = TSDB_MGMT_TABLE_STB;
165,949✔
89
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLES, len) == 0) {
1,129,744✔
90
    type = TSDB_MGMT_TABLE_TABLE;
×
91
  } else if (strncasecmp(name, TSDB_INS_TABLE_TAGS, len) == 0) {
1,129,744✔
92
    type = TSDB_MGMT_TABLE_TAG;
×
93
  } else if (strncasecmp(name, TSDB_INS_TABLE_COLS, len) == 0) {
1,129,744✔
94
    type = TSDB_MGMT_TABLE_COL;
263,680✔
95
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLE_DISTRIBUTED, len) == 0) {
866,064✔
96
    //    type = TSDB_MGMT_TABLE_DIST;
97
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS, len) == 0) {
866,064✔
98
    type = TSDB_MGMT_TABLE_USER;
9,914✔
99
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS_FULL, len) == 0) {
856,150✔
100
    type = TSDB_MGMT_TABLE_USER_FULL;
×
101
  } else if (strncasecmp(name, TSDB_INS_TABLE_LICENCES, len) == 0) {
856,150✔
102
    type = TSDB_MGMT_TABLE_GRANTS;
2,167✔
103
  } else if (strncasecmp(name, TSDB_INS_TABLE_VGROUPS, len) == 0) {
853,983✔
104
    type = TSDB_MGMT_TABLE_VGROUP;
178,078✔
105
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONSUMERS, len) == 0) {
675,905✔
106
    type = TSDB_MGMT_TABLE_CONSUMERS;
3,459✔
107
  } else if (strncasecmp(name, TSDB_INS_TABLE_SUBSCRIPTIONS, len) == 0) {
672,446✔
108
    type = TSDB_MGMT_TABLE_SUBSCRIPTIONS;
3,456✔
109
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_TRANS, len) == 0) {
668,990✔
110
    type = TSDB_MGMT_TABLE_TRANS;
233,763✔
111
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_SMAS, len) == 0) {
435,227✔
112
    type = TSDB_MGMT_TABLE_SMAS;
×
113
  } else if (strncasecmp(name, TSDB_INS_TABLE_CONFIGS, len) == 0) {
435,227✔
114
    type = TSDB_MGMT_TABLE_CONFIGS;
1,407✔
115
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONNECTIONS, len) == 0) {
433,820✔
116
    type = TSDB_MGMT_TABLE_CONNS;
8,894✔
117
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_QUERIES, len) == 0) {
424,926✔
118
    type = TSDB_MGMT_TABLE_QUERIES;
3,670✔
119
  } else if (strncasecmp(name, TSDB_INS_TABLE_VNODES, len) == 0) {
421,256✔
120
    type = TSDB_MGMT_TABLE_VNODES;
209✔
121
  } else if (strncasecmp(name, TSDB_INS_TABLE_TOPICS, len) == 0) {
421,047✔
122
    type = TSDB_MGMT_TABLE_TOPICS;
12,257✔
123
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAMS, len) == 0) {
408,790✔
124
    type = TSDB_MGMT_TABLE_STREAMS;
64,761✔
125
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_APPS, len) == 0) {
344,029✔
126
    type = TSDB_MGMT_TABLE_APPS;
3,446✔
127
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_INSTANCES, len) == 0) {
340,583✔
128
    type = TSDB_MGMT_TABLE_INSTANCE;
×
129
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAM_TASKS, len) == 0) {
340,583✔
130
    type = TSDB_MGMT_TABLE_STREAM_TASKS;
21,544✔
131
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAM_RECALCULATES, len) == 0) {
319,039✔
132
    type = TSDB_MGMT_TABLE_STREAM_RECALCULATES;
×
133
  } else if (strncasecmp(name, TSDB_INS_TABLE_USER_PRIVILEGES, len) == 0) {
319,039✔
134
    type = TSDB_MGMT_TABLE_PRIVILEGES;
7,470✔
135
  } else if (strncasecmp(name, TSDB_INS_TABLE_VIEWS, len) == 0) {
311,569✔
136
    type = TSDB_MGMT_TABLE_VIEWS;
16,388✔
137
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACTS, len) == 0) {
295,181✔
138
    type = TSDB_MGMT_TABLE_COMPACT;
216,107✔
139
  } else if (strncasecmp(name, TSDB_INS_TABLE_ENCRYPT_ALGORITHMS, len) == 0) {
79,074✔
140
    type = TSDB_MGMT_TABLE_ENCRYPT_ALGORITHMS;
×
141
  } else if (strncasecmp(name, TSDB_INS_TABLE_SCANS, len) == 0) {
79,074✔
142
    type = TSDB_MGMT_TABLE_SCAN;
519✔
143
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACT_DETAILS, len) == 0) {
78,555✔
144
    type = TSDB_MGMT_TABLE_COMPACT_DETAIL;
22,889✔
145
  } else if (strncasecmp(name, TSDB_INS_TABLE_SCAN_DETAILS, len) == 0) {
55,666✔
146
    type = TSDB_MGMT_TABLE_SCAN_DETAIL;
504✔
147
  } else if (strncasecmp(name, TSDB_INS_TABLE_SSMIGRATES, len) == 0) {
55,162✔
148
    type = TSDB_MGMT_TABLE_SSMIGRATE;
×
149
  } else if (strncasecmp(name, TSDB_INS_TABLE_TRANSACTION_DETAILS, len) == 0) {
55,162✔
150
    type = TSDB_MGMT_TABLE_TRANSACTION_DETAIL;
410✔
151
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_FULL, len) == 0) {
54,752✔
152
    type = TSDB_MGMT_TABLE_GRANTS_FULL;
1,216✔
153
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_LOGS, len) == 0) {
53,536✔
154
    type = TSDB_MGMT_TABLE_GRANTS_LOGS;
1,216✔
155
  } else if (strncasecmp(name, TSDB_INS_TABLE_MACHINES, len) == 0) {
52,320✔
156
    type = TSDB_MGMT_TABLE_MACHINES;
1,425✔
157
  } else if (strncasecmp(name, TSDB_INS_TABLE_ENCRYPTIONS, len) == 0) {
50,895✔
158
    type = TSDB_MGMT_TABLE_ENCRYPTIONS;
249✔
159
  } else if (strncasecmp(name, TSDB_INS_TABLE_TSMAS, len) == 0) {
50,646✔
160
    type = TSDB_MGMT_TABLE_TSMAS;
×
161
  } else if (strncasecmp(name, TSDB_INS_DISK_USAGE, len) == 0) {
50,646✔
162
    type = TSDB_MGMT_TABLE_USAGE;
×
163
  } else if (strncasecmp(name, TSDB_INS_TABLE_FILESETS, len) == 0) {
50,646✔
164
    type = TSDB_MGMT_TABLE_FILESETS;
×
165
  } else if (strncasecmp(name, TSDB_INS_TABLE_VC_COLS, len) == 0) {
50,646✔
166
    type = TSDB_MGMT_TABLE_VC_COL;
×
167
  } else if (strncasecmp(name, TSDB_INS_TABLE_MOUNTS, len) == 0) {
50,646✔
168
    type = TSDB_MGMT_TABLE_MOUNT;
7,986✔
169
  } else if (strncasecmp(name, TSDB_INS_TABLE_RSMAS, len) == 0) {
42,660✔
170
    type = TSDB_MGMT_TABLE_RSMA;
11,880✔
171
  } else if (strncasecmp(name, TSDB_INS_TABLE_RETENTIONS, len) == 0) {
30,780✔
172
    type = TSDB_MGMT_TABLE_RETENTION;
29,160✔
173
  } else if (strncasecmp(name, TSDB_INS_TABLE_RETENTION_DETAILS, len) == 0) {
1,620✔
174
    type = TSDB_MGMT_TABLE_RETENTION_DETAIL;
1,620✔
175
  } else {
176
    mError("invalid show name:%s len:%d", name, len);
×
177
  }
178

179
  return type;
2,371,786✔
180
}
181

182
static SShowObj *mndCreateShowObj(SMnode *pMnode, SRetrieveTableReq *pReq) {
2,371,786✔
183
  SShowMgmt *pMgmt = &pMnode->showMgmt;
2,371,786✔
184

185
  int64_t showId = atomic_add_fetch_64(&pMgmt->showId, 1);
2,371,786✔
186
  if (showId == 0) atomic_add_fetch_64(&pMgmt->showId, 1);
2,371,786✔
187

188
  int32_t size = sizeof(SShowObj);
2,371,786✔
189

190
  SShowObj showObj = {0};
2,371,786✔
191

192
  showObj.id = showId;
2,371,786✔
193
  showObj.pMnode = pMnode;
2,371,786✔
194
  showObj.type = convertToRetrieveType(pReq->tb, tListLen(pReq->tb));
2,371,786✔
195
  (void)memcpy(showObj.db, pReq->db, TSDB_DB_FNAME_LEN);
2,371,786✔
196
  tstrncpy(showObj.filterTb, pReq->filterTb, TSDB_TABLE_NAME_LEN);
2,371,786✔
197

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

206
  mTrace("show:0x%" PRIx64 ", is created, data:%p", showId, pShow);
2,371,694✔
207
  return pShow;
2,371,694✔
208
}
209

210
static void mndFreeShowObj(SShowObj *pShow) {
2,371,786✔
211
  SMnode    *pMnode = pShow->pMnode;
2,371,786✔
212
  SShowMgmt *pMgmt = &pMnode->showMgmt;
2,371,786✔
213

214
  ShowFreeIterFp freeFp = pMgmt->freeIterFps[pShow->type];
2,371,786✔
215
  if (freeFp != NULL) {
2,371,786✔
216
    if (pShow->pIter != NULL) {
2,126,281✔
217
      mTrace("show:0x%" PRIx64 ", is destroying, data:%p, pIter:%p, ", pShow->id, pShow, pShow->pIter);
10✔
218

219
      (*freeFp)(pMnode, pShow->pIter);
10✔
220

221
      pShow->pIter = NULL;
10✔
222
    }
223
  }
224

225
  mTrace("show:0x%" PRIx64 ", is destroyed, data:%p", pShow->id, pShow);
2,371,786✔
226
}
2,371,786✔
227

228
static SShowObj *mndAcquireShowObj(SMnode *pMnode, int64_t showId) {
1,522✔
229
  SShowMgmt *pMgmt = &pMnode->showMgmt;
1,522✔
230

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

237
  mTrace("show:0x%" PRIx64 ", acquired from cache, data:%p", pShow->id, pShow);
1,522✔
238
  return pShow;
1,522✔
239
}
240

241
static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove) {
2,372,124✔
242
  if (pShow == NULL) return;
2,372,124✔
243
  mTrace("show:0x%" PRIx64 ", released from cache, data:%p force:%d", pShow->id, pShow, forceRemove);
2,372,124✔
244

245
  // A bug in tcache.c
246
  forceRemove = 0;
2,372,124✔
247

248
  SMnode    *pMnode = pShow->pMnode;
2,372,124✔
249
  SShowMgmt *pMgmt = &pMnode->showMgmt;
2,372,124✔
250
  taosCacheRelease(pMgmt->cache, (void **)(&pShow), forceRemove);
2,372,124✔
251
}
252

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

265
  mDebug("process to retrieve systable req db:%s, tb:%s, compactId:%" PRId64, retrieveReq.db, retrieveReq.tb,
2,373,308✔
266
         retrieveReq.compactId);
267

268
  if (retrieveReq.showId == 0) {
2,373,308✔
269
    STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, retrieveReq.tb, strlen(retrieveReq.tb));
2,371,786✔
270
    if (pMeta == NULL) {
2,371,786✔
271
      pMeta = taosHashGet(pMnode->perfsMeta, retrieveReq.tb, strlen(retrieveReq.tb));
253,232✔
272
      if (pMeta == NULL) {
253,232✔
273
        code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
×
274
        mError("failed to process show-retrieve req:%p since %s", pShow, tstrerror(code));
×
275
        TAOS_RETURN(code);
×
276
      }
277
    }
278

279
    pShow = mndCreateShowObj(pMnode, &retrieveReq);
2,371,786✔
280
    if (pShow == NULL) {
2,371,694✔
281
      code = terrno;
×
282
      mError("failed to process show-meta req since %s", tstrerror(code));
×
283
      TAOS_RETURN(code);
×
284
    }
285

286
    pShow->pMeta = pMeta;
2,371,694✔
287
    pShow->numOfColumns = pShow->pMeta->numOfColumns;
2,371,694✔
288
  } else {
289
    pShow = mndAcquireShowObj(pMnode, retrieveReq.showId);
1,522✔
290
    if (pShow == NULL) {
1,522✔
291
      code = TSDB_CODE_MND_INVALID_SHOWOBJ;
×
292
      mError("failed to process show-retrieve req:%p since %s", pShow, tstrerror(code));
×
293
      TAOS_RETURN(code);
×
294
    }
295
  }
296

297
  if (pShow->type == TSDB_MGMT_TABLE_COL) {  // expend capacity for ins_columns
2,373,216✔
298
    rowsToRead = SHOW_COLS_STEP_SIZE;
263,828✔
299
  } else if (pShow->type == TSDB_MGMT_TABLE_PRIVILEGES) {
2,109,388✔
300
    rowsToRead = SHOW_PRIVILEGES_STEP_SIZE;
7,470✔
301
  }
302
  ShowRetrieveFp retrieveFp = pMgmt->retrieveFps[pShow->type];
2,373,216✔
303
  if (retrieveFp == NULL) {
2,373,216✔
304
    mndReleaseShowObj(pShow, false);
×
305
    code = TSDB_CODE_MSG_NOT_PROCESSED;
×
306
    mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, tstrerror(code));
×
307
    TAOS_RETURN(code);
×
308
  }
309

310
  mDebug("show:0x%" PRIx64 ", start retrieve data, type:%d", pShow->id, pShow->type);
2,373,216✔
311
  if (retrieveReq.user[0] != 0) {
2,373,308✔
312
    (void)memcpy(pReq->info.conn.user, retrieveReq.user, TSDB_USER_LEN);
2,373,308✔
313
  } else {
314
    (void)memcpy(pReq->info.conn.user, TSDB_DEFAULT_USER, strlen(TSDB_DEFAULT_USER) + 1);
×
315
  }
316
  code = -1;
2,373,308✔
317
  if (retrieveReq.db[0] &&
3,408,018✔
318
      (code = mndCheckShowPrivilege(pMnode, pReq->info.conn.user, pShow->type, retrieveReq.db)) != 0) {
1,034,710✔
319
    TAOS_RETURN(code);
1,184✔
320
  }
321
  if (pShow->type == TSDB_MGMT_TABLE_USER_FULL) {
2,372,124✔
322
    if (strcmp(pReq->info.conn.user, "root") != 0) {
×
323
      mError("The operation is not permitted, user:%s, pShow->type:%d", pReq->info.conn.user, pShow->type);
×
324
      code = TSDB_CODE_MND_NO_RIGHTS;
×
325
      TAOS_RETURN(code);
×
326
    }
327
  }
328

329
  int32_t numOfCols = pShow->pMeta->numOfColumns;
2,372,124✔
330

331
  SSDataBlock *pBlock = NULL;
2,372,124✔
332
  code = createDataBlock(&pBlock);
2,372,124✔
333
  if (code) {
2,372,124✔
334
    TAOS_RETURN(code);
×
335
  }
336

337
  for (int32_t i = 0; i < numOfCols; ++i) {
34,960,647✔
338
    SColumnInfoData idata = {0};
32,588,523✔
339

340
    SSchema *p = &pShow->pMeta->pSchemas[i];
32,588,523✔
341

342
    idata.info.bytes = p->bytes;
32,588,523✔
343
    idata.info.type = p->type;
32,588,523✔
344
    idata.info.colId = p->colId;
32,588,523✔
345
    TAOS_CHECK_RETURN(blockDataAppendColInfo(pBlock, &idata));
32,588,523✔
346
  }
347

348
  TAOS_CHECK_RETURN(blockDataEnsureCapacity(pBlock, rowsToRead));
2,372,124✔
349

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

363
    pBlock->info.rows = rowsRead;
2,371,143✔
364
    mDebug("show:0x%" PRIx64 ", stop retrieve data, rowsRead:%d numOfRows:%d", pShow->id, rowsRead, pShow->numOfRows);
2,371,143✔
365
  }
366

367
  size_t dataEncodeBufSize = blockGetEncodeSize(pBlock);
2,371,143✔
368
  size = sizeof(SRetrieveMetaTableRsp) + sizeof(int32_t) + sizeof(SSysTableSchema) * pShow->pMeta->numOfColumns +
2,371,143✔
369
         dataEncodeBufSize;
370

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

378
  pRsp->handle = htobe64(pShow->id);
2,371,143✔
379

380
  if (rowsRead > 0) {
2,371,143✔
381
    char    *pStart = pRsp->data;
2,199,001✔
382
    SSchema *ps = pShow->pMeta->pSchemas;
2,199,001✔
383

384
    *(int32_t *)pStart = htonl(pShow->pMeta->numOfColumns);
2,199,001✔
385
    pStart += sizeof(int32_t);  // number of columns
2,199,001✔
386

387
    for (int32_t i = 0; i < pShow->pMeta->numOfColumns; ++i) {
33,247,282✔
388
      SSysTableSchema *pSchema = (SSysTableSchema *)pStart;
31,048,281✔
389
      pSchema->bytes = htonl(ps[i].bytes);
31,048,281✔
390
      pSchema->colId = htons(ps[i].colId);
31,048,281✔
391
      pSchema->type = ps[i].type;
31,048,281✔
392

393
      pStart += sizeof(SSysTableSchema);
31,048,281✔
394
    }
395

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

404
  pRsp->numOfRows = htonl(rowsRead);
2,371,143✔
405
  pRsp->precision = TSDB_TIME_PRECISION_MILLI;  // millisecond time precision
2,371,143✔
406
  pReq->info.rsp = pRsp;
2,371,143✔
407
  pReq->info.rspLen = size;
2,371,143✔
408

409
  if (rowsRead == 0 || mndCheckRetrieveFinished(pShow)) {
2,371,143✔
410
    pRsp->completed = 1;
2,369,611✔
411
    mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
2,369,611✔
412
    mndReleaseShowObj(pShow, true);
2,369,611✔
413
  } else {
414
    mDebug("show:0x%" PRIx64 ", retrieve not completed yet", pShow->id);
1,532✔
415
    mndReleaseShowObj(pShow, false);
1,532✔
416
  }
417

418
  blockDataDestroy(pBlock);
2,371,143✔
419
  return TSDB_CODE_SUCCESS;
2,371,143✔
420
_exit:
×
421
  mndReleaseShowObj(pShow, false);
×
422
  blockDataDestroy(pBlock);
×
423
  if (pRsp) {
×
424
    rpcFreeCont(pRsp);
×
425
  }
426
  return code;
×
427
}
428

429
static bool mndCheckRetrieveFinished(SShowObj *pShow) {
4,571,125✔
430
  if (pShow->pIter == NULL && pShow->numOfRows != 0) {
4,571,125✔
431
    return true;
2,197,469✔
432
  }
433
  return false;
2,373,656✔
434
}
435

436
void mndAddShowRetrieveHandle(SMnode *pMnode, EShowType showType, ShowRetrieveFp fp) {
11,115,356✔
437
  SShowMgmt *pMgmt = &pMnode->showMgmt;
11,115,356✔
438
  pMgmt->retrieveFps[showType] = fp;
11,115,356✔
439
}
11,115,356✔
440

441
void mndAddShowFreeIterHandle(SMnode *pMnode, EShowType showType, ShowFreeIterFp fp) {
9,073,760✔
442
  SShowMgmt *pMgmt = &pMnode->showMgmt;
9,073,760✔
443
  pMgmt->freeIterFps[showType] = fp;
9,073,760✔
444
}
9,073,760✔
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