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

taosdata / TDengine / #4788

14 Oct 2025 11:21AM UTC coverage: 60.992% (-2.3%) from 63.264%
#4788

push

travis-ci

web-flow
Merge 7ca9b50f9 into 19574fe21

154868 of 324306 branches covered (47.75%)

Branch coverage included in aggregate %.

207304 of 269498 relevant lines covered (76.92%)

125773493.22 hits per line

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

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

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

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

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

59
  if (strncasecmp(name, TSDB_INS_TABLE_DNODES, len) == 0) {
4,966,906✔
60
    type = TSDB_MGMT_TABLE_DNODE;
1,019,670✔
61
  } else if (strncasecmp(name, TSDB_INS_TABLE_MNODES, len) == 0) {
3,947,236✔
62
    type = TSDB_MGMT_TABLE_MNODE;
427,415✔
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,519,821!
68
    type = TSDB_MGMT_TABLE_QNODE;
10,697✔
69
  } else if (strncasecmp(name, TSDB_INS_TABLE_SNODES, len) == 0) {
3,509,124✔
70
    type = TSDB_MGMT_TABLE_SNODE;
217,951✔
71
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES, len) == 0) {
3,291,173!
72
    type = TSDB_MGMT_TABLE_ANODE;
504✔
73
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES_FULL, len) == 0) {
3,290,669!
74
    type = TSDB_MGMT_TABLE_ANODE_FULL;
×
75
  } else if (strncasecmp(name, TSDB_INS_TABLE_BNODES, len) == 0) {
3,290,669!
76
    type = TSDB_MGMT_TABLE_BNODE;
164,978✔
77
  } else if (strncasecmp(name, TSDB_INS_TABLE_ARBGROUPS, len) == 0) {
3,125,691!
78
    type = TSDB_MGMT_TABLE_ARBGROUP;
9,084✔
79
  } else if (strncasecmp(name, TSDB_INS_TABLE_CLUSTER, len) == 0) {
3,116,607✔
80
    type = TSDB_MGMT_TABLE_CLUSTER;
3,829✔
81
  } else if (strncasecmp(name, TSDB_INS_TABLE_DATABASES, len) == 0) {
3,112,778!
82
    type = TSDB_MGMT_TABLE_DB;
674,035✔
83
  } else if (strncasecmp(name, TSDB_INS_TABLE_FUNCTIONS, len) == 0) {
2,438,743✔
84
    type = TSDB_MGMT_TABLE_FUNC;
11,306✔
85
  } else if (strncasecmp(name, TSDB_INS_TABLE_INDEXES, len) == 0) {
2,427,437!
86
    type = TSDB_MGMT_TABLE_INDEX;
15,609✔
87
  } else if (strncasecmp(name, TSDB_INS_TABLE_STABLES, len) == 0) {
2,411,828✔
88
    type = TSDB_MGMT_TABLE_STB;
386,564✔
89
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLES, len) == 0) {
2,025,264!
90
    type = TSDB_MGMT_TABLE_TABLE;
×
91
  } else if (strncasecmp(name, TSDB_INS_TABLE_TAGS, len) == 0) {
2,025,264!
92
    type = TSDB_MGMT_TABLE_TAG;
×
93
  } else if (strncasecmp(name, TSDB_INS_TABLE_COLS, len) == 0) {
2,025,264!
94
    type = TSDB_MGMT_TABLE_COL;
496,328✔
95
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLE_DISTRIBUTED, len) == 0) {
1,528,936!
96
    //    type = TSDB_MGMT_TABLE_DIST;
97
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS, len) == 0) {
1,528,936!
98
    type = TSDB_MGMT_TABLE_USER;
25,423✔
99
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS_FULL, len) == 0) {
1,503,513!
100
    type = TSDB_MGMT_TABLE_USER_FULL;
×
101
  } else if (strncasecmp(name, TSDB_INS_TABLE_LICENCES, len) == 0) {
1,503,513!
102
    type = TSDB_MGMT_TABLE_GRANTS;
4,385✔
103
  } else if (strncasecmp(name, TSDB_INS_TABLE_VGROUPS, len) == 0) {
1,499,128!
104
    type = TSDB_MGMT_TABLE_VGROUP;
291,431✔
105
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONSUMERS, len) == 0) {
1,207,697!
106
    type = TSDB_MGMT_TABLE_CONSUMERS;
11,680✔
107
  } else if (strncasecmp(name, TSDB_INS_TABLE_SUBSCRIPTIONS, len) == 0) {
1,196,017!
108
    type = TSDB_MGMT_TABLE_SUBSCRIPTIONS;
13,572✔
109
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_TRANS, len) == 0) {
1,182,445!
110
    type = TSDB_MGMT_TABLE_TRANS;
202,488✔
111
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_SMAS, len) == 0) {
979,957!
112
    type = TSDB_MGMT_TABLE_SMAS;
×
113
  } else if (strncasecmp(name, TSDB_INS_TABLE_CONFIGS, len) == 0) {
979,957!
114
    type = TSDB_MGMT_TABLE_CONFIGS;
3,528✔
115
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONNECTIONS, len) == 0) {
976,429✔
116
    type = TSDB_MGMT_TABLE_CONNS;
21,428✔
117
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_QUERIES, len) == 0) {
955,001✔
118
    type = TSDB_MGMT_TABLE_QUERIES;
8,403✔
119
  } else if (strncasecmp(name, TSDB_INS_TABLE_VNODES, len) == 0) {
946,598!
120
    type = TSDB_MGMT_TABLE_VNODES;
1,909✔
121
  } else if (strncasecmp(name, TSDB_INS_TABLE_TOPICS, len) == 0) {
944,689!
122
    type = TSDB_MGMT_TABLE_TOPICS;
35,165✔
123
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAMS, len) == 0) {
909,524✔
124
    type = TSDB_MGMT_TABLE_STREAMS;
355,232✔
125
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_APPS, len) == 0) {
554,292!
126
    type = TSDB_MGMT_TABLE_APPS;
7,314✔
127
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAM_TASKS, len) == 0) {
546,978✔
128
    type = TSDB_MGMT_TABLE_STREAM_TASKS;
242,774✔
129
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAM_RECALCULATES, len) == 0) {
304,204!
130
    type = TSDB_MGMT_TABLE_STREAM_RECALCULATES;
575✔
131
  } else if (strncasecmp(name, TSDB_INS_TABLE_USER_PRIVILEGES, len) == 0) {
303,629!
132
    type = TSDB_MGMT_TABLE_PRIVILEGES;
25,481✔
133
  } else if (strncasecmp(name, TSDB_INS_TABLE_VIEWS, len) == 0) {
278,148!
134
    type = TSDB_MGMT_TABLE_VIEWS;
34,119✔
135
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACTS, len) == 0) {
244,029!
136
    type = TSDB_MGMT_TABLE_COMPACT;
172,546✔
137
  } else if (strncasecmp(name, TSDB_INS_TABLE_SCANS, len) == 0) {
71,483!
138
    type = TSDB_MGMT_TABLE_SCAN;
4,316✔
139
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACT_DETAILS, len) == 0) {
67,167!
140
    type = TSDB_MGMT_TABLE_COMPACT_DETAIL;
4,667✔
141
  } else if (strncasecmp(name, TSDB_INS_TABLE_SCAN_DETAILS, len) == 0) {
62,500!
142
    type = TSDB_MGMT_TABLE_SCAN_DETAIL;
4,200✔
143
  } else if (strncasecmp(name, TSDB_INS_TABLE_SSMIGRATES, len) == 0) {
58,300!
144
    type = TSDB_MGMT_TABLE_SSMIGRATE;
×
145
  } else if (strncasecmp(name, TSDB_INS_TABLE_TRANSACTION_DETAILS, len) == 0) {
58,300!
146
    type = TSDB_MGMT_TABLE_TRANSACTION_DETAIL;
270✔
147
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_FULL, len) == 0) {
58,030!
148
    type = TSDB_MGMT_TABLE_GRANTS_FULL;
3,147✔
149
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_LOGS, len) == 0) {
54,883!
150
    type = TSDB_MGMT_TABLE_GRANTS_LOGS;
3,147✔
151
  } else if (strncasecmp(name, TSDB_INS_TABLE_MACHINES, len) == 0) {
51,736!
152
    type = TSDB_MGMT_TABLE_MACHINES;
3,556✔
153
  } else if (strncasecmp(name, TSDB_INS_TABLE_ENCRYPTIONS, len) == 0) {
48,180!
154
    type = TSDB_MGMT_TABLE_ENCRYPTIONS;
997✔
155
  } else if (strncasecmp(name, TSDB_INS_TABLE_TSMAS, len) == 0) {
47,183!
156
    type = TSDB_MGMT_TABLE_TSMAS;
×
157
  } else if (strncasecmp(name, TSDB_INS_DISK_USAGE, len) == 0) {
47,183!
158
    type = TSDB_MGMT_TABLE_USAGE;
×
159
  } else if (strncasecmp(name, TSDB_INS_TABLE_FILESETS, len) == 0) {
47,183!
160
    type = TSDB_MGMT_TABLE_FILESETS;
×
161
  } else if (strncasecmp(name, TSDB_INS_TABLE_VC_COLS, len) == 0) {
47,183!
162
    type = TSDB_MGMT_TABLE_VC_COL;
×
163
  } else if (strncasecmp(name, TSDB_INS_TABLE_MOUNTS, len) == 0) {
47,183!
164
    type = TSDB_MGMT_TABLE_MOUNT;
7,871✔
165
  } else if (strncasecmp(name, TSDB_INS_TABLE_RSMAS, len) == 0) {
39,312!
166
    type = TSDB_MGMT_TABLE_RSMA;
10,080✔
167
  } else if (strncasecmp(name, TSDB_INS_TABLE_RETENTIONS, len) == 0) {
29,232!
168
    type = TSDB_MGMT_TABLE_RETENTION;
27,720✔
169
  } else if (strncasecmp(name, TSDB_INS_TABLE_RETENTION_DETAILS, len) == 0) {
1,512!
170
    type = TSDB_MGMT_TABLE_RETENTION_DETAIL;
1,512✔
171
  } else {
172
    mError("invalid show name:%s len:%d", name, len);
×
173
  }
174

175
  return type;
4,966,906✔
176
}
177

178
static SShowObj *mndCreateShowObj(SMnode *pMnode, SRetrieveTableReq *pReq) {
4,966,906✔
179
  SShowMgmt *pMgmt = &pMnode->showMgmt;
4,966,906✔
180

181
  int64_t showId = atomic_add_fetch_64(&pMgmt->showId, 1);
4,966,906✔
182
  if (showId == 0) atomic_add_fetch_64(&pMgmt->showId, 1);
4,966,906!
183

184
  int32_t size = sizeof(SShowObj);
4,966,906✔
185

186
  SShowObj showObj = {0};
4,966,906✔
187

188
  showObj.id = showId;
4,966,906✔
189
  showObj.pMnode = pMnode;
4,966,906✔
190
  showObj.type = convertToRetrieveType(pReq->tb, tListLen(pReq->tb));
4,966,906✔
191
  (void)memcpy(showObj.db, pReq->db, TSDB_DB_FNAME_LEN);
4,966,906✔
192
  tstrncpy(showObj.filterTb, pReq->filterTb, TSDB_TABLE_NAME_LEN);
4,966,906!
193

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

202
  mTrace("show:0x%" PRIx64 ", is created, data:%p", showId, pShow);
4,966,906✔
203
  return pShow;
4,966,906✔
204
}
205

206
static void mndFreeShowObj(SShowObj *pShow) {
4,966,906✔
207
  SMnode    *pMnode = pShow->pMnode;
4,966,906✔
208
  SShowMgmt *pMgmt = &pMnode->showMgmt;
4,966,906✔
209

210
  ShowFreeIterFp freeFp = pMgmt->freeIterFps[pShow->type];
4,966,906✔
211
  if (freeFp != NULL) {
4,966,906✔
212
    if (pShow->pIter != NULL) {
4,765,823✔
213
      mTrace("show:0x%" PRIx64 ", is destroying, data:%p, pIter:%p, ", pShow->id, pShow, pShow->pIter);
123!
214

215
      (*freeFp)(pMnode, pShow->pIter);
123✔
216

217
      pShow->pIter = NULL;
123✔
218
    }
219
  }
220

221
  mTrace("show:0x%" PRIx64 ", is destroyed, data:%p", pShow->id, pShow);
4,966,906✔
222
}
4,966,906✔
223

224
static SShowObj *mndAcquireShowObj(SMnode *pMnode, int64_t showId) {
93,939✔
225
  SShowMgmt *pMgmt = &pMnode->showMgmt;
93,939✔
226

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

233
  mTrace("show:0x%" PRIx64 ", acquired from cache, data:%p", pShow->id, pShow);
93,939!
234
  return pShow;
93,939✔
235
}
236

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

241
  // A bug in tcache.c
242
  forceRemove = 0;
5,058,533✔
243

244
  SMnode    *pMnode = pShow->pMnode;
5,058,533✔
245
  SShowMgmt *pMgmt = &pMnode->showMgmt;
5,058,533✔
246
  taosCacheRelease(pMgmt->cache, (void **)(&pShow), forceRemove);
5,058,533✔
247
}
248

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

261
  mDebug("process to retrieve systable req db:%s, tb:%s, compactId:%" PRId64, retrieveReq.db, retrieveReq.tb,
5,060,845✔
262
         retrieveReq.compactId);
263

264
  if (retrieveReq.showId == 0) {
5,060,845✔
265
    STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, retrieveReq.tb, strlen(retrieveReq.tb));
4,966,906✔
266
    if (pMeta == NULL) {
4,966,906✔
267
      pMeta = taosHashGet(pMnode->perfsMeta, retrieveReq.tb, strlen(retrieveReq.tb));
251,313✔
268
      if (pMeta == NULL) {
251,313!
269
        code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
×
270
        mError("failed to process show-retrieve req:%p since %s", pShow, tstrerror(code));
×
271
        TAOS_RETURN(code);
×
272
      }
273
    }
274

275
    pShow = mndCreateShowObj(pMnode, &retrieveReq);
4,966,906✔
276
    if (pShow == NULL) {
4,966,906!
277
      code = terrno;
×
278
      mError("failed to process show-meta req since %s", tstrerror(code));
×
279
      TAOS_RETURN(code);
×
280
    }
281

282
    pShow->pMeta = pMeta;
4,966,906✔
283
    pShow->numOfColumns = pShow->pMeta->numOfColumns;
4,966,906✔
284
  } else {
285
    pShow = mndAcquireShowObj(pMnode, retrieveReq.showId);
93,939✔
286
    if (pShow == NULL) {
93,939!
287
      code = TSDB_CODE_MND_INVALID_SHOWOBJ;
×
288
      mError("failed to process show-retrieve req:%p since %s", pShow, tstrerror(code));
×
289
      TAOS_RETURN(code);
×
290
    }
291
  }
292

293
  if (pShow->type == TSDB_MGMT_TABLE_COL) {  // expend capacity for ins_columns
5,060,845✔
294
    rowsToRead = SHOW_COLS_STEP_SIZE;
499,280✔
295
  } else if (pShow->type == TSDB_MGMT_TABLE_PRIVILEGES) {
4,561,565✔
296
    rowsToRead = SHOW_PRIVILEGES_STEP_SIZE;
25,481✔
297
  }
298
  ShowRetrieveFp retrieveFp = pMgmt->retrieveFps[pShow->type];
5,060,845✔
299
  if (retrieveFp == NULL) {
5,060,845!
300
    mndReleaseShowObj(pShow, false);
×
301
    code = TSDB_CODE_MSG_NOT_PROCESSED;
×
302
    mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, tstrerror(code));
×
303
    TAOS_RETURN(code);
×
304
  }
305

306
  mDebug("show:0x%" PRIx64 ", start retrieve data, type:%d", pShow->id, pShow->type);
5,060,845✔
307
  if (retrieveReq.user[0] != 0) {
5,060,845✔
308
    (void)memcpy(pReq->info.conn.user, retrieveReq.user, TSDB_USER_LEN);
5,060,647✔
309
  } else {
310
    (void)memcpy(pReq->info.conn.user, TSDB_DEFAULT_USER, strlen(TSDB_DEFAULT_USER) + 1);
198!
311
  }
312
  code = -1;
5,060,845✔
313
  if (retrieveReq.db[0] &&
7,465,963✔
314
      (code = mndCheckShowPrivilege(pMnode, pReq->info.conn.user, pShow->type, retrieveReq.db)) != 0) {
2,405,118✔
315
    TAOS_RETURN(code);
2,312✔
316
  }
317
  if (pShow->type == TSDB_MGMT_TABLE_USER_FULL) {
5,058,533!
318
    if (strcmp(pReq->info.conn.user, "root") != 0) {
×
319
      mError("The operation is not permitted, user:%s, pShow->type:%d", pReq->info.conn.user, pShow->type);
×
320
      code = TSDB_CODE_MND_NO_RIGHTS;
×
321
      TAOS_RETURN(code);
×
322
    }
323
  }
324

325
  int32_t numOfCols = pShow->pMeta->numOfColumns;
5,058,533✔
326

327
  SSDataBlock *pBlock = NULL;
5,058,533✔
328
  code = createDataBlock(&pBlock);
5,058,533✔
329
  if (code) {
5,058,533!
330
    TAOS_RETURN(code);
×
331
  }
332

333
  for (int32_t i = 0; i < numOfCols; ++i) {
72,327,320✔
334
    SColumnInfoData idata = {0};
67,268,787✔
335

336
    SSchema *p = &pShow->pMeta->pSchemas[i];
67,268,787✔
337

338
    idata.info.bytes = p->bytes;
67,268,787✔
339
    idata.info.type = p->type;
67,268,787✔
340
    idata.info.colId = p->colId;
67,268,787✔
341
    TAOS_CHECK_RETURN(blockDataAppendColInfo(pBlock, &idata));
67,268,787!
342
  }
343

344
  TAOS_CHECK_RETURN(blockDataEnsureCapacity(pBlock, rowsToRead));
5,058,533!
345

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

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

363
  size_t dataEncodeBufSize = blockGetEncodeSize(pBlock);
5,057,020✔
364
  size = sizeof(SRetrieveMetaTableRsp) + sizeof(int32_t) + sizeof(SSysTableSchema) * pShow->pMeta->numOfColumns +
5,057,020✔
365
         dataEncodeBufSize;
366

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

374
  pRsp->handle = htobe64(pShow->id);
5,057,020✔
375

376
  if (rowsRead > 0) {
5,057,020✔
377
    char    *pStart = pRsp->data;
4,685,074✔
378
    SSchema *ps = pShow->pMeta->pSchemas;
4,685,074✔
379

380
    *(int32_t *)pStart = htonl(pShow->pMeta->numOfColumns);
4,685,074✔
381
    pStart += sizeof(int32_t);  // number of columns
4,685,074✔
382

383
    for (int32_t i = 0; i < pShow->pMeta->numOfColumns; ++i) {
68,324,211✔
384
      SSysTableSchema *pSchema = (SSysTableSchema *)pStart;
63,639,137✔
385
      pSchema->bytes = htonl(ps[i].bytes);
63,639,137✔
386
      pSchema->colId = htons(ps[i].colId);
63,639,137✔
387
      pSchema->type = ps[i].type;
63,639,137✔
388

389
      pStart += sizeof(SSysTableSchema);
63,639,137✔
390
    }
391

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

400
  pRsp->numOfRows = htonl(rowsRead);
5,057,020✔
401
  pRsp->precision = TSDB_TIME_PRECISION_MILLI;  // millisecond time precision
5,057,020✔
402
  pReq->info.rsp = pRsp;
5,057,020✔
403
  pReq->info.rspLen = size;
5,057,020✔
404

405
  if (rowsRead == 0 || mndCheckRetrieveFinished(pShow)) {
5,057,020✔
406
    pRsp->completed = 1;
4,962,958✔
407
    mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
4,962,958✔
408
    mndReleaseShowObj(pShow, true);
4,962,958✔
409
  } else {
410
    mDebug("show:0x%" PRIx64 ", retrieve not completed yet", pShow->id);
94,062✔
411
    mndReleaseShowObj(pShow, false);
94,062✔
412
  }
413

414
  blockDataDestroy(pBlock);
5,057,020✔
415
  return TSDB_CODE_SUCCESS;
5,057,020✔
416
_exit:
×
417
  mndReleaseShowObj(pShow, false);
×
418
  blockDataDestroy(pBlock);
×
419
  if (pRsp) {
×
420
    rpcFreeCont(pRsp);
×
421
  }
422
  return code;
×
423
}
424

425
static bool mndCheckRetrieveFinished(SShowObj *pShow) {
9,743,607✔
426
  if (pShow->pIter == NULL && pShow->numOfRows != 0) {
9,743,607✔
427
    return true;
4,591,012✔
428
  }
429
  return false;
5,152,595✔
430
}
431

432
void mndAddShowRetrieveHandle(SMnode *pMnode, EShowType showType, ShowRetrieveFp fp) {
25,890,937✔
433
  SShowMgmt *pMgmt = &pMnode->showMgmt;
25,890,937✔
434
  pMgmt->retrieveFps[showType] = fp;
25,890,937✔
435
}
25,890,937✔
436

437
void mndAddShowFreeIterHandle(SMnode *pMnode, EShowType showType, ShowFreeIterFp fp) {
22,034,840✔
438
  SShowMgmt *pMgmt = &pMnode->showMgmt;
22,034,840✔
439
  pMgmt->freeIterFps[showType] = fp;
22,034,840✔
440
}
22,034,840✔
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