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

taosdata / TDengine / #4875

09 Dec 2025 01:22AM UTC coverage: 64.472% (-0.2%) from 64.623%
#4875

push

travis-ci

guanshengliang
fix: temporarily disable memory leak detection for UDF tests (#33856)

162014 of 251293 relevant lines covered (64.47%)

104318075.66 hits per line

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

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

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

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

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

59
  if (strncasecmp(name, TSDB_INS_TABLE_DNODES, len) == 0) {
5,268,043✔
60
    type = TSDB_MGMT_TABLE_DNODE;
894,336✔
61
  } else if (strncasecmp(name, TSDB_INS_TABLE_MNODES, len) == 0) {
4,373,707✔
62
    type = TSDB_MGMT_TABLE_MNODE;
366,698✔
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,007,009✔
68
    type = TSDB_MGMT_TABLE_QNODE;
8,135✔
69
  } else if (strncasecmp(name, TSDB_INS_TABLE_SNODES, len) == 0) {
3,998,874✔
70
    type = TSDB_MGMT_TABLE_SNODE;
172,211✔
71
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES, len) == 0) {
3,826,663✔
72
    type = TSDB_MGMT_TABLE_ANODE;
359✔
73
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES_FULL, len) == 0) {
3,826,304✔
74
    type = TSDB_MGMT_TABLE_ANODE_FULL;
×
75
  } else if (strncasecmp(name, TSDB_INS_TABLE_BNODES, len) == 0) {
3,826,304✔
76
    type = TSDB_MGMT_TABLE_BNODE;
124,221✔
77
  } else if (strncasecmp(name, TSDB_INS_TABLE_ARBGROUPS, len) == 0) {
3,702,083✔
78
    type = TSDB_MGMT_TABLE_ARBGROUP;
×
79
  } else if (strncasecmp(name, TSDB_INS_TABLE_CLUSTER, len) == 0) {
3,702,083✔
80
    type = TSDB_MGMT_TABLE_CLUSTER;
3,594✔
81
  } else if (strncasecmp(name, TSDB_INS_TABLE_DATABASES, len) == 0) {
3,698,489✔
82
    type = TSDB_MGMT_TABLE_DB;
632,325✔
83
  } else if (strncasecmp(name, TSDB_INS_TABLE_FUNCTIONS, len) == 0) {
3,066,164✔
84
    type = TSDB_MGMT_TABLE_FUNC;
12,754✔
85
  } else if (strncasecmp(name, TSDB_INS_TABLE_INDEXES, len) == 0) {
3,053,410✔
86
    type = TSDB_MGMT_TABLE_INDEX;
14,464✔
87
  } else if (strncasecmp(name, TSDB_INS_TABLE_STABLES, len) == 0) {
3,038,946✔
88
    type = TSDB_MGMT_TABLE_STB;
349,136✔
89
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLES, len) == 0) {
2,689,810✔
90
    type = TSDB_MGMT_TABLE_TABLE;
×
91
  } else if (strncasecmp(name, TSDB_INS_TABLE_TAGS, len) == 0) {
2,689,810✔
92
    type = TSDB_MGMT_TABLE_TAG;
×
93
  } else if (strncasecmp(name, TSDB_INS_TABLE_COLS, len) == 0) {
2,689,810✔
94
    type = TSDB_MGMT_TABLE_COL;
537,593✔
95
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLE_DISTRIBUTED, len) == 0) {
2,152,217✔
96
    //    type = TSDB_MGMT_TABLE_DIST;
97
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS, len) == 0) {
2,152,217✔
98
    type = TSDB_MGMT_TABLE_USER;
20,273✔
99
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS_FULL, len) == 0) {
2,131,944✔
100
    type = TSDB_MGMT_TABLE_USER_FULL;
×
101
  } else if (strncasecmp(name, TSDB_INS_TABLE_LICENCES, len) == 0) {
2,131,944✔
102
    type = TSDB_MGMT_TABLE_GRANTS;
4,289✔
103
  } else if (strncasecmp(name, TSDB_INS_TABLE_VGROUPS, len) == 0) {
2,127,655✔
104
    type = TSDB_MGMT_TABLE_VGROUP;
313,692✔
105
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONSUMERS, len) == 0) {
1,813,963✔
106
    type = TSDB_MGMT_TABLE_CONSUMERS;
9,979✔
107
  } else if (strncasecmp(name, TSDB_INS_TABLE_SUBSCRIPTIONS, len) == 0) {
1,803,984✔
108
    type = TSDB_MGMT_TABLE_SUBSCRIPTIONS;
10,782✔
109
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_TRANS, len) == 0) {
1,793,202✔
110
    type = TSDB_MGMT_TABLE_TRANS;
504,957✔
111
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_SMAS, len) == 0) {
1,288,245✔
112
    type = TSDB_MGMT_TABLE_SMAS;
×
113
  } else if (strncasecmp(name, TSDB_INS_TABLE_CONFIGS, len) == 0) {
1,288,245✔
114
    type = TSDB_MGMT_TABLE_CONFIGS;
2,513✔
115
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONNECTIONS, len) == 0) {
1,285,732✔
116
    type = TSDB_MGMT_TABLE_CONNS;
17,284✔
117
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_QUERIES, len) == 0) {
1,268,448✔
118
    type = TSDB_MGMT_TABLE_QUERIES;
6,579✔
119
  } else if (strncasecmp(name, TSDB_INS_TABLE_VNODES, len) == 0) {
1,261,869✔
120
    type = TSDB_MGMT_TABLE_VNODES;
1,951✔
121
  } else if (strncasecmp(name, TSDB_INS_TABLE_TOPICS, len) == 0) {
1,259,918✔
122
    type = TSDB_MGMT_TABLE_TOPICS;
26,253✔
123
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAMS, len) == 0) {
1,233,665✔
124
    type = TSDB_MGMT_TABLE_STREAMS;
322,520✔
125
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_APPS, len) == 0) {
911,145✔
126
    type = TSDB_MGMT_TABLE_APPS;
6,108✔
127
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_INSTANCES, len) == 0) {
905,037✔
128
    type = TSDB_MGMT_TABLE_INSTANCE;
×
129
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAM_TASKS, len) == 0) {
905,037✔
130
    type = TSDB_MGMT_TABLE_STREAM_TASKS;
290,719✔
131
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAM_RECALCULATES, len) == 0) {
614,318✔
132
    type = TSDB_MGMT_TABLE_STREAM_RECALCULATES;
434✔
133
  } else if (strncasecmp(name, TSDB_INS_TABLE_USER_PRIVILEGES, len) == 0) {
613,884✔
134
    type = TSDB_MGMT_TABLE_PRIVILEGES;
20,129✔
135
  } else if (strncasecmp(name, TSDB_INS_TABLE_VIEWS, len) == 0) {
593,755✔
136
    type = TSDB_MGMT_TABLE_VIEWS;
33,057✔
137
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACTS, len) == 0) {
560,698✔
138
    type = TSDB_MGMT_TABLE_COMPACT;
364,659✔
139
  } else if (strncasecmp(name, TSDB_INS_TABLE_ENCRYPT_ALGORITHMS, len) == 0) {
196,039✔
140
    type = TSDB_MGMT_TABLE_ENCRYPT_ALGORITHMS;
×
141
  } else if (strncasecmp(name, TSDB_INS_TABLE_SCANS, len) == 0) {
196,039✔
142
    type = TSDB_MGMT_TABLE_SCAN;
5,592✔
143
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACT_DETAILS, len) == 0) {
190,447✔
144
    type = TSDB_MGMT_TABLE_COMPACT_DETAIL;
32,490✔
145
  } else if (strncasecmp(name, TSDB_INS_TABLE_SCAN_DETAILS, len) == 0) {
157,957✔
146
    type = TSDB_MGMT_TABLE_SCAN_DETAIL;
4,484✔
147
  } else if (strncasecmp(name, TSDB_INS_TABLE_SSMIGRATES, len) == 0) {
153,473✔
148
    type = TSDB_MGMT_TABLE_SSMIGRATE;
×
149
  } else if (strncasecmp(name, TSDB_INS_TABLE_TRANSACTION_DETAILS, len) == 0) {
153,473✔
150
    type = TSDB_MGMT_TABLE_TRANSACTION_DETAIL;
1,036✔
151
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_FULL, len) == 0) {
152,437✔
152
    type = TSDB_MGMT_TABLE_GRANTS_FULL;
2,283✔
153
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_LOGS, len) == 0) {
150,154✔
154
    type = TSDB_MGMT_TABLE_GRANTS_LOGS;
2,283✔
155
  } else if (strncasecmp(name, TSDB_INS_TABLE_MACHINES, len) == 0) {
147,871✔
156
    type = TSDB_MGMT_TABLE_MACHINES;
2,643✔
157
  } else if (strncasecmp(name, TSDB_INS_TABLE_ENCRYPTIONS, len) == 0) {
145,228✔
158
    type = TSDB_MGMT_TABLE_ENCRYPTIONS;
876✔
159
  } else if (strncasecmp(name, TSDB_INS_TABLE_TSMAS, len) == 0) {
144,352✔
160
    type = TSDB_MGMT_TABLE_TSMAS;
×
161
  } else if (strncasecmp(name, TSDB_INS_DISK_USAGE, len) == 0) {
144,352✔
162
    type = TSDB_MGMT_TABLE_USAGE;
×
163
  } else if (strncasecmp(name, TSDB_INS_TABLE_FILESETS, len) == 0) {
144,352✔
164
    type = TSDB_MGMT_TABLE_FILESETS;
×
165
  } else if (strncasecmp(name, TSDB_INS_TABLE_VC_COLS, len) == 0) {
144,352✔
166
    type = TSDB_MGMT_TABLE_VC_COL;
×
167
  } else if (strncasecmp(name, TSDB_INS_TABLE_MOUNTS, len) == 0) {
144,352✔
168
    type = TSDB_MGMT_TABLE_MOUNT;
15,908✔
169
  } else if (strncasecmp(name, TSDB_INS_TABLE_RSMAS, len) == 0) {
128,444✔
170
    type = TSDB_MGMT_TABLE_RSMA;
34,672✔
171
  } else if (strncasecmp(name, TSDB_INS_TABLE_RETENTIONS, len) == 0) {
93,772✔
172
    type = TSDB_MGMT_TABLE_RETENTION;
89,044✔
173
  } else if (strncasecmp(name, TSDB_INS_TABLE_RETENTION_DETAILS, len) == 0) {
4,728✔
174
    type = TSDB_MGMT_TABLE_RETENTION_DETAIL;
4,728✔
175
  } else {
176
    mError("invalid show name:%s len:%d", name, len);
×
177
  }
178

179
  return type;
5,268,043✔
180
}
181

182
static SShowObj *mndCreateShowObj(SMnode *pMnode, SRetrieveTableReq *pReq) {
5,268,043✔
183
  SShowMgmt *pMgmt = &pMnode->showMgmt;
5,268,043✔
184

185
  int64_t showId = atomic_add_fetch_64(&pMgmt->showId, 1);
5,268,043✔
186
  if (showId == 0) atomic_add_fetch_64(&pMgmt->showId, 1);
5,268,043✔
187

188
  int32_t size = sizeof(SShowObj);
5,268,043✔
189

190
  SShowObj showObj = {0};
5,268,043✔
191

192
  showObj.id = showId;
5,268,043✔
193
  showObj.pMnode = pMnode;
5,268,043✔
194
  showObj.type = convertToRetrieveType(pReq->tb, tListLen(pReq->tb));
5,268,043✔
195
  (void)memcpy(showObj.db, pReq->db, TSDB_DB_FNAME_LEN);
5,268,043✔
196
  tstrncpy(showObj.filterTb, pReq->filterTb, TSDB_TABLE_NAME_LEN);
5,268,043✔
197

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

206
  mTrace("show:0x%" PRIx64 ", is created, data:%p", showId, pShow);
5,267,838✔
207
  return pShow;
5,268,043✔
208
}
209

210
static void mndFreeShowObj(SShowObj *pShow) {
5,268,043✔
211
  SMnode    *pMnode = pShow->pMnode;
5,268,043✔
212
  SShowMgmt *pMgmt = &pMnode->showMgmt;
5,268,043✔
213

214
  ShowFreeIterFp freeFp = pMgmt->freeIterFps[pShow->type];
5,268,043✔
215
  if (freeFp != NULL) {
5,268,043✔
216
    if (pShow->pIter != NULL) {
4,844,272✔
217
      mTrace("show:0x%" PRIx64 ", is destroying, data:%p, pIter:%p, ", pShow->id, pShow, pShow->pIter);
129✔
218

219
      (*freeFp)(pMnode, pShow->pIter);
129✔
220

221
      pShow->pIter = NULL;
129✔
222
    }
223
  }
224

225
  mTrace("show:0x%" PRIx64 ", is destroyed, data:%p", pShow->id, pShow);
5,268,043✔
226
}
5,268,043✔
227

228
static SShowObj *mndAcquireShowObj(SMnode *pMnode, int64_t showId) {
126,133✔
229
  SShowMgmt *pMgmt = &pMnode->showMgmt;
126,133✔
230

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

237
  mTrace("show:0x%" PRIx64 ", acquired from cache, data:%p", pShow->id, pShow);
126,133✔
238
  return pShow;
126,133✔
239
}
240

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

245
  // A bug in tcache.c
246
  forceRemove = 0;
5,392,028✔
247

248
  SMnode    *pMnode = pShow->pMnode;
5,392,028✔
249
  SShowMgmt *pMgmt = &pMnode->showMgmt;
5,392,028✔
250
  taosCacheRelease(pMgmt->cache, (void **)(&pShow), forceRemove);
5,392,028✔
251
}
252

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

265
  mDebug("process to retrieve systable req db:%s, tb:%s, compactId:%" PRId64, retrieveReq.db, retrieveReq.tb,
5,394,176✔
266
         retrieveReq.compactId);
267

268
  if (retrieveReq.showId == 0) {
5,394,176✔
269
    STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, retrieveReq.tb, strlen(retrieveReq.tb));
5,268,043✔
270
    if (pMeta == NULL) {
5,268,043✔
271
      pMeta = taosHashGet(pMnode->perfsMeta, retrieveReq.tb, strlen(retrieveReq.tb));
544,907✔
272
      if (pMeta == NULL) {
544,907✔
273
        code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
×
274
        mError("failed to process show-retrieve req:%p since %s", pShow, tstrerror(code));
×
275
        TAOS_RETURN(code);
×
276
      }
277
    }
278

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

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

297
  if (pShow->type == TSDB_MGMT_TABLE_COL) {  // expend capacity for ins_columns
5,393,971✔
298
    rowsToRead = SHOW_COLS_STEP_SIZE;
540,484✔
299
  } else if (pShow->type == TSDB_MGMT_TABLE_PRIVILEGES) {
4,853,487✔
300
    rowsToRead = SHOW_PRIVILEGES_STEP_SIZE;
20,129✔
301
  }
302
  ShowRetrieveFp retrieveFp = pMgmt->retrieveFps[pShow->type];
5,393,971✔
303
  if (retrieveFp == NULL) {
5,393,766✔
304
    mndReleaseShowObj(pShow, false);
×
305
    code = TSDB_CODE_MSG_NOT_PROCESSED;
×
306
    mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, tstrerror(code));
×
307
    TAOS_RETURN(code);
×
308
  }
309

310
  mDebug("show:0x%" PRIx64 ", start retrieve data, type:%d", pShow->id, pShow->type);
5,393,766✔
311
  if (retrieveReq.user[0] != 0) {
5,394,176✔
312
    (void)memcpy(pReq->info.conn.user, retrieveReq.user, TSDB_USER_LEN);
5,394,176✔
313
  } else {
314
    (void)memcpy(pReq->info.conn.user, TSDB_DEFAULT_USER, strlen(TSDB_DEFAULT_USER) + 1);
×
315
  }
316
  code = -1;
5,394,176✔
317
  if (retrieveReq.db[0] &&
7,571,870✔
318
      (code = mndCheckShowPrivilege(pMnode, pReq->info.conn.user, pShow->type, retrieveReq.db)) != 0) {
2,177,694✔
319
    TAOS_RETURN(code);
2,148✔
320
  }
321
  if (pShow->type == TSDB_MGMT_TABLE_USER_FULL) {
5,392,028✔
322
    if (strcmp(pReq->info.conn.user, "root") != 0) {
×
323
      mError("The operation is not permitted, user:%s, pShow->type:%d", pReq->info.conn.user, pShow->type);
×
324
      code = TSDB_CODE_MND_NO_RIGHTS;
×
325
      TAOS_RETURN(code);
×
326
    }
327
  }
328

329
  int32_t numOfCols = pShow->pMeta->numOfColumns;
5,392,028✔
330

331
  SSDataBlock *pBlock = NULL;
5,392,028✔
332
  code = createDataBlock(&pBlock);
5,392,028✔
333
  if (code) {
5,392,028✔
334
    TAOS_RETURN(code);
×
335
  }
336

337
  for (int32_t i = 0; i < numOfCols; ++i) {
75,142,085✔
338
    SColumnInfoData idata = {0};
69,750,262✔
339

340
    SSchema *p = &pShow->pMeta->pSchemas[i];
69,750,262✔
341

342
    idata.info.bytes = p->bytes;
69,750,262✔
343
    idata.info.type = p->type;
69,750,262✔
344
    idata.info.colId = p->colId;
69,750,262✔
345
    TAOS_CHECK_RETURN(blockDataAppendColInfo(pBlock, &idata));
69,750,262✔
346
  }
347

348
  TAOS_CHECK_RETURN(blockDataEnsureCapacity(pBlock, rowsToRead));
5,391,823✔
349

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

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

367
  size_t dataEncodeBufSize = blockGetEncodeSize(pBlock);
5,389,705✔
368
  size = sizeof(SRetrieveMetaTableRsp) + sizeof(int32_t) + sizeof(SSysTableSchema) * pShow->pMeta->numOfColumns +
5,389,705✔
369
         dataEncodeBufSize;
370

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

378
  pRsp->handle = htobe64(pShow->id);
5,389,705✔
379

380
  if (rowsRead > 0) {
5,389,705✔
381
    char    *pStart = pRsp->data;
5,035,757✔
382
    SSchema *ps = pShow->pMeta->pSchemas;
5,035,757✔
383

384
    *(int32_t *)pStart = htonl(pShow->pMeta->numOfColumns);
5,035,757✔
385
    pStart += sizeof(int32_t);  // number of columns
5,035,757✔
386

387
    for (int32_t i = 0; i < pShow->pMeta->numOfColumns; ++i) {
71,503,827✔
388
      SSysTableSchema *pSchema = (SSysTableSchema *)pStart;
66,468,070✔
389
      pSchema->bytes = htonl(ps[i].bytes);
66,468,070✔
390
      pSchema->colId = htons(ps[i].colId);
66,468,070✔
391
      pSchema->type = ps[i].type;
66,467,865✔
392

393
      pStart += sizeof(SSysTableSchema);
66,467,865✔
394
    }
395

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

404
  pRsp->numOfRows = htonl(rowsRead);
5,389,705✔
405
  pRsp->precision = TSDB_TIME_PRECISION_MILLI;  // millisecond time precision
5,389,705✔
406
  pReq->info.rsp = pRsp;
5,389,705✔
407
  pReq->info.rspLen = size;
5,389,705✔
408

409
  if (rowsRead == 0 || mndCheckRetrieveFinished(pShow)) {
5,389,705✔
410
    pRsp->completed = 1;
5,263,443✔
411
    mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
5,263,443✔
412
    mndReleaseShowObj(pShow, true);
5,263,443✔
413
  } else {
414
    mDebug("show:0x%" PRIx64 ", retrieve not completed yet", pShow->id);
126,262✔
415
    mndReleaseShowObj(pShow, false);
126,262✔
416
  }
417

418
  blockDataDestroy(pBlock);
5,389,705✔
419
  return TSDB_CODE_SUCCESS;
5,389,705✔
420
_exit:
×
421
  mndReleaseShowObj(pShow, false);
×
422
  blockDataDestroy(pBlock);
×
423
  if (pRsp) {
×
424
    rpcFreeCont(pRsp);
×
425
  }
426
  return code;
×
427
}
428

429
static bool mndCheckRetrieveFinished(SShowObj *pShow) {
10,427,785✔
430
  if (pShow->pIter == NULL && pShow->numOfRows != 0) {
10,427,785✔
431
    return true;
4,909,495✔
432
  }
433
  return false;
5,518,290✔
434
}
435

436
void mndAddShowRetrieveHandle(SMnode *pMnode, EShowType showType, ShowRetrieveFp fp) {
24,633,133✔
437
  SShowMgmt *pMgmt = &pMnode->showMgmt;
24,633,133✔
438
  pMgmt->retrieveFps[showType] = fp;
24,633,133✔
439
}
24,633,133✔
440

441
void mndAddShowFreeIterHandle(SMnode *pMnode, EShowType showType, ShowFreeIterFp fp) {
20,108,680✔
442
  SShowMgmt *pMgmt = &pMnode->showMgmt;
20,108,680✔
443
  pMgmt->freeIterFps[showType] = fp;
20,108,680✔
444
}
20,108,680✔
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