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

taosdata / TDengine / #4871

04 Dec 2025 01:55AM UTC coverage: 64.654% (+0.1%) from 64.545%
#4871

push

travis-ci

guanshengliang
Merge branch '3.0' into cover/3.0

869 of 2219 new or added lines in 36 files covered. (39.16%)

441 existing lines in 120 files now uncovered.

159620 of 246882 relevant lines covered (64.65%)

110922946.31 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) {
489,676✔
34
  int32_t    code = 0;
489,676✔
35
  SShowMgmt *pMgmt = &pMnode->showMgmt;
489,676✔
36

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

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

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

59
  if (strncasecmp(name, TSDB_INS_TABLE_DNODES, len) == 0) {
5,099,814✔
60
    type = TSDB_MGMT_TABLE_DNODE;
874,703✔
61
  } else if (strncasecmp(name, TSDB_INS_TABLE_MNODES, len) == 0) {
4,225,111✔
62
    type = TSDB_MGMT_TABLE_MNODE;
357,762✔
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) {
3,867,349✔
68
    type = TSDB_MGMT_TABLE_QNODE;
7,951✔
69
  } else if (strncasecmp(name, TSDB_INS_TABLE_SNODES, len) == 0) {
3,859,398✔
70
    type = TSDB_MGMT_TABLE_SNODE;
158,865✔
71
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES, len) == 0) {
3,700,533✔
72
    type = TSDB_MGMT_TABLE_ANODE;
351✔
73
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES_FULL, len) == 0) {
3,700,182✔
74
    type = TSDB_MGMT_TABLE_ANODE_FULL;
×
75
  } else if (strncasecmp(name, TSDB_INS_TABLE_BNODES, len) == 0) {
3,700,182✔
76
    type = TSDB_MGMT_TABLE_BNODE;
121,955✔
77
  } else if (strncasecmp(name, TSDB_INS_TABLE_ARBGROUPS, len) == 0) {
3,578,227✔
78
    type = TSDB_MGMT_TABLE_ARBGROUP;
×
79
  } else if (strncasecmp(name, TSDB_INS_TABLE_CLUSTER, len) == 0) {
3,578,227✔
80
    type = TSDB_MGMT_TABLE_CLUSTER;
3,538✔
81
  } else if (strncasecmp(name, TSDB_INS_TABLE_DATABASES, len) == 0) {
3,574,689✔
82
    type = TSDB_MGMT_TABLE_DB;
621,970✔
83
  } else if (strncasecmp(name, TSDB_INS_TABLE_FUNCTIONS, len) == 0) {
2,952,719✔
84
    type = TSDB_MGMT_TABLE_FUNC;
16,046✔
85
  } else if (strncasecmp(name, TSDB_INS_TABLE_INDEXES, len) == 0) {
2,936,673✔
86
    type = TSDB_MGMT_TABLE_INDEX;
14,162✔
87
  } else if (strncasecmp(name, TSDB_INS_TABLE_STABLES, len) == 0) {
2,922,511✔
88
    type = TSDB_MGMT_TABLE_STB;
342,660✔
89
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLES, len) == 0) {
2,579,851✔
90
    type = TSDB_MGMT_TABLE_TABLE;
×
91
  } else if (strncasecmp(name, TSDB_INS_TABLE_TAGS, len) == 0) {
2,579,851✔
92
    type = TSDB_MGMT_TABLE_TAG;
×
93
  } else if (strncasecmp(name, TSDB_INS_TABLE_COLS, len) == 0) {
2,579,851✔
94
    type = TSDB_MGMT_TABLE_COL;
522,385✔
95
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLE_DISTRIBUTED, len) == 0) {
2,057,466✔
96
    //    type = TSDB_MGMT_TABLE_DIST;
97
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS, len) == 0) {
2,057,466✔
98
    type = TSDB_MGMT_TABLE_USER;
20,193✔
99
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS_FULL, len) == 0) {
2,037,273✔
100
    type = TSDB_MGMT_TABLE_USER_FULL;
×
101
  } else if (strncasecmp(name, TSDB_INS_TABLE_LICENCES, len) == 0) {
2,037,273✔
102
    type = TSDB_MGMT_TABLE_GRANTS;
4,163✔
103
  } else if (strncasecmp(name, TSDB_INS_TABLE_VGROUPS, len) == 0) {
2,033,110✔
104
    type = TSDB_MGMT_TABLE_VGROUP;
302,331✔
105
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONSUMERS, len) == 0) {
1,730,779✔
106
    type = TSDB_MGMT_TABLE_CONSUMERS;
9,639✔
107
  } else if (strncasecmp(name, TSDB_INS_TABLE_SUBSCRIPTIONS, len) == 0) {
1,721,140✔
108
    type = TSDB_MGMT_TABLE_SUBSCRIPTIONS;
10,220✔
109
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_TRANS, len) == 0) {
1,710,920✔
110
    type = TSDB_MGMT_TABLE_TRANS;
425,286✔
111
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_SMAS, len) == 0) {
1,285,634✔
112
    type = TSDB_MGMT_TABLE_SMAS;
×
113
  } else if (strncasecmp(name, TSDB_INS_TABLE_CONFIGS, len) == 0) {
1,285,634✔
114
    type = TSDB_MGMT_TABLE_CONFIGS;
2,457✔
115
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONNECTIONS, len) == 0) {
1,283,177✔
116
    type = TSDB_MGMT_TABLE_CONNS;
16,813✔
117
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_QUERIES, len) == 0) {
1,266,364✔
118
    type = TSDB_MGMT_TABLE_QUERIES;
6,443✔
119
  } else if (strncasecmp(name, TSDB_INS_TABLE_VNODES, len) == 0) {
1,259,921✔
120
    type = TSDB_MGMT_TABLE_VNODES;
1,627✔
121
  } else if (strncasecmp(name, TSDB_INS_TABLE_TOPICS, len) == 0) {
1,258,294✔
122
    type = TSDB_MGMT_TABLE_TOPICS;
25,746✔
123
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAMS, len) == 0) {
1,232,548✔
124
    type = TSDB_MGMT_TABLE_STREAMS;
311,255✔
125
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_APPS, len) == 0) {
921,293✔
126
    type = TSDB_MGMT_TABLE_APPS;
5,989✔
127
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_INSTANCES, len) == 0) {
915,304✔
NEW
128
    type = TSDB_MGMT_TABLE_INSTANCE;
×
129
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAM_TASKS, len) == 0) {
915,304✔
130
    type = TSDB_MGMT_TABLE_STREAM_TASKS;
285,468✔
131
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAM_RECALCULATES, len) == 0) {
629,836✔
132
    type = TSDB_MGMT_TABLE_STREAM_RECALCULATES;
429✔
133
  } else if (strncasecmp(name, TSDB_INS_TABLE_USER_PRIVILEGES, len) == 0) {
629,407✔
134
    type = TSDB_MGMT_TABLE_PRIVILEGES;
26,205✔
135
  } else if (strncasecmp(name, TSDB_INS_TABLE_VIEWS, len) == 0) {
603,202✔
136
    type = TSDB_MGMT_TABLE_VIEWS;
32,197✔
137
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACTS, len) == 0) {
571,005✔
138
    type = TSDB_MGMT_TABLE_COMPACT;
379,314✔
139
  } else if (strncasecmp(name, TSDB_INS_TABLE_SCANS, len) == 0) {
191,691✔
140
    type = TSDB_MGMT_TABLE_SCAN;
3,680✔
141
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACT_DETAILS, len) == 0) {
188,011✔
142
    type = TSDB_MGMT_TABLE_COMPACT_DETAIL;
33,710✔
143
  } else if (strncasecmp(name, TSDB_INS_TABLE_SCAN_DETAILS, len) == 0) {
154,301✔
144
    type = TSDB_MGMT_TABLE_SCAN_DETAIL;
3,680✔
145
  } else if (strncasecmp(name, TSDB_INS_TABLE_SSMIGRATES, len) == 0) {
150,621✔
146
    type = TSDB_MGMT_TABLE_SSMIGRATE;
×
147
  } else if (strncasecmp(name, TSDB_INS_TABLE_TRANSACTION_DETAILS, len) == 0) {
150,621✔
148
    type = TSDB_MGMT_TABLE_TRANSACTION_DETAIL;
1,018✔
149
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_FULL, len) == 0) {
149,603✔
150
    type = TSDB_MGMT_TABLE_GRANTS_FULL;
2,216✔
151
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_LOGS, len) == 0) {
147,387✔
152
    type = TSDB_MGMT_TABLE_GRANTS_LOGS;
2,216✔
153
  } else if (strncasecmp(name, TSDB_INS_TABLE_MACHINES, len) == 0) {
145,171✔
154
    type = TSDB_MGMT_TABLE_MACHINES;
2,574✔
155
  } else if (strncasecmp(name, TSDB_INS_TABLE_ENCRYPTIONS, len) == 0) {
142,597✔
156
    type = TSDB_MGMT_TABLE_ENCRYPTIONS;
795✔
157
  } else if (strncasecmp(name, TSDB_INS_TABLE_TSMAS, len) == 0) {
141,802✔
158
    type = TSDB_MGMT_TABLE_TSMAS;
×
159
  } else if (strncasecmp(name, TSDB_INS_DISK_USAGE, len) == 0) {
141,802✔
160
    type = TSDB_MGMT_TABLE_USAGE;
×
161
  } else if (strncasecmp(name, TSDB_INS_TABLE_FILESETS, len) == 0) {
141,802✔
162
    type = TSDB_MGMT_TABLE_FILESETS;
×
163
  } else if (strncasecmp(name, TSDB_INS_TABLE_VC_COLS, len) == 0) {
141,802✔
164
    type = TSDB_MGMT_TABLE_VC_COL;
×
165
  } else if (strncasecmp(name, TSDB_INS_TABLE_MOUNTS, len) == 0) {
141,802✔
166
    type = TSDB_MGMT_TABLE_MOUNT;
15,358✔
167
  } else if (strncasecmp(name, TSDB_INS_TABLE_RSMAS, len) == 0) {
126,444✔
168
    type = TSDB_MGMT_TABLE_RSMA;
33,924✔
169
  } else if (strncasecmp(name, TSDB_INS_TABLE_RETENTIONS, len) == 0) {
92,520✔
170
    type = TSDB_MGMT_TABLE_RETENTION;
87,894✔
171
  } else if (strncasecmp(name, TSDB_INS_TABLE_RETENTION_DETAILS, len) == 0) {
4,626✔
172
    type = TSDB_MGMT_TABLE_RETENTION_DETAIL;
4,626✔
173
  } else {
174
    mError("invalid show name:%s len:%d", name, len);
×
175
  }
176

177
  return type;
5,099,814✔
178
}
179

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

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

186
  int32_t size = sizeof(SShowObj);
5,099,814✔
187

188
  SShowObj showObj = {0};
5,099,814✔
189

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

196
  int32_t   keepTime = tsShellActivityTimer * 6 * 1000;
5,099,814✔
197
  SShowObj *pShow = taosCachePut(pMgmt->cache, &showId, sizeof(int64_t), &showObj, size, keepTime);
5,099,814✔
198
  if (pShow == NULL) {
5,099,814✔
199
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
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,099,814✔
205
  return pShow;
5,099,814✔
206
}
207

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

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

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

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

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

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

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

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

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

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

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

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

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

266
  if (retrieveReq.showId == 0) {
5,226,597✔
267
    STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, retrieveReq.tb, strlen(retrieveReq.tb));
5,099,814✔
268
    if (pMeta == NULL) {
5,099,814✔
269
      pMeta = taosHashGet(pMnode->perfsMeta, retrieveReq.tb, strlen(retrieveReq.tb));
464,170✔
270
      if (pMeta == NULL) {
464,170✔
271
        code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
×
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,099,814✔
278
    if (pShow == NULL) {
5,099,814✔
279
      code = terrno;
×
280
      mError("failed to process show-meta req since %s", tstrerror(code));
×
281
      TAOS_RETURN(code);
×
282
    }
283

284
    pShow->pMeta = pMeta;
5,099,814✔
285
    pShow->numOfColumns = pShow->pMeta->numOfColumns;
5,099,814✔
286
  } else {
287
    pShow = mndAcquireShowObj(pMnode, retrieveReq.showId);
126,783✔
288
    if (pShow == NULL) {
126,783✔
289
      code = TSDB_CODE_MND_INVALID_SHOWOBJ;
×
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,226,597✔
296
    rowsToRead = SHOW_COLS_STEP_SIZE;
525,025✔
297
  } else if (pShow->type == TSDB_MGMT_TABLE_PRIVILEGES) {
4,701,572✔
298
    rowsToRead = SHOW_PRIVILEGES_STEP_SIZE;
26,205✔
299
  }
300
  ShowRetrieveFp retrieveFp = pMgmt->retrieveFps[pShow->type];
5,226,597✔
301
  if (retrieveFp == NULL) {
5,226,597✔
302
    mndReleaseShowObj(pShow, false);
×
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,226,597✔
309
  if (retrieveReq.user[0] != 0) {
5,226,597✔
310
    (void)memcpy(pReq->info.conn.user, retrieveReq.user, TSDB_USER_LEN);
5,226,597✔
311
  } else {
312
    (void)memcpy(pReq->info.conn.user, TSDB_DEFAULT_USER, strlen(TSDB_DEFAULT_USER) + 1);
×
313
  }
314
  code = -1;
5,226,597✔
315
  if (retrieveReq.db[0] &&
7,280,251✔
316
      (code = mndCheckShowPrivilege(pMnode, pReq->info.conn.user, pShow->type, retrieveReq.db)) != 0) {
2,053,654✔
317
    TAOS_RETURN(code);
2,098✔
318
  }
319
  if (pShow->type == TSDB_MGMT_TABLE_USER_FULL) {
5,224,499✔
320
    if (strcmp(pReq->info.conn.user, "root") != 0) {
×
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,224,499✔
328

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

335
  for (int32_t i = 0; i < numOfCols; ++i) {
72,872,525✔
336
    SColumnInfoData idata = {0};
67,648,026✔
337

338
    SSchema *p = &pShow->pMeta->pSchemas[i];
67,648,026✔
339

340
    idata.info.bytes = p->bytes;
67,648,026✔
341
    idata.info.type = p->type;
67,648,026✔
342
    idata.info.colId = p->colId;
67,648,026✔
343
    TAOS_CHECK_RETURN(blockDataAppendColInfo(pBlock, &idata));
67,648,026✔
344
  }
345

346
  TAOS_CHECK_RETURN(blockDataEnsureCapacity(pBlock, rowsToRead));
5,224,499✔
347

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

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

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

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

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

378
  if (rowsRead > 0) {
5,222,225✔
379
    char    *pStart = pRsp->data;
4,853,139✔
380
    SSchema *ps = pShow->pMeta->pSchemas;
4,853,139✔
381

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

385
    for (int32_t i = 0; i < pShow->pMeta->numOfColumns; ++i) {
68,961,456✔
386
      SSysTableSchema *pSchema = (SSysTableSchema *)pStart;
64,108,317✔
387
      pSchema->bytes = htonl(ps[i].bytes);
64,108,317✔
388
      pSchema->colId = htons(ps[i].colId);
64,108,317✔
389
      pSchema->type = ps[i].type;
64,108,317✔
390

391
      pStart += sizeof(SSysTableSchema);
64,108,317✔
392
    }
393

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

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

407
  if (rowsRead == 0 || mndCheckRetrieveFinished(pShow)) {
5,222,225✔
408
    pRsp->completed = 1;
5,095,332✔
409
    mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
5,095,332✔
410
    mndReleaseShowObj(pShow, true);
5,095,332✔
411
  } else {
412
    mDebug("show:0x%" PRIx64 ", retrieve not completed yet", pShow->id);
126,893✔
413
    mndReleaseShowObj(pShow, false);
126,893✔
414
  }
415

416
  blockDataDestroy(pBlock);
5,222,225✔
417
  return TSDB_CODE_SUCCESS;
5,222,225✔
418
_exit:
×
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,077,638✔
428
  if (pShow->pIter == NULL && pShow->numOfRows != 0) {
10,077,638✔
429
    return true;
4,726,246✔
430
  }
431
  return false;
5,351,392✔
432
}
433

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

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