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

taosdata / TDengine / #3621

22 Feb 2025 11:44AM UTC coverage: 2.037% (-61.5%) from 63.573%
#3621

push

travis-ci

web-flow
Merge pull request #29874 from taosdata/merge/mainto3.0

merge: from main to 3.0 branch

4357 of 287032 branches covered (1.52%)

Branch coverage included in aggregate %.

0 of 174 new or added lines in 18 files covered. (0.0%)

213359 existing lines in 469 files now uncovered.

7260 of 283369 relevant lines covered (2.56%)

23737.72 hits per line

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

0.0
/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

UNCOV
33
int32_t mndInitShow(SMnode *pMnode) {
×
UNCOV
34
  int32_t    code = 0;
×
UNCOV
35
  SShowMgmt *pMgmt = &pMnode->showMgmt;
×
36

UNCOV
37
  pMgmt->cache = taosCacheInit(TSDB_DATA_TYPE_INT, 5000, true, (__cache_free_fn_t)mndFreeShowObj, "show");
×
UNCOV
38
  if (pMgmt->cache == NULL) {
×
39
    code = TSDB_CODE_OUT_OF_MEMORY;
×
40
    mError("failed to alloc show cache since %s", tstrerror(code));
×
41
    TAOS_RETURN(code);
×
42
  }
43

UNCOV
44
  mndSetMsgHandle(pMnode, TDMT_MND_SYSTABLE_RETRIEVE, mndProcessRetrieveSysTableReq);
×
UNCOV
45
  TAOS_RETURN(code);
×
46
}
47

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

UNCOV
56
static int32_t convertToRetrieveType(char *name, int32_t len) {
×
UNCOV
57
  int32_t type = -1;
×
58

UNCOV
59
  if (strncasecmp(name, TSDB_INS_TABLE_DNODES, len) == 0) {
×
UNCOV
60
    type = TSDB_MGMT_TABLE_DNODE;
×
UNCOV
61
  } else if (strncasecmp(name, TSDB_INS_TABLE_MNODES, len) == 0) {
×
UNCOV
62
    type = TSDB_MGMT_TABLE_MNODE;
×
63
    /*
64
      } else if (strncasecmp(name, TSDB_INS_TABLE_MODULES, len) == 0) {
65
        type = TSDB_MGMT_TABLE_MODULE;
66
    */
UNCOV
67
  } else if (strncasecmp(name, TSDB_INS_TABLE_QNODES, len) == 0) {
×
UNCOV
68
    type = TSDB_MGMT_TABLE_QNODE;
×
UNCOV
69
  } else if (strncasecmp(name, TSDB_INS_TABLE_SNODES, len) == 0) {
×
UNCOV
70
    type = TSDB_MGMT_TABLE_SNODE;
×
UNCOV
71
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES, len) == 0) {
×
UNCOV
72
    type = TSDB_MGMT_TABLE_ANODE;
×
UNCOV
73
  } else if (strncasecmp(name, TSDB_INS_TABLE_ANODES_FULL, len) == 0) {
×
UNCOV
74
    type = TSDB_MGMT_TABLE_ANODE_FULL;
×
UNCOV
75
  } else if (strncasecmp(name, TSDB_INS_TABLE_ARBGROUPS, len) == 0) {
×
76
    type = TSDB_MGMT_TABLE_ARBGROUP;
×
UNCOV
77
  } else if (strncasecmp(name, TSDB_INS_TABLE_CLUSTER, len) == 0) {
×
UNCOV
78
    type = TSDB_MGMT_TABLE_CLUSTER;
×
UNCOV
79
  } else if (strncasecmp(name, TSDB_INS_TABLE_DATABASES, len) == 0) {
×
UNCOV
80
    type = TSDB_MGMT_TABLE_DB;
×
UNCOV
81
  } else if (strncasecmp(name, TSDB_INS_TABLE_FUNCTIONS, len) == 0) {
×
UNCOV
82
    type = TSDB_MGMT_TABLE_FUNC;
×
UNCOV
83
  } else if (strncasecmp(name, TSDB_INS_TABLE_INDEXES, len) == 0) {
×
UNCOV
84
    type = TSDB_MGMT_TABLE_INDEX;
×
UNCOV
85
  } else if (strncasecmp(name, TSDB_INS_TABLE_STABLES, len) == 0) {
×
UNCOV
86
    type = TSDB_MGMT_TABLE_STB;
×
UNCOV
87
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLES, len) == 0) {
×
88
    type = TSDB_MGMT_TABLE_TABLE;
×
UNCOV
89
  } else if (strncasecmp(name, TSDB_INS_TABLE_TAGS, len) == 0) {
×
90
    type = TSDB_MGMT_TABLE_TAG;
×
UNCOV
91
  } else if (strncasecmp(name, TSDB_INS_TABLE_COLS, len) == 0) {
×
UNCOV
92
    type = TSDB_MGMT_TABLE_COL;
×
UNCOV
93
  } else if (strncasecmp(name, TSDB_INS_TABLE_TABLE_DISTRIBUTED, len) == 0) {
×
94
    //    type = TSDB_MGMT_TABLE_DIST;
UNCOV
95
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS, len) == 0) {
×
UNCOV
96
    type = TSDB_MGMT_TABLE_USER;
×
UNCOV
97
  } else if (strncasecmp(name, TSDB_INS_TABLE_USERS_FULL, len) == 0) {
×
98
    type = TSDB_MGMT_TABLE_USER_FULL;
×
UNCOV
99
  } else if (strncasecmp(name, TSDB_INS_TABLE_LICENCES, len) == 0) {
×
UNCOV
100
    type = TSDB_MGMT_TABLE_GRANTS;
×
UNCOV
101
  } else if (strncasecmp(name, TSDB_INS_TABLE_VGROUPS, len) == 0) {
×
UNCOV
102
    type = TSDB_MGMT_TABLE_VGROUP;
×
UNCOV
103
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONSUMERS, len) == 0) {
×
UNCOV
104
    type = TSDB_MGMT_TABLE_CONSUMERS;
×
UNCOV
105
  } else if (strncasecmp(name, TSDB_INS_TABLE_SUBSCRIPTIONS, len) == 0) {
×
UNCOV
106
    type = TSDB_MGMT_TABLE_SUBSCRIPTIONS;
×
UNCOV
107
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_TRANS, len) == 0) {
×
UNCOV
108
    type = TSDB_MGMT_TABLE_TRANS;
×
UNCOV
109
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_SMAS, len) == 0) {
×
110
    type = TSDB_MGMT_TABLE_SMAS;
×
UNCOV
111
  } else if (strncasecmp(name, TSDB_INS_TABLE_CONFIGS, len) == 0) {
×
UNCOV
112
    type = TSDB_MGMT_TABLE_CONFIGS;
×
UNCOV
113
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONNECTIONS, len) == 0) {
×
UNCOV
114
    type = TSDB_MGMT_TABLE_CONNS;
×
UNCOV
115
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_QUERIES, len) == 0) {
×
UNCOV
116
    type = TSDB_MGMT_TABLE_QUERIES;
×
UNCOV
117
  } else if (strncasecmp(name, TSDB_INS_TABLE_VNODES, len) == 0) {
×
UNCOV
118
    type = TSDB_MGMT_TABLE_VNODES;
×
UNCOV
119
  } else if (strncasecmp(name, TSDB_INS_TABLE_TOPICS, len) == 0) {
×
UNCOV
120
    type = TSDB_MGMT_TABLE_TOPICS;
×
UNCOV
121
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAMS, len) == 0) {
×
UNCOV
122
    type = TSDB_MGMT_TABLE_STREAMS;
×
UNCOV
123
  } else if (strncasecmp(name, TSDB_PERFS_TABLE_APPS, len) == 0) {
×
UNCOV
124
    type = TSDB_MGMT_TABLE_APPS;
×
UNCOV
125
  } else if (strncasecmp(name, TSDB_INS_TABLE_STREAM_TASKS, len) == 0) {
×
UNCOV
126
    type = TSDB_MGMT_TABLE_STREAM_TASKS;
×
UNCOV
127
  } else if (strncasecmp(name, TSDB_INS_TABLE_USER_PRIVILEGES, len) == 0) {
×
UNCOV
128
    type = TSDB_MGMT_TABLE_PRIVILEGES;
×
UNCOV
129
  } else if (strncasecmp(name, TSDB_INS_TABLE_VIEWS, len) == 0) {
×
UNCOV
130
    type = TSDB_MGMT_TABLE_VIEWS;
×
UNCOV
131
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACTS, len) == 0) {
×
UNCOV
132
    type = TSDB_MGMT_TABLE_COMPACT;
×
UNCOV
133
  } else if (strncasecmp(name, TSDB_INS_TABLE_COMPACT_DETAILS, len) == 0) {
×
UNCOV
134
    type = TSDB_MGMT_TABLE_COMPACT_DETAIL;
×
UNCOV
135
  } else if (strncasecmp(name, TSDB_INS_TABLE_TRANSACTION_DETAILS, len) == 0) {
×
136
    type = TSDB_MGMT_TABLE_TRANSACTION_DETAIL;
×
UNCOV
137
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_FULL, len) == 0) {
×
UNCOV
138
    type = TSDB_MGMT_TABLE_GRANTS_FULL;
×
UNCOV
139
  } else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_LOGS, len) == 0) {
×
UNCOV
140
    type = TSDB_MGMT_TABLE_GRANTS_LOGS;
×
UNCOV
141
  } else if (strncasecmp(name, TSDB_INS_TABLE_MACHINES, len) == 0) {
×
UNCOV
142
    type = TSDB_MGMT_TABLE_MACHINES;
×
UNCOV
143
  } else if (strncasecmp(name, TSDB_INS_TABLE_ENCRYPTIONS, len) == 0) {
×
144
    type = TSDB_MGMT_TABLE_ENCRYPTIONS;
×
UNCOV
145
  } else if (strncasecmp(name, TSDB_INS_TABLE_TSMAS, len) == 0) {
×
UNCOV
146
    type = TSDB_MGMT_TABLE_TSMAS;
×
UNCOV
147
  } else if (strncasecmp(name, TSDB_INS_DISK_USAGE, len) == 0) {
×
148
    type = TSDB_MGMT_TABLE_USAGE;
×
UNCOV
149
  } else if (strncasecmp(name, TSDB_INS_TABLE_FILESETS, len) == 0) {
×
150
    type = TSDB_MGMT_TABLE_FILESETS;
×
151
  } else {
UNCOV
152
    mError("invalid show name:%s len:%d", name, len);
×
153
  }
154

UNCOV
155
  return type;
×
156
}
157

UNCOV
158
static SShowObj *mndCreateShowObj(SMnode *pMnode, SRetrieveTableReq *pReq) {
×
UNCOV
159
  SShowMgmt *pMgmt = &pMnode->showMgmt;
×
160

UNCOV
161
  int64_t showId = atomic_add_fetch_64(&pMgmt->showId, 1);
×
UNCOV
162
  if (showId == 0) atomic_add_fetch_64(&pMgmt->showId, 1);
×
163

UNCOV
164
  int32_t size = sizeof(SShowObj);
×
165

UNCOV
166
  SShowObj showObj = {0};
×
167

UNCOV
168
  showObj.id = showId;
×
UNCOV
169
  showObj.pMnode = pMnode;
×
UNCOV
170
  showObj.type = convertToRetrieveType(pReq->tb, tListLen(pReq->tb));
×
UNCOV
171
  (void)memcpy(showObj.db, pReq->db, TSDB_DB_FNAME_LEN);
×
UNCOV
172
  tstrncpy(showObj.filterTb, pReq->filterTb, TSDB_TABLE_NAME_LEN);
×
173

UNCOV
174
  int32_t   keepTime = tsShellActivityTimer * 6 * 1000;
×
UNCOV
175
  SShowObj *pShow = taosCachePut(pMgmt->cache, &showId, sizeof(int64_t), &showObj, size, keepTime);
×
UNCOV
176
  if (pShow == NULL) {
×
177
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
178
    mError("show:0x%" PRIx64 ", failed to put into cache since %s", showId, terrstr());
×
179
    return NULL;
×
180
  }
181

UNCOV
182
  mTrace("show:0x%" PRIx64 ", is created, data:%p", showId, pShow);
×
UNCOV
183
  return pShow;
×
184
}
185

UNCOV
186
static void mndFreeShowObj(SShowObj *pShow) {
×
UNCOV
187
  SMnode    *pMnode = pShow->pMnode;
×
UNCOV
188
  SShowMgmt *pMgmt = &pMnode->showMgmt;
×
189

UNCOV
190
  ShowFreeIterFp freeFp = pMgmt->freeIterFps[pShow->type];
×
UNCOV
191
  if (freeFp != NULL) {
×
UNCOV
192
    if (pShow->pIter != NULL) {
×
193
      mTrace("show:0x%" PRIx64 ", is destroying, data:%p, pIter:%p, ", pShow->id, pShow, pShow->pIter);
×
194

195
      (*freeFp)(pMnode, pShow->pIter);
×
196

197
      pShow->pIter = NULL;
×
198
    }
199
  }
200

UNCOV
201
  mTrace("show:0x%" PRIx64 ", is destroyed, data:%p", pShow->id, pShow);
×
UNCOV
202
}
×
203

UNCOV
204
static SShowObj *mndAcquireShowObj(SMnode *pMnode, int64_t showId) {
×
UNCOV
205
  SShowMgmt *pMgmt = &pMnode->showMgmt;
×
206

UNCOV
207
  SShowObj *pShow = taosCacheAcquireByKey(pMgmt->cache, &showId, sizeof(showId));
×
UNCOV
208
  if (pShow == NULL) {
×
209
    mError("show:0x%" PRIx64 ", already destroyed", showId);
×
210
    return NULL;
×
211
  }
212

UNCOV
213
  mTrace("show:0x%" PRIx64 ", acquired from cache, data:%p", pShow->id, pShow);
×
UNCOV
214
  return pShow;
×
215
}
216

UNCOV
217
static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove) {
×
UNCOV
218
  if (pShow == NULL) return;
×
UNCOV
219
  mTrace("show:0x%" PRIx64 ", released from cache, data:%p force:%d", pShow->id, pShow, forceRemove);
×
220

221
  // A bug in tcache.c
UNCOV
222
  forceRemove = 0;
×
223

UNCOV
224
  SMnode    *pMnode = pShow->pMnode;
×
UNCOV
225
  SShowMgmt *pMgmt = &pMnode->showMgmt;
×
UNCOV
226
  taosCacheRelease(pMgmt->cache, (void **)(&pShow), forceRemove);
×
227
}
228

UNCOV
229
static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) {
×
UNCOV
230
  int32_t    code = 0;
×
UNCOV
231
  SMnode    *pMnode = pReq->info.node;
×
UNCOV
232
  SShowMgmt *pMgmt = &pMnode->showMgmt;
×
UNCOV
233
  SShowObj  *pShow = NULL;
×
UNCOV
234
  int32_t    rowsToRead = SHOW_STEP_SIZE;
×
UNCOV
235
  int32_t    size = 0;
×
UNCOV
236
  int32_t    rowsRead = 0;
×
UNCOV
237
  mDebug("mndProcessRetrieveSysTableReq start");
×
UNCOV
238
  SRetrieveTableReq retrieveReq = {0};
×
UNCOV
239
  TAOS_CHECK_RETURN(tDeserializeSRetrieveTableReq(pReq->pCont, pReq->contLen, &retrieveReq));
×
240

UNCOV
241
  mDebug("process to retrieve systable req db:%s, tb:%s, compactId:%" PRId64, retrieveReq.db, retrieveReq.tb,
×
242
         retrieveReq.compactId);
243

UNCOV
244
  if (retrieveReq.showId == 0) {
×
UNCOV
245
    STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, retrieveReq.tb, strlen(retrieveReq.tb));
×
UNCOV
246
    if (pMeta == NULL) {
×
UNCOV
247
      pMeta = taosHashGet(pMnode->perfsMeta, retrieveReq.tb, strlen(retrieveReq.tb));
×
UNCOV
248
      if (pMeta == NULL) {
×
249
        code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
×
250
        mError("failed to process show-retrieve req:%p since %s", pShow, tstrerror(code));
×
251
        TAOS_RETURN(code);
×
252
      }
253
    }
254

UNCOV
255
    pShow = mndCreateShowObj(pMnode, &retrieveReq);
×
UNCOV
256
    if (pShow == NULL) {
×
UNCOV
257
      code = terrno;
×
258
      mError("failed to process show-meta req since %s", tstrerror(code));
×
259
      TAOS_RETURN(code);
×
260
    }
261

UNCOV
262
    pShow->pMeta = pMeta;
×
UNCOV
263
    pShow->numOfColumns = pShow->pMeta->numOfColumns;
×
264
  } else {
UNCOV
265
    pShow = mndAcquireShowObj(pMnode, retrieveReq.showId);
×
UNCOV
266
    if (pShow == NULL) {
×
UNCOV
267
      code = TSDB_CODE_MND_INVALID_SHOWOBJ;
×
UNCOV
268
      mError("failed to process show-retrieve req:%p since %s", pShow, tstrerror(code));
×
UNCOV
269
      TAOS_RETURN(code);
×
270
    }
271
  }
272

UNCOV
273
  if (pShow->type == TSDB_MGMT_TABLE_COL) {  // expend capacity for ins_columns
×
UNCOV
274
    rowsToRead = SHOW_COLS_STEP_SIZE;
×
UNCOV
275
  } else if (pShow->type == TSDB_MGMT_TABLE_PRIVILEGES) {
×
UNCOV
276
    rowsToRead = SHOW_PRIVILEGES_STEP_SIZE;
×
277
  }
UNCOV
278
  ShowRetrieveFp retrieveFp = pMgmt->retrieveFps[pShow->type];
×
UNCOV
279
  if (retrieveFp == NULL) {
×
280
    mndReleaseShowObj(pShow, false);
×
281
    code = TSDB_CODE_MSG_NOT_PROCESSED;
×
282
    mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, tstrerror(code));
×
283
    TAOS_RETURN(code);
×
284
  }
285

UNCOV
286
  mDebug("show:0x%" PRIx64 ", start retrieve data, type:%d", pShow->id, pShow->type);
×
UNCOV
287
  if (retrieveReq.user[0] != 0) {
×
UNCOV
288
    (void)memcpy(pReq->info.conn.user, retrieveReq.user, TSDB_USER_LEN);
×
289
  } else {
UNCOV
290
    (void)memcpy(pReq->info.conn.user, TSDB_DEFAULT_USER, strlen(TSDB_DEFAULT_USER) + 1);
×
291
  }
UNCOV
292
  code = -1;
×
UNCOV
293
  if (retrieveReq.db[0] &&
×
UNCOV
294
      (code = mndCheckShowPrivilege(pMnode, pReq->info.conn.user, pShow->type, retrieveReq.db)) != 0) {
×
UNCOV
295
    TAOS_RETURN(code);
×
296
  }
UNCOV
297
  if (pShow->type == TSDB_MGMT_TABLE_USER_FULL) {
×
298
    if (strcmp(pReq->info.conn.user, "root") != 0) {
×
299
      mError("The operation is not permitted, user:%s, pShow->type:%d", pReq->info.conn.user, pShow->type);
×
300
      code = TSDB_CODE_MND_NO_RIGHTS;
×
301
      TAOS_RETURN(code);
×
302
    }
303
  }
304

UNCOV
305
  int32_t numOfCols = pShow->pMeta->numOfColumns;
×
306

UNCOV
307
  SSDataBlock *pBlock = NULL;
×
UNCOV
308
  code = createDataBlock(&pBlock);
×
UNCOV
309
  if (code) {
×
UNCOV
310
    TAOS_RETURN(code);
×
311
  }
312

UNCOV
313
  for (int32_t i = 0; i < numOfCols; ++i) {
×
UNCOV
314
    SColumnInfoData idata = {0};
×
315

UNCOV
316
    SSchema *p = &pShow->pMeta->pSchemas[i];
×
317

UNCOV
318
    idata.info.bytes = p->bytes;
×
UNCOV
319
    idata.info.type = p->type;
×
UNCOV
320
    idata.info.colId = p->colId;
×
UNCOV
321
    TAOS_CHECK_RETURN(blockDataAppendColInfo(pBlock, &idata));
×
322
  }
323

UNCOV
324
  TAOS_CHECK_RETURN(blockDataEnsureCapacity(pBlock, rowsToRead));
×
325

UNCOV
326
  if (mndCheckRetrieveFinished(pShow)) {
×
327
    mDebug("show:0x%" PRIx64 ", read finished, numOfRows:%d", pShow->id, pShow->numOfRows);
×
328
    rowsRead = 0;
×
329
  } else {
UNCOV
330
    rowsRead = (*retrieveFp)(pReq, pShow, pBlock, rowsToRead);
×
UNCOV
331
    if (rowsRead < 0) {
×
UNCOV
332
      code = rowsRead;
×
UNCOV
333
      mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
×
UNCOV
334
      mndReleaseShowObj(pShow, true);
×
UNCOV
335
      blockDataDestroy(pBlock);
×
UNCOV
336
      TAOS_RETURN(code);
×
337
    }
338

UNCOV
339
    pBlock->info.rows = rowsRead;
×
UNCOV
340
    mDebug("show:0x%" PRIx64 ", stop retrieve data, rowsRead:%d numOfRows:%d", pShow->id, rowsRead, pShow->numOfRows);
×
341
  }
342

UNCOV
343
  size_t dataEncodeBufSize = blockGetEncodeSize(pBlock);
×
UNCOV
344
  size = sizeof(SRetrieveMetaTableRsp) + sizeof(int32_t) + sizeof(SSysTableSchema) * pShow->pMeta->numOfColumns +
×
345
         dataEncodeBufSize;
346

UNCOV
347
  SRetrieveMetaTableRsp *pRsp = rpcMallocCont(size);
×
UNCOV
348
  if (pRsp == NULL) {
×
349
    mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, tstrerror(code));
×
350
    code = terrno;
×
351
    goto _exit;
×
352
  }
353

UNCOV
354
  pRsp->handle = htobe64(pShow->id);
×
355

UNCOV
356
  if (rowsRead > 0) {
×
UNCOV
357
    char    *pStart = pRsp->data;
×
UNCOV
358
    SSchema *ps = pShow->pMeta->pSchemas;
×
359

UNCOV
360
    *(int32_t *)pStart = htonl(pShow->pMeta->numOfColumns);
×
UNCOV
361
    pStart += sizeof(int32_t);  // number of columns
×
362

UNCOV
363
    for (int32_t i = 0; i < pShow->pMeta->numOfColumns; ++i) {
×
UNCOV
364
      SSysTableSchema *pSchema = (SSysTableSchema *)pStart;
×
UNCOV
365
      pSchema->bytes = htonl(ps[i].bytes);
×
UNCOV
366
      pSchema->colId = htons(ps[i].colId);
×
UNCOV
367
      pSchema->type = ps[i].type;
×
368

UNCOV
369
      pStart += sizeof(SSysTableSchema);
×
370
    }
371

UNCOV
372
    int32_t len = blockEncode(pBlock, pStart, dataEncodeBufSize, pShow->pMeta->numOfColumns);
×
UNCOV
373
    if (len < 0) {
×
374
      mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, tstrerror(code));
×
375
      code = terrno;
×
376
      return code;
×
377
    }
378
  }
379

UNCOV
380
  pRsp->numOfRows = htonl(rowsRead);
×
UNCOV
381
  pRsp->precision = TSDB_TIME_PRECISION_MILLI;  // millisecond time precision
×
UNCOV
382
  pReq->info.rsp = pRsp;
×
UNCOV
383
  pReq->info.rspLen = size;
×
384

UNCOV
385
  if (rowsRead == 0 || mndCheckRetrieveFinished(pShow)) {
×
UNCOV
386
    pRsp->completed = 1;
×
UNCOV
387
    mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
×
UNCOV
388
    mndReleaseShowObj(pShow, true);
×
389
  } else {
UNCOV
390
    mDebug("show:0x%" PRIx64 ", retrieve not completed yet", pShow->id);
×
UNCOV
391
    mndReleaseShowObj(pShow, false);
×
392
  }
393

UNCOV
394
  blockDataDestroy(pBlock);
×
UNCOV
395
  return TSDB_CODE_SUCCESS;
×
396
_exit:
×
397
  mndReleaseShowObj(pShow, false);
×
398
  blockDataDestroy(pBlock);
×
399
  if (pRsp) {
×
400
    rpcFreeCont(pRsp);
×
401
  }
402
  return code;
×
403
}
404

UNCOV
405
static bool mndCheckRetrieveFinished(SShowObj *pShow) {
×
UNCOV
406
  if (pShow->pIter == NULL && pShow->numOfRows != 0) {
×
UNCOV
407
    return true;
×
408
  }
UNCOV
409
  return false;
×
410
}
411

UNCOV
412
void mndAddShowRetrieveHandle(SMnode *pMnode, EShowType showType, ShowRetrieveFp fp) {
×
UNCOV
413
  SShowMgmt *pMgmt = &pMnode->showMgmt;
×
UNCOV
414
  pMgmt->retrieveFps[showType] = fp;
×
UNCOV
415
}
×
416

UNCOV
417
void mndAddShowFreeIterHandle(SMnode *pMnode, EShowType showType, ShowFreeIterFp fp) {
×
UNCOV
418
  SShowMgmt *pMgmt = &pMnode->showMgmt;
×
UNCOV
419
  pMgmt->freeIterFps[showType] = fp;
×
UNCOV
420
}
×
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