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

taosdata / TDengine / #4897

25 Dec 2025 10:17AM UTC coverage: 65.717% (-0.2%) from 65.929%
#4897

push

travis-ci

web-flow
fix: [6622889291] Fix invalid rowSize. (#34043)

186011 of 283047 relevant lines covered (65.72%)

113853896.64 hits per line

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

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

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

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

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

59
  if (strncasecmp(name, TSDB_INS_TABLE_DNODES, len) == 0) {
5,093,156✔
60
    type = TSDB_MGMT_TABLE_DNODE;
901,827✔
61
  } else if (strncasecmp(name, TSDB_INS_TABLE_MNODES, len) == 0) {
4,191,329✔
62
    type = TSDB_MGMT_TABLE_MNODE;
383,808✔
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,807,521✔
68
    type = TSDB_MGMT_TABLE_QNODE;
8,042✔
69
  } else if (strncasecmp(name, TSDB_INS_TABLE_SNODES, len) == 0) {
3,799,479✔
70
    type = TSDB_MGMT_TABLE_SNODE;
166,059✔
71
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES, len) == 0) {
3,633,420✔
72
    type = TSDB_MGMT_TABLE_ANODE;
355✔
73
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES_FULL, len) == 0) {
3,633,065✔
74
    type = TSDB_MGMT_TABLE_ANODE_FULL;
×
75
  } else if (strncasecmp(name, TSDB_INS_TABLE_BNODES, len) == 0) {
3,633,065✔
76
    type = TSDB_MGMT_TABLE_BNODE;
124,080✔
77
  } else if (strncasecmp(name, TSDB_INS_TABLE_ARBGROUPS, len) == 0) {
3,508,985✔
78
    type = TSDB_MGMT_TABLE_ARBGROUP;
×
79
  } else if (strncasecmp(name, TSDB_INS_TABLE_CLUSTER, len) == 0) {
3,508,985✔
80
    type = TSDB_MGMT_TABLE_CLUSTER;
3,582✔
81
  } else if (strncasecmp(name, TSDB_INS_TABLE_DATABASES, len) == 0) {
3,505,403✔
82
    type = TSDB_MGMT_TABLE_DB;
616,574✔
83
  } else if (strncasecmp(name, TSDB_INS_TABLE_FUNCTIONS, len) == 0) {
2,888,829✔
84
    type = TSDB_MGMT_TABLE_FUNC;
12,558✔
85
  } else if (strncasecmp(name, TSDB_INS_TABLE_INDEXES, len) == 0) {
2,876,271✔
86
    type = TSDB_MGMT_TABLE_INDEX;
14,338✔
87
  } else if (strncasecmp(name, TSDB_INS_TABLE_STABLES, len) == 0) {
2,861,933✔
88
    type = TSDB_MGMT_TABLE_STB;
343,561✔
89
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLES, len) == 0) {
2,518,372✔
90
    type = TSDB_MGMT_TABLE_TABLE;
×
91
  } else if (strncasecmp(name, TSDB_INS_TABLE_TAGS, len) == 0) {
2,518,372✔
92
    type = TSDB_MGMT_TABLE_TAG;
×
93
  } else if (strncasecmp(name, TSDB_INS_TABLE_COLS, len) == 0) {
2,518,372✔
94
    type = TSDB_MGMT_TABLE_COL;
531,833✔
95
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLE_DISTRIBUTED, len) == 0) {
1,986,539✔
96
    //    type = TSDB_MGMT_TABLE_DIST;
97
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS, len) == 0) {
1,986,539✔
98
    type = TSDB_MGMT_TABLE_USER;
20,118✔
99
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS_FULL, len) == 0) {
1,966,421✔
100
    type = TSDB_MGMT_TABLE_USER_FULL;
×
101
  } else if (strncasecmp(name, TSDB_INS_TABLE_TOKENS, len) == 0) {
1,966,421✔
102
    type = TSDB_MGMT_TABLE_TOKEN;
×
103
  } else if (strncasecmp(name, TSDB_INS_TABLE_LICENCES, len) == 0) {
1,966,421✔
104
    type = TSDB_MGMT_TABLE_GRANTS;
4,227✔
105
  } else if (strncasecmp(name, TSDB_INS_TABLE_VGROUPS, len) == 0) {
1,962,194✔
106
    type = TSDB_MGMT_TABLE_VGROUP;
264,245✔
107
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONSUMERS, len) == 0) {
1,697,949✔
108
    type = TSDB_MGMT_TABLE_CONSUMERS;
9,551✔
109
  } else if (strncasecmp(name, TSDB_INS_TABLE_SUBSCRIPTIONS, len) == 0) {
1,688,398✔
110
    type = TSDB_MGMT_TABLE_SUBSCRIPTIONS;
10,296✔
111
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_TRANS, len) == 0) {
1,678,102✔
112
    type = TSDB_MGMT_TABLE_TRANS;
454,454✔
113
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_SMAS, len) == 0) {
1,223,648✔
114
    type = TSDB_MGMT_TABLE_SMAS;
×
115
  } else if (strncasecmp(name, TSDB_INS_TABLE_CONFIGS, len) == 0) {
1,223,648✔
116
    type = TSDB_MGMT_TABLE_CONFIGS;
2,485✔
117
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONNECTIONS, len) == 0) {
1,221,163✔
118
    type = TSDB_MGMT_TABLE_CONNS;
17,036✔
119
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_QUERIES, len) == 0) {
1,204,127✔
120
    type = TSDB_MGMT_TABLE_QUERIES;
6,448✔
121
  } else if (strncasecmp(name, TSDB_INS_TABLE_VNODES, len) == 0) {
1,197,679✔
122
    type = TSDB_MGMT_TABLE_VNODES;
1,581✔
123
  } else if (strncasecmp(name, TSDB_INS_TABLE_TOPICS, len) == 0) {
1,196,098✔
124
    type = TSDB_MGMT_TABLE_TOPICS;
25,957✔
125
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAMS, len) == 0) {
1,170,141✔
126
    type = TSDB_MGMT_TABLE_STREAMS;
303,557✔
127
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_APPS, len) == 0) {
866,584✔
128
    type = TSDB_MGMT_TABLE_APPS;
6,060✔
129
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_INSTANCES, len) == 0) {
860,524✔
130
    type = TSDB_MGMT_TABLE_INSTANCE;
×
131
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAM_TASKS, len) == 0) {
860,524✔
132
    type = TSDB_MGMT_TABLE_STREAM_TASKS;
289,373✔
133
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAM_RECALCULATES, len) == 0) {
571,151✔
134
    type = TSDB_MGMT_TABLE_STREAM_RECALCULATES;
434✔
135
  } else if (strncasecmp(name, TSDB_INS_TABLE_USER_PRIVILEGES, len) == 0) {
570,717✔
136
    type = TSDB_MGMT_TABLE_PRIVILEGES;
19,830✔
137
  } else if (strncasecmp(name, TSDB_INS_TABLE_VIEWS, len) == 0) {
550,887✔
138
    type = TSDB_MGMT_TABLE_VIEWS;
32,596✔
139
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACTS, len) == 0) {
518,291✔
140
    type = TSDB_MGMT_TABLE_COMPACT;
386,781✔
141
  } else if (strncasecmp(name, TSDB_INS_TABLE_ENCRYPT_ALGORITHMS, len) == 0) {
131,510✔
142
    type = TSDB_MGMT_TABLE_ENCRYPT_ALGORITHMS;
×
143
  } else if (strncasecmp(name, TSDB_INS_TABLE_SCANS, len) == 0) {
131,510✔
144
    type = TSDB_MGMT_TABLE_SCAN;
4,907✔
145
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACT_DETAILS, len) == 0) {
126,603✔
146
    type = TSDB_MGMT_TABLE_COMPACT_DETAIL;
33,671✔
147
  } else if (strncasecmp(name, TSDB_INS_TABLE_SCAN_DETAILS, len) == 0) {
92,932✔
148
    type = TSDB_MGMT_TABLE_SCAN_DETAIL;
3,798✔
149
  } else if (strncasecmp(name, TSDB_INS_TABLE_SSMIGRATES, len) == 0) {
89,134✔
150
    type = TSDB_MGMT_TABLE_SSMIGRATE;
×
151
  } else if (strncasecmp(name, TSDB_INS_TABLE_TRANSACTION_DETAILS, len) == 0) {
89,134✔
152
    type = TSDB_MGMT_TABLE_TRANSACTION_DETAIL;
1,031✔
153
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_FULL, len) == 0) {
88,103✔
154
    type = TSDB_MGMT_TABLE_GRANTS_FULL;
2,243✔
155
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_LOGS, len) == 0) {
85,860✔
156
    type = TSDB_MGMT_TABLE_GRANTS_LOGS;
2,243✔
157
  } else if (strncasecmp(name, TSDB_INS_TABLE_MACHINES, len) == 0) {
83,617✔
158
    type = TSDB_MGMT_TABLE_MACHINES;
2,606✔
159
  } else if (strncasecmp(name, TSDB_INS_TABLE_ENCRYPTIONS, len) == 0) {
81,011✔
160
    type = TSDB_MGMT_TABLE_ENCRYPTIONS;
814✔
161
  } else if (strncasecmp(name, TSDB_INS_TABLE_TSMAS, len) == 0) {
80,197✔
162
    type = TSDB_MGMT_TABLE_TSMAS;
×
163
  } else if (strncasecmp(name, TSDB_INS_DISK_USAGE, len) == 0) {
80,197✔
164
    type = TSDB_MGMT_TABLE_USAGE;
×
165
  } else if (strncasecmp(name, TSDB_INS_TABLE_FILESETS, len) == 0) {
80,197✔
166
    type = TSDB_MGMT_TABLE_FILESETS;
×
167
  } else if (strncasecmp(name, TSDB_INS_TABLE_VC_COLS, len) == 0) {
80,197✔
168
    type = TSDB_MGMT_TABLE_VC_COL;
×
169
  } else if (strncasecmp(name, TSDB_INS_TABLE_MOUNTS, len) == 0) {
80,197✔
170
    type = TSDB_MGMT_TABLE_MOUNT;
15,499✔
171
  } else if (strncasecmp(name, TSDB_INS_TABLE_RSMAS, len) == 0) {
64,698✔
172
    type = TSDB_MGMT_TABLE_RSMA;
17,358✔
173
  } else if (strncasecmp(name, TSDB_INS_TABLE_RETENTIONS, len) == 0) {
47,340✔
174
    type = TSDB_MGMT_TABLE_RETENTION;
44,973✔
175
  } else if (strncasecmp(name, TSDB_INS_TABLE_RETENTION_DETAILS, len) == 0) {
2,367✔
176
    type = TSDB_MGMT_TABLE_RETENTION_DETAIL;
2,367✔
177
  } else {
178
    mError("invalid show name:%s len:%d", name, len);
×
179
  }
180

181
  return type;
5,093,156✔
182
}
183

184
static SShowObj *mndCreateShowObj(SMnode *pMnode, SRetrieveTableReq *pReq) {
5,093,156✔
185
  SShowMgmt *pMgmt = &pMnode->showMgmt;
5,093,156✔
186

187
  int64_t showId = atomic_add_fetch_64(&pMgmt->showId, 1);
5,093,156✔
188
  if (showId == 0) atomic_add_fetch_64(&pMgmt->showId, 1);
5,093,156✔
189

190
  int32_t size = sizeof(SShowObj);
5,093,156✔
191

192
  SShowObj showObj = {0};
5,093,156✔
193

194
  showObj.id = showId;
5,093,156✔
195
  showObj.pMnode = pMnode;
5,093,156✔
196
  showObj.type = convertToRetrieveType(pReq->tb, tListLen(pReq->tb));
5,093,156✔
197
  (void)memcpy(showObj.db, pReq->db, TSDB_DB_FNAME_LEN);
5,093,156✔
198
  tstrncpy(showObj.filterTb, pReq->filterTb, TSDB_TABLE_NAME_LEN);
5,093,156✔
199

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

208
  mTrace("show:0x%" PRIx64 ", is created, data:%p", showId, pShow);
5,093,156✔
209
  return pShow;
5,093,156✔
210
}
211

212
static void mndFreeShowObj(SShowObj *pShow) {
5,093,156✔
213
  SMnode    *pMnode = pShow->pMnode;
5,093,156✔
214
  SShowMgmt *pMgmt = &pMnode->showMgmt;
5,093,156✔
215

216
  ShowFreeIterFp freeFp = pMgmt->freeIterFps[pShow->type];
5,093,156✔
217
  if (freeFp != NULL) {
5,093,156✔
218
    if (pShow->pIter != NULL) {
4,650,305✔
219
      mTrace("show:0x%" PRIx64 ", is destroying, data:%p, pIter:%p, ", pShow->id, pShow, pShow->pIter);
113✔
220

221
      (*freeFp)(pMnode, pShow->pIter);
113✔
222

223
      pShow->pIter = NULL;
113✔
224
    }
225
  }
226

227
  mTrace("show:0x%" PRIx64 ", is destroyed, data:%p", pShow->id, pShow);
5,093,156✔
228
}
5,093,156✔
229

230
static SShowObj *mndAcquireShowObj(SMnode *pMnode, int64_t showId) {
141,448✔
231
  SShowMgmt *pMgmt = &pMnode->showMgmt;
141,448✔
232

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

239
  mTrace("show:0x%" PRIx64 ", acquired from cache, data:%p", pShow->id, pShow);
141,448✔
240
  return pShow;
141,448✔
241
}
242

243
static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove) {
5,232,492✔
244
  if (pShow == NULL) return;
5,232,492✔
245
  mTrace("show:0x%" PRIx64 ", released from cache, data:%p force:%d", pShow->id, pShow, forceRemove);
5,232,492✔
246

247
  // A bug in tcache.c
248
  forceRemove = 0;
5,232,492✔
249

250
  SMnode    *pMnode = pShow->pMnode;
5,232,492✔
251
  SShowMgmt *pMgmt = &pMnode->showMgmt;
5,232,492✔
252
  taosCacheRelease(pMgmt->cache, (void **)(&pShow), forceRemove);
5,232,492✔
253
}
254

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

267
  mDebug("process to retrieve systable req db:%s, tb:%s, compactId:%" PRId64, retrieveReq.db, retrieveReq.tb,
5,234,604✔
268
         retrieveReq.compactId);
269

270
  if (retrieveReq.showId == 0) {
5,234,604✔
271
    STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, retrieveReq.tb, strlen(retrieveReq.tb));
5,093,156✔
272
    if (pMeta == NULL) {
5,093,156✔
273
      pMeta = taosHashGet(pMnode->perfsMeta, retrieveReq.tb, strlen(retrieveReq.tb));
493,549✔
274
      if (pMeta == NULL) {
493,549✔
275
        code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
×
276
        mError("failed to process show-retrieve req:%p since %s", pShow, tstrerror(code));
×
277
        TAOS_RETURN(code);
×
278
      }
279
    }
280

281
    pShow = mndCreateShowObj(pMnode, &retrieveReq);
5,093,156✔
282
    if (pShow == NULL) {
5,093,156✔
283
      code = terrno;
×
284
      mError("failed to process show-meta req since %s", tstrerror(code));
×
285
      TAOS_RETURN(code);
×
286
    }
287

288
    pShow->pMeta = pMeta;
5,093,156✔
289
    pShow->numOfColumns = pShow->pMeta->numOfColumns;
5,093,156✔
290
  } else {
291
    pShow = mndAcquireShowObj(pMnode, retrieveReq.showId);
141,448✔
292
    if (pShow == NULL) {
141,448✔
293
      code = TSDB_CODE_MND_INVALID_SHOWOBJ;
×
294
      mError("failed to process show-retrieve req:%p since %s", pShow, tstrerror(code));
×
295
      TAOS_RETURN(code);
×
296
    }
297
  }
298

299
  if (pShow->type == TSDB_MGMT_TABLE_COL) {  // expend capacity for ins_columns
5,234,604✔
300
    rowsToRead = SHOW_COLS_STEP_SIZE;
534,545✔
301
  } else if (pShow->type == TSDB_MGMT_TABLE_PRIVILEGES) {
4,700,059✔
302
    rowsToRead = SHOW_PRIVILEGES_STEP_SIZE;
19,830✔
303
  }
304
  ShowRetrieveFp retrieveFp = pMgmt->retrieveFps[pShow->type];
5,234,604✔
305
  if (retrieveFp == NULL) {
5,234,604✔
306
    mndReleaseShowObj(pShow, false);
×
307
    code = TSDB_CODE_MSG_NOT_PROCESSED;
×
308
    mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, tstrerror(code));
×
309
    TAOS_RETURN(code);
×
310
  }
311

312
  mDebug("show:0x%" PRIx64 ", start retrieve data, type:%d", pShow->id, pShow->type);
5,234,604✔
313
  if (retrieveReq.user[0] != 0) {
5,234,604✔
314
    (void)memcpy(pReq->info.conn.user, retrieveReq.user, TSDB_USER_LEN);
5,234,604✔
315
  } else {
316
    (void)memcpy(pReq->info.conn.user, TSDB_DEFAULT_USER, strlen(TSDB_DEFAULT_USER) + 1);
×
317
  }
318
  code = -1;
5,234,604✔
319
  if (retrieveReq.db[0] &&
7,252,254✔
320
      (code = mndCheckShowPrivilege(pMnode, RPC_MSG_USER(pReq), RPC_MSG_TOKEN(pReq), pShow->type, retrieveReq.db)) != 0) {
2,017,650✔
321
    TAOS_RETURN(code);
2,112✔
322
  }
323
  if (pShow->type == TSDB_MGMT_TABLE_USER_FULL) {
5,232,492✔
324
    if (strcmp(RPC_MSG_USER(pReq), "root") != 0) {
×
325
      mError("The operation is not permitted, user:%s, pShow->type:%d", RPC_MSG_USER(pReq), pShow->type);
×
326
      code = TSDB_CODE_MND_NO_RIGHTS;
×
327
      TAOS_RETURN(code);
×
328
    }
329
  }
330

331
  int32_t numOfCols = pShow->pMeta->numOfColumns;
5,232,492✔
332

333
  SSDataBlock *pBlock = NULL;
5,232,492✔
334
  code = createDataBlock(&pBlock);
5,232,492✔
335
  if (code) {
5,232,492✔
336
    TAOS_RETURN(code);
×
337
  }
338

339
  for (int32_t i = 0; i < numOfCols; ++i) {
73,408,385✔
340
    SColumnInfoData idata = {0};
68,175,893✔
341

342
    SSchema *p = &pShow->pMeta->pSchemas[i];
68,175,893✔
343

344
    idata.info.bytes = p->bytes;
68,175,893✔
345
    idata.info.type = p->type;
68,175,893✔
346
    idata.info.colId = p->colId;
68,175,893✔
347
    TAOS_CHECK_RETURN(blockDataAppendColInfo(pBlock, &idata));
68,175,893✔
348
  }
349

350
  TAOS_CHECK_RETURN(blockDataEnsureCapacity(pBlock, rowsToRead));
5,232,492✔
351

352
  if (mndCheckRetrieveFinished(pShow)) {
5,232,492✔
353
    mDebug("show:0x%" PRIx64 ", read finished, numOfRows:%d", pShow->id, pShow->numOfRows);
×
354
    rowsRead = 0;
×
355
  } else {
356
    rowsRead = (*retrieveFp)(pReq, pShow, pBlock, rowsToRead);
5,232,492✔
357
    if (rowsRead < 0) {
5,232,492✔
358
      code = rowsRead;
2,271✔
359
      mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
2,271✔
360
      mndReleaseShowObj(pShow, true);
2,271✔
361
      blockDataDestroy(pBlock);
2,271✔
362
      TAOS_RETURN(code);
2,271✔
363
    }
364

365
    pBlock->info.rows = rowsRead;
5,230,221✔
366
    mDebug("show:0x%" PRIx64 ", stop retrieve data, rowsRead:%d numOfRows:%d", pShow->id, rowsRead, pShow->numOfRows);
5,230,221✔
367
  }
368

369
  size_t dataEncodeBufSize = blockGetEncodeSize(pBlock);
5,230,221✔
370
  size = sizeof(SRetrieveMetaTableRsp) + sizeof(int32_t) + sizeof(SSysTableSchema) * pShow->pMeta->numOfColumns +
5,230,221✔
371
         dataEncodeBufSize;
372

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

380
  pRsp->handle = htobe64(pShow->id);
5,230,221✔
381

382
  if (rowsRead > 0) {
5,230,221✔
383
    char    *pStart = pRsp->data;
4,891,973✔
384
    SSchema *ps = pShow->pMeta->pSchemas;
4,891,973✔
385

386
    *(int32_t *)pStart = htonl(pShow->pMeta->numOfColumns);
4,891,973✔
387
    pStart += sizeof(int32_t);  // number of columns
4,891,973✔
388

389
    for (int32_t i = 0; i < pShow->pMeta->numOfColumns; ++i) {
69,898,692✔
390
      SSysTableSchema *pSchema = (SSysTableSchema *)pStart;
65,006,719✔
391
      pSchema->bytes = htonl(ps[i].bytes);
65,006,719✔
392
      pSchema->colId = htons(ps[i].colId);
65,006,719✔
393
      pSchema->type = ps[i].type;
65,006,719✔
394

395
      pStart += sizeof(SSysTableSchema);
65,006,719✔
396
    }
397

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

406
  pRsp->numOfRows = htonl(rowsRead);
5,230,221✔
407
  pRsp->precision = TSDB_TIME_PRECISION_MILLI;  // millisecond time precision
5,230,221✔
408
  pReq->info.rsp = pRsp;
5,230,221✔
409
  pReq->info.rspLen = size;
5,230,221✔
410

411
  if (rowsRead == 0 || mndCheckRetrieveFinished(pShow)) {
5,230,221✔
412
    pRsp->completed = 1;
5,088,660✔
413
    mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
5,088,660✔
414
    mndReleaseShowObj(pShow, true);
5,088,660✔
415
  } else {
416
    mDebug("show:0x%" PRIx64 ", retrieve not completed yet", pShow->id);
141,561✔
417
    mndReleaseShowObj(pShow, false);
141,561✔
418
  }
419

420
  blockDataDestroy(pBlock);
5,230,221✔
421
  return TSDB_CODE_SUCCESS;
5,230,221✔
422
_exit:
×
423
  mndReleaseShowObj(pShow, false);
×
424
  blockDataDestroy(pBlock);
×
425
  if (pRsp) {
×
426
    rpcFreeCont(pRsp);
×
427
  }
428
  return code;
×
429
}
430

431
static bool mndCheckRetrieveFinished(SShowObj *pShow) {
10,124,465✔
432
  if (pShow->pIter == NULL && pShow->numOfRows != 0) {
10,124,465✔
433
    return true;
4,750,412✔
434
  }
435
  return false;
5,374,053✔
436
}
437

438
void mndAddShowRetrieveHandle(SMnode *pMnode, EShowType showType, ShowRetrieveFp fp) {
25,640,700✔
439
  SShowMgmt *pMgmt = &pMnode->showMgmt;
25,640,700✔
440
  pMgmt->retrieveFps[showType] = fp;
25,640,700✔
441
}
25,640,700✔
442

443
void mndAddShowFreeIterHandle(SMnode *pMnode, EShowType showType, ShowFreeIterFp fp) {
21,025,374✔
444
  SShowMgmt *pMgmt = &pMnode->showMgmt;
21,025,374✔
445
  pMgmt->freeIterFps[showType] = fp;
21,025,374✔
446
}
21,025,374✔
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