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

taosdata / TDengine / #5011

03 Apr 2026 03:59PM UTC coverage: 72.3% (+0.008%) from 72.292%
#5011

push

travis-ci

web-flow
merge: from main to 3.0 branch #35067

4053 of 5985 new or added lines in 68 files covered. (67.72%)

732 existing lines in 143 files now uncovered.

257430 of 356056 relevant lines covered (72.3%)

131834103.52 hits per line

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

72.68
/source/libs/catalog/src/ctgRemote.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
#include "ctgRemote.h"
17
#include "catalogInt.h"
18
#include "query.h"
19
#include "systable.h"
20
#include "tname.h"
21
#include "tref.h"
22
#include "trpc.h"
23

24
typedef void* (*MallocType)(int64_t);
25

26
int32_t ctgHandleBatchRsp(SCtgJob* pJob, SCtgTaskCallbackParam* cbParam, SDataBuf* pMsg, int32_t rspCode) {
67,379,835✔
27
  int32_t       code = 0;
67,379,835✔
28
  SCatalog*     pCtg = pJob->pCtg;
67,379,835✔
29
  int32_t       taskNum = taosArrayGetSize(cbParam->taskId);
67,379,628✔
30
  SDataBuf      taskMsg = *pMsg;
67,379,950✔
31
  int32_t       msgNum = 0;
67,379,950✔
32
  SBatchRsp     batchRsp = {0};
67,379,950✔
33
  SBatchRspMsg  rsp = {0};
67,379,929✔
34
  SBatchRspMsg* pRsp = NULL;
67,380,947✔
35

36
  if (TSDB_CODE_SUCCESS == rspCode && pMsg->pData && (pMsg->len > 0)) {
67,380,947✔
37
    code = tDeserializeSBatchRsp(pMsg->pData, pMsg->len, &batchRsp);
67,342,368✔
38
    if (code < 0) {
67,338,320✔
39
      ctgError("tDeserializeSBatchRsp failed, msgLen:%d", pMsg->len);
×
40
      CTG_ERR_RET(code);
×
41
    }
42

43
    msgNum = taosArrayGetSize(batchRsp.pRsps);
67,338,320✔
44
  }
45

46
  if (taskNum != msgNum && 0 != msgNum) {
67,370,887✔
47
    ctgError("taskNum %d mis-match msgNum %d", taskNum, msgNum);
×
48
    msgNum = 0;
×
49
  }
50

51
  ctgDebug("QID:0x%" PRIx64 ", catalog got batch:%d rsp:%s", pJob->queryId, cbParam->batchId,
67,370,887✔
52
           TMSG_INFO(cbParam->reqType + 1));
53

54
  SHashObj* pBatchs = taosHashInit(taskNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK);
67,384,396✔
55
  if (NULL == pBatchs) {
67,379,639✔
56
    ctgError("taosHashInit %d batch failed", taskNum);
×
57
    CTG_ERR_JRET(terrno);
×
58
  }
59

60
  for (int32_t i = 0; i < taskNum; ++i) {
174,790,309✔
61
    int32_t* taskId = taosArrayGet(cbParam->taskId, i);
107,408,813✔
62
    if (NULL == taskId) {
107,410,051✔
63
      ctgError("taosArrayGet %d taskId failed, total:%d", i, (int32_t)taosArrayGetSize(cbParam->taskId));
×
64
      CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
×
65
    }
66

67
    int32_t* msgIdx = taosArrayGet(cbParam->msgIdx, i);
107,410,051✔
68
    if (NULL == msgIdx) {
107,410,668✔
69
      ctgError("taosArrayGet %d msgIdx failed, total:%d", i, (int32_t)taosArrayGetSize(cbParam->msgIdx));
×
70
      CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
×
71
    }
72

73
    SCtgTask* pTask = taosArrayGet(pJob->pTasks, *taskId);
107,410,668✔
74
    if (NULL == pTask) {
107,409,871✔
75
      ctgError("taosArrayGet %d SCtgTask failed, total:%d", *taskId, (int32_t)taosArrayGetSize(pJob->pTasks));
×
UNCOV
76
      CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
×
77
    }
78

79
    if (msgNum > 0) {
107,408,563✔
80
      pRsp = taosArrayGet(batchRsp.pRsps, i);
107,343,814✔
81

82
      if (pRsp->msgIdx != *msgIdx) {
107,343,710✔
83
        ctgError("rsp msgIdx %d mis-match msgIdx %d", pRsp->msgIdx, *msgIdx);
×
84

85
        pRsp = &rsp;
×
86
        pRsp->msgIdx = *msgIdx;
×
87
        pRsp->reqType = -1;
×
88
        pRsp->rspCode = 0;
×
89
        taskMsg.msgType = -1;
×
90
        taskMsg.pData = NULL;
×
91
        taskMsg.len = 0;
×
92
      } else {
93
        taskMsg.msgType = pRsp->reqType;
107,341,649✔
94
        taskMsg.pData = pRsp->msg;
107,343,778✔
95
        taskMsg.len = pRsp->msgLen;
107,342,458✔
96
      }
97
    } else {
98
      pRsp = &rsp;
64,749✔
99
      pRsp->msgIdx = *msgIdx;
64,749✔
100
      pRsp->reqType = -1;
64,749✔
101
      pRsp->rspCode = 0;
64,749✔
102
      taskMsg.msgType = -1;
64,749✔
103
      taskMsg.pData = NULL;
64,749✔
104
      taskMsg.len = 0;
64,749✔
105
    }
106

107
    SCtgTaskReq tReq;
106,135,101✔
108
    tReq.pTask = pTask;
107,408,792✔
109
    tReq.msgIdx = pRsp->msgIdx;
107,408,792✔
110
    SCtgMsgCtx* pMsgCtx = CTG_GET_TASK_MSGCTX(pTask, tReq.msgIdx);
107,410,682✔
111
    if (NULL == pMsgCtx) {
107,405,292✔
112
      ctgError("task:%d, get SCtgMsgCtx failed, taskType:%d", tReq.msgIdx, pTask->type);
×
113
      CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
×
114
    }
115

116
    pMsgCtx->pBatchs = pBatchs;
107,405,292✔
117

118
    ctgDebug("QID:0x%" PRIx64 ", catalog task:%d handle rsp:%s, idx:%d pBatchs:%p", pJob->queryId, pTask->taskId,
107,408,831✔
119
             TMSG_INFO(taskMsg.msgType + 1), pRsp->msgIdx, pBatchs);
120

121
    (void)(*gCtgAsyncFps[pTask->type].handleRspFp)(
213,550,429✔
122
        &tReq, pRsp->reqType, &taskMsg, (pRsp->rspCode ? pRsp->rspCode : rspCode));  // error handled internal
107,410,651✔
123
  }
124

125
  CTG_ERR_JRET(ctgLaunchBatchs(pJob->pCtg, pJob, pBatchs));
67,381,496✔
126

127
_return:
67,380,873✔
128

129
  taosArrayDestroyEx(batchRsp.pRsps, tFreeSBatchRspMsg);
67,380,947✔
130

131
  ctgFreeBatchs(pBatchs);
67,380,910✔
132
  CTG_RET(code);
67,380,871✔
133
}
134

135
int32_t ctgProcessRspMsg(void* out, int32_t reqType, char* msg, int32_t msgSize, int32_t rspCode, char* target) {
115,296,963✔
136
  int32_t code = 0;
115,296,963✔
137

138
  switch (reqType) {
115,296,963✔
139
    case TDMT_MND_QNODE_LIST: {
50,492✔
140
      if (TSDB_CODE_SUCCESS != rspCode) {
50,492✔
141
        qError("error rsp for qnode list, error:%s", tstrerror(rspCode));
×
142
        CTG_ERR_RET(rspCode);
×
143
      }
144

145
      code = queryProcessMsgRsp[TMSG_INDEX(reqType)](out, msg, msgSize);
50,492✔
146
      if (code) {
50,492✔
147
        qError("process qnode list rsp failed, error:%s", tstrerror(rspCode));
×
148
        CTG_ERR_RET(code);
×
149
      }
150

151
      qDebug("got qnode list from mnode, listNum:%d", (int32_t)taosArrayGetSize(out));
50,492✔
152
      break;
50,492✔
153
    }
154
    case TDMT_MND_DNODE_LIST: {
43,843✔
155
      if (TSDB_CODE_SUCCESS != rspCode) {
43,843✔
156
        qError("error rsp for dnode list, error:%s", tstrerror(rspCode));
×
157
        CTG_ERR_RET(rspCode);
×
158
      }
159

160
      code = queryProcessMsgRsp[TMSG_INDEX(reqType)](out, msg, msgSize);
43,843✔
161
      if (code) {
43,843✔
162
        qError("process dnode list rsp failed, error:%s", tstrerror(rspCode));
×
163
        CTG_ERR_RET(code);
×
164
      }
165

166
      qDebug("got dnode list from mnode, listNum:%d", (int32_t)taosArrayGetSize(*(SArray**)out));
43,843✔
167
      break;
43,843✔
168
    }
169
    case TDMT_MND_USE_DB: {
24,816,916✔
170
      if (TSDB_CODE_SUCCESS != rspCode) {
24,816,916✔
171
        qError("db:%s, error rsp for use db, error:%s", target, tstrerror(rspCode));
110,078✔
172
        CTG_ERR_RET(rspCode);
110,078✔
173
      }
174

175
      code = queryProcessMsgRsp[TMSG_INDEX(reqType)](out, msg, msgSize);
24,706,838✔
176
      if (code) {
24,706,877✔
177
        qError("db:%s, process use db rsp failed, error:%s", target, tstrerror(code));
×
178
        CTG_ERR_RET(code);
×
179
      }
180

181
      qDebug("db:%s, got db vgInfo from mnode", target);
24,706,877✔
182
      break;
24,706,877✔
183
    }
184
    case TDMT_MND_GET_DB_CFG: {
5,335,854✔
185
      if (TSDB_CODE_SUCCESS != rspCode) {
5,335,854✔
186
        qError("db:%s, error rsp for get db cfg, error:%s", target, tstrerror(rspCode));
581,420✔
187
        CTG_ERR_RET(rspCode);
581,420✔
188
      }
189

190
      code = queryProcessMsgRsp[TMSG_INDEX(reqType)](out, msg, msgSize);
4,754,434✔
191
      if (code) {
4,754,434✔
192
        qError("db:%s, process get db cfg rsp failed, error:%s", target, tstrerror(code));
×
193
        CTG_ERR_RET(code);
×
194
      }
195

196
      qDebug("db:%s, got db cfg from mnode", target);
4,754,434✔
197
      break;
4,754,434✔
198
    }
199
    case TDMT_MND_GET_INDEX: {
96✔
200
      if (TSDB_CODE_SUCCESS != rspCode) {
96✔
201
        qError("index:%s, error rsp for get index, error:%s", target, tstrerror(rspCode));
96✔
202
        CTG_ERR_RET(rspCode);
96✔
203
      }
204

205
      code = queryProcessMsgRsp[TMSG_INDEX(reqType)](out, msg, msgSize);
×
206
      if (code) {
×
207
        qError("index:%s, process get index rsp failed, error:%s", target, tstrerror(code));
×
208
        CTG_ERR_RET(code);
×
209
      }
210

211
      qDebug("index:%s, got index from mnode", target);
×
212
      break;
×
213
    }
214
    case TDMT_MND_GET_TABLE_INDEX: {
96✔
215
      if (TSDB_CODE_SUCCESS != rspCode) {
96✔
216
        qError("tb:%s, error rsp for get table index, error:%s", target, tstrerror(rspCode));
×
217
        CTG_ERR_RET(rspCode);
×
218
      }
219

220
      code = queryProcessMsgRsp[TMSG_INDEX(reqType)](out, msg, msgSize);
96✔
221
      if (code) {
96✔
222
        qError("tb:%s, process get table index rsp failed, error:%s", target, tstrerror(code));
×
223
        CTG_ERR_RET(code);
×
224
      }
225

226
      qDebug("tb:%s, got table index from mnode", target);
96✔
227
      break;
96✔
228
    }
229
    case TDMT_MND_RETRIEVE_FUNC: {
151,694✔
230
      if (TSDB_CODE_SUCCESS != rspCode) {
151,694✔
231
        qError("func:%s, error rsp for get udf, error:%s", target, tstrerror(rspCode));
6,759✔
232
        CTG_ERR_RET(rspCode);
6,759✔
233
      }
234

235
      code = queryProcessMsgRsp[TMSG_INDEX(reqType)](out, msg, msgSize);
144,935✔
236
      if (code) {
144,935✔
237
        qError("func:%s, Process get udf rsp failed, error:%s", target, tstrerror(code));
×
238
        CTG_ERR_RET(code);
×
239
      }
240

241
      qDebug("func:%s, got udf from mnode", target);
144,935✔
242
      break;
144,935✔
243
    }
244
    case TDMT_MND_GET_USER_AUTH: {
6,434,509✔
245
      if (TSDB_CODE_SUCCESS != rspCode) {
6,434,509✔
246
        qError("user:%s, error rsp for get user auth, error:%s", target, tstrerror(rspCode));
1,206✔
247
        CTG_ERR_RET(rspCode);
1,206✔
248
      }
249

250
      code = queryProcessMsgRsp[TMSG_INDEX(reqType)](out, msg, msgSize);
6,433,303✔
251
      if (code) {
6,433,187✔
252
        qError("user:%s, process get user auth rsp failed, error:%s", target, tstrerror(code));
×
253
        CTG_ERR_RET(code);
×
254
      }
255

256
      qDebug("user:%s, got user auth from mnode", target);
6,433,187✔
257
      break;
6,433,303✔
258
    }
259
    case TDMT_MND_TABLE_META: {
19,088,532✔
260
      if (TSDB_CODE_SUCCESS != rspCode) {
19,088,532✔
261
        if (CTG_TABLE_NOT_EXIST(rspCode)) {
948,875✔
262
          SET_META_TYPE_NULL(((STableMetaOutput*)out)->metaType);
943,539✔
263
          qDebug("tb:%s, stablemeta not exist in mnode", target);
943,539✔
264
          return TSDB_CODE_SUCCESS;
943,525✔
265
        }
266

267
        qError("tb:%s, error rsp for stablemeta from mnode, error:%s", target, tstrerror(rspCode));
5,336✔
268
        CTG_ERR_RET(rspCode);
5,336✔
269
      }
270

271
      code = queryProcessMsgRsp[TMSG_INDEX(reqType)](out, msg, msgSize);
18,139,657✔
272
      if (code) {
18,139,724✔
273
        qError("tb:%s, process mnode stablemeta rsp failed, error:%s", target, tstrerror(code));
×
274
        CTG_ERR_RET(code);
×
275
      }
276

277
      qDebug("tb:%s, got table meta from mnode", target);
18,139,724✔
278
      break;
18,139,724✔
279
    }
280
    case TDMT_VND_TABLE_META: {
30,766,419✔
281
      if (TSDB_CODE_SUCCESS != rspCode) {
30,766,419✔
282
        if (CTG_TABLE_NOT_EXIST(rspCode)) {
9,792,388✔
283
          SET_META_TYPE_NULL(((STableMetaOutput*)out)->metaType);
9,792,388✔
284
          qDebug("tb:%s, tablemeta not exist in vnode", target);
9,792,388✔
285
          return TSDB_CODE_SUCCESS;
9,792,388✔
286
        }
287

288
        qError("tb:%s, error rsp for table meta from vnode, code:%s", target, tstrerror(rspCode));
×
289
        CTG_ERR_RET(rspCode);
×
290
      }
291

292
      code = queryProcessMsgRsp[TMSG_INDEX(reqType)](out, msg, msgSize);
20,974,031✔
293
      if (code) {
20,974,031✔
294
        qError("tb:%s, process vnode tablemeta rsp failed, code:%s", target, tstrerror(code));
×
295
        CTG_ERR_RET(code);
×
296
      }
297

298
      qDebug("tb:%s, got table meta from vnode", target);
20,974,031✔
299
      break;
20,974,031✔
300
    }
301
    case TDMT_VND_TABLE_NAME: {
266,952✔
302
      if (TSDB_CODE_SUCCESS != rspCode) {
266,952✔
303
        if (CTG_TABLE_NOT_EXIST(rspCode)) {
96,180✔
304
          SET_META_TYPE_NULL(((STableMetaOutput*)out)->metaType);
96,180✔
305
          qDebug("tb:%s, tablemeta not exist in vnode", target);
96,180✔
306
          return TSDB_CODE_SUCCESS;
96,180✔
307
        }
308

309
        qError("tb:%s, error rsp for table meta from vnode, code:%s", target, tstrerror(rspCode));
×
310
        CTG_ERR_RET(rspCode);
×
311
      }
312

313
      code = queryProcessMsgRsp[TMSG_INDEX(reqType)](out, msg, msgSize);
170,772✔
314
      if (code) {
170,772✔
315
        qError("tb:%s, process vnode tablemeta rsp failed, code:%s", target, tstrerror(code));
×
316
        CTG_ERR_RET(code);
×
317
      }
318

319
      qDebug("tb:%s, got table meta from vnode", target);
170,772✔
320
      break;
170,772✔
321
    }
322
    case TDMT_VND_TABLE_CFG: {
65,046✔
323
      if (TSDB_CODE_SUCCESS != rspCode) {
65,046✔
324
        qError("tb:%s, error rsp for table cfg from vnode, code:%s,", target, tstrerror(rspCode));
×
325
        CTG_ERR_RET(rspCode);
×
326
      }
327

328
      code = queryProcessMsgRsp[TMSG_INDEX(reqType)](out, msg, msgSize);
65,046✔
329
      if (code) {
65,046✔
330
        qError("tb:%s, process vnode tb cfg rsp failed, code:%s", target, tstrerror(code));
×
331
        CTG_ERR_RET(code);
×
332
      }
333

334
      qDebug("tb:%s, got table cfg from vnode", target);
65,046✔
335
      break;
65,046✔
336
    }
337
    case TDMT_MND_TABLE_CFG: {
34,140✔
338
      if (TSDB_CODE_SUCCESS != rspCode) {
34,140✔
339
        qError("tb:%s, error rsp for stb cfg from mnode, error:%s", target, tstrerror(rspCode));
×
340
        CTG_ERR_RET(rspCode);
×
341
      }
342

343
      code = queryProcessMsgRsp[TMSG_INDEX(reqType)](out, msg, msgSize);
34,140✔
344
      if (code) {
34,140✔
345
        qError("tb:%s, Process mnode stb cfg rsp failed, error:%s", target, tstrerror(code));
×
346
        CTG_ERR_RET(code);
×
347
      }
348

349
      qDebug("tb:%s, got stb cfg from mnode", target);
34,140✔
350
      break;
34,140✔
351
    }
352
    case TDMT_MND_SERVER_VERSION: {
96✔
353
      if (TSDB_CODE_SUCCESS != rspCode) {
96✔
354
        qError("error rsp for svr ver from mnode, error:%s", tstrerror(rspCode));
×
355
        CTG_ERR_RET(rspCode);
×
356
      }
357

358
      code = queryProcessMsgRsp[TMSG_INDEX(reqType)](out, msg, msgSize);
96✔
359
      if (code) {
96✔
360
        qError("process svr ver rsp failed, error:%s", tstrerror(code));
×
361
        CTG_ERR_RET(code);
×
362
      }
363

364
      qDebug("got svr ver from mnode");
96✔
365
      break;
96✔
366
    }
367
    case TDMT_MND_VIEW_META: {
19,753,217✔
368
      if (TSDB_CODE_SUCCESS != rspCode) {
19,753,217✔
369
        if (TSDB_CODE_MND_VIEW_NOT_EXIST == rspCode) {
19,506,181✔
370
          qDebug("no success rsp for get view-meta, error:%s, viewFName:%s", tstrerror(rspCode), target);
19,506,181✔
371
        } else {
372
          qError("error rsp for get view-meta, error:%s, viewFName:%s", tstrerror(rspCode), target);
×
373
        }
374
        CTG_ERR_RET(rspCode);
19,506,181✔
375
      }
376

377
      code = queryProcessMsgRsp[TMSG_INDEX(reqType)](out, msg, msgSize);
247,036✔
378
      if (code) {
247,036✔
379
        qError("view:%s, process get view-meta rsp failed, error:%s", target, tstrerror(code));
×
380
        CTG_ERR_RET(code);
×
381
      }
382

383
      qDebug("view:%s, got view-meta from mnode", target);
247,036✔
384
      break;
247,036✔
385
    }
386
    case TDMT_MND_GET_TSMA:
13,104✔
387
    case TDMT_MND_GET_TABLE_TSMA: {
388
      if (TSDB_CODE_SUCCESS != rspCode) {
13,104✔
389
        if (TSDB_CODE_MND_SMA_NOT_EXIST != rspCode) {
7,476✔
390
          qError("tb:%s, error rsp for get table tsma, error:%s", target, tstrerror(rspCode));
5,719✔
391
        }
392
        CTG_ERR_RET(rspCode);
7,476✔
393
      }
394

395
      code = queryProcessMsgRsp[TMSG_INDEX(reqType)](out, msg, msgSize);
5,628✔
396
      if (code) {
5,628✔
397
        qError("tb:%s, process get table tsma rsp failed, error:%s", target, tstrerror(code));
×
398
        CTG_ERR_RET(code);
×
399
      }
400

401
      qDebug("tb:%s, got table tsma from mnode", target);
5,628✔
402
      break;
5,628✔
403
    }
404
    case TDMT_MND_GET_STREAM_PROGRESS: {
6,251✔
405
      if (TSDB_CODE_SUCCESS != rspCode) {
6,251✔
406
        CTG_ERR_RET(rspCode);
×
407
      }
408
      code = queryProcessMsgRsp[TMSG_INDEX(reqType)](out, msg, msgSize);
6,251✔
409
      if (code) {
6,251✔
410
        qError("tb:%s, process get stream progress rsp failed, error:%s", target, tstrerror(code));
×
411
        CTG_ERR_RET(code);
×
412
      }
413
      break;
6,251✔
414
    }
415
    case TDMT_VND_VSTB_REF_DBS: {
8,381,150✔
416
      if (TSDB_CODE_SUCCESS != rspCode) {
8,381,150✔
417
        CTG_ERR_RET(rspCode);
×
418
      }
419
      code = queryProcessMsgRsp[TMSG_INDEX(reqType)](out, msg, msgSize);
8,381,150✔
420
      if (code) {
8,375,433✔
421
        qError("Process get vnode virtual subtable ref dbs rsp failed, err: %s, tbFName: %s", tstrerror(code), target);
×
422
        CTG_ERR_RET(code);
609✔
423
      }
424
      break;
8,376,042✔
425
    }
426
    case TDMT_MND_GET_RSMA: {
24,423✔
427
      if (TSDB_CODE_SUCCESS != rspCode) {
24,423✔
428
        CTG_ERR_RET(rspCode);
5,390✔
429
      }
430
      code = queryProcessMsgRsp[TMSG_INDEX(reqType)](out, msg, msgSize);
19,033✔
431
      if (code) {
19,033✔
432
        qError("Process get mnode rsma info rsp failed, err: %s, name: %s", tstrerror(code), target);
×
433
        CTG_ERR_RET(code);
×
434
      }
435
      break;
19,033✔
436
    }
437
    default:
64,133✔
438
      if (TSDB_CODE_SUCCESS != rspCode) {
64,133✔
439
        qError("get error rsp, error:%s", tstrerror(rspCode));
64,749✔
440
        CTG_ERR_RET(rspCode);
64,749✔
441
      }
442

443
      qError("invalid req type %s", TMSG_INFO(reqType));
×
444
      return TSDB_CODE_APP_ERROR;
×
445
  }
446

447
  return TSDB_CODE_SUCCESS;
84,171,779✔
448
}
449

450
int32_t ctgHandleMsgCallback(void* param, SDataBuf* pMsg, int32_t rspCode) {
67,380,244✔
451
  SCtgTaskCallbackParam* cbParam = (SCtgTaskCallbackParam*)param;
67,380,244✔
452
  int32_t                code = 0;
67,380,244✔
453
  SCtgJob*               pJob = NULL;
67,380,244✔
454

455
  CTG_API_JENTER();
67,380,244✔
456

457
  pJob = taosAcquireRef(gCtgMgmt.jobPool, cbParam->refId);
67,379,657✔
458
  if (NULL == pJob) {
67,380,947✔
459
    qDebug("catalog job refId 0x%" PRIx64 " already dropped", cbParam->refId);
×
460
    goto _return;
×
461
  }
462

463
  SCatalog* pCtg = pJob->pCtg;
67,380,947✔
464

465
  if (TDMT_VND_BATCH_META == cbParam->reqType || TDMT_MND_BATCH_META == cbParam->reqType || TDMT_SND_BATCH_META == cbParam->reqType) {
67,380,371✔
466
    CTG_ERR_JRET(ctgHandleBatchRsp(pJob, cbParam, pMsg, rspCode));
67,380,371✔
467
  } else {
468
    int32_t* taskId = taosArrayGet(cbParam->taskId, 0);
×
469
    if (NULL == taskId) {
×
470
      ctgError("taosArrayGet %d taskId failed, total:%d", 0, (int32_t)taosArrayGetSize(cbParam->taskId));
×
471
      CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
×
472
    }
473

474
    SCtgTask* pTask = taosArrayGet(pJob->pTasks, *taskId);
×
475
    if (NULL == pTask) {
×
476
      ctgError("taosArrayGet %d SCtgTask failed, total:%d", *taskId, (int32_t)taosArrayGetSize(pJob->pTasks));
×
477
      CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
×
478
    }
479

480
    qDebug("QID:0x%" PRIx64 ", catalog task:%d handle rsp:%s", pJob->queryId, pTask->taskId,
×
481
           TMSG_INFO(cbParam->reqType + 1));
482

483
#if CTG_BATCH_FETCH
484
    SHashObj* pBatchs =
485
        taosHashInit(CTG_DEFAULT_BATCH_NUM, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK);
×
486
    if (NULL == pBatchs) {
×
487
      ctgError("taosHashInit %d batch failed", CTG_DEFAULT_BATCH_NUM);
×
488
      CTG_ERR_JRET(terrno);
×
489
    }
490

491
    SCtgMsgCtx* pMsgCtx = CTG_GET_TASK_MSGCTX(pTask, -1);
×
492
    if (NULL == pMsgCtx) {
×
493
      ctgError("task:%d, get SCtgMsgCtx failed, taskType:%d", -1, pTask->type);
×
494
      CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
×
495
    }
496

497
    pMsgCtx->pBatchs = pBatchs;
×
498
#endif
499

500
    SCtgTaskReq tReq;
×
501
    tReq.pTask = pTask;
×
502
    tReq.msgIdx = -1;
×
503

504
    CTG_ERR_JRET((*gCtgAsyncFps[pTask->type].handleRspFp)(&tReq, cbParam->reqType, pMsg, rspCode));
×
505

506
#if CTG_BATCH_FETCH
507
    CTG_ERR_JRET(ctgLaunchBatchs(pJob->pCtg, pJob, pBatchs));
×
508
#endif
509
  }
510

511
_return:
67,380,910✔
512

513
  taosMemoryFree(pMsg->pData);
67,380,910✔
514
  taosMemoryFree(pMsg->pEpSet);
67,380,947✔
515

516
  if (pJob) {
67,380,863✔
517
    int32_t code2 = taosReleaseRef(gCtgMgmt.jobPool, cbParam->refId);
67,380,863✔
518
    if (code2) {
67,380,947✔
519
      qError("release catalog job refId:%" PRId64 " failed, error:%s", cbParam->refId, tstrerror(code2));
×
520
    }
521
  }
522

523
  CTG_API_LEAVE(code);
67,380,910✔
524
}
525

526
int32_t ctgMakeMsgSendInfo(SCtgJob* pJob, SArray* pTaskId, int32_t batchId, SArray* pMsgIdx, int32_t msgType,
67,380,709✔
527
                           SMsgSendInfo** pMsgSendInfo) {
528
  int32_t       code = 0;
67,380,709✔
529
  SMsgSendInfo* msgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo));
67,380,709✔
530
  if (NULL == msgSendInfo) {
67,380,739✔
531
    qError("calloc %d failed", (int32_t)sizeof(SMsgSendInfo));
×
532
    CTG_ERR_JRET(terrno);
×
533
  }
534

535
  SCtgTaskCallbackParam* param = taosMemoryCalloc(1, sizeof(SCtgTaskCallbackParam));
67,380,739✔
536
  if (NULL == param) {
67,380,858✔
537
    qError("calloc %d failed", (int32_t)sizeof(SCtgTaskCallbackParam));
×
538
    taosMemoryFree(msgSendInfo);
×
539
    CTG_ERR_JRET(terrno);
×
540
  }
541

542
  param->reqType = msgType;
67,380,858✔
543
  param->queryId = pJob->queryId;
67,380,897✔
544
  param->refId = pJob->refId;
67,380,880✔
545
  param->taskId = pTaskId;
67,380,314✔
546
  param->batchId = batchId;
67,380,858✔
547
  param->msgIdx = pMsgIdx;
67,380,858✔
548

549
  msgSendInfo->param = param;
67,380,701✔
550
  msgSendInfo->paramFreeFp = ctgFreeMsgSendParam;
67,380,758✔
551
  msgSendInfo->fp = ctgHandleMsgCallback;
67,380,836✔
552

553
  *pMsgSendInfo = msgSendInfo;
67,380,811✔
554

555
  return TSDB_CODE_SUCCESS;
67,380,755✔
556

557
_return:
×
558

559
  taosArrayDestroy(pTaskId);
×
560
  destroySendMsgInfo(msgSendInfo);
×
561

562
  CTG_RET(code);
×
563
}
564

565
int32_t ctgAsyncSendMsg(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgJob* pJob, SArray* pTaskId, int32_t batchId,
67,380,722✔
566
                        SArray* pMsgIdx, char* dbFName, int32_t vgId, int32_t msgType, void** msg, uint32_t msgSize) {
567
  int32_t       code = 0;
67,380,722✔
568
  SMsgSendInfo* pMsgSendInfo = NULL;
67,380,722✔
569
  CTG_ERR_JRET(ctgMakeMsgSendInfo(pJob, pTaskId, batchId, pMsgIdx, msgType, &pMsgSendInfo));
67,380,759✔
570

571
  CTG_ERR_JRET(ctgUpdateSendTargetInfo(pMsgSendInfo, msgType, dbFName, vgId));
67,380,739✔
572

573
  pMsgSendInfo->requestId = pConn->requestId;
67,380,779✔
574
  pMsgSendInfo->requestObjRefId = pConn->requestObjRefId;
67,380,858✔
575
  pMsgSendInfo->msgInfo.pData = *msg;
67,380,799✔
576
  pMsgSendInfo->msgInfo.len = msgSize;
67,380,763✔
577
  pMsgSendInfo->msgInfo.handle = NULL;
67,380,727✔
578
  pMsgSendInfo->msgType = msgType;
67,380,858✔
579
  *msg = NULL;
67,380,827✔
580

581
  code = asyncSendMsgToServer(pConn->pTrans, &pConn->mgmtEps, NULL, pMsgSendInfo);
67,380,934✔
582
  pMsgSendInfo = NULL;
67,380,947✔
583
  if (code) {
67,380,947✔
584
    ctgError("asyncSendMsgToSever failed, error: %s", tstrerror(code));
×
585
    CTG_ERR_JRET(code);
×
586
  }
587

588
  ctgDebug("QID:0x%" PRIx64 ", catalog req msg sent, type:%s", pJob->queryId, TMSG_INFO(msgType));
67,380,947✔
589
  return TSDB_CODE_SUCCESS;
67,380,910✔
590

591
_return:
×
592

593
  if (pMsgSendInfo) {
×
594
    // msg will be freed outside.
595
    destroySendMsgInfo(pMsgSendInfo);
×
596
  }
597

598
  CTG_RET(code);
×
599
}
600

601
int32_t ctgAddBatch(SCatalog* pCtg, int32_t vgId, SRequestConnInfo* pConn, SCtgTaskReq* tReq, int32_t msgType,
107,409,992✔
602
                    void* msg, uint32_t msgSize) {
603
  int32_t     code = 0;
107,409,992✔
604
  SCtgTask*   pTask = tReq->pTask;
107,409,992✔
605
  SCtgJob*    pJob = pTask->pJob;
107,410,617✔
606
  SCtgBatch   newBatch = {0};
107,410,612✔
607
  SBatchMsg   req = {0};
107,410,699✔
608
  bool        toSnode = false;
107,410,699✔
609
  SCtgMsgCtx* pMsgCtx = CTG_GET_TASK_MSGCTX(pTask, tReq->msgIdx);
107,410,699✔
610
  if (NULL == pMsgCtx) {
107,410,766✔
611
    ctgError("task:%d, get SCtgMsgCtx failed, taskType:%d", tReq->msgIdx, pTask->type);
×
612
    CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
×
613
  }
614

615
  SHashObj*  pBatchs = pMsgCtx->pBatchs;
107,410,766✔
616
  SCtgBatch* pBatch = taosHashGet(pBatchs, &vgId, sizeof(vgId));
107,410,572✔
617
  if (NULL == pBatch) {
107,410,504✔
618
    newBatch.pMsgs = taosArrayInit(pJob->subTaskNum, sizeof(SBatchMsg));
67,380,727✔
619
    newBatch.pTaskIds = taosArrayInit(pJob->subTaskNum, sizeof(int32_t));
67,380,826✔
620
    newBatch.pMsgIdxs = taosArrayInit(pJob->subTaskNum, sizeof(int32_t));
67,380,800✔
621
    if (NULL == newBatch.pMsgs || NULL == newBatch.pTaskIds || NULL == newBatch.pMsgIdxs) {
67,380,667✔
622
      taosArrayDestroy(newBatch.pMsgs);
×
623
      taosArrayDestroy(newBatch.pTaskIds);
×
624
      taosArrayDestroy(newBatch.pMsgIdxs);
×
625
      CTG_ERR_JRET(terrno);
×
626
    }
627

628
    newBatch.conn = *pConn;
67,380,667✔
629

630
    req.msgIdx = tReq->msgIdx;
67,380,672✔
631
    req.msgType = msgType;
67,380,753✔
632
    req.msgLen = msgSize;
67,380,753✔
633
    req.msg = msg;
67,380,753✔
634
    if (NULL == taosArrayPush(newBatch.pMsgs, &req)) {
134,761,576✔
635
      CTG_ERR_JRET(terrno);
×
636
    }
637
    msg = NULL;
67,380,823✔
638
    if (NULL == taosArrayPush(newBatch.pTaskIds, &pTask->taskId)) {
134,761,770✔
639
      CTG_ERR_JRET(terrno);
×
640
    }
641
    if (NULL == taosArrayPush(newBatch.pMsgIdxs, &req.msgIdx)) {
134,761,844✔
642
      CTG_ERR_JRET(terrno);
×
643
    }
644

645
    if (vgId > 0) {
67,380,897✔
646
      SName* pName = NULL;
32,800,890✔
647
      if (TDMT_VND_TABLE_CFG == msgType) {
32,800,890✔
648
        SCtgTbCfgCtx* ctx = (SCtgTbCfgCtx*)pTask->taskCtx;
63,110✔
649
        pName = ctx->pName;
63,110✔
650
      } else if (TDMT_VND_TABLE_META == msgType || TDMT_VND_TABLE_NAME == msgType ||
32,737,780✔
651
                 TDMT_VND_VSTB_REF_DBS == msgType) {
652
        if (CTG_TASK_GET_TB_META_BATCH == pTask->type) {
32,733,657✔
653
          SCtgTbMetasCtx* ctx = (SCtgTbMetasCtx*)pTask->taskCtx;
24,184,994✔
654
          SCtgFetch*      fetch = taosArrayGet(ctx->pFetchs, tReq->msgIdx);
24,184,994✔
655
          CTG_ERR_JRET(ctgGetFetchName(ctx->pNames, fetch, &pName));
24,184,994✔
656
        } else if (CTG_TASK_GET_TB_TSMA == pTask->type) {
8,548,663✔
657
          SCtgTbTSMACtx* pCtx = pTask->taskCtx;
×
658
          SCtgTSMAFetch* pFetch = taosArrayGet(pCtx->pFetches, tReq->msgIdx);
×
659
          STablesReq*    pTbReq = taosArrayGet(pCtx->pNames, pFetch->dbIdx);
×
660
          pName = taosArrayGet(pTbReq->pTables, pFetch->tbIdx);
×
661
          if (NULL == pName) {
×
662
            ctgError("fail to get %d SName, totalTables:%d", pFetch->tbIdx, (int32_t)taosArrayGetSize(pTbReq->pTables));
×
663
            CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
×
664
          }
665
        } else if (CTG_TASK_GET_TB_NAME == pTask->type) {
8,548,663✔
666
          SCtgTbNamesCtx* ctx = (SCtgTbNamesCtx*)pTask->taskCtx;
94,927✔
667
          SCtgFetch*      fetch = taosArrayGet(ctx->pFetchs, tReq->msgIdx);
94,927✔
668
          CTG_ERR_JRET(ctgGetFetchName(ctx->pNames, fetch, &pName));
94,927✔
669
        } else {
670
          SCtgTbMetaCtx* ctx = (SCtgTbMetaCtx*)pTask->taskCtx;
8,453,736✔
671
          pName = ctx->pName;
8,453,736✔
672
        }
673
      } else if (TDMT_MND_GET_STREAM_PROGRESS == msgType) {
4,123✔
674
        SCtgTbTSMACtx* pCtx = pTask->taskCtx;
4,123✔
675
        SCtgTSMAFetch* pFetch = taosArrayGet(pCtx->pFetches, tReq->msgIdx);
4,123✔
676
        if (NULL == pFetch) {
4,123✔
677
          ctgError("fail to get %d SCtgTSMAFetch, totalFetchs:%d", tReq->msgIdx,
×
678
                   (int32_t)taosArrayGetSize(pCtx->pFetches));
679
          CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
×
680
        }
681
        STablesReq* pTbReq = taosArrayGet(pCtx->pNames, pFetch->dbIdx);
4,123✔
682
        if (NULL == pTbReq) {
4,123✔
683
          ctgError("fail to get %d STablesReq, totalTables:%d", pFetch->dbIdx, (int32_t)taosArrayGetSize(pCtx->pNames));
×
684
          CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
×
685
        }
686
        pName = taosArrayGet(pTbReq->pTables, pFetch->tbIdx);
4,123✔
687
        if (NULL == pName) {
4,123✔
688
          ctgError("fail to get %d SName, totalTables:%d", pFetch->tbIdx, (int32_t)taosArrayGetSize(pTbReq->pTables));
×
689
          CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
×
690
        }
691
        toSnode = true;
4,123✔
692
      } else {
693
        ctgError("invalid vnode msgType %d", msgType);
×
694
        CTG_ERR_JRET(TSDB_CODE_APP_ERROR);
×
695
      }
696

697
      (void)tNameGetFullDbName(pName, newBatch.dbFName);
32,800,851✔
698
    }
699

700
    newBatch.msgType = (vgId > 0) ? (toSnode ? TDMT_SND_BATCH_META : TDMT_VND_BATCH_META) : TDMT_MND_BATCH_META;
67,380,762✔
701
    newBatch.batchId = atomic_add_fetch_32(&pJob->batchId, 1);
67,380,762✔
702

703
    if (0 != taosHashPut(pBatchs, &vgId, sizeof(vgId), &newBatch, sizeof(newBatch))) {
67,380,863✔
704
      CTG_ERR_JRET(terrno);
×
705
    }
706

707
    qDebug("QID:0x%" PRIx64 ", job:0x%" PRIx64 ", catalog task:%d, %s req added to batch:%d, target vgId:%d",
67,380,910✔
708
           pTask->pJob->queryId, pTask->pJob->refId, pTask->taskId, TMSG_INFO(msgType), newBatch.batchId, vgId);
709

710
    return TSDB_CODE_SUCCESS;
67,380,897✔
711
  }
712

713
  req.msgIdx = tReq->msgIdx;
40,029,777✔
714
  req.msgType = msgType;
40,029,740✔
715
  req.msgLen = msgSize;
40,029,740✔
716
  req.msg = msg;
40,029,740✔
717
  if (NULL == taosArrayPush(pBatch->pMsgs, &req)) {
80,059,554✔
718
    CTG_ERR_JRET(terrno);
×
719
  }
720
  msg = NULL;
40,029,814✔
721
  if (NULL == taosArrayPush(pBatch->pTaskIds, &pTask->taskId)) {
80,059,476✔
722
    CTG_ERR_JRET(terrno);
×
723
  }
724
  if (NULL == taosArrayPush(pBatch->pMsgIdxs, &req.msgIdx)) {
80,059,555✔
725
    CTG_ERR_JRET(terrno);
×
726
  }
727

728
  if (vgId > 0) {
40,029,893✔
729
    SName* pName = NULL;
5,746,455✔
730
    if (TDMT_VND_TABLE_CFG == msgType) {
5,746,455✔
731
      SCtgTbCfgCtx* ctx = (SCtgTbCfgCtx*)pTask->taskCtx;
1,840✔
732
      pName = ctx->pName;
1,840✔
733
    } else if (TDMT_VND_TABLE_META == msgType || TDMT_VND_TABLE_NAME == msgType ||
5,744,615✔
734
               TDMT_VND_VSTB_REF_DBS == msgType) {
735
      if (CTG_TASK_GET_TB_META_BATCH == pTask->type) {
5,742,487✔
736
        SCtgTbMetasCtx* ctx = (SCtgTbMetasCtx*)pTask->taskCtx;
167,750✔
737
        SCtgFetch*      fetch = taosArrayGet(ctx->pFetchs, tReq->msgIdx);
167,750✔
738
        CTG_ERR_JRET(ctgGetFetchName(ctx->pNames, fetch, &pName));
167,750✔
739
      } else if (CTG_TASK_GET_TB_TSMA == pTask->type) {
5,574,737✔
740
        SCtgTbTSMACtx* pCtx = pTask->taskCtx;
5,614✔
741
        SCtgTSMAFetch* pFetch = taosArrayGet(pCtx->pFetches, tReq->msgIdx);
5,614✔
742
        STablesReq*    pTbReq = taosArrayGet(pCtx->pNames, pFetch->dbIdx);
5,614✔
743
        pName = taosArrayGet(pTbReq->pTables, pFetch->tbIdx);
5,614✔
744
        if (NULL == pName) {
5,614✔
745
          ctgError("fail to get %d SName, totalTables:%d", pFetch->tbIdx, (int32_t)taosArrayGetSize(pTbReq->pTables));
×
746
          CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
×
747
        }
748
      } else if (CTG_TASK_GET_TB_NAME == pTask->type) {
5,569,123✔
749
        SCtgTbMetasCtx* ctx = (SCtgTbMetasCtx*)pTask->taskCtx;
172,025✔
750
        SCtgFetch*      fetch = taosArrayGet(ctx->pFetchs, tReq->msgIdx);
172,025✔
751
        CTG_ERR_JRET(ctgGetFetchName(ctx->pNames, fetch, &pName));
172,025✔
752
      } else {
753
        SCtgTbMetaCtx* ctx = (SCtgTbMetaCtx*)pTask->taskCtx;
5,397,098✔
754
        pName = ctx->pName;
5,397,098✔
755
      }
756
    } else if (TDMT_MND_GET_STREAM_PROGRESS == msgType) {
2,128✔
757
      SCtgTbTSMACtx* pCtx = pTask->taskCtx;
2,128✔
758
      SCtgTSMAFetch* pFetch = taosArrayGet(pCtx->pFetches, tReq->msgIdx);
2,128✔
759
      if (NULL == pFetch) {
2,128✔
760
        ctgError("fail to get %d SCtgTSMAFetch, totalFetchs:%d", tReq->msgIdx,
×
761
                 (int32_t)taosArrayGetSize(pCtx->pFetches));
762
        CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
×
763
      }
764
      STablesReq* pTbReq = taosArrayGet(pCtx->pNames, pFetch->dbIdx);
2,128✔
765
      if (NULL == pTbReq) {
2,128✔
766
        ctgError("fail to get %d STablesReq, totalTables:%d", pFetch->dbIdx, (int32_t)taosArrayGetSize(pCtx->pNames));
×
767
        CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
×
768
      }
769
      pName = taosArrayGet(pTbReq->pTables, pFetch->tbIdx);
2,128✔
770
      if (NULL == pName) {
2,128✔
771
        ctgError("fail to get %d SName, totalTables:%d", pFetch->tbIdx, (int32_t)taosArrayGetSize(pTbReq->pTables));
×
772
        CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
×
773
      }
774
    } else {
775
      ctgError("invalid vnode msgType %d", msgType);
×
776
      CTG_ERR_JRET(TSDB_CODE_APP_ERROR);
×
777
    }
778

779
    (void)tNameGetFullDbName(pName, pBatch->dbFName);
5,746,395✔
780
  }
781

782
  qDebug("QID:0x%" PRIx64 ", job:0x%" PRIx64 ", catalog task:%d, %s req added to batch:%d, target vgId:%d",
40,029,701✔
783
         pTask->pJob->queryId, pTask->pJob->refId, pTask->taskId, TMSG_INFO(msgType), pBatch->batchId, vgId);
784

785
  return TSDB_CODE_SUCCESS;
40,029,804✔
786

787
_return:
327✔
788

789
  ctgFreeBatch(&newBatch);
×
790
  taosMemoryFree(msg);
×
791

792
  return code;
×
793
}
794

795
int32_t ctgBuildBatchReqMsg(SCtgBatch* pBatch, int32_t vgId, void** msg, int32_t* pSize) {
67,380,858✔
796
  int32_t num = taosArrayGetSize(pBatch->pMsgs);
67,380,858✔
797
  if (num >= CTG_MAX_REQ_IN_BATCH) {
67,380,895✔
798
    qError("too many msgs %d in one batch request", num);
×
799
    CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT);
×
800
  }
801

802
  SBatchReq batchReq = {0};
67,380,895✔
803

804
  batchReq.header.vgId = vgId;
67,380,858✔
805
  batchReq.pMsgs = pBatch->pMsgs;
67,380,858✔
806

807
  int32_t msgSize = tSerializeSBatchReq(NULL, 0, &batchReq);
67,380,854✔
808
  if (msgSize < 0) {
67,380,722✔
809
    qError("tSerializeSBatchReq failed");
×
810
    CTG_ERR_RET(msgSize);
×
811
  }
812

813
  *msg = taosMemoryCalloc(1, msgSize);
67,380,722✔
814
  if (NULL == (*msg)) {
67,380,777✔
815
    qError("calloc batchReq msg failed, size:%d", msgSize);
×
816
    CTG_ERR_RET(terrno);
×
817
  }
818
  msgSize = tSerializeSBatchReq(*msg, msgSize, &batchReq);
67,380,777✔
819
  if (msgSize < 0) {
67,380,753✔
820
    taosMemoryFree(*msg);
×
821
    qError("tSerializeSBatchReq failed");
×
822
    CTG_ERR_RET(msgSize);
×
823
  }
824

825
  *pSize = msgSize;
67,380,753✔
826

827
  qTrace("batch:%d, batch req to vgId:%d msg built with %d meta reqs", pBatch->batchId, vgId, num);
67,380,798✔
828

829
  return TSDB_CODE_SUCCESS;
67,380,692✔
830
}
831

832
int32_t ctgLaunchBatchs(SCatalog* pCtg, SCtgJob* pJob, SHashObj* pBatchs) {
532,954,825✔
833
  int32_t code = 0;
532,954,825✔
834
  void*   msg = NULL;
532,954,825✔
835
  void*   p = taosHashIterate(pBatchs, NULL);
532,953,932✔
836
  while (NULL != p) {
600,352,728✔
837
    size_t     len = 0;
67,380,819✔
838
    int32_t*   vgId = taosHashGetKey(p, &len);
67,380,819✔
839
    SCtgBatch* pBatch = (SCtgBatch*)p;
67,380,895✔
840
    int32_t    msgSize = 0;
67,380,895✔
841

842
    qDebug("QID:0x%" PRIx64 ", job:0x%" PRIx64 ", catalog start to launch batch:%d", pJob->queryId, pJob->refId,
67,380,934✔
843
           pBatch->batchId);
844

845
    CTG_ERR_JRET(ctgBuildBatchReqMsg(pBatch, *vgId, &msg, &msgSize));
67,380,934✔
846
    code = ctgAsyncSendMsg(pCtg, &pBatch->conn, pJob, pBatch->pTaskIds, pBatch->batchId, pBatch->pMsgIdxs,
134,050,170✔
847
                           pBatch->dbFName, *vgId, pBatch->msgType, &msg, msgSize);
67,380,669✔
848
    pBatch->pTaskIds = NULL;
67,380,910✔
849
    CTG_ERR_JRET(code);
67,380,910✔
850

851
    p = taosHashIterate(pBatchs, p);
67,380,910✔
852
  }
853

854
  return TSDB_CODE_SUCCESS;
532,971,909✔
855

856
_return:
×
857

858
  if (p) {
×
859
    taosHashCancelIterate(pBatchs, p);
×
860
  }
861
  if (msg) {
×
862
    taosMemoryFree(msg);
×
863
  }
864

865
  CTG_RET(code);
×
866
}
867

868
int32_t ctgGetQnodeListFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, SArray* out, SCtgTask* pTask) {
50,492✔
869
  char*   msg = NULL;
50,492✔
870
  int32_t msgLen = 0;
50,492✔
871
  int32_t reqType = TDMT_MND_QNODE_LIST;
50,492✔
872
  void* (*mallocFp)(int64_t) = pTask ? (MallocType)taosMemMalloc : (MallocType)rpcMallocCont;
50,492✔
873
  void (*freeFp)(void*) = pTask ? taosMemFree : rpcFreeCont;
50,492✔
874

875
  ctgDebug("try to get qnode list from mnode, mgmtEpInUse:%d", pConn->mgmtEps.inUse);
50,492✔
876

877
  int32_t code = queryBuildMsg[TMSG_INDEX(reqType)](NULL, &msg, 0, &msgLen, mallocFp, freeFp);
50,492✔
878
  if (code) {
50,492✔
879
    ctgError("Build qnode list msg failed, error:%s", tstrerror(code));
×
880
    CTG_ERR_RET(code);
×
881
  }
882

883
  if (pTask) {
50,492✔
884
    void* pOut = taosArrayInit(4, sizeof(SQueryNodeLoad));
50,396✔
885
    if (NULL == pOut) {
50,396✔
886
      CTG_ERR_RET(terrno);
×
887
    }
888

889
    CTG_ERR_RET(ctgUpdateMsgCtx(CTG_GET_TASK_MSGCTX(pTask, -1), reqType, pOut, NULL));
50,396✔
890

891
#if CTG_BATCH_FETCH
892
    SCtgTaskReq tReq;
50,396✔
893
    tReq.pTask = pTask;
50,396✔
894
    tReq.msgIdx = -1;
50,396✔
895
    CTG_RET(ctgAddBatch(pCtg, 0, pConn, &tReq, reqType, msg, msgLen));
50,396✔
896
#else
897
    SArray* pTaskId = taosArrayInit(1, sizeof(int32_t));
898
    if (NULL == pTaskId) {
899
      CTG_ERR_RET(terrno);
900
    }
901
    if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) {
902
      taosArrayDestroy(pTaskId);
903
      CTG_ERR_RET(terrno);
904
    }
905

906
    CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen));
907
#endif
908
  }
909

910
  SRpcMsg rpcMsg = {
96✔
911
      .msgType = reqType,
912
      .pCont = msg,
913
      .contLen = msgLen,
914
  };
915

916
  SRpcMsg rpcRsp = {0};
96✔
917
  CTG_ERR_RET(rpcSendRecv(pConn->pTrans, &pConn->mgmtEps, &rpcMsg, &rpcRsp));
96✔
918

919
  CTG_ERR_RET(ctgProcessRspMsg(out, reqType, rpcRsp.pCont, rpcRsp.contLen, rpcRsp.code, NULL));
96✔
920

921
  rpcFreeCont(rpcRsp.pCont);
96✔
922

923
  return TSDB_CODE_SUCCESS;
96✔
924
}
925

926
int32_t ctgGetDnodeListFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, SArray** out, SCtgTask* pTask) {
43,843✔
927
  char*   msg = NULL;
43,843✔
928
  int32_t msgLen = 0;
43,843✔
929
  int32_t reqType = TDMT_MND_DNODE_LIST;
43,843✔
930
  void* (*mallocFp)(int64_t) = pTask ? (MallocType)taosMemMalloc : (MallocType)rpcMallocCont;
43,843✔
931
  void (*freeFp)(void*) = pTask ? taosMemFree : rpcFreeCont;
43,843✔
932

933
  ctgDebug("try to get dnode list from mnode, mgmtEpInUse:%d", pConn->mgmtEps.inUse);
43,843✔
934

935
  int32_t code = queryBuildMsg[TMSG_INDEX(reqType)](NULL, &msg, 0, &msgLen, mallocFp, freeFp);
43,843✔
936
  if (code) {
43,843✔
937
    ctgError("Build dnode list msg failed, error:%s", tstrerror(code));
×
938
    CTG_ERR_RET(code);
×
939
  }
940

941
  if (pTask) {
43,843✔
942
    CTG_ERR_RET(ctgUpdateMsgCtx(CTG_GET_TASK_MSGCTX(pTask, -1), reqType, NULL, NULL));
43,747✔
943

944
#if CTG_BATCH_FETCH
945
    SCtgTaskReq tReq;
43,747✔
946
    tReq.pTask = pTask;
43,747✔
947
    tReq.msgIdx = -1;
43,747✔
948
    CTG_RET(ctgAddBatch(pCtg, 0, pConn, &tReq, reqType, msg, msgLen));
43,747✔
949
#else
950
    SArray* pTaskId = taosArrayInit(1, sizeof(int32_t));
951
    if (NULL == pTaskId) {
952
      CTG_ERR_RET(terrno);
953
    }
954
    if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) {
955
      taosArrayDestroy(pTaskId);
956
      CTG_ERR_RET(terrno);
957
    }
958

959
    CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen));
960
#endif
961
  }
962

963
  SRpcMsg rpcMsg = {
96✔
964
      .msgType = reqType,
965
      .pCont = msg,
966
      .contLen = msgLen,
967
  };
968

969
  SRpcMsg rpcRsp = {0};
96✔
970
  CTG_ERR_RET(rpcSendRecv(pConn->pTrans, &pConn->mgmtEps, &rpcMsg, &rpcRsp));
96✔
971

972
  CTG_ERR_RET(ctgProcessRspMsg(out, reqType, rpcRsp.pCont, rpcRsp.contLen, rpcRsp.code, NULL));
96✔
973

974
  rpcFreeCont(rpcRsp.pCont);
96✔
975

976
  return TSDB_CODE_SUCCESS;
96✔
977
}
978

979
int32_t ctgGetDBVgInfoFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, SBuildUseDBInput* input, SUseDbOutput* out,
24,829,785✔
980
                                SCtgTaskReq* tReq) {
981
  char*     msg = NULL;
24,829,785✔
982
  int32_t   msgLen = 0;
24,829,785✔
983
  int32_t   reqType = TDMT_MND_USE_DB;
24,829,785✔
984
  SCtgTask* pTask = tReq ? tReq->pTask : NULL;
24,829,785✔
985
  void* (*mallocFp)(int64_t) = pTask ? (MallocType)taosMemMalloc : (MallocType)rpcMallocCont;
24,829,824✔
986
  void (*freeFp)(void*) = pTask ? taosMemFree : rpcFreeCont;
24,829,824✔
987

988
  ctgDebug("db:%s, try to get db vgInfo from mnode", input->db);
24,829,824✔
989

990
  int32_t code = queryBuildMsg[TMSG_INDEX(reqType)](input, &msg, 0, &msgLen, mallocFp, freeFp);
24,829,824✔
991
  if (code) {
24,829,824✔
992
    ctgError("db:%s, build use db msg failed, code:%s", input->db, tstrerror(code));
×
993
    CTG_ERR_RET(code);
×
994
  }
995

996
  if (pTask) {
24,829,824✔
997
    void* pOut = taosMemoryCalloc(1, sizeof(SUseDbOutput));
19,055,351✔
998
    if (NULL == pOut) {
19,055,267✔
999
      CTG_ERR_RET(terrno);
×
1000
    }
1001

1002
    CTG_ERR_RET(ctgUpdateMsgCtx(CTG_GET_TASK_MSGCTX(pTask, tReq->msgIdx), reqType, pOut, input->db));
19,055,267✔
1003

1004
#if CTG_BATCH_FETCH
1005
    CTG_RET(ctgAddBatch(pCtg, 0, pConn, tReq, reqType, msg, msgLen));
19,055,309✔
1006
#else
1007
    SArray* pTaskId = taosArrayInit(1, sizeof(int32_t));
1008
    if (NULL == pTaskId) {
1009
      CTG_ERR_RET(terrno);
1010
    }
1011
    if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) {
1012
      taosArrayDestroy(pTaskId);
1013
      CTG_ERR_RET(terrno);
1014
    }
1015

1016
    CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen));
1017
#endif
1018
  }
1019

1020
  SRpcMsg rpcMsg = {
5,774,473✔
1021
      .msgType = reqType,
1022
      .pCont = msg,
1023
      .contLen = msgLen,
1024
  };
1025

1026
  SRpcMsg rpcRsp = {0};
5,774,473✔
1027
  CTG_ERR_RET(rpcSendRecv(pConn->pTrans, &pConn->mgmtEps, &rpcMsg, &rpcRsp));
5,774,473✔
1028

1029
  CTG_ERR_RET(ctgProcessRspMsg(out, reqType, rpcRsp.pCont, rpcRsp.contLen, rpcRsp.code, input->db));
5,774,473✔
1030

1031
  rpcFreeCont(rpcRsp.pCont);
5,774,369✔
1032

1033
  return TSDB_CODE_SUCCESS;
5,774,369✔
1034
}
1035

1036
int32_t ctgGetRsmaMetaFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const char* name, SRsmaMetaOutput* out,
24,423✔
1037
                                SCtgTaskReq* tReq) {
1038
  SCtgTask* pTask = tReq ? tReq->pTask : NULL;
24,423✔
1039
  char*     msg = NULL;
24,423✔
1040
  SEpSet*   pVnodeEpSet = NULL;
24,423✔
1041
  int32_t   msgLen = 0;
24,423✔
1042
  int32_t   reqType = TDMT_MND_GET_RSMA;
24,423✔
1043
  void* (*mallocFp)(int64_t) = pTask ? (MallocType)taosMemMalloc : (MallocType)rpcMallocCont;
24,423✔
1044
  void (*freeFp)(void*) = pTask ? taosMemFree : rpcFreeCont;
24,423✔
1045

1046
  ctgDebug("rsma:%s, try to get rsma info from mnode", name);
24,423✔
1047

1048
  int32_t code = queryBuildMsg[TMSG_INDEX(reqType)]((void*)name, &msg, 0, &msgLen, mallocFp, freeFp);
24,423✔
1049
  if (code) {
24,423✔
1050
    ctgError("rsma:%s, build mnode rsmaInfoReq msg failed, code:%s", name, tstrerror(code));
×
1051
    CTG_ERR_RET(code);
×
1052
  }
1053

1054
  SRpcMsg rpcMsg = {
24,423✔
1055
      .msgType = reqType,
1056
      .pCont = msg,
1057
      .contLen = msgLen,
1058
  };
1059

1060
  SRpcMsg rpcRsp = {0};
24,423✔
1061
  CTG_ERR_RET(rpcSendRecvWithTimeout(pConn->pTrans, &pConn->mgmtEps, &rpcMsg, &rpcRsp, NULL, CATLOG_TIMEOUT));
24,423✔
1062

1063
  code = ctgProcessRspMsg(out, reqType, rpcRsp.pCont, rpcRsp.contLen, rpcRsp.code, (char*)name);
24,423✔
1064

1065
  rpcFreeCont(rpcRsp.pCont);
24,423✔
1066

1067
  return code;
24,423✔
1068
}
1069

1070
int32_t ctgGetDBCfgFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const char* dbFName, SDbCfgInfo* out,
5,335,828✔
1071
                             SCtgTask* pTask) {
1072
  char*   msg = NULL;
5,335,828✔
1073
  int32_t msgLen = 0;
5,335,828✔
1074
  int32_t reqType = TDMT_MND_GET_DB_CFG;
5,335,828✔
1075
  void* (*mallocFp)(int64_t) = pTask ? (MallocType)taosMemMalloc : (MallocType)rpcMallocCont;
5,335,828✔
1076
  void (*freeFp)(void*) = pTask ? taosMemFree : rpcFreeCont;
5,335,828✔
1077

1078
  ctgDebug("db:%s, try to get db cfg from mnode", dbFName);
5,335,828✔
1079

1080
  int32_t code = queryBuildMsg[TMSG_INDEX(reqType)]((void*)dbFName, &msg, 0, &msgLen, mallocFp, freeFp);
5,335,828✔
1081
  if (code) {
5,335,854✔
1082
    ctgError("db:%s, build get db cfg msg failed, code:%s", dbFName, tstrerror(code));
×
1083
    CTG_ERR_RET(code);
×
1084
  }
1085

1086
  if (pTask) {
5,335,854✔
1087
    void* pOut = taosMemoryCalloc(1, sizeof(SDbCfgInfo));
5,335,758✔
1088
    if (NULL == pOut) {
5,335,758✔
1089
      CTG_ERR_RET(terrno);
×
1090
    }
1091

1092
    CTG_ERR_RET(ctgUpdateMsgCtx(CTG_GET_TASK_MSGCTX(pTask, -1), reqType, pOut, (char*)dbFName));
5,335,758✔
1093

1094
#if CTG_BATCH_FETCH
1095
    SCtgTaskReq tReq;
5,267,766✔
1096
    tReq.pTask = pTask;
5,335,758✔
1097
    tReq.msgIdx = -1;
5,335,758✔
1098
    CTG_RET(ctgAddBatch(pCtg, 0, pConn, &tReq, reqType, msg, msgLen));
5,335,758✔
1099
#else
1100
    SArray* pTaskId = taosArrayInit(1, sizeof(int32_t));
1101
    if (NULL == pTaskId) {
1102
      CTG_ERR_RET(terrno);
1103
    }
1104
    if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) {
1105
      taosArrayDestroy(pTaskId);
1106
      CTG_ERR_RET(terrno);
1107
    }
1108

1109
    CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen));
1110
#endif
1111
  }
1112

1113
  SRpcMsg rpcMsg = {
96✔
1114
      .msgType = TDMT_MND_GET_DB_CFG,
1115
      .pCont = msg,
1116
      .contLen = msgLen,
1117
  };
1118

1119
  SRpcMsg rpcRsp = {0};
96✔
1120
  CTG_ERR_RET(rpcSendRecv(pConn->pTrans, &pConn->mgmtEps, &rpcMsg, &rpcRsp));
96✔
1121

1122
  CTG_ERR_RET(ctgProcessRspMsg(out, reqType, rpcRsp.pCont, rpcRsp.contLen, rpcRsp.code, (char*)dbFName));
96✔
1123

1124
  rpcFreeCont(rpcRsp.pCont);
96✔
1125

1126
  return TSDB_CODE_SUCCESS;
96✔
1127
}
1128

1129
int32_t ctgGetIndexInfoFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const char* indexName, SIndexInfo* out,
96✔
1130
                                 SCtgTask* pTask) {
1131
  char*   msg = NULL;
96✔
1132
  int32_t msgLen = 0;
96✔
1133
  int32_t reqType = TDMT_MND_GET_INDEX;
96✔
1134
  void* (*mallocFp)(int64_t) = pTask ? (MallocType)taosMemMalloc : (MallocType)rpcMallocCont;
96✔
1135
  void (*freeFp)(void*) = pTask ? taosMemFree : rpcFreeCont;
96✔
1136

1137
  ctgDebug("index:%s, try to get index from mnode", indexName);
96✔
1138

1139
  int32_t code = queryBuildMsg[TMSG_INDEX(reqType)]((void*)indexName, &msg, 0, &msgLen, mallocFp, freeFp);
96✔
1140
  if (code) {
96✔
1141
    ctgError("index:%s, build get index msg failed, code:%s", indexName, tstrerror(code));
×
1142
    CTG_ERR_RET(code);
×
1143
  }
1144

1145
  if (pTask) {
96✔
1146
    void* pOut = taosMemoryCalloc(1, sizeof(SIndexInfo));
×
1147
    if (NULL == pOut) {
×
1148
      CTG_ERR_RET(terrno);
×
1149
    }
1150

1151
    CTG_ERR_RET(ctgUpdateMsgCtx(CTG_GET_TASK_MSGCTX(pTask, -1), reqType, pOut, (char*)indexName));
×
1152

1153
#if CTG_BATCH_FETCH
1154
    SCtgTaskReq tReq;
×
1155
    tReq.pTask = pTask;
×
1156
    tReq.msgIdx = -1;
×
1157
    CTG_RET(ctgAddBatch(pCtg, 0, pConn, &tReq, reqType, msg, msgLen));
×
1158
#else
1159
    SArray* pTaskId = taosArrayInit(1, sizeof(int32_t));
1160
    if (NULL == pTaskId) {
1161
      CTG_ERR_RET(terrno);
1162
    }
1163
    if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) {
1164
      taosArrayDestroy(pTaskId);
1165
      CTG_ERR_RET(terrno);
1166
    }
1167

1168
    CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen));
1169
#endif
1170
  }
1171

1172
  SRpcMsg rpcMsg = {
96✔
1173
      .msgType = reqType,
1174
      .pCont = msg,
1175
      .contLen = msgLen,
1176
  };
1177

1178
  SRpcMsg rpcRsp = {0};
96✔
1179
  CTG_ERR_RET(rpcSendRecv(pConn->pTrans, &pConn->mgmtEps, &rpcMsg, &rpcRsp));
96✔
1180

1181
  CTG_ERR_RET(ctgProcessRspMsg(out, reqType, rpcRsp.pCont, rpcRsp.contLen, rpcRsp.code, (char*)indexName));
96✔
1182

1183
  rpcFreeCont(rpcRsp.pCont);
×
1184

1185
  return TSDB_CODE_SUCCESS;
×
1186
}
1187

1188
int32_t ctgGetTbIndexFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, SName* name, STableIndex* out,
96✔
1189
                               SCtgTask* pTask) {
1190
  char*   msg = NULL;
96✔
1191
  int32_t msgLen = 0;
96✔
1192
  int32_t reqType = TDMT_MND_GET_TABLE_INDEX;
96✔
1193
  void* (*mallocFp)(int64_t) = pTask ? (MallocType)taosMemMalloc : (MallocType)rpcMallocCont;
96✔
1194
  void (*freeFp)(void*) = pTask ? taosMemFree : rpcFreeCont;
96✔
1195
  char tbFName[TSDB_TABLE_FNAME_LEN];
×
1196

1197
  ctgDebug("tb:%s, try to get tb index from mnode", tbFName);
96✔
1198

1199
  int32_t code = tNameExtractFullName(name, tbFName);
96✔
1200
  if (code) {
96✔
1201
    ctgError("tb:%s, tNameExtractFullName failed, code:%s, type:%d, dbName:%s", name->tname, tstrerror(code),
×
1202
             name->type, name->dbname);
1203
    CTG_ERR_RET(code);
×
1204
  }
1205

1206
  code = queryBuildMsg[TMSG_INDEX(reqType)]((void*)tbFName, &msg, 0, &msgLen, mallocFp, freeFp);
96✔
1207
  if (code) {
96✔
1208
    ctgError("tb:%s, build get index msg failed, code:%s", tbFName, tstrerror(code));
×
1209
    CTG_ERR_RET(code);
×
1210
  }
1211

1212
  if (pTask) {
96✔
1213
    void* pOut = taosMemoryCalloc(1, sizeof(STableIndex));
×
1214
    if (NULL == pOut) {
×
1215
      CTG_ERR_RET(terrno);
×
1216
    }
1217

1218
    CTG_ERR_RET(ctgUpdateMsgCtx(CTG_GET_TASK_MSGCTX(pTask, -1), reqType, pOut, (char*)tbFName));
×
1219

1220
#if CTG_BATCH_FETCH
1221
    SCtgTaskReq tReq;
×
1222
    tReq.pTask = pTask;
×
1223
    tReq.msgIdx = -1;
×
1224
    CTG_RET(ctgAddBatch(pCtg, 0, pConn, &tReq, reqType, msg, msgLen));
×
1225
#else
1226
    SArray* pTaskId = taosArrayInit(1, sizeof(int32_t));
1227
    if (NULL == pTaskId) {
1228
      CTG_ERR_RET(terrno);
1229
    }
1230
    if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) {
1231
      taosArrayDestroy(pTaskId);
1232
      CTG_ERR_RET(terrno);
1233
    }
1234

1235
    CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen));
1236
#endif
1237
  }
1238

1239
  SRpcMsg rpcMsg = {
96✔
1240
      .msgType = reqType,
1241
      .pCont = msg,
1242
      .contLen = msgLen,
1243
  };
1244

1245
  SRpcMsg rpcRsp = {0};
96✔
1246
  CTG_ERR_RET(rpcSendRecv(pConn->pTrans, &pConn->mgmtEps, &rpcMsg, &rpcRsp));
96✔
1247

1248
  CTG_ERR_RET(ctgProcessRspMsg(out, reqType, rpcRsp.pCont, rpcRsp.contLen, rpcRsp.code, (char*)tbFName));
96✔
1249

1250
  rpcFreeCont(rpcRsp.pCont);
96✔
1251

1252
  return TSDB_CODE_SUCCESS;
96✔
1253
}
1254

1255
int32_t ctgGetUdfInfoFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const char* funcName, SFuncInfo* out,
151,694✔
1256
                               SCtgTask* pTask) {
1257
  char*   msg = NULL;
151,694✔
1258
  int32_t msgLen = 0;
151,694✔
1259
  int32_t reqType = TDMT_MND_RETRIEVE_FUNC;
151,694✔
1260
  void* (*mallocFp)(int64_t) = pTask ? (MallocType)taosMemMalloc : (MallocType)rpcMallocCont;
151,694✔
1261
  void (*freeFp)(void*) = pTask ? taosMemFree : rpcFreeCont;
151,694✔
1262

1263
  ctgDebug("func:%s, try to get udf info from mnode", funcName);
151,694✔
1264

1265
  int32_t code = queryBuildMsg[TMSG_INDEX(reqType)]((void*)funcName, &msg, 0, &msgLen, mallocFp, freeFp);
151,694✔
1266
  if (code) {
151,694✔
1267
    ctgError("func:%s, build get udf msg failed, code:%s", funcName, tstrerror(code));
×
1268
    CTG_ERR_RET(code);
×
1269
  }
1270

1271
  if (pTask) {
151,694✔
1272
    void* pOut = taosMemoryCalloc(1, sizeof(SFuncInfo));
151,598✔
1273
    if (NULL == pOut) {
151,598✔
1274
      CTG_ERR_RET(terrno);
×
1275
    }
1276

1277
    CTG_ERR_RET(ctgUpdateMsgCtx(CTG_GET_TASK_MSGCTX(pTask, -1), reqType, pOut, (char*)funcName));
151,598✔
1278

1279
#if CTG_BATCH_FETCH
1280
    SCtgTaskReq tReq;
84,430✔
1281
    tReq.pTask = pTask;
151,598✔
1282
    tReq.msgIdx = -1;
151,598✔
1283
    CTG_RET(ctgAddBatch(pCtg, 0, pConn, &tReq, reqType, msg, msgLen));
151,598✔
1284
#else
1285
    SArray* pTaskId = taosArrayInit(1, sizeof(int32_t));
1286
    if (NULL == pTaskId) {
1287
      CTG_ERR_RET(terrno);
1288
    }
1289
    if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) {
1290
      taosArrayDestroy(pTaskId);
1291
      CTG_ERR_RET(terrno);
1292
    }
1293

1294
    CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen));
1295
#endif
1296
  }
1297

1298
  SRpcMsg rpcMsg = {
96✔
1299
      .msgType = reqType,
1300
      .pCont = msg,
1301
      .contLen = msgLen,
1302
  };
1303

1304
  SRpcMsg rpcRsp = {0};
96✔
1305
  CTG_ERR_RET(rpcSendRecv(pConn->pTrans, &pConn->mgmtEps, &rpcMsg, &rpcRsp));
96✔
1306

1307
  CTG_ERR_RET(ctgProcessRspMsg(out, reqType, rpcRsp.pCont, rpcRsp.contLen, rpcRsp.code, (char*)funcName));
96✔
1308

1309
  rpcFreeCont(rpcRsp.pCont);
96✔
1310

1311
  return TSDB_CODE_SUCCESS;
96✔
1312
}
1313

1314
int32_t ctgGetUserDbAuthFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const char* user, SGetUserAuthRsp* out,
6,433,903✔
1315
                                  SCtgTask* pTask) {
1316
  char*   msg = NULL;
6,433,903✔
1317
  int32_t msgLen = 0;
6,434,483✔
1318
  int32_t reqType = TDMT_MND_GET_USER_AUTH;
6,434,483✔
1319
  void* (*mallocFp)(int64_t) = pTask ? (MallocType)taosMemMalloc : (MallocType)rpcMallocCont;
6,434,483✔
1320
  void (*freeFp)(void*) = pTask ? taosMemFree : rpcFreeCont;
6,434,483✔
1321

1322
  ctgDebug("user:%s, try to get user auth from mnode", user);
6,434,483✔
1323

1324
  int32_t code = queryBuildMsg[TMSG_INDEX(reqType)]((void*)user, &msg, 0, &msgLen, mallocFp, freeFp);
6,434,483✔
1325
  if (code) {
6,434,509✔
1326
    ctgError("user:%s, build get user auth msg failed, code:%s", user, tstrerror(code));
×
1327
    CTG_ERR_RET(code);
×
1328
  }
1329

1330
  if (pTask) {
6,434,509✔
1331
    void* pOut = taosMemoryCalloc(1, sizeof(SGetUserAuthRsp));
6,423,307✔
1332
    if (NULL == pOut) {
6,423,307✔
1333
      CTG_ERR_RET(terrno);
×
1334
    }
1335

1336
    CTG_ERR_RET(ctgUpdateMsgCtx(CTG_GET_TASK_MSGCTX(pTask, -1), reqType, pOut, (char*)user));
6,423,307✔
1337

1338
#if CTG_BATCH_FETCH
1339
    SCtgTaskReq tReq;
6,393,995✔
1340
    tReq.pTask = pTask;
6,423,307✔
1341
    tReq.msgIdx = -1;
6,423,307✔
1342
    CTG_RET(ctgAddBatch(pCtg, 0, pConn, &tReq, reqType, msg, msgLen));
6,423,307✔
1343
#else
1344
    SArray* pTaskId = taosArrayInit(1, sizeof(int32_t));
1345
    if (NULL == pTaskId) {
1346
      CTG_ERR_RET(terrno);
1347
    }
1348
    if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) {
1349
      taosArrayDestroy(pTaskId);
1350
      CTG_ERR_RET(terrno);
1351
    }
1352

1353
    CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen));
1354
#endif
1355
  }
1356

1357
  SRpcMsg rpcMsg = {
11,202✔
1358
      .msgType = reqType,
1359
      .pCont = msg,
1360
      .contLen = msgLen,
1361
  };
1362

1363
  SRpcMsg rpcRsp = {0};
11,202✔
1364
  CTG_ERR_RET(rpcSendRecv(pConn->pTrans, &pConn->mgmtEps, &rpcMsg, &rpcRsp));
11,202✔
1365

1366
  CTG_ERR_RET(ctgProcessRspMsg(out, reqType, rpcRsp.pCont, rpcRsp.contLen, rpcRsp.code, (char*)user));
11,202✔
1367

1368
  rpcFreeCont(rpcRsp.pCont);
11,202✔
1369

1370
  return TSDB_CODE_SUCCESS;
11,202✔
1371
}
1372

1373
int32_t ctgGetTbMetaFromMnodeImpl(SCatalog* pCtg, SRequestConnInfo* pConn, const char* dbFName, const char* tbName,
19,101,354✔
1374
                                  STableMetaOutput* out, SCtgTaskReq* tReq) {
1375
  SCtgTask*        pTask = tReq ? tReq->pTask : NULL;
19,101,354✔
1376
  SBuildTableInput bInput = {.vgId = 0, .dbFName = dbFName, .tbName = tbName};
19,101,354✔
1377
  char*            msg = NULL;
19,101,557✔
1378
  SEpSet*          pVnodeEpSet = NULL;
19,101,557✔
1379
  int32_t          msgLen = 0;
19,101,557✔
1380
  int32_t          reqType = TDMT_MND_TABLE_META;
19,101,557✔
1381
  char             tbFName[TSDB_TABLE_FNAME_LEN];
18,926,050✔
1382
  (void)snprintf(tbFName, sizeof(tbFName), "%s.%s", dbFName, tbName);
19,101,557✔
1383
  void* (*mallocFp)(int64_t) = pTask ? (MallocType)taosMemMalloc : (MallocType)rpcMallocCont;
19,101,557✔
1384
  void (*freeFp)(void*) = pTask ? taosMemFree : rpcFreeCont;
19,101,557✔
1385

1386
  ctgDebug("tb:%s, try to get table meta from mnode", tbFName);
19,101,557✔
1387

1388
  int32_t code = queryBuildMsg[TMSG_INDEX(reqType)](&bInput, &msg, 0, &msgLen, mallocFp, freeFp);
19,101,557✔
1389
  if (code) {
19,101,599✔
1390
    ctgError("tb:%s, build mnode stablemeta msg failed, code:%s", tbFName, tstrerror(code));
×
1391
    CTG_ERR_RET(code);
×
1392
  }
1393

1394
  if (pTask) {
19,101,503✔
1395
    void* pOut = taosMemoryCalloc(1, sizeof(STableMetaOutput));
17,996,319✔
1396
    if (NULL == pOut) {
17,996,319✔
1397
      CTG_ERR_RET(terrno);
×
1398
    }
1399

1400
    CTG_ERR_RET(ctgUpdateMsgCtx(CTG_GET_TASK_MSGCTX(pTask, tReq->msgIdx), reqType, pOut, tbFName));
17,996,319✔
1401

1402
#if CTG_BATCH_FETCH
1403
    CTG_RET(ctgAddBatch(pCtg, 0, pConn, tReq, reqType, msg, msgLen));
17,996,251✔
1404
#else
1405
    SArray* pTaskId = taosArrayInit(1, sizeof(int32_t));
1406
    if (NULL == pTaskId) {
1407
      CTG_ERR_RET(terrno);
1408
    }
1409
    if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) {
1410
      taosArrayDestroy(pTaskId);
1411
      CTG_ERR_RET(terrno);
1412
    }
1413

1414
    CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen));
1415
#endif
1416
  }
1417

1418
  SRpcMsg rpcMsg = {
1,105,184✔
1419
      .msgType = reqType,
1420
      .pCont = msg,
1421
      .contLen = msgLen,
1422
  };
1423

1424
  SRpcMsg rpcRsp = {0};
1,105,184✔
1425
  CTG_ERR_RET(rpcSendRecvWithTimeout(pConn->pTrans, &pConn->mgmtEps, &rpcMsg, &rpcRsp, NULL, CATLOG_TIMEOUT));
1,105,184✔
1426

1427
  CTG_ERR_RET(ctgProcessRspMsg(out, reqType, rpcRsp.pCont, rpcRsp.contLen, rpcRsp.code, tbFName));
1,105,212✔
1428

1429
  rpcFreeCont(rpcRsp.pCont);
1,105,198✔
1430

1431
  return TSDB_CODE_SUCCESS;
1,105,212✔
1432
}
1433

1434
int32_t ctgGetTbMetaFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, STableMetaOutput* out,
4,979,914✔
1435
                              SCtgTaskReq* tReq) {
1436
  char dbFName[TSDB_DB_FNAME_LEN];
4,854,032✔
1437
  (void)tNameGetFullDbName(pTableName, dbFName);
4,979,914✔
1438

1439
  return ctgGetTbMetaFromMnodeImpl(pCtg, pConn, dbFName, (char*)pTableName->tname, out, tReq);
4,979,942✔
1440
}
1441

1442
int32_t ctgGetTbMetaFromVnode(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, SVgroupInfo* vgroupInfo,
31,065,787✔
1443
                              STableMetaOutput* out, SCtgTaskReq* tReq) {
1444
  SCtgTask* pTask = tReq ? tReq->pTask : NULL;
31,065,787✔
1445
  uint8_t   autoCreateCtb = tReq ? tReq->autoCreateCtb : 0;
31,065,787✔
1446
  char      dbFName[TSDB_DB_FNAME_LEN];
30,674,206✔
1447
  (void)tNameGetFullDbName(pTableName, dbFName);
31,065,658✔
1448
  int32_t reqType = (pTask && pTask->type == CTG_TASK_GET_TB_NAME ? TDMT_VND_TABLE_NAME : TDMT_VND_TABLE_META);
31,065,813✔
1449
  char    tbFName[TSDB_TABLE_FNAME_LEN];
30,674,209✔
1450
  (void)snprintf(tbFName, sizeof(tbFName), "%s.%s", dbFName, pTableName->tname);
31,065,729✔
1451
  void* (*mallocFp)(int64_t) = pTask ? (MallocType)taosMemMalloc : (MallocType)rpcMallocCont;
31,065,165✔
1452
  void (*freeFp)(void*) = pTask ? taosMemFree : rpcFreeCont;
31,065,165✔
1453

1454
  SEp* pEp = &vgroupInfo->epSet.eps[vgroupInfo->epSet.inUse];
31,065,165✔
1455
  ctgDebug("tb:%s, try to get table meta from vnode, vgId:%d, ep num:%d, ep:%s:%u", tbFName, vgroupInfo->vgId,
31,065,204✔
1456
           vgroupInfo->epSet.numOfEps, pEp->fqdn, pEp->port);
1457

1458
  SBuildTableInput bInput = {.vgId = vgroupInfo->vgId,
31,456,794✔
1459
                             .option = reqType == TDMT_VND_TABLE_NAME ? REQ_OPT_TBUID : REQ_OPT_TBNAME,
31,065,204✔
1460
                             .autoCreateCtb = autoCreateCtb,
1461
                             .dbFName = dbFName,
1462
                             .tbName = (char*)tNameGetTableName(pTableName)};
31,065,204✔
1463
  char*            msg = NULL;
31,065,101✔
1464
  int32_t          msgLen = 0;
31,065,148✔
1465

1466
  int32_t code = queryBuildMsg[TMSG_INDEX(reqType)](&bInput, &msg, 0, &msgLen, mallocFp, freeFp);
31,065,760✔
1467
  if (code) {
31,065,028✔
1468
    ctgError("tb:%s, build vnode tablemeta msg failed, code:%s", tbFName, tstrerror(code));
×
1469
    CTG_ERR_RET(code);
163✔
1470
  }
1471

1472
  if (pTask) {
31,065,162✔
1473
    void* pOut = taosMemoryCalloc(1, sizeof(STableMetaOutput));
30,094,981✔
1474
    if (NULL == pOut) {
30,094,829✔
1475
      CTG_ERR_RET(terrno);
×
1476
    }
1477

1478
    SRequestConnInfo vConn = {.pTrans = pConn->pTrans,
59,822,218✔
1479
                              .requestId = pConn->requestId,
30,094,910✔
1480
                              .requestObjRefId = pConn->requestObjRefId,
30,094,910✔
1481
                              .mgmtEps = vgroupInfo->epSet};
1482

1483
    CTG_ERR_RET(ctgUpdateMsgCtx(CTG_GET_TASK_MSGCTX(pTask, tReq->msgIdx), reqType, pOut, tbFName));
30,094,952✔
1484

1485
#if CTG_BATCH_FETCH
1486
    CTG_RET(ctgAddBatch(pCtg, vgroupInfo->vgId, &vConn, tReq, reqType, msg, msgLen));
30,094,994✔
1487
#else
1488
    SCtgTbMetaCtx* ctx = (SCtgTbMetaCtx*)pTask->taskCtx;
1489
    char           dbFName[TSDB_DB_FNAME_LEN];
1490
    (void)tNameGetFullDbName(ctx->pName, dbFName);
1491
    SArray* pTaskId = taosArrayInit(1, sizeof(int32_t));
1492
    if (NULL == pTaskId) {
1493
      CTG_ERR_RET(terrno);
1494
    }
1495
    if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) {
1496
      taosArrayDestroy(pTaskId);
1497
      CTG_ERR_RET(terrno);
1498
    }
1499

1500
    CTG_RET(ctgAsyncSendMsg(pCtg, &vConn, pTask->pJob, pTaskId, -1, NULL, dbFName, ctx->vgId, reqType, msg, msgLen));
1501
#endif
1502
  }
1503

1504
  SRpcMsg rpcMsg = {
970,181✔
1505
      .msgType = reqType,
1506
      .pCont = msg,
1507
      .contLen = msgLen,
1508
  };
1509

1510
  SRpcMsg rpcRsp = {0};
970,181✔
1511
  CTG_ERR_RET(rpcSendRecvWithTimeout(pConn->pTrans, &vgroupInfo->epSet, &rpcMsg, &rpcRsp, NULL, CATLOG_TIMEOUT));
970,142✔
1512

1513
  CTG_ERR_RET(ctgProcessRspMsg(out, reqType, rpcRsp.pCont, rpcRsp.contLen, rpcRsp.code, tbFName));
970,861✔
1514

1515
  rpcFreeCont(rpcRsp.pCont);
970,861✔
1516

1517
  return TSDB_CODE_SUCCESS;
970,861✔
1518
}
1519

1520
int32_t ctgGetTableCfgFromVnode(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName,
65,046✔
1521
                                SVgroupInfo* vgroupInfo, STableCfg** out, SCtgTask* pTask) {
1522
  char*   msg = NULL;
65,046✔
1523
  int32_t msgLen = 0;
65,046✔
1524
  int32_t reqType = TDMT_VND_TABLE_CFG;
65,046✔
1525
  char    tbFName[TSDB_TABLE_FNAME_LEN];
64,950✔
1526
  void* (*mallocFp)(int64_t) = pTask ? (MallocType)taosMemMalloc : (MallocType)rpcMallocCont;
65,046✔
1527
  void (*freeFp)(void*) = pTask ? taosMemFree : rpcFreeCont;
65,046✔
1528
  char dbFName[TSDB_DB_FNAME_LEN];
64,950✔
1529
  (void)tNameGetFullDbName(pTableName, dbFName);
65,046✔
1530
  SBuildTableInput bInput = {.vgId = vgroupInfo->vgId, .dbFName = dbFName, .tbName = (char*)pTableName->tname};
65,046✔
1531

1532
  int32_t code = tNameExtractFullName(pTableName, tbFName);
65,046✔
1533
  if (code) {
65,046✔
1534
    ctgError("tb:%s, tNameExtractFullName failed, code:%s, type:%d, dbName:%s", pTableName->tname, tstrerror(code),
×
1535
             pTableName->type, pTableName->dbname);
1536
    CTG_ERR_RET(code);
×
1537
  }
1538

1539
  SEp* pEp = &vgroupInfo->epSet.eps[vgroupInfo->epSet.inUse];
65,046✔
1540
  ctgDebug("tb:%s, try to get table cfg from vnode, vgId:%d, ep num:%d, ep %s:%d", tbFName, vgroupInfo->vgId,
65,046✔
1541
           vgroupInfo->epSet.numOfEps, pEp->fqdn, pEp->port);
1542

1543
  code = queryBuildMsg[TMSG_INDEX(reqType)](&bInput, &msg, 0, &msgLen, mallocFp, freeFp);
65,046✔
1544
  if (code) {
65,046✔
1545
    ctgError("tb:%s, build get tb cfg msg failed, code:%s", tbFName, tstrerror(code));
×
1546
    CTG_ERR_RET(code);
×
1547
  }
1548

1549
  if (pTask) {
65,046✔
1550
    CTG_ERR_RET(ctgUpdateMsgCtx(CTG_GET_TASK_MSGCTX(pTask, -1), reqType, NULL, (char*)tbFName));
64,950✔
1551

1552
    SRequestConnInfo vConn = {.pTrans = pConn->pTrans,
129,900✔
1553
                              .requestId = pConn->requestId,
64,950✔
1554
                              .requestObjRefId = pConn->requestObjRefId,
64,950✔
1555
                              .mgmtEps = vgroupInfo->epSet};
1556
#if CTG_BATCH_FETCH
1557
    SCtgTaskReq tReq;
64,950✔
1558
    tReq.pTask = pTask;
64,950✔
1559
    tReq.msgIdx = -1;
64,950✔
1560
    CTG_RET(ctgAddBatch(pCtg, vgroupInfo->vgId, &vConn, &tReq, reqType, msg, msgLen));
64,950✔
1561
#else
1562
    SCtgTbCfgCtx* ctx = (SCtgTbCfgCtx*)pTask->taskCtx;
1563
    char          dbFName[TSDB_DB_FNAME_LEN];
1564
    (void)tNameGetFullDbName(ctx->pName, dbFName);
1565
    SArray* pTaskId = taosArrayInit(1, sizeof(int32_t));
1566
    if (NULL == pTaskId) {
1567
      CTG_ERR_RET(terrno);
1568
    }
1569
    if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) {
1570
      taosArrayDestroy(pTaskId);
1571
      CTG_ERR_RET(terrno);
1572
    }
1573

1574
    CTG_RET(ctgAsyncSendMsg(pCtg, &vConn, pTask->pJob, pTaskId, -1, NULL, dbFName, ctx->pVgInfo->vgId, reqType, msg,
1575
                            msgLen));
1576
#endif
1577
  }
1578

1579
  SRpcMsg rpcMsg = {
96✔
1580
      .msgType = reqType,
1581
      .pCont = msg,
1582
      .contLen = msgLen,
1583
  };
1584

1585
  SRpcMsg rpcRsp = {0};
96✔
1586
  CTG_ERR_RET(rpcSendRecv(pConn->pTrans, &vgroupInfo->epSet, &rpcMsg, &rpcRsp));
96✔
1587

1588
  CTG_ERR_RET(ctgProcessRspMsg(out, reqType, rpcRsp.pCont, rpcRsp.contLen, rpcRsp.code, (char*)tbFName));
96✔
1589

1590
  rpcFreeCont(rpcRsp.pCont);
96✔
1591

1592
  return TSDB_CODE_SUCCESS;
96✔
1593
}
1594

1595
int32_t ctgGetTableCfgFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, STableCfg** out,
34,140✔
1596
                                SCtgTask* pTask) {
1597
  char*   msg = NULL;
34,140✔
1598
  int32_t msgLen = 0;
34,140✔
1599
  int32_t reqType = TDMT_MND_TABLE_CFG;
34,140✔
1600
  char    tbFName[TSDB_TABLE_FNAME_LEN];
34,140✔
1601
  void* (*mallocFp)(int64_t) = pTask ? (MallocType)taosMemMalloc : (MallocType)rpcMallocCont;
34,140✔
1602
  void (*freeFp)(void*) = pTask ? taosMemFree : rpcFreeCont;
34,140✔
1603
  char dbFName[TSDB_DB_FNAME_LEN];
34,140✔
1604
  (void)tNameGetFullDbName(pTableName, dbFName);
34,140✔
1605
  SBuildTableInput bInput = {.vgId = 0, .dbFName = dbFName, .tbName = (char*)pTableName->tname};
34,140✔
1606

1607
  int32_t code = tNameExtractFullName(pTableName, tbFName);
34,140✔
1608
  if (code) {
34,140✔
1609
    ctgError("tb:%s, tNameExtractFullName failed, code:%s, type:%d, dbName:%s", pTableName->tname, tstrerror(code),
×
1610
             pTableName->type, pTableName->dbname);
1611
    CTG_ERR_RET(code);
×
1612
  }
1613

1614
  ctgDebug("tb:%s, try to get table cfg from mnode", tbFName);
34,140✔
1615

1616
  code = queryBuildMsg[TMSG_INDEX(reqType)](&bInput, &msg, 0, &msgLen, mallocFp, freeFp);
34,140✔
1617
  if (code) {
34,140✔
1618
    ctgError("tb:%s, build get tb cfg msg failed, code:%s", tbFName, tstrerror(code));
×
1619
    CTG_ERR_RET(code);
×
1620
  }
1621

1622
  if (pTask) {
34,140✔
1623
    CTG_ERR_RET(ctgUpdateMsgCtx(CTG_GET_TASK_MSGCTX(pTask, -1), reqType, NULL, (char*)tbFName));
34,140✔
1624

1625
#if CTG_BATCH_FETCH
1626
    SCtgTaskReq tReq;
34,140✔
1627
    tReq.pTask = pTask;
34,140✔
1628
    tReq.msgIdx = -1;
34,140✔
1629
    CTG_RET(ctgAddBatch(pCtg, 0, pConn, &tReq, reqType, msg, msgLen));
34,140✔
1630
#else
1631
    SArray* pTaskId = taosArrayInit(1, sizeof(int32_t));
1632
    if (NULL == pTaskId) {
1633
      CTG_ERR_RET(terrno);
1634
    }
1635
    if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) {
1636
      taosArrayDestroy(pTaskId);
1637
      CTG_ERR_RET(terrno);
1638
    }
1639

1640
    CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen));
1641
#endif
1642
  }
1643

1644
  SRpcMsg rpcMsg = {
×
1645
      .msgType = reqType,
1646
      .pCont = msg,
1647
      .contLen = msgLen,
1648
  };
1649

1650
  SRpcMsg rpcRsp = {0};
×
1651
  CTG_ERR_RET(rpcSendRecv(pConn->pTrans, &pConn->mgmtEps, &rpcMsg, &rpcRsp));
×
1652

1653
  CTG_ERR_RET(ctgProcessRspMsg(out, reqType, rpcRsp.pCont, rpcRsp.contLen, rpcRsp.code, (char*)tbFName));
×
1654

1655
  rpcFreeCont(rpcRsp.pCont);
×
1656

1657
  return TSDB_CODE_SUCCESS;
×
1658
}
1659

1660
int32_t ctgGetSvrVerFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, char** out, SCtgTask* pTask) {
96✔
1661
  char*   msg = NULL;
96✔
1662
  int32_t msgLen = 0;
96✔
1663
  int32_t reqType = TDMT_MND_SERVER_VERSION;
96✔
1664
  void* (*mallocFp)(int64_t) = pTask ? (MallocType)taosMemMalloc : (MallocType)rpcMallocCont;
96✔
1665
  void (*freeFp)(void*) = pTask ? taosMemFree : rpcFreeCont;
96✔
1666

1667
  qDebug("try to get svr ver from mnode");
96✔
1668

1669
  int32_t code = queryBuildMsg[TMSG_INDEX(reqType)](NULL, &msg, 0, &msgLen, mallocFp, freeFp);
96✔
1670
  if (code) {
96✔
1671
    ctgError("build get svr ver msg failed, code:%s", tstrerror(code));
×
1672
    CTG_ERR_RET(code);
×
1673
  }
1674

1675
  if (pTask) {
96✔
1676
    CTG_ERR_RET(ctgUpdateMsgCtx(CTG_GET_TASK_MSGCTX(pTask, -1), reqType, NULL, NULL));
×
1677

1678
#if CTG_BATCH_FETCH
1679
    SCtgTaskReq tReq;
×
1680
    tReq.pTask = pTask;
×
1681
    tReq.msgIdx = -1;
×
1682
    CTG_RET(ctgAddBatch(pCtg, 0, pConn, &tReq, reqType, msg, msgLen));
×
1683
#else
1684
    SArray* pTaskId = taosArrayInit(1, sizeof(int32_t));
1685
    if (NULL == pTaskId) {
1686
      CTG_ERR_RET(terrno);
1687
    }
1688
    if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) {
1689
      taosArrayDestroy(pTaskId);
1690
      CTG_ERR_RET(terrno);
1691
    }
1692

1693
    CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen));
1694
#endif
1695
  }
1696

1697
  SRpcMsg rpcMsg = {
96✔
1698
      .msgType = reqType,
1699
      .pCont = msg,
1700
      .contLen = msgLen,
1701
  };
1702

1703
  SRpcMsg rpcRsp = {0};
96✔
1704
  CTG_ERR_RET(rpcSendRecv(pConn->pTrans, &pConn->mgmtEps, &rpcMsg, &rpcRsp));
96✔
1705

1706
  CTG_ERR_RET(ctgProcessRspMsg(out, reqType, rpcRsp.pCont, rpcRsp.contLen, rpcRsp.code, NULL));
96✔
1707

1708
  rpcFreeCont(rpcRsp.pCont);
96✔
1709

1710
  return TSDB_CODE_SUCCESS;
96✔
1711
}
1712

1713
int32_t ctgGetViewInfoFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, SName* pName, SViewMetaOutput* out,
19,758,635✔
1714
                                SCtgTaskReq* tReq) {
1715
  char*     msg = NULL;
19,758,635✔
1716
  int32_t   msgLen = 0;
19,759,670✔
1717
  int32_t   reqType = TDMT_MND_VIEW_META;
19,759,633✔
1718
  SCtgTask* pTask = tReq ? tReq->pTask : NULL;
19,759,633✔
1719
  void* (*mallocFp)(int64_t) = pTask ? (MallocType)taosMemMalloc : (MallocType)rpcMallocCont;
19,759,633✔
1720
  void (*freeFp)(void*) = pTask ? taosMemFree : rpcFreeCont;
19,759,633✔
1721
  char    fullName[TSDB_TABLE_FNAME_LEN];
19,299,796✔
1722
  int32_t code = tNameExtractFullName(pName, fullName);
19,759,591✔
1723
  if (code) {
19,759,633✔
1724
    ctgError("view:%s, tNameExtractFullName failed, code:%s, type:%d, dbName:%s", pName->tname, tstrerror(code), pName->type,
×
1725
             pName->dbname);
1726
    CTG_ERR_RET(code);
×
1727
  }
1728

1729
  ctgDebug("view:%s, try to get view info from mnode", fullName);
19,759,633✔
1730

1731
  code = queryBuildMsg[TMSG_INDEX(reqType)](fullName, &msg, 0, &msgLen, mallocFp, freeFp);
19,759,633✔
1732
  if (code) {
19,759,633✔
1733
    ctgError("view:%s, build view-meta msg failed, code:%s", fullName, tstrerror(code));
×
UNCOV
1734
    CTG_ERR_RET(code);
×
1735
  }
1736

1737
  if (pTask) {
19,759,633✔
1738
    void* pOut = taosMemoryCalloc(1, POINTER_BYTES);
19,759,633✔
1739
    if (NULL == pOut) {
19,759,633✔
1740
      CTG_ERR_RET(terrno);
×
1741
    }
1742

1743
    CTG_ERR_RET(ctgUpdateMsgCtx(CTG_GET_TASK_MSGCTX(pTask, tReq->msgIdx), reqType, pOut, fullName));
19,759,633✔
1744

1745
#if CTG_BATCH_FETCH
1746
    CTG_RET(ctgAddBatch(pCtg, 0, pConn, tReq, reqType, msg, msgLen));
19,759,594✔
1747
#else
1748
    SArray* pTaskId = taosArrayInit(1, sizeof(int32_t));
1749
    if (NULL == pTaskId) {
1750
      CTG_ERR_RET(terrno);
1751
    }
1752
    if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) {
1753
      taosArrayDestroy(pTaskId);
1754
      CTG_ERR_RET(terrno);
1755
    }
1756

1757
    CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen));
1758
#endif
1759
  }
1760

1761
  SRpcMsg rpcMsg = {
×
1762
      .msgType = reqType,
1763
      .pCont = msg,
1764
      .contLen = msgLen,
1765
  };
1766

1767
  SRpcMsg rpcRsp = {0};
×
1768
  CTG_ERR_RET(rpcSendRecv(pConn->pTrans, &pConn->mgmtEps, &rpcMsg, &rpcRsp));
×
1769

1770
  CTG_ERR_RET(ctgProcessRspMsg(out, reqType, rpcRsp.pCont, rpcRsp.contLen, rpcRsp.code, fullName));
×
1771

1772
  rpcFreeCont(rpcRsp.pCont);
×
1773

1774
  return TSDB_CODE_SUCCESS;
×
1775
}
1776

1777
int32_t ctgGetTbTSMAFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* name, STableTSMAInfoRsp* out,
13,104✔
1778
                              SCtgTaskReq* tReq, int32_t reqType) {
1779
  char*     msg = NULL;
13,104✔
1780
  int32_t   msgLen = 0;
13,104✔
1781
  SCtgTask* pTask = tReq ? tReq->pTask : NULL;
13,104✔
1782
  void* (*mallocFp)(int64_t) = pTask ? (MallocType)taosMemMalloc : (MallocType)rpcMallocCont;
13,104✔
1783
  void (*freeFp)(void*) = pTask ? taosMemFree : rpcFreeCont;
13,104✔
1784
  char    tbFName[TSDB_TABLE_FNAME_LEN];
13,104✔
1785
  int32_t code = tNameExtractFullName(name, tbFName);
13,104✔
1786
  if (code) {
13,104✔
1787
    ctgError("tb:%s, tNameExtractFullName failed, code:%s, type:%d, dbName:%s", name->tname, tstrerror(code),
×
1788
             name->type, name->dbname);
1789
    CTG_ERR_RET(code);
×
1790
  }
1791

1792
  ctgDebug("tb:%s, try to get tb index from mnode", tbFName);
13,104✔
1793

1794
  code = queryBuildMsg[TMSG_INDEX(reqType)]((void*)tbFName, &msg, 0, &msgLen, mallocFp, freeFp);
13,104✔
1795
  if (code) {
13,104✔
1796
    ctgError("tb:%s, build get index msg failed, code:%s", tbFName, tstrerror(code));
×
1797
    CTG_ERR_RET(code);
×
1798
  }
1799

1800
  if (pTask) {
13,104✔
1801
    void* pOut = taosMemoryCalloc(1, sizeof(STableTSMAInfoRsp));
13,104✔
1802
    if (NULL == pOut) {
13,104✔
1803
      CTG_ERR_RET(terrno);
×
1804
    }
1805

1806
    CTG_ERR_RET(ctgUpdateMsgCtx(CTG_GET_TASK_MSGCTX(pTask, tReq->msgIdx), reqType, pOut, (char*)tbFName));
13,104✔
1807

1808
#if CTG_BATCH_FETCH
1809
    CTG_RET(ctgAddBatch(pCtg, 0, pConn, tReq, reqType, msg, msgLen));
13,104✔
1810
#else
1811
    SArray* pTaskId = taosArrayInit(1, sizeof(int32_t));
1812
    if (NULL == pTaskId) {
1813
      CTG_ERR_RET(terrno);
1814
    }
1815
    if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) {
1816
      taosArrayDestroy(pTaskId);
1817
      CTG_ERR_RET(terrno);
1818
    }
1819

1820
    CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen));
1821
#endif
1822
  }
1823

1824
  SRpcMsg rpcMsg = {
×
1825
      .msgType = reqType,
1826
      .pCont = msg,
1827
      .contLen = msgLen,
1828
  };
1829

1830
  SRpcMsg rpcRsp = {0};
×
1831
  CTG_ERR_RET(rpcSendRecv(pConn->pTrans, &pConn->mgmtEps, &rpcMsg, &rpcRsp));
×
1832

1833
  CTG_ERR_RET(ctgProcessRspMsg(out, reqType, rpcRsp.pCont, rpcRsp.contLen, rpcRsp.code, (char*)tbFName));
×
1834

1835
  rpcFreeCont(rpcRsp.pCont);
×
1836

1837
  return TSDB_CODE_SUCCESS;
×
1838
}
1839

1840
int32_t ctgGetStreamProgressFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTbName,
6,251✔
1841
                                      SStreamProgressRsp* out, SCtgTaskReq* tReq, void* bInput, int32_t nodeId) {
1842
  char*   msg = NULL;
6,251✔
1843
  int32_t msgLen = 0;
6,251✔
1844
  int32_t reqType = TDMT_MND_GET_STREAM_PROGRESS;
6,251✔
1845
  char    tbFName[TSDB_TABLE_FNAME_LEN];
6,251✔
1846
  int32_t code = tNameExtractFullName(pTbName, tbFName);
6,251✔
1847
  if (code) {
6,251✔
1848
    ctgError("tb:%s, tNameExtractFullName failed, code:%s, type:%d, dbName:%s", pTbName->tname, tstrerror(code),
×
1849
             pTbName->type, pTbName->dbname);
1850
    CTG_ERR_RET(code);
×
1851
  }
1852

1853
  SCtgTask* pTask = tReq ? tReq->pTask : NULL;
6,251✔
1854
  void* (*mallocFp)(int64_t) = pTask ? (MallocType)taosMemMalloc : (MallocType)rpcMallocCont;
6,251✔
1855
  void (*freeFp)(void*) = pTask ? taosMemFree : rpcFreeCont;
6,251✔
1856

1857
  code = queryBuildMsg[TMSG_INDEX(reqType)](bInput, &msg, 0, &msgLen, mallocFp, freeFp);
6,251✔
1858
  if (code) {
6,251✔
1859
    ctgError("tb:%s, build get stream progress failed, code:%s", tbFName, tstrerror(code));
×
1860
    CTG_ERR_RET(code);
×
1861
  }
1862

1863
  if (pTask) {
6,251✔
1864
    SStreamProgressRsp* pOut = taosMemoryCalloc(1, sizeof(SStreamProgressRsp));
6,251✔
1865
    if (!pOut) {
6,251✔
1866
      CTG_ERR_RET(terrno);
×
1867
    }
1868
    CTG_ERR_RET(ctgUpdateMsgCtx(CTG_GET_TASK_MSGCTX(pTask, tReq->msgIdx), reqType, pOut, (char*)tbFName));
6,251✔
1869

1870
#if CTG_BATCH_FETCH
1871
    CTG_RET(ctgAddBatch(pCtg, nodeId, pConn, tReq, reqType, msg, msgLen));
6,251✔
1872
#else
1873
    char dbFName[TSDB_DB_FNAME_LEN];
1874
    (void)tNameGetFullDbName(pTbName, dbFName);
1875
    SArray* pTaskId = taosArrayInit(1, sizeof(int32_t));
1876
    if (NULL == pTaskId) {
1877
      CTG_ERR_RET(terrno);
1878
    }
1879
    if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) {
1880
      taosArrayDestroy(pTaskId);
1881
      CTG_ERR_RET(terrno);
1882
    }
1883

1884
    CTG_RET(
1885
        ctgAsyncSendMsg(pCtg, &vConn, pTask->pJob, pTaskId, -1, NULL, dbFName, vgroupInfo->vgId, reqType, msg, msgLen));
1886
#endif
1887
  }
1888

1889
  SRpcMsg rpcMsg = {
×
1890
      .msgType = reqType,
1891
      .pCont = msg,
1892
      .contLen = msgLen,
1893
  };
1894

1895
  SRpcMsg rpcRsp = {0};
×
1896
  CTG_ERR_RET(rpcSendRecv(pConn->pTrans, &pConn->mgmtEps, &rpcMsg, &rpcRsp));
×
1897

1898
  CTG_ERR_RET(ctgProcessRspMsg(out, reqType, rpcRsp.pCont, rpcRsp.contLen, rpcRsp.code, (char*)tbFName));
×
1899

1900
  rpcFreeCont(rpcRsp.pCont);
×
1901

1902
  return TSDB_CODE_SUCCESS;
×
1903
}
1904

1905
int32_t ctgGetVStbRefDbsFromVnode(SCatalog* pCtg, SRequestConnInfo* pConn, int64_t suid, SVgroupInfo* vgroupInfo, SCtgTaskReq* tReq) {
8,381,150✔
1906
  SCtgTask* pTask = tReq ? tReq->pTask : NULL;
8,381,150✔
1907
  void* (*mallocFp)(int64_t) = pTask ? (MallocType)taosMemMalloc : (MallocType)rpcMallocCont;
8,381,150✔
1908
  void (*freeFp)(void*) = pTask ? taosMemFree : rpcFreeCont;
8,381,150✔
1909
  int32_t reqType = TDMT_VND_VSTB_REF_DBS;
8,381,150✔
1910
  SEp* pEp = &vgroupInfo->epSet.eps[vgroupInfo->epSet.inUse];
8,381,150✔
1911
  ctgDebug("try to get vstb's ref dbs from vnode, vgId:%d, ep num:%d, ep %s:%d, suid:%" PRIu64, vgroupInfo->vgId,
8,381,150✔
1912
           vgroupInfo->epSet.numOfEps, pEp->fqdn, pEp->port, suid);
1913

1914
  char*            msg = NULL;
8,381,150✔
1915
  int32_t          msgLen = 0;
8,381,150✔
1916

1917
  int32_t code = queryBuildMsg[TMSG_INDEX(reqType)](&suid, &msg, 0, &msgLen, mallocFp, freeFp);
8,381,150✔
1918
  if (code) {
8,381,150✔
1919
    ctgError("Build vnode vsubtables meta msg failed, code:%x, suid:%" PRIu64, code, suid);
×
1920
    CTG_ERR_RET(code);
×
1921
  }
1922

1923
  SRequestConnInfo vConn = {.pTrans = pConn->pTrans,
16,743,649✔
1924
                            .requestId = pConn->requestId,
8,381,150✔
1925
                            .requestObjRefId = pConn->requestObjRefId,
8,381,150✔
1926
                            .mgmtEps = vgroupInfo->epSet};
1927

1928
  return ctgAddBatch(pCtg, vgroupInfo->vgId, &vConn, tReq, reqType, msg, msgLen);
8,381,150✔
1929
}
1930

1931

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc