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

taosdata / TDengine / #4872

04 Dec 2025 01:55AM UTC coverage: 64.678% (+0.02%) from 64.654%
#4872

push

travis-ci

guanshengliang
Merge branch '3.0' into cover/3.0

880 of 2219 new or added lines in 36 files covered. (39.66%)

6146 existing lines in 122 files now uncovered.

159679 of 246882 relevant lines covered (64.68%)

110947965.82 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,355✔
34
  int32_t    code = 0;
490,355✔
35
  SShowMgmt *pMgmt = &pMnode->showMgmt;
490,355✔
36

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

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

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

59
  if (strncasecmp(name, TSDB_INS_TABLE_DNODES, len) == 0) {
5,299,800✔
60
    type = TSDB_MGMT_TABLE_DNODE;
876,284✔
61
  } else if (strncasecmp(name, TSDB_INS_TABLE_MNODES, len) == 0) {
4,423,516✔
62
    type = TSDB_MGMT_TABLE_MNODE;
358,907✔
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,064,609✔
68
    type = TSDB_MGMT_TABLE_QNODE;
7,928✔
69
  } else if (strncasecmp(name, TSDB_INS_TABLE_SNODES, len) == 0) {
4,056,681✔
70
    type = TSDB_MGMT_TABLE_SNODE;
171,966✔
71
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES, len) == 0) {
3,884,715✔
72
    type = TSDB_MGMT_TABLE_ANODE;
350✔
73
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES_FULL, len) == 0) {
3,884,365✔
74
    type = TSDB_MGMT_TABLE_ANODE_FULL;
×
75
  } else if (strncasecmp(name, TSDB_INS_TABLE_BNODES, len) == 0) {
3,884,365✔
76
    type = TSDB_MGMT_TABLE_BNODE;
121,788✔
77
  } else if (strncasecmp(name, TSDB_INS_TABLE_ARBGROUPS, len) == 0) {
3,762,577✔
78
    type = TSDB_MGMT_TABLE_ARBGROUP;
×
79
  } else if (strncasecmp(name, TSDB_INS_TABLE_CLUSTER, len) == 0) {
3,762,577✔
80
    type = TSDB_MGMT_TABLE_CLUSTER;
3,532✔
81
  } else if (strncasecmp(name, TSDB_INS_TABLE_DATABASES, len) == 0) {
3,759,045✔
82
    type = TSDB_MGMT_TABLE_DB;
618,973✔
83
  } else if (strncasecmp(name, TSDB_INS_TABLE_FUNCTIONS, len) == 0) {
3,140,072✔
84
    type = TSDB_MGMT_TABLE_FUNC;
12,426✔
85
  } else if (strncasecmp(name, TSDB_INS_TABLE_INDEXES, len) == 0) {
3,127,646✔
86
    type = TSDB_MGMT_TABLE_INDEX;
14,154✔
87
  } else if (strncasecmp(name, TSDB_INS_TABLE_STABLES, len) == 0) {
3,113,492✔
88
    type = TSDB_MGMT_TABLE_STB;
337,926✔
89
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLES, len) == 0) {
2,775,566✔
90
    type = TSDB_MGMT_TABLE_TABLE;
×
91
  } else if (strncasecmp(name, TSDB_INS_TABLE_TAGS, len) == 0) {
2,775,566✔
92
    type = TSDB_MGMT_TABLE_TAG;
×
93
  } else if (strncasecmp(name, TSDB_INS_TABLE_COLS, len) == 0) {
2,775,566✔
94
    type = TSDB_MGMT_TABLE_COL;
523,913✔
95
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLE_DISTRIBUTED, len) == 0) {
2,251,653✔
96
    //    type = TSDB_MGMT_TABLE_DIST;
97
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS, len) == 0) {
2,251,653✔
98
    type = TSDB_MGMT_TABLE_USER;
20,160✔
99
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS_FULL, len) == 0) {
2,231,493✔
100
    type = TSDB_MGMT_TABLE_USER_FULL;
×
101
  } else if (strncasecmp(name, TSDB_INS_TABLE_LICENCES, len) == 0) {
2,231,493✔
102
    type = TSDB_MGMT_TABLE_GRANTS;
4,172✔
103
  } else if (strncasecmp(name, TSDB_INS_TABLE_VGROUPS, len) == 0) {
2,227,321✔
104
    type = TSDB_MGMT_TABLE_VGROUP;
297,261✔
105
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONSUMERS, len) == 0) {
1,930,060✔
106
    type = TSDB_MGMT_TABLE_CONSUMERS;
9,557✔
107
  } else if (strncasecmp(name, TSDB_INS_TABLE_SUBSCRIPTIONS, len) == 0) {
1,920,503✔
108
    type = TSDB_MGMT_TABLE_SUBSCRIPTIONS;
10,019✔
109
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_TRANS, len) == 0) {
1,910,484✔
110
    type = TSDB_MGMT_TABLE_TRANS;
658,149✔
111
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_SMAS, len) == 0) {
1,252,335✔
112
    type = TSDB_MGMT_TABLE_SMAS;
×
113
  } else if (strncasecmp(name, TSDB_INS_TABLE_CONFIGS, len) == 0) {
1,252,335✔
114
    type = TSDB_MGMT_TABLE_CONFIGS;
2,450✔
115
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONNECTIONS, len) == 0) {
1,249,885✔
116
    type = TSDB_MGMT_TABLE_CONNS;
16,806✔
117
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_QUERIES, len) == 0) {
1,233,079✔
118
    type = TSDB_MGMT_TABLE_QUERIES;
6,422✔
119
  } else if (strncasecmp(name, TSDB_INS_TABLE_VNODES, len) == 0) {
1,226,657✔
120
    type = TSDB_MGMT_TABLE_VNODES;
1,627✔
121
  } else if (strncasecmp(name, TSDB_INS_TABLE_TOPICS, len) == 0) {
1,225,030✔
122
    type = TSDB_MGMT_TABLE_TOPICS;
25,695✔
123
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAMS, len) == 0) {
1,199,335✔
124
    type = TSDB_MGMT_TABLE_STREAMS;
314,072✔
125
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_APPS, len) == 0) {
885,263✔
126
    type = TSDB_MGMT_TABLE_APPS;
5,974✔
127
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_INSTANCES, len) == 0) {
879,289✔
NEW
128
    type = TSDB_MGMT_TABLE_INSTANCE;
×
129
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAM_TASKS, len) == 0) {
879,289✔
130
    type = TSDB_MGMT_TABLE_STREAM_TASKS;
250,113✔
131
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAM_RECALCULATES, len) == 0) {
629,176✔
132
    type = TSDB_MGMT_TABLE_STREAM_RECALCULATES;
428✔
133
  } else if (strncasecmp(name, TSDB_INS_TABLE_USER_PRIVILEGES, len) == 0) {
628,748✔
134
    type = TSDB_MGMT_TABLE_PRIVILEGES;
26,189✔
135
  } else if (strncasecmp(name, TSDB_INS_TABLE_VIEWS, len) == 0) {
602,559✔
136
    type = TSDB_MGMT_TABLE_VIEWS;
32,188✔
137
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACTS, len) == 0) {
570,371✔
138
    type = TSDB_MGMT_TABLE_COMPACT;
380,699✔
139
  } else if (strncasecmp(name, TSDB_INS_TABLE_SCANS, len) == 0) {
189,672✔
140
    type = TSDB_MGMT_TABLE_SCAN;
4,674✔
141
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACT_DETAILS, len) == 0) {
184,998✔
142
    type = TSDB_MGMT_TABLE_COMPACT_DETAIL;
33,798✔
143
  } else if (strncasecmp(name, TSDB_INS_TABLE_SCAN_DETAILS, len) == 0) {
151,200✔
144
    type = TSDB_MGMT_TABLE_SCAN_DETAIL;
3,648✔
145
  } else if (strncasecmp(name, TSDB_INS_TABLE_SSMIGRATES, len) == 0) {
147,552✔
UNCOV
146
    type = TSDB_MGMT_TABLE_SSMIGRATE;
×
147
  } else if (strncasecmp(name, TSDB_INS_TABLE_TRANSACTION_DETAILS, len) == 0) {
147,552✔
148
    type = TSDB_MGMT_TABLE_TRANSACTION_DETAIL;
1,017✔
149
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_FULL, len) == 0) {
146,535✔
150
    type = TSDB_MGMT_TABLE_GRANTS_FULL;
2,210✔
151
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_LOGS, len) == 0) {
144,325✔
152
    type = TSDB_MGMT_TABLE_GRANTS_LOGS;
2,210✔
153
  } else if (strncasecmp(name, TSDB_INS_TABLE_MACHINES, len) == 0) {
142,115✔
154
    type = TSDB_MGMT_TABLE_MACHINES;
2,568✔
155
  } else if (strncasecmp(name, TSDB_INS_TABLE_ENCRYPTIONS, len) == 0) {
139,547✔
156
    type = TSDB_MGMT_TABLE_ENCRYPTIONS;
796✔
157
  } else if (strncasecmp(name, TSDB_INS_TABLE_TSMAS, len) == 0) {
138,751✔
UNCOV
158
    type = TSDB_MGMT_TABLE_TSMAS;
×
159
  } else if (strncasecmp(name, TSDB_INS_DISK_USAGE, len) == 0) {
138,751✔
160
    type = TSDB_MGMT_TABLE_USAGE;
×
161
  } else if (strncasecmp(name, TSDB_INS_TABLE_FILESETS, len) == 0) {
138,751✔
162
    type = TSDB_MGMT_TABLE_FILESETS;
×
163
  } else if (strncasecmp(name, TSDB_INS_TABLE_VC_COLS, len) == 0) {
138,751✔
164
    type = TSDB_MGMT_TABLE_VC_COL;
×
165
  } else if (strncasecmp(name, TSDB_INS_TABLE_MOUNTS, len) == 0) {
138,751✔
166
    type = TSDB_MGMT_TABLE_MOUNT;
15,311✔
167
  } else if (strncasecmp(name, TSDB_INS_TABLE_RSMAS, len) == 0) {
123,440✔
168
    type = TSDB_MGMT_TABLE_RSMA;
33,946✔
169
  } else if (strncasecmp(name, TSDB_INS_TABLE_RETENTIONS, len) == 0) {
89,494✔
170
    type = TSDB_MGMT_TABLE_RETENTION;
84,865✔
171
  } else if (strncasecmp(name, TSDB_INS_TABLE_RETENTION_DETAILS, len) == 0) {
4,629✔
172
    type = TSDB_MGMT_TABLE_RETENTION_DETAIL;
4,629✔
173
  } else {
UNCOV
174
    mError("invalid show name:%s len:%d", name, len);
×
175
  }
176

177
  return type;
5,299,800✔
178
}
179

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

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

186
  int32_t size = sizeof(SShowObj);
5,299,800✔
187

188
  SShowObj showObj = {0};
5,299,800✔
189

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

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

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

212
  ShowFreeIterFp freeFp = pMgmt->freeIterFps[pShow->type];
5,299,800✔
213
  if (freeFp != NULL) {
5,299,800✔
214
    if (pShow->pIter != NULL) {
4,861,316✔
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,299,800✔
224
}
5,299,800✔
225

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

229
  SShowObj *pShow = taosCacheAcquireByKey(pMgmt->cache, &showId, sizeof(showId));
119,101✔
230
  if (pShow == NULL) {
119,101✔
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);
119,101✔
236
  return pShow;
119,101✔
237
}
238

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

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

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

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

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

266
  if (retrieveReq.showId == 0) {
5,418,901✔
267
    STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, retrieveReq.tb, strlen(retrieveReq.tb));
5,299,800✔
268
    if (pMeta == NULL) {
5,299,800✔
269
      pMeta = taosHashGet(pMnode->perfsMeta, retrieveReq.tb, strlen(retrieveReq.tb));
696,908✔
270
      if (pMeta == NULL) {
696,908✔
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,299,800✔
278
    if (pShow == NULL) {
5,299,800✔
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,299,800✔
285
    pShow->numOfColumns = pShow->pMeta->numOfColumns;
5,299,800✔
286
  } else {
287
    pShow = mndAcquireShowObj(pMnode, retrieveReq.showId);
119,101✔
288
    if (pShow == NULL) {
119,101✔
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,418,901✔
296
    rowsToRead = SHOW_COLS_STEP_SIZE;
526,553✔
297
  } else if (pShow->type == TSDB_MGMT_TABLE_PRIVILEGES) {
4,892,348✔
298
    rowsToRead = SHOW_PRIVILEGES_STEP_SIZE;
26,189✔
299
  }
300
  ShowRetrieveFp retrieveFp = pMgmt->retrieveFps[pShow->type];
5,418,901✔
301
  if (retrieveFp == NULL) {
5,418,901✔
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,418,901✔
309
  if (retrieveReq.user[0] != 0) {
5,418,901✔
310
    (void)memcpy(pReq->info.conn.user, retrieveReq.user, TSDB_USER_LEN);
5,418,901✔
311
  } else {
UNCOV
312
    (void)memcpy(pReq->info.conn.user, TSDB_DEFAULT_USER, strlen(TSDB_DEFAULT_USER) + 1);
×
313
  }
314
  code = -1;
5,418,901✔
315
  if (retrieveReq.db[0] &&
7,689,983✔
316
      (code = mndCheckShowPrivilege(pMnode, pReq->info.conn.user, pShow->type, retrieveReq.db)) != 0) {
2,271,082✔
317
    TAOS_RETURN(code);
2,090✔
318
  }
319
  if (pShow->type == TSDB_MGMT_TABLE_USER_FULL) {
5,416,811✔
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,416,811✔
328

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

335
  for (int32_t i = 0; i < numOfCols; ++i) {
74,592,386✔
336
    SColumnInfoData idata = {0};
69,175,575✔
337

338
    SSchema *p = &pShow->pMeta->pSchemas[i];
69,175,575✔
339

340
    idata.info.bytes = p->bytes;
69,175,378✔
341
    idata.info.type = p->type;
69,175,378✔
342
    idata.info.colId = p->colId;
69,175,575✔
343
    TAOS_CHECK_RETURN(blockDataAppendColInfo(pBlock, &idata));
69,175,575✔
344
  }
345

346
  TAOS_CHECK_RETURN(blockDataEnsureCapacity(pBlock, rowsToRead));
5,416,811✔
347

348
  if (mndCheckRetrieveFinished(pShow)) {
5,416,811✔
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,416,811✔
353
    if (rowsRead < 0) {
5,416,811✔
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,414,537✔
362
    mDebug("show:0x%" PRIx64 ", stop retrieve data, rowsRead:%d numOfRows:%d", pShow->id, rowsRead, pShow->numOfRows);
5,414,537✔
363
  }
364

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

369
  SRetrieveMetaTableRsp *pRsp = rpcMallocCont(size);
5,414,537✔
370
  if (pRsp == NULL) {
5,414,537✔
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,414,537✔
377

378
  if (rowsRead > 0) {
5,414,537✔
379
    char    *pStart = pRsp->data;
5,064,378✔
380
    SSchema *ps = pShow->pMeta->pSchemas;
5,064,378✔
381

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

385
    for (int32_t i = 0; i < pShow->pMeta->numOfColumns; ++i) {
70,993,703✔
386
      SSysTableSchema *pSchema = (SSysTableSchema *)pStart;
65,929,325✔
387
      pSchema->bytes = htonl(ps[i].bytes);
65,929,325✔
388
      pSchema->colId = htons(ps[i].colId);
65,929,325✔
389
      pSchema->type = ps[i].type;
65,929,325✔
390

391
      pStart += sizeof(SSysTableSchema);
65,929,325✔
392
    }
393

394
    int32_t len = blockEncode(pBlock, pStart, dataEncodeBufSize, pShow->pMeta->numOfColumns);
5,064,378✔
395
    if (len < 0) {
5,064,378✔
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,414,537✔
403
  pRsp->precision = TSDB_TIME_PRECISION_MILLI;  // millisecond time precision
5,414,537✔
404
  pReq->info.rsp = pRsp;
5,414,537✔
405
  pReq->info.rspLen = size;
5,414,537✔
406

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

416
  blockDataDestroy(pBlock);
5,414,537✔
417
  return TSDB_CODE_SUCCESS;
5,414,537✔
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,481,189✔
428
  if (pShow->pIter == NULL && pShow->numOfRows != 0) {
10,481,189✔
429
    return true;
4,945,167✔
430
  }
431
  return false;
5,536,022✔
432
}
433

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

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