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

taosdata / TDengine / #4828

29 Oct 2025 11:10AM UTC coverage: 61.071% (-0.3%) from 61.383%
#4828

push

travis-ci

web-flow
Merge pull request #33419 from taosdata/3.0

3.0

155924 of 324872 branches covered (48.0%)

Branch coverage included in aggregate %.

207404 of 270051 relevant lines covered (76.8%)

243478715.98 hits per line

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

74.39
/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) {
1,753,531✔
34
  int32_t    code = 0;
1,753,531✔
35
  SShowMgmt *pMgmt = &pMnode->showMgmt;
1,753,531✔
36

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

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

56
static int32_t convertToRetrieveType(char *name, int32_t len) {
18,981,879✔
57
  int32_t type = -1;
18,981,879✔
58

59
  if (strncasecmp(name, TSDB_INS_TABLE_DNODES, len) == 0) {
18,981,879✔
60
    type = TSDB_MGMT_TABLE_DNODE;
2,695,826✔
61
  } else if (strncasecmp(name, TSDB_INS_TABLE_MNODES, len) == 0) {
16,286,053✔
62
    type = TSDB_MGMT_TABLE_MNODE;
1,363,513✔
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) {
14,922,540!
68
    type = TSDB_MGMT_TABLE_QNODE;
28,347✔
69
  } else if (strncasecmp(name, TSDB_INS_TABLE_SNODES, len) == 0) {
14,894,193✔
70
    type = TSDB_MGMT_TABLE_SNODE;
512,213✔
71
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES, len) == 0) {
14,381,980!
72
    type = TSDB_MGMT_TABLE_ANODE;
1,240✔
73
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES_FULL, len) == 0) {
14,380,740!
74
    type = TSDB_MGMT_TABLE_ANODE_FULL;
×
75
  } else if (strncasecmp(name, TSDB_INS_TABLE_BNODES, len) == 0) {
14,380,740!
76
    type = TSDB_MGMT_TABLE_BNODE;
371,339✔
77
  } else if (strncasecmp(name, TSDB_INS_TABLE_ARBGROUPS, len) == 0) {
14,009,401!
78
    type = TSDB_MGMT_TABLE_ARBGROUP;
×
79
  } else if (strncasecmp(name, TSDB_INS_TABLE_CLUSTER, len) == 0) {
14,009,401✔
80
    type = TSDB_MGMT_TABLE_CLUSTER;
12,608✔
81
  } else if (strncasecmp(name, TSDB_INS_TABLE_DATABASES, len) == 0) {
13,996,793!
82
    type = TSDB_MGMT_TABLE_DB;
1,683,183✔
83
  } else if (strncasecmp(name, TSDB_INS_TABLE_FUNCTIONS, len) == 0) {
12,313,610✔
84
    type = TSDB_MGMT_TABLE_FUNC;
37,158✔
85
  } else if (strncasecmp(name, TSDB_INS_TABLE_INDEXES, len) == 0) {
12,276,452!
86
    type = TSDB_MGMT_TABLE_INDEX;
47,897✔
87
  } else if (strncasecmp(name, TSDB_INS_TABLE_STABLES, len) == 0) {
12,228,555✔
88
    type = TSDB_MGMT_TABLE_STB;
939,184✔
89
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLES, len) == 0) {
11,289,371!
90
    type = TSDB_MGMT_TABLE_TABLE;
×
91
  } else if (strncasecmp(name, TSDB_INS_TABLE_TAGS, len) == 0) {
11,289,371!
92
    type = TSDB_MGMT_TABLE_TAG;
×
93
  } else if (strncasecmp(name, TSDB_INS_TABLE_COLS, len) == 0) {
11,289,371!
94
    type = TSDB_MGMT_TABLE_COL;
6,434,224✔
95
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLE_DISTRIBUTED, len) == 0) {
4,855,147!
96
    //    type = TSDB_MGMT_TABLE_DIST;
97
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS, len) == 0) {
4,855,147!
98
    type = TSDB_MGMT_TABLE_USER;
69,318✔
99
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS_FULL, len) == 0) {
4,785,829!
100
    type = TSDB_MGMT_TABLE_USER_FULL;
×
101
  } else if (strncasecmp(name, TSDB_INS_TABLE_LICENCES, len) == 0) {
4,785,829!
102
    type = TSDB_MGMT_TABLE_GRANTS;
17,183✔
103
  } else if (strncasecmp(name, TSDB_INS_TABLE_VGROUPS, len) == 0) {
4,768,646!
104
    type = TSDB_MGMT_TABLE_VGROUP;
691,062✔
105
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONSUMERS, len) == 0) {
4,077,584!
106
    type = TSDB_MGMT_TABLE_CONSUMERS;
54,714✔
107
  } else if (strncasecmp(name, TSDB_INS_TABLE_SUBSCRIPTIONS, len) == 0) {
4,022,870!
108
    type = TSDB_MGMT_TABLE_SUBSCRIPTIONS;
74,211✔
109
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_TRANS, len) == 0) {
3,948,659!
110
    type = TSDB_MGMT_TABLE_TRANS;
1,011,896✔
111
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_SMAS, len) == 0) {
2,936,763!
112
    type = TSDB_MGMT_TABLE_SMAS;
×
113
  } else if (strncasecmp(name, TSDB_INS_TABLE_CONFIGS, len) == 0) {
2,936,763!
114
    type = TSDB_MGMT_TABLE_CONFIGS;
8,680✔
115
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONNECTIONS, len) == 0) {
2,928,083✔
116
    type = TSDB_MGMT_TABLE_CONNS;
52,100✔
117
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_QUERIES, len) == 0) {
2,875,983✔
118
    type = TSDB_MGMT_TABLE_QUERIES;
22,378✔
119
  } else if (strncasecmp(name, TSDB_INS_TABLE_VNODES, len) == 0) {
2,853,605!
120
    type = TSDB_MGMT_TABLE_VNODES;
38,540✔
121
  } else if (strncasecmp(name, TSDB_INS_TABLE_TOPICS, len) == 0) {
2,815,065!
122
    type = TSDB_MGMT_TABLE_TOPICS;
89,615✔
123
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAMS, len) == 0) {
2,725,450✔
124
    type = TSDB_MGMT_TABLE_STREAMS;
834,701✔
125
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_APPS, len) == 0) {
1,890,749!
126
    type = TSDB_MGMT_TABLE_APPS;
19,844✔
127
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAM_TASKS, len) == 0) {
1,870,905✔
128
    type = TSDB_MGMT_TABLE_STREAM_TASKS;
639,090✔
129
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAM_RECALCULATES, len) == 0) {
1,231,815!
130
    type = TSDB_MGMT_TABLE_STREAM_RECALCULATES;
1,309✔
131
  } else if (strncasecmp(name, TSDB_INS_TABLE_USER_PRIVILEGES, len) == 0) {
1,230,506!
132
    type = TSDB_MGMT_TABLE_PRIVILEGES;
79,664✔
133
  } else if (strncasecmp(name, TSDB_INS_TABLE_VIEWS, len) == 0) {
1,150,842!
134
    type = TSDB_MGMT_TABLE_VIEWS;
91,250✔
135
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACTS, len) == 0) {
1,059,592!
136
    type = TSDB_MGMT_TABLE_COMPACT;
794,936✔
137
  } else if (strncasecmp(name, TSDB_INS_TABLE_SCANS, len) == 0) {
264,656!
138
    type = TSDB_MGMT_TABLE_SCAN;
37,924✔
139
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACT_DETAILS, len) == 0) {
226,732!
140
    type = TSDB_MGMT_TABLE_COMPACT_DETAIL;
28,992✔
141
  } else if (strncasecmp(name, TSDB_INS_TABLE_SCAN_DETAILS, len) == 0) {
197,740!
142
    type = TSDB_MGMT_TABLE_SCAN_DETAIL;
29,570✔
143
  } else if (strncasecmp(name, TSDB_INS_TABLE_SSMIGRATES, len) == 0) {
168,170!
144
    type = TSDB_MGMT_TABLE_SSMIGRATE;
×
145
  } else if (strncasecmp(name, TSDB_INS_TABLE_TRANSACTION_DETAILS, len) == 0) {
168,170!
146
    type = TSDB_MGMT_TABLE_TRANSACTION_DETAIL;
1,850✔
147
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_FULL, len) == 0) {
166,320!
148
    type = TSDB_MGMT_TABLE_GRANTS_FULL;
7,440✔
149
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_LOGS, len) == 0) {
158,880!
150
    type = TSDB_MGMT_TABLE_GRANTS_LOGS;
7,440✔
151
  } else if (strncasecmp(name, TSDB_INS_TABLE_MACHINES, len) == 0) {
151,440!
152
    type = TSDB_MGMT_TABLE_MACHINES;
8,682✔
153
  } else if (strncasecmp(name, TSDB_INS_TABLE_ENCRYPTIONS, len) == 0) {
142,758!
154
    type = TSDB_MGMT_TABLE_ENCRYPTIONS;
1,242✔
155
  } else if (strncasecmp(name, TSDB_INS_TABLE_TSMAS, len) == 0) {
141,516!
156
    type = TSDB_MGMT_TABLE_TSMAS;
×
157
  } else if (strncasecmp(name, TSDB_INS_DISK_USAGE, len) == 0) {
141,516!
158
    type = TSDB_MGMT_TABLE_USAGE;
×
159
  } else if (strncasecmp(name, TSDB_INS_TABLE_FILESETS, len) == 0) {
141,516!
160
    type = TSDB_MGMT_TABLE_FILESETS;
×
161
  } else if (strncasecmp(name, TSDB_INS_TABLE_VC_COLS, len) == 0) {
141,516!
162
    type = TSDB_MGMT_TABLE_VC_COL;
×
163
  } else if (strncasecmp(name, TSDB_INS_TABLE_MOUNTS, len) == 0) {
141,516!
164
    type = TSDB_MGMT_TABLE_MOUNT;
45,882✔
165
  } else if (strncasecmp(name, TSDB_INS_TABLE_RSMAS, len) == 0) {
95,634!
166
    type = TSDB_MGMT_TABLE_RSMA;
24,840✔
167
  } else if (strncasecmp(name, TSDB_INS_TABLE_RETENTIONS, len) == 0) {
70,794!
168
    type = TSDB_MGMT_TABLE_RETENTION;
67,068✔
169
  } else if (strncasecmp(name, TSDB_INS_TABLE_RETENTION_DETAILS, len) == 0) {
3,726!
170
    type = TSDB_MGMT_TABLE_RETENTION_DETAIL;
3,726✔
171
  } else {
172
    mError("invalid show name:%s len:%d", name, len);
×
173
  }
174

175
  return type;
18,981,879✔
176
}
177

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

181
  int64_t showId = atomic_add_fetch_64(&pMgmt->showId, 1);
18,981,879✔
182
  if (showId == 0) atomic_add_fetch_64(&pMgmt->showId, 1);
18,981,879!
183

184
  int32_t size = sizeof(SShowObj);
18,981,879✔
185

186
  SShowObj showObj = {0};
18,981,879✔
187

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

194
  int32_t   keepTime = tsShellActivityTimer * 6 * 1000;
18,981,879✔
195
  SShowObj *pShow = taosCachePut(pMgmt->cache, &showId, sizeof(int64_t), &showObj, size, keepTime);
18,981,879✔
196
  if (pShow == NULL) {
18,980,884!
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);
18,980,884✔
203
  return pShow;
18,980,884✔
204
}
205

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

210
  ShowFreeIterFp freeFp = pMgmt->freeIterFps[pShow->type];
18,981,879✔
211
  if (freeFp != NULL) {
18,981,879✔
212
    if (pShow->pIter != NULL) {
18,010,670!
213
      mTrace("show:0x%" PRIx64 ", is destroying, data:%p, pIter:%p, ", pShow->id, pShow, pShow->pIter);
×
214

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

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

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

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

227
  SShowObj *pShow = taosCacheAcquireByKey(pMgmt->cache, &showId, sizeof(showId));
245,203✔
228
  if (pShow == NULL) {
245,203!
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);
245,203!
234
  return pShow;
245,203✔
235
}
236

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

241
  // A bug in tcache.c
242
  forceRemove = 0;
19,220,248✔
243

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

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

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

264
  if (retrieveReq.showId == 0) {
19,227,082✔
265
    STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, retrieveReq.tb, strlen(retrieveReq.tb));
18,981,879✔
266
    if (pMeta == NULL) {
18,981,879✔
267
      pMeta = taosHashGet(pMnode->perfsMeta, retrieveReq.tb, strlen(retrieveReq.tb));
1,160,932✔
268
      if (pMeta == NULL) {
1,160,932!
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);
18,981,879✔
276
    if (pShow == NULL) {
18,981,879!
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;
18,981,879✔
283
    pShow->numOfColumns = pShow->pMeta->numOfColumns;
18,981,879✔
284
  } else {
285
    pShow = mndAcquireShowObj(pMnode, retrieveReq.showId);
245,203✔
286
    if (pShow == NULL) {
245,203!
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
19,227,082✔
294
    rowsToRead = SHOW_COLS_STEP_SIZE;
6,434,224✔
295
  } else if (pShow->type == TSDB_MGMT_TABLE_PRIVILEGES) {
12,792,858✔
296
    rowsToRead = SHOW_PRIVILEGES_STEP_SIZE;
79,664✔
297
  }
298
  ShowRetrieveFp retrieveFp = pMgmt->retrieveFps[pShow->type];
19,227,082✔
299
  if (retrieveFp == NULL) {
19,226,087!
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);
19,226,087✔
307
  if (retrieveReq.user[0] != 0) {
19,227,082✔
308
    (void)memcpy(pReq->info.conn.user, retrieveReq.user, TSDB_USER_LEN);
19,222,682✔
309
  } else {
310
    (void)memcpy(pReq->info.conn.user, TSDB_DEFAULT_USER, strlen(TSDB_DEFAULT_USER) + 1);
4,400!
311
  }
312
  code = -1;
19,227,082✔
313
  if (retrieveReq.db[0] &&
24,855,067✔
314
      (code = mndCheckShowPrivilege(pMnode, pReq->info.conn.user, pShow->type, retrieveReq.db)) != 0) {
5,627,985✔
315
    TAOS_RETURN(code);
6,834✔
316
  }
317
  if (pShow->type == TSDB_MGMT_TABLE_USER_FULL) {
19,220,248!
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;
19,220,248✔
326

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

333
  for (int32_t i = 0; i < numOfCols; ++i) {
254,098,257✔
334
    SColumnInfoData idata = {0};
234,878,009✔
335

336
    SSchema *p = &pShow->pMeta->pSchemas[i];
234,878,009✔
337

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

344
  TAOS_CHECK_RETURN(blockDataEnsureCapacity(pBlock, rowsToRead));
19,220,248!
345

346
  if (mndCheckRetrieveFinished(pShow)) {
19,220,248!
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);
19,220,248✔
351
    if (rowsRead < 0) {
19,220,248✔
352
      code = rowsRead;
7,432✔
353
      mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
7,432!
354
      mndReleaseShowObj(pShow, true);
7,432✔
355
      blockDataDestroy(pBlock);
7,432✔
356
      TAOS_RETURN(code);
7,432✔
357
    }
358

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

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

367
  SRetrieveMetaTableRsp *pRsp = rpcMallocCont(size);
19,212,816✔
368
  if (pRsp == NULL) {
19,212,816!
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);
19,212,816✔
375

376
  if (rowsRead > 0) {
19,212,816✔
377
    char    *pStart = pRsp->data;
18,324,734✔
378
    SSchema *ps = pShow->pMeta->pSchemas;
18,324,734✔
379

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

383
    for (int32_t i = 0; i < pShow->pMeta->numOfColumns; ++i) {
244,643,017✔
384
      SSysTableSchema *pSchema = (SSysTableSchema *)pStart;
226,318,283✔
385
      pSchema->bytes = htonl(ps[i].bytes);
226,318,283✔
386
      pSchema->colId = htons(ps[i].colId);
226,318,283✔
387
      pSchema->type = ps[i].type;
226,318,283✔
388

389
      pStart += sizeof(SSysTableSchema);
226,318,283✔
390
    }
391

392
    int32_t len = blockEncode(pBlock, pStart, dataEncodeBufSize, pShow->pMeta->numOfColumns);
18,324,734✔
393
    if (len < 0) {
18,324,734!
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);
19,212,816✔
401
  pRsp->precision = TSDB_TIME_PRECISION_MILLI;  // millisecond time precision
19,212,142✔
402
  pReq->info.rsp = pRsp;
19,212,142✔
403
  pReq->info.rspLen = size;
19,212,142✔
404

405
  if (rowsRead == 0 || mndCheckRetrieveFinished(pShow)) {
19,212,816✔
406
    pRsp->completed = 1;
18,968,287✔
407
    mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
18,967,613✔
408
    mndReleaseShowObj(pShow, true);
18,968,287✔
409
  } else {
410
    mDebug("show:0x%" PRIx64 ", retrieve not completed yet", pShow->id);
245,203✔
411
    mndReleaseShowObj(pShow, false);
245,203✔
412
  }
413

414
  blockDataDestroy(pBlock);
19,212,816✔
415
  return TSDB_CODE_SUCCESS;
19,212,816✔
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) {
37,544,308✔
426
  if (pShow->pIter == NULL && pShow->numOfRows != 0) {
37,544,308✔
427
    return true;
18,078,857✔
428
  }
429
  return false;
19,465,451✔
430
}
431

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

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