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

taosdata / TDengine / #4899

27 Dec 2025 07:32AM UTC coverage: 65.534% (+0.5%) from 65.061%
#4899

push

travis-ci

web-flow
test: remove semaphore test (#34071)

189567 of 289265 relevant lines covered (65.53%)

114701701.06 hits per line

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

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

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

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

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

59
  if (strncasecmp(name, TSDB_INS_TABLE_DNODES, len) == 0) {
4,118,756✔
60
    type = TSDB_MGMT_TABLE_DNODE;
687,892✔
61
  } else if (strncasecmp(name, TSDB_INS_TABLE_MNODES, len) == 0) {
3,430,864✔
62
    type = TSDB_MGMT_TABLE_MNODE;
288,734✔
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,142,130✔
68
    type = TSDB_MGMT_TABLE_QNODE;
3,316✔
69
  } else if (strncasecmp(name, TSDB_INS_TABLE_SNODES, len) == 0) {
3,138,814✔
70
    type = TSDB_MGMT_TABLE_SNODE;
83,577✔
71
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES, len) == 0) {
3,055,237✔
72
    type = TSDB_MGMT_TABLE_ANODE;
151✔
73
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES_FULL, len) == 0) {
3,055,086✔
74
    type = TSDB_MGMT_TABLE_ANODE_FULL;
×
75
  } else if (strncasecmp(name, TSDB_INS_TABLE_BNODES, len) == 0) {
3,055,086✔
76
    type = TSDB_MGMT_TABLE_BNODE;
67,532✔
77
  } else if (strncasecmp(name, TSDB_INS_TABLE_ARBGROUPS, len) == 0) {
2,987,554✔
78
    type = TSDB_MGMT_TABLE_ARBGROUP;
×
79
  } else if (strncasecmp(name, TSDB_INS_TABLE_CLUSTER, len) == 0) {
2,987,554✔
80
    type = TSDB_MGMT_TABLE_CLUSTER;
1,538✔
81
  } else if (strncasecmp(name, TSDB_INS_TABLE_DATABASES, len) == 0) {
2,986,016✔
82
    type = TSDB_MGMT_TABLE_DB;
417,426✔
83
  } else if (strncasecmp(name, TSDB_INS_TABLE_FUNCTIONS, len) == 0) {
2,568,590✔
84
    type = TSDB_MGMT_TABLE_FUNC;
7,452✔
85
  } else if (strncasecmp(name, TSDB_INS_TABLE_INDEXES, len) == 0) {
2,561,138✔
86
    type = TSDB_MGMT_TABLE_INDEX;
6,355✔
87
  } else if (strncasecmp(name, TSDB_INS_TABLE_STABLES, len) == 0) {
2,554,783✔
88
    type = TSDB_MGMT_TABLE_STB;
241,089✔
89
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLES, len) == 0) {
2,313,694✔
90
    type = TSDB_MGMT_TABLE_TABLE;
×
91
  } else if (strncasecmp(name, TSDB_INS_TABLE_TAGS, len) == 0) {
2,313,694✔
92
    type = TSDB_MGMT_TABLE_TAG;
×
93
  } else if (strncasecmp(name, TSDB_INS_TABLE_COLS, len) == 0) {
2,313,694✔
94
    type = TSDB_MGMT_TABLE_COL;
839,763✔
95
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLE_DISTRIBUTED, len) == 0) {
1,473,931✔
96
    //    type = TSDB_MGMT_TABLE_DIST;
97
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS, len) == 0) {
1,473,931✔
98
    type = TSDB_MGMT_TABLE_USER;
8,081✔
99
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS_FULL, len) == 0) {
1,465,850✔
100
    type = TSDB_MGMT_TABLE_USER_FULL;
×
101
  } else if (strncasecmp(name, TSDB_INS_TABLE_TOKENS, len) == 0) {
1,465,850✔
102
    type = TSDB_MGMT_TABLE_TOKEN;
×
103
  } else if (strncasecmp(name, TSDB_INS_TABLE_LICENCES, len) == 0) {
1,465,850✔
104
    type = TSDB_MGMT_TABLE_GRANTS;
1,748✔
105
  } else if (strncasecmp(name, TSDB_INS_TABLE_VGROUPS, len) == 0) {
1,464,102✔
106
    type = TSDB_MGMT_TABLE_VGROUP;
235,017✔
107
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONSUMERS, len) == 0) {
1,229,085✔
108
    type = TSDB_MGMT_TABLE_CONSUMERS;
14,465✔
109
  } else if (strncasecmp(name, TSDB_INS_TABLE_SUBSCRIPTIONS, len) == 0) {
1,214,620✔
110
    type = TSDB_MGMT_TABLE_SUBSCRIPTIONS;
21,615✔
111
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_TRANS, len) == 0) {
1,193,005✔
112
    type = TSDB_MGMT_TABLE_TRANS;
329,851✔
113
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_SMAS, len) == 0) {
863,154✔
114
    type = TSDB_MGMT_TABLE_SMAS;
×
115
  } else if (strncasecmp(name, TSDB_INS_TABLE_CONFIGS, len) == 0) {
863,154✔
116
    type = TSDB_MGMT_TABLE_CONFIGS;
1,057✔
117
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONNECTIONS, len) == 0) {
862,097✔
118
    type = TSDB_MGMT_TABLE_CONNS;
11,454✔
119
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_QUERIES, len) == 0) {
850,643✔
120
    type = TSDB_MGMT_TABLE_QUERIES;
2,561✔
121
  } else if (strncasecmp(name, TSDB_INS_TABLE_VNODES, len) == 0) {
848,082✔
122
    type = TSDB_MGMT_TABLE_VNODES;
16,133✔
123
  } else if (strncasecmp(name, TSDB_INS_TABLE_TOPICS, len) == 0) {
831,949✔
124
    type = TSDB_MGMT_TABLE_TOPICS;
16,495✔
125
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAMS, len) == 0) {
815,454✔
126
    type = TSDB_MGMT_TABLE_STREAMS;
209,789✔
127
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_APPS, len) == 0) {
605,665✔
128
    type = TSDB_MGMT_TABLE_APPS;
2,590✔
129
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_INSTANCES, len) == 0) {
603,075✔
130
    type = TSDB_MGMT_TABLE_INSTANCE;
×
131
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAM_TASKS, len) == 0) {
603,075✔
132
    type = TSDB_MGMT_TABLE_STREAM_TASKS;
142,653✔
133
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAM_RECALCULATES, len) == 0) {
460,422✔
134
    type = TSDB_MGMT_TABLE_STREAM_RECALCULATES;
227✔
135
  } else if (strncasecmp(name, TSDB_INS_TABLE_USER_PRIVILEGES, len) == 0) {
460,195✔
136
    type = TSDB_MGMT_TABLE_PRIVILEGES;
10,484✔
137
  } else if (strncasecmp(name, TSDB_INS_TABLE_VIEWS, len) == 0) {
449,711✔
138
    type = TSDB_MGMT_TABLE_VIEWS;
24,184✔
139
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACTS, len) == 0) {
425,527✔
140
    type = TSDB_MGMT_TABLE_COMPACT;
322,739✔
141
  } else if (strncasecmp(name, TSDB_INS_TABLE_ENCRYPT_ALGORITHMS, len) == 0) {
102,788✔
142
    type = TSDB_MGMT_TABLE_ENCRYPT_ALGORITHMS;
×
143
  } else if (strncasecmp(name, TSDB_INS_TABLE_ENCRYPT_STATUS, len) == 0) {
102,788✔
144
    type = TSDB_MGMT_TABLE_ENCRYPT_STATUS;
×
145
  } else if (strncasecmp(name, TSDB_INS_TABLE_SCANS, len) == 0) {
102,788✔
146
    type = TSDB_MGMT_TABLE_SCAN;
1,890✔
147
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACT_DETAILS, len) == 0) {
100,898✔
148
    type = TSDB_MGMT_TABLE_COMPACT_DETAIL;
31,310✔
149
  } else if (strncasecmp(name, TSDB_INS_TABLE_SCAN_DETAILS, len) == 0) {
69,588✔
150
    type = TSDB_MGMT_TABLE_SCAN_DETAIL;
1,680✔
151
  } else if (strncasecmp(name, TSDB_INS_TABLE_SSMIGRATES, len) == 0) {
67,908✔
152
    type = TSDB_MGMT_TABLE_SSMIGRATE;
×
153
  } else if (strncasecmp(name, TSDB_INS_TABLE_TRANSACTION_DETAILS, len) == 0) {
67,908✔
154
    type = TSDB_MGMT_TABLE_TRANSACTION_DETAIL;
416✔
155
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_FULL, len) == 0) {
67,492✔
156
    type = TSDB_MGMT_TABLE_GRANTS_FULL;
906✔
157
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_LOGS, len) == 0) {
66,586✔
158
    type = TSDB_MGMT_TABLE_GRANTS_LOGS;
906✔
159
  } else if (strncasecmp(name, TSDB_INS_TABLE_MACHINES, len) == 0) {
65,680✔
160
    type = TSDB_MGMT_TABLE_MACHINES;
1,064✔
161
  } else if (strncasecmp(name, TSDB_INS_TABLE_ENCRYPTIONS, len) == 0) {
64,616✔
162
    type = TSDB_MGMT_TABLE_ENCRYPTIONS;
158✔
163
  } else if (strncasecmp(name, TSDB_INS_TABLE_TSMAS, len) == 0) {
64,458✔
164
    type = TSDB_MGMT_TABLE_TSMAS;
×
165
  } else if (strncasecmp(name, TSDB_INS_DISK_USAGE, len) == 0) {
64,458✔
166
    type = TSDB_MGMT_TABLE_USAGE;
×
167
  } else if (strncasecmp(name, TSDB_INS_TABLE_FILESETS, len) == 0) {
64,458✔
168
    type = TSDB_MGMT_TABLE_FILESETS;
×
169
  } else if (strncasecmp(name, TSDB_INS_TABLE_VC_COLS, len) == 0) {
64,458✔
170
    type = TSDB_MGMT_TABLE_VC_COL;
×
171
  } else if (strncasecmp(name, TSDB_INS_TABLE_MOUNTS, len) == 0) {
64,458✔
172
    type = TSDB_MGMT_TABLE_MOUNT;
5,611✔
173
  } else if (strncasecmp(name, TSDB_INS_TABLE_RSMAS, len) == 0) {
58,847✔
174
    type = TSDB_MGMT_TABLE_RSMA;
15,598✔
175
  } else if (strncasecmp(name, TSDB_INS_TABLE_RETENTIONS, len) == 0) {
43,249✔
176
    type = TSDB_MGMT_TABLE_RETENTION;
41,122✔
177
  } else if (strncasecmp(name, TSDB_INS_TABLE_RETENTION_DETAILS, len) == 0) {
2,127✔
178
    type = TSDB_MGMT_TABLE_RETENTION_DETAIL;
2,127✔
179
  } else {
180
    mError("invalid show name:%s len:%d", name, len);
×
181
  }
182

183
  return type;
4,118,756✔
184
}
185

186
static SShowObj *mndCreateShowObj(SMnode *pMnode, SRetrieveTableReq *pReq) {
4,118,756✔
187
  SShowMgmt *pMgmt = &pMnode->showMgmt;
4,118,756✔
188

189
  int64_t showId = atomic_add_fetch_64(&pMgmt->showId, 1);
4,118,756✔
190
  if (showId == 0) atomic_add_fetch_64(&pMgmt->showId, 1);
4,118,756✔
191

192
  int32_t size = sizeof(SShowObj);
4,118,756✔
193

194
  SShowObj showObj = {0};
4,118,756✔
195

196
  showObj.id = showId;
4,118,756✔
197
  showObj.pMnode = pMnode;
4,118,756✔
198
  showObj.type = convertToRetrieveType(pReq->tb, tListLen(pReq->tb));
4,118,756✔
199
  (void)memcpy(showObj.db, pReq->db, TSDB_DB_FNAME_LEN);
4,118,756✔
200
  tstrncpy(showObj.filterTb, pReq->filterTb, TSDB_TABLE_NAME_LEN);
4,118,756✔
201

202
  int32_t   keepTime = tsShellActivityTimer * 6 * 1000;
4,118,756✔
203
  SShowObj *pShow = taosCachePut(pMgmt->cache, &showId, sizeof(int64_t), &showObj, size, keepTime);
4,118,756✔
204
  if (pShow == NULL) {
4,118,756✔
205
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
206
    mError("show:0x%" PRIx64 ", failed to put into cache since %s", showId, terrstr());
×
207
    return NULL;
×
208
  }
209

210
  mTrace("show:0x%" PRIx64 ", is created, data:%p", showId, pShow);
4,118,756✔
211
  return pShow;
4,118,756✔
212
}
213

214
static void mndFreeShowObj(SShowObj *pShow) {
4,118,756✔
215
  SMnode    *pMnode = pShow->pMnode;
4,118,756✔
216
  SShowMgmt *pMgmt = &pMnode->showMgmt;
4,118,756✔
217

218
  ShowFreeIterFp freeFp = pMgmt->freeIterFps[pShow->type];
4,118,756✔
219
  if (freeFp != NULL) {
4,118,756✔
220
    if (pShow->pIter != NULL) {
3,736,979✔
221
      mTrace("show:0x%" PRIx64 ", is destroying, data:%p, pIter:%p, ", pShow->id, pShow, pShow->pIter);
×
222

223
      (*freeFp)(pMnode, pShow->pIter);
×
224

225
      pShow->pIter = NULL;
×
226
    }
227
  }
228

229
  mTrace("show:0x%" PRIx64 ", is destroyed, data:%p", pShow->id, pShow);
4,118,756✔
230
}
4,118,756✔
231

232
static SShowObj *mndAcquireShowObj(SMnode *pMnode, int64_t showId) {
76,942✔
233
  SShowMgmt *pMgmt = &pMnode->showMgmt;
76,942✔
234

235
  SShowObj *pShow = taosCacheAcquireByKey(pMgmt->cache, &showId, sizeof(showId));
76,942✔
236
  if (pShow == NULL) {
76,942✔
237
    mError("show:0x%" PRIx64 ", already destroyed", showId);
×
238
    return NULL;
×
239
  }
240

241
  mTrace("show:0x%" PRIx64 ", acquired from cache, data:%p", pShow->id, pShow);
76,942✔
242
  return pShow;
76,942✔
243
}
244

245
static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove) {
4,194,816✔
246
  if (pShow == NULL) return;
4,194,816✔
247
  mTrace("show:0x%" PRIx64 ", released from cache, data:%p force:%d", pShow->id, pShow, forceRemove);
4,194,816✔
248

249
  // A bug in tcache.c
250
  forceRemove = 0;
4,194,816✔
251

252
  SMnode    *pMnode = pShow->pMnode;
4,194,816✔
253
  SShowMgmt *pMgmt = &pMnode->showMgmt;
4,194,816✔
254
  taosCacheRelease(pMgmt->cache, (void **)(&pShow), forceRemove);
4,194,816✔
255
}
256

257
static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) {
4,195,698✔
258
  int32_t    code = 0;
4,195,698✔
259
  SMnode    *pMnode = pReq->info.node;
4,195,698✔
260
  SShowMgmt *pMgmt = &pMnode->showMgmt;
4,195,698✔
261
  SShowObj  *pShow = NULL;
4,195,225✔
262
  int32_t    rowsToRead = SHOW_STEP_SIZE;
4,195,225✔
263
  int32_t    size = 0;
4,195,225✔
264
  int32_t    rowsRead = 0;
4,195,225✔
265
  mDebug("mndProcessRetrieveSysTableReq start");
4,195,225✔
266
  SRetrieveTableReq retrieveReq = {0};
4,195,698✔
267
  TAOS_CHECK_RETURN(tDeserializeSRetrieveTableReq(pReq->pCont, pReq->contLen, &retrieveReq));
4,195,698✔
268

269
  mDebug("process to retrieve systable req db:%s, tb:%s, compactId:%" PRId64, retrieveReq.db, retrieveReq.tb,
4,195,698✔
270
         retrieveReq.compactId);
271

272
  if (retrieveReq.showId == 0) {
4,195,698✔
273
    STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, retrieveReq.tb, strlen(retrieveReq.tb));
4,118,756✔
274
    if (pMeta == NULL) {
4,118,756✔
275
      pMeta = taosHashGet(pMnode->perfsMeta, retrieveReq.tb, strlen(retrieveReq.tb));
360,921✔
276
      if (pMeta == NULL) {
360,921✔
277
        code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
×
278
        mError("failed to process show-retrieve req:%p since %s", pShow, tstrerror(code));
×
279
        TAOS_RETURN(code);
×
280
      }
281
    }
282

283
    pShow = mndCreateShowObj(pMnode, &retrieveReq);
4,118,756✔
284
    if (pShow == NULL) {
4,118,756✔
285
      code = terrno;
×
286
      mError("failed to process show-meta req since %s", tstrerror(code));
×
287
      TAOS_RETURN(code);
×
288
    }
289

290
    pShow->pMeta = pMeta;
4,118,756✔
291
    pShow->numOfColumns = pShow->pMeta->numOfColumns;
4,118,756✔
292
  } else {
293
    pShow = mndAcquireShowObj(pMnode, retrieveReq.showId);
76,942✔
294
    if (pShow == NULL) {
76,942✔
295
      code = TSDB_CODE_MND_INVALID_SHOWOBJ;
×
296
      mError("failed to process show-retrieve req:%p since %s", pShow, tstrerror(code));
×
297
      TAOS_RETURN(code);
×
298
    }
299
  }
300

301
  if (pShow->type == TSDB_MGMT_TABLE_COL) {  // expend capacity for ins_columns
4,195,698✔
302
    rowsToRead = SHOW_COLS_STEP_SIZE;
839,763✔
303
  } else if (pShow->type == TSDB_MGMT_TABLE_PRIVILEGES) {
3,355,935✔
304
    rowsToRead = SHOW_PRIVILEGES_STEP_SIZE;
10,484✔
305
  }
306
  ShowRetrieveFp retrieveFp = pMgmt->retrieveFps[pShow->type];
4,195,698✔
307
  if (retrieveFp == NULL) {
4,195,698✔
308
    mndReleaseShowObj(pShow, false);
×
309
    code = TSDB_CODE_MSG_NOT_PROCESSED;
×
310
    mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, tstrerror(code));
×
311
    TAOS_RETURN(code);
×
312
  }
313

314
  mDebug("show:0x%" PRIx64 ", start retrieve data, type:%d", pShow->id, pShow->type);
4,195,698✔
315
  if (retrieveReq.user[0] != 0) {
4,195,698✔
316
    (void)memcpy(pReq->info.conn.user, retrieveReq.user, TSDB_USER_LEN);
4,195,698✔
317
  } else {
318
    (void)memcpy(pReq->info.conn.user, TSDB_DEFAULT_USER, strlen(TSDB_DEFAULT_USER) + 1);
×
319
  }
320
  code = -1;
4,195,698✔
321
  if (retrieveReq.db[0] &&
5,739,067✔
322
      (code = mndCheckShowPrivilege(pMnode, RPC_MSG_USER(pReq), RPC_MSG_TOKEN(pReq), pShow->type, retrieveReq.db)) != 0) {
1,543,369✔
323
    TAOS_RETURN(code);
882✔
324
  }
325
  if (pShow->type == TSDB_MGMT_TABLE_USER_FULL) {
4,194,816✔
326
    if (strcmp(RPC_MSG_USER(pReq), "root") != 0) {
×
327
      mError("The operation is not permitted, user:%s, pShow->type:%d", RPC_MSG_USER(pReq), pShow->type);
×
328
      code = TSDB_CODE_MND_NO_RIGHTS;
×
329
      TAOS_RETURN(code);
×
330
    }
331
  }
332

333
  int32_t numOfCols = pShow->pMeta->numOfColumns;
4,194,816✔
334

335
  SSDataBlock *pBlock = NULL;
4,194,816✔
336
  code = createDataBlock(&pBlock);
4,194,816✔
337
  if (code) {
4,194,816✔
338
    TAOS_RETURN(code);
×
339
  }
340

341
  for (int32_t i = 0; i < numOfCols; ++i) {
57,422,047✔
342
    SColumnInfoData idata = {0};
53,227,231✔
343

344
    SSchema *p = &pShow->pMeta->pSchemas[i];
53,227,231✔
345

346
    idata.info.bytes = p->bytes;
53,227,231✔
347
    idata.info.type = p->type;
53,227,231✔
348
    idata.info.colId = p->colId;
53,227,231✔
349
    TAOS_CHECK_RETURN(blockDataAppendColInfo(pBlock, &idata));
53,227,231✔
350
  }
351

352
  TAOS_CHECK_RETURN(blockDataEnsureCapacity(pBlock, rowsToRead));
4,194,816✔
353

354
  if (mndCheckRetrieveFinished(pShow)) {
4,194,816✔
355
    mDebug("show:0x%" PRIx64 ", read finished, numOfRows:%d", pShow->id, pShow->numOfRows);
×
356
    rowsRead = 0;
×
357
  } else {
358
    rowsRead = (*retrieveFp)(pReq, pShow, pBlock, rowsToRead);
4,194,816✔
359
    if (rowsRead < 0) {
4,193,870✔
360
      code = rowsRead;
1,588✔
361
      mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
1,588✔
362
      mndReleaseShowObj(pShow, true);
1,588✔
363
      blockDataDestroy(pBlock);
1,588✔
364
      TAOS_RETURN(code);
1,588✔
365
    }
366

367
    pBlock->info.rows = rowsRead;
4,192,282✔
368
    mDebug("show:0x%" PRIx64 ", stop retrieve data, rowsRead:%d numOfRows:%d", pShow->id, rowsRead, pShow->numOfRows);
4,193,228✔
369
  }
370

371
  size_t dataEncodeBufSize = blockGetEncodeSize(pBlock);
4,193,228✔
372
  size = sizeof(SRetrieveMetaTableRsp) + sizeof(int32_t) + sizeof(SSysTableSchema) * pShow->pMeta->numOfColumns +
4,193,228✔
373
         dataEncodeBufSize;
374

375
  SRetrieveMetaTableRsp *pRsp = rpcMallocCont(size);
4,193,228✔
376
  if (pRsp == NULL) {
4,193,228✔
377
    mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, tstrerror(terrno));
×
378
    code = terrno;
×
379
    goto _exit;
×
380
  }
381

382
  pRsp->handle = htobe64(pShow->id);
4,193,228✔
383

384
  if (rowsRead > 0) {
4,193,228✔
385
    char    *pStart = pRsp->data;
3,949,731✔
386
    SSchema *ps = pShow->pMeta->pSchemas;
3,949,731✔
387

388
    *(int32_t *)pStart = htonl(pShow->pMeta->numOfColumns);
3,949,731✔
389
    pStart += sizeof(int32_t);  // number of columns
3,949,731✔
390

391
    for (int32_t i = 0; i < pShow->pMeta->numOfColumns; ++i) {
54,901,118✔
392
      SSysTableSchema *pSchema = (SSysTableSchema *)pStart;
50,951,387✔
393
      pSchema->bytes = htonl(ps[i].bytes);
50,951,387✔
394
      pSchema->colId = htons(ps[i].colId);
50,951,728✔
395
      pSchema->type = ps[i].type;
50,951,728✔
396

397
      pStart += sizeof(SSysTableSchema);
50,951,387✔
398
    }
399

400
    int32_t len = blockEncode(pBlock, pStart, dataEncodeBufSize, pShow->pMeta->numOfColumns);
3,949,731✔
401
    if (len < 0) {
3,949,390✔
402
      mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, tstrerror(terrno));
×
403
      code = terrno;
×
404
      return code;
×
405
    }
406
  }
407

408
  pRsp->numOfRows = htonl(rowsRead);
4,192,887✔
409
  pRsp->precision = TSDB_TIME_PRECISION_MILLI;  // millisecond time precision
4,193,228✔
410
  pReq->info.rsp = pRsp;
4,193,228✔
411
  pReq->info.rspLen = size;
4,193,228✔
412

413
  if (rowsRead == 0 || mndCheckRetrieveFinished(pShow)) {
4,192,887✔
414
    pRsp->completed = 1;
4,115,945✔
415
    mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
4,116,286✔
416
    mndReleaseShowObj(pShow, true);
4,116,286✔
417
  } else {
418
    mDebug("show:0x%" PRIx64 ", retrieve not completed yet", pShow->id);
76,942✔
419
    mndReleaseShowObj(pShow, false);
76,942✔
420
  }
421

422
  blockDataDestroy(pBlock);
4,193,228✔
423
  return TSDB_CODE_SUCCESS;
4,193,228✔
424
_exit:
×
425
  mndReleaseShowObj(pShow, false);
×
426
  blockDataDestroy(pBlock);
×
427
  if (pRsp) {
×
428
    rpcFreeCont(pRsp);
×
429
  }
430
  return code;
×
431
}
432

433
static bool mndCheckRetrieveFinished(SShowObj *pShow) {
8,144,547✔
434
  if (pShow->pIter == NULL && pShow->numOfRows != 0) {
8,144,547✔
435
    return true;
3,872,448✔
436
  }
437
  return false;
4,271,758✔
438
}
439

440
void mndAddShowRetrieveHandle(SMnode *pMnode, EShowType showType, ShowRetrieveFp fp) {
19,625,463✔
441
  SShowMgmt *pMgmt = &pMnode->showMgmt;
19,625,463✔
442
  pMgmt->retrieveFps[showType] = fp;
19,625,463✔
443
}
19,625,463✔
444

445
void mndAddShowFreeIterHandle(SMnode *pMnode, EShowType showType, ShowFreeIterFp fp) {
15,777,333✔
446
  SShowMgmt *pMgmt = &pMnode->showMgmt;
15,777,333✔
447
  pMgmt->freeIterFps[showType] = fp;
15,777,333✔
448
}
15,777,333✔
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