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

taosdata / TDengine / #3778

28 Mar 2025 06:51AM UTC coverage: 63.374% (+0.4%) from 62.934%
#3778

push

travis-ci

web-flow
fix(tdb): disable page recycling (#30529)

155771 of 313582 branches covered (49.67%)

Branch coverage included in aggregate %.

241569 of 313390 relevant lines covered (77.08%)

20705705.27 hits per line

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

51.95
/source/libs/qcom/src/querymsg.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 "query.h"
17
#include "queryInt.h"
18
#include "systable.h"
19
#include "tmsg.h"
20
#include "trpc.h"
21

22
#pragma GCC diagnostic push
23
#ifdef COMPILER_SUPPORTS_CXX13
24
#pragma GCC diagnostic ignored "-Wformat-truncation"
25
#endif
26

27
int32_t (*queryBuildMsg[TDMT_MAX])(void *input, char **msg, int32_t msgSize, int32_t *msgLen,
28
                                   void *(*mallocFp)(int64_t)) = {0};
29
int32_t (*queryProcessMsgRsp[TDMT_MAX])(void *output, char *msg, int32_t msgSize) = {0};
30

31
int32_t queryBuildUseDbOutput(SUseDbOutput *pOut, SUseDbRsp *usedbRsp) {
125,948✔
32
  QUERY_PARAM_CHECK(pOut);
125,948!
33
  QUERY_PARAM_CHECK(usedbRsp);
125,948!
34
  memcpy(pOut->db, usedbRsp->db, TSDB_DB_FNAME_LEN);
125,948✔
35
  pOut->dbId = usedbRsp->uid;
125,948✔
36

37
  pOut->dbVgroup = taosMemoryCalloc(1, sizeof(SDBVgInfo));
125,948!
38
  if (NULL == pOut->dbVgroup) {
125,948!
39
    return terrno;
×
40
  }
41

42
  pOut->dbVgroup->vgVersion = usedbRsp->vgVersion;
125,948✔
43
  pOut->dbVgroup->hashMethod = usedbRsp->hashMethod;
125,948✔
44
  pOut->dbVgroup->hashPrefix = usedbRsp->hashPrefix;
125,948✔
45
  pOut->dbVgroup->hashSuffix = usedbRsp->hashSuffix;
125,948✔
46
  pOut->dbVgroup->stateTs = usedbRsp->stateTs;
125,948✔
47

48
  qDebug("db:%s, get %d vgroup, vgVersion:%d, stateTs:%" PRId64, usedbRsp->db, usedbRsp->vgNum, usedbRsp->vgVersion,
125,948✔
49
         usedbRsp->stateTs);
50

51
  if (usedbRsp->vgNum <= 0) {
125,948✔
52
    return TSDB_CODE_SUCCESS;
10,941✔
53
  }
54

55
  pOut->dbVgroup->vgHash =
230,014✔
56
      taosHashInit(usedbRsp->vgNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
115,007✔
57
  if (NULL == pOut->dbVgroup->vgHash) {
115,007!
58
    return terrno;
×
59
  }
60

61
  for (int32_t i = 0; i < usedbRsp->vgNum; ++i) {
410,676✔
62
    SVgroupInfo *pVgInfo = taosArrayGet(usedbRsp->pVgroupInfos, i);
295,669✔
63
    pOut->dbVgroup->numOfTable += pVgInfo->numOfTable;
295,668✔
64
    qDebug("db:%s, vgId:%d, epNum:%d, current ep:%s:%u", usedbRsp->db, pVgInfo->vgId, pVgInfo->epSet.numOfEps,
295,668✔
65
           pVgInfo->epSet.eps[pVgInfo->epSet.inUse].fqdn, pVgInfo->epSet.eps[pVgInfo->epSet.inUse].port);
66
    if (0 != taosHashPut(pOut->dbVgroup->vgHash, &pVgInfo->vgId, sizeof(int32_t), pVgInfo, sizeof(SVgroupInfo))) {
295,668!
67
      return terrno;
×
68
    }
69
  }
70

71
  return TSDB_CODE_SUCCESS;
115,007✔
72
}
73

74
int32_t queryBuildTableMetaReqMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen,
207,736✔
75
                                  void *(*mallcFp)(int64_t)) {
76
  QUERY_PARAM_CHECK(input);
207,736!
77
  QUERY_PARAM_CHECK(msg);
207,736!
78
  QUERY_PARAM_CHECK(msgLen);
207,736!
79
  SBuildTableInput *pInput = input;
207,736✔
80

81
  STableInfoReq infoReq = {0};
207,736✔
82
  infoReq.option = pInput->option;
207,736✔
83
  infoReq.header.vgId = pInput->vgId;
207,736✔
84
  infoReq.autoCreateCtb = pInput->autoCreateCtb;
207,736✔
85

86
  if (pInput->dbFName) {
207,736✔
87
    tstrncpy(infoReq.dbFName, pInput->dbFName, TSDB_DB_FNAME_LEN);
207,734✔
88
  }
89
  tstrncpy(infoReq.tbName, pInput->tbName, TSDB_TABLE_NAME_LEN);
207,736✔
90

91
  int32_t bufLen = tSerializeSTableInfoReq(NULL, 0, &infoReq);
207,736✔
92
  void   *pBuf = (*mallcFp)(bufLen);
207,740✔
93
  if (NULL == pBuf) {
207,756!
94
    return terrno;
×
95
  }
96
  int32_t ret = tSerializeSTableInfoReq(pBuf, bufLen, &infoReq);
207,756✔
97
  if (ret < 0) return ret;
207,768!
98

99
  *msg = pBuf;
207,768✔
100
  *msgLen = bufLen;
207,768✔
101

102
  return TSDB_CODE_SUCCESS;
207,768✔
103
}
104

105
int32_t queryBuildUseDbMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
117,505✔
106
  QUERY_PARAM_CHECK(input);
117,505!
107
  QUERY_PARAM_CHECK(msg);
117,505!
108
  QUERY_PARAM_CHECK(msgLen);
117,505!
109
  SBuildUseDBInput *pInput = input;
117,505✔
110

111
  SUseDbReq usedbReq = {0};
117,505✔
112
  tstrncpy(usedbReq.db, pInput->db, TSDB_DB_FNAME_LEN);
117,505✔
113
  usedbReq.db[sizeof(usedbReq.db) - 1] = 0;
117,505✔
114
  usedbReq.vgVersion = pInput->vgVersion;
117,505✔
115
  usedbReq.dbId = pInput->dbId;
117,505✔
116
  usedbReq.numOfTable = pInput->numOfTable;
117,505✔
117
  usedbReq.stateTs = pInput->stateTs;
117,505✔
118

119
  int32_t bufLen = tSerializeSUseDbReq(NULL, 0, &usedbReq);
117,505✔
120
  void   *pBuf = (*mallcFp)(bufLen);
117,504✔
121
  if (NULL == pBuf) {
117,504!
122
    return terrno;
×
123
  }
124
  int32_t ret = tSerializeSUseDbReq(pBuf, bufLen, &usedbReq);
117,504✔
125
  if (ret < 0) return ret;
117,505!
126

127
  *msg = pBuf;
117,505✔
128
  *msgLen = bufLen;
117,505✔
129

130
  return TSDB_CODE_SUCCESS;
117,505✔
131
}
132

133
int32_t queryBuildQnodeListMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
12,411✔
134
  QUERY_PARAM_CHECK(msg);
12,411!
135
  QUERY_PARAM_CHECK(msgLen);
12,411!
136

137
  SQnodeListReq qnodeListReq = {0};
12,411✔
138
  qnodeListReq.rowNum = -1;
12,411✔
139

140
  int32_t bufLen = tSerializeSQnodeListReq(NULL, 0, &qnodeListReq);
12,411✔
141
  void   *pBuf = (*mallcFp)(bufLen);
12,411✔
142
  if (NULL == pBuf) {
12,411!
143
    return terrno;
×
144
  }
145

146
  int32_t ret = tSerializeSQnodeListReq(pBuf, bufLen, &qnodeListReq);
12,411✔
147
  if (ret < 0) return ret;
12,411!
148

149
  *msg = pBuf;
12,411✔
150
  *msgLen = bufLen;
12,411✔
151

152
  return TSDB_CODE_SUCCESS;
12,411✔
153
}
154

155
int32_t queryBuildDnodeListMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
354✔
156
  QUERY_PARAM_CHECK(msg);
354!
157
  QUERY_PARAM_CHECK(msgLen);
354!
158

159
  SDnodeListReq dnodeListReq = {0};
354✔
160
  dnodeListReq.rowNum = -1;
354✔
161

162
  int32_t bufLen = tSerializeSDnodeListReq(NULL, 0, &dnodeListReq);
354✔
163
  void   *pBuf = (*mallcFp)(bufLen);
354✔
164
  if (NULL == pBuf) {
354!
165
    return terrno;
×
166
  }
167
  int32_t ret = tSerializeSDnodeListReq(pBuf, bufLen, &dnodeListReq);
354✔
168
  if (ret < 0) return ret;
354!
169

170
  *msg = pBuf;
354✔
171
  *msgLen = bufLen;
354✔
172

173
  return TSDB_CODE_SUCCESS;
354✔
174
}
175

176
int32_t queryBuildGetSerVerMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
1✔
177
  QUERY_PARAM_CHECK(msg);
1!
178
  QUERY_PARAM_CHECK(msgLen);
1!
179

180
  SServerVerReq req = {0};
1✔
181

182
  int32_t bufLen = tSerializeSServerVerReq(NULL, 0, &req);
1✔
183
  void   *pBuf = (*mallcFp)(bufLen);
1✔
184
  if (NULL == pBuf) {
1!
185
    return terrno;
×
186
  }
187
  int32_t ret = tSerializeSServerVerReq(pBuf, bufLen, &req);
1✔
188
  if (ret < 0) return ret;
1!
189

190
  *msg = pBuf;
1✔
191
  *msgLen = bufLen;
1✔
192

193
  return TSDB_CODE_SUCCESS;
1✔
194
}
195

196
int32_t queryBuildGetDBCfgMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
5,676✔
197
  QUERY_PARAM_CHECK(input);
5,676!
198
  QUERY_PARAM_CHECK(msg);
5,676!
199
  QUERY_PARAM_CHECK(msgLen);
5,676!
200

201
  SDbCfgReq dbCfgReq = {0};
5,676✔
202
  tstrncpy(dbCfgReq.db, input, TSDB_DB_FNAME_LEN);
5,676✔
203

204
  int32_t bufLen = tSerializeSDbCfgReq(NULL, 0, &dbCfgReq);
5,676✔
205
  void   *pBuf = (*mallcFp)(bufLen);
5,676✔
206
  if (NULL == pBuf) {
5,676!
207
    return terrno;
×
208
  }
209
  int32_t ret = tSerializeSDbCfgReq(pBuf, bufLen, &dbCfgReq);
5,676✔
210
  if (ret < 0) return ret;
5,676!
211

212
  *msg = pBuf;
5,676✔
213
  *msgLen = bufLen;
5,676✔
214

215
  return TSDB_CODE_SUCCESS;
5,676✔
216
}
217

218
int32_t queryBuildGetIndexMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
1✔
219
  QUERY_PARAM_CHECK(input);
1!
220
  QUERY_PARAM_CHECK(msg);
1!
221
  QUERY_PARAM_CHECK(msgLen);
1!
222

223
  SUserIndexReq indexReq = {0};
1✔
224
  tstrncpy(indexReq.indexFName, input, TSDB_INDEX_FNAME_LEN);
1✔
225

226
  int32_t bufLen = tSerializeSUserIndexReq(NULL, 0, &indexReq);
1✔
227
  void   *pBuf = (*mallcFp)(bufLen);
1✔
228
  if (NULL == pBuf) {
1!
229
    return terrno;
×
230
  }
231
  int32_t ret = tSerializeSUserIndexReq(pBuf, bufLen, &indexReq);
1✔
232
  if (ret < 0) return ret;
1!
233

234
  *msg = pBuf;
1✔
235
  *msgLen = bufLen;
1✔
236

237
  return TSDB_CODE_SUCCESS;
1✔
238
}
239

240
int32_t queryBuildRetrieveFuncMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen,
97✔
241
                                  void *(*mallcFp)(int64_t)) {
242
  QUERY_PARAM_CHECK(input);
97!
243
  QUERY_PARAM_CHECK(msg);
97!
244
  QUERY_PARAM_CHECK(msgLen);
97!
245

246
  SRetrieveFuncReq funcReq = {0};
97✔
247
  funcReq.numOfFuncs = 1;
97✔
248
  funcReq.ignoreCodeComment = true;
97✔
249
  funcReq.pFuncNames = taosArrayInit(1, strlen(input) + 1);
97✔
250
  if (NULL == funcReq.pFuncNames) {
97!
251
    return terrno;
×
252
  }
253
  if (taosArrayPush(funcReq.pFuncNames, input) == NULL) {
194!
254
    taosArrayDestroy(funcReq.pFuncNames);
×
255
    return terrno;
×
256
  }
257

258
  int32_t bufLen = tSerializeSRetrieveFuncReq(NULL, 0, &funcReq);
97✔
259
  void   *pBuf = (*mallcFp)(bufLen);
97✔
260
  if (NULL == pBuf) {
97!
261
    taosArrayDestroy(funcReq.pFuncNames);
×
262
    return terrno;
×
263
  }
264
  int32_t ret = tSerializeSRetrieveFuncReq(pBuf, bufLen, &funcReq);
97✔
265
  if (ret < 0) {
97!
266
    taosArrayDestroy(funcReq.pFuncNames);
×
267
    return ret;
×
268
  }
269

270
  taosArrayDestroy(funcReq.pFuncNames);
97✔
271

272
  *msg = pBuf;
97✔
273
  *msgLen = bufLen;
97✔
274

275
  return TSDB_CODE_SUCCESS;
97✔
276
}
277

278
int32_t queryBuildGetUserAuthMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
22,056✔
279
  QUERY_PARAM_CHECK(input);
22,056!
280
  QUERY_PARAM_CHECK(msg);
22,056!
281
  QUERY_PARAM_CHECK(msgLen);
22,056!
282

283
  SGetUserAuthReq req = {0};
22,056✔
284
  tstrncpy(req.user, input, TSDB_USER_LEN);
22,056✔
285

286
  int32_t bufLen = tSerializeSGetUserAuthReq(NULL, 0, &req);
22,056✔
287
  void   *pBuf = (*mallcFp)(bufLen);
22,056✔
288
  if (NULL == pBuf) {
22,056!
289
    return terrno;
×
290
  }
291
  int32_t ret = tSerializeSGetUserAuthReq(pBuf, bufLen, &req);
22,056✔
292
  if (ret < 0) return ret;
22,057!
293

294
  *msg = pBuf;
22,057✔
295
  *msgLen = bufLen;
22,057✔
296

297
  return TSDB_CODE_SUCCESS;
22,057✔
298
}
299

300
int32_t queryBuildGetTbIndexMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
7,236✔
301
  QUERY_PARAM_CHECK(input);
7,236!
302
  QUERY_PARAM_CHECK(msg);
7,236!
303
  QUERY_PARAM_CHECK(msgLen);
7,236!
304

305
  STableIndexReq indexReq = {0};
7,236✔
306
  tstrncpy(indexReq.tbFName, input, TSDB_TABLE_FNAME_LEN);
7,236✔
307

308
  int32_t bufLen = tSerializeSTableIndexReq(NULL, 0, &indexReq);
7,236✔
309
  void   *pBuf = (*mallcFp)(bufLen);
7,236✔
310
  if (NULL == pBuf) {
7,236!
311
    return terrno;
×
312
  }
313
  int32_t ret = tSerializeSTableIndexReq(pBuf, bufLen, &indexReq);
7,236✔
314
  if (ret < 0) return ret;
7,236!
315

316
  *msg = pBuf;
7,236✔
317
  *msgLen = bufLen;
7,236✔
318

319
  return TSDB_CODE_SUCCESS;
7,236✔
320
}
321

322
int32_t queryBuildGetTbCfgMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
225✔
323
  QUERY_PARAM_CHECK(input);
225!
324
  QUERY_PARAM_CHECK(msg);
225!
325
  QUERY_PARAM_CHECK(msgLen);
225!
326

327
  SBuildTableInput *pInput = input;
225✔
328
  STableCfgReq      cfgReq = {0};
225✔
329
  cfgReq.header.vgId = pInput->vgId;
225✔
330
  tstrncpy(cfgReq.dbFName, pInput->dbFName, TSDB_DB_FNAME_LEN);
225✔
331
  tstrncpy(cfgReq.tbName, pInput->tbName, TSDB_TABLE_NAME_LEN);
225✔
332

333
  int32_t bufLen = tSerializeSTableCfgReq(NULL, 0, &cfgReq);
225✔
334
  void   *pBuf = (*mallcFp)(bufLen);
225✔
335
  if (NULL == pBuf) {
225!
336
    return terrno;
×
337
  }
338
  int32_t ret = tSerializeSTableCfgReq(pBuf, bufLen, &cfgReq);
225✔
339
  if (ret < 0) return ret;
225!
340

341
  *msg = pBuf;
225✔
342
  *msgLen = bufLen;
225✔
343

344
  return TSDB_CODE_SUCCESS;
225✔
345
}
346

347
int32_t queryBuildGetViewMetaMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
44,150✔
348
  QUERY_PARAM_CHECK(input);
44,150!
349
  QUERY_PARAM_CHECK(msg);
44,150!
350
  QUERY_PARAM_CHECK(msgLen);
44,150!
351

352
  SViewMetaReq req = {0};
44,150✔
353
  tstrncpy(req.fullname, input, TSDB_VIEW_FNAME_LEN);
44,150✔
354

355
  int32_t bufLen = tSerializeSViewMetaReq(NULL, 0, &req);
44,150✔
356
  void   *pBuf = (*mallcFp)(bufLen);
44,151✔
357
  if (NULL == pBuf) {
44,151!
358
    return terrno;
×
359
  }
360
  int32_t ret = tSerializeSViewMetaReq(pBuf, bufLen, &req);
44,151✔
361
  if (ret < 0) return ret;
44,152!
362

363
  *msg = pBuf;
44,152✔
364
  *msgLen = bufLen;
44,152✔
365

366
  return TSDB_CODE_SUCCESS;
44,152✔
367
}
368

369
int32_t queryBuildGetTableTSMAMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen,
973✔
370
                                  void *(*mallcFp)(int64_t)) {
371
  QUERY_PARAM_CHECK(input);
973!
372
  QUERY_PARAM_CHECK(msg);
973!
373
  QUERY_PARAM_CHECK(msgLen);
973!
374

375
  STableTSMAInfoReq req = {0};
973✔
376
  tstrncpy(req.name, input, TSDB_TABLE_FNAME_LEN);
973✔
377

378
  int32_t bufLen = tSerializeTableTSMAInfoReq(NULL, 0, &req);
973✔
379
  void *  pBuf = (*mallcFp)(bufLen);
973✔
380
  if (NULL == pBuf) {
973!
381
    return terrno;
×
382
  }
383
  int32_t ret = tSerializeTableTSMAInfoReq(pBuf, bufLen, &req);
973✔
384
  if (ret < 0) return ret;
973!
385

386
  *msg = pBuf;
973✔
387
  *msgLen = bufLen;
973✔
388
  return TSDB_CODE_SUCCESS;
973✔
389
}
390

391
int32_t queryBuildGetTSMAMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen,
76✔
392
                                  void *(*mallcFp)(int64_t)) {
393
  QUERY_PARAM_CHECK(input);
76!
394
  QUERY_PARAM_CHECK(msg);
76!
395
  QUERY_PARAM_CHECK(msgLen);
76!
396

397
  STableTSMAInfoReq req = {0};
76✔
398
  req.fetchingWithTsmaName = true;
76✔
399
  tstrncpy(req.name, input, TSDB_TABLE_FNAME_LEN);
76✔
400

401
  int32_t bufLen = tSerializeTableTSMAInfoReq(NULL, 0, &req);
76✔
402
  void *  pBuf = (*mallcFp)(bufLen);
76✔
403
  if(pBuf == NULL)
76!
404
  {
405
    return terrno;
×
406
  }
407
  int32_t ret = tSerializeTableTSMAInfoReq(pBuf, bufLen, &req);
76✔
408
  if(ret < 0) return ret;
76!
409

410
  *msg = pBuf;
76✔
411
  *msgLen = bufLen;
76✔
412
  return TSDB_CODE_SUCCESS;
76✔
413
}
414

415
int32_t queryBuildGetStreamProgressMsg(void* input, char** msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int64_t)) {
4,404✔
416
  QUERY_PARAM_CHECK(input);
4,404!
417
  QUERY_PARAM_CHECK(msg);
4,404!
418
  QUERY_PARAM_CHECK(msgLen);
4,404!
419

420
  int32_t len = tSerializeStreamProgressReq(NULL, 0, input);
4,404✔
421
  void* pBuf = (*mallcFp)(len);
4,404✔
422
  if (NULL == pBuf) {
4,404!
423
    return terrno;
×
424
  }
425

426
  int32_t ret = tSerializeStreamProgressReq(pBuf, len, input);
4,404✔
427
  if (ret < 0) return ret;
4,404!
428

429
  *msg = pBuf;
4,404✔
430
  *msgLen = len;
4,404✔
431
  return TSDB_CODE_SUCCESS;
4,404✔
432
}
433

434

435
int32_t queryBuildVSubTablesMsg(void* input, char** msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int64_t)) {
24✔
436
  QUERY_PARAM_CHECK(input);
24!
437
  QUERY_PARAM_CHECK(msg);
24!
438
  QUERY_PARAM_CHECK(msgLen);
24!
439

440
  SVSubTablesReq req = {0};
24✔
441
  req.suid = *(int64_t*)input;
24✔
442

443
  int32_t bufLen = tSerializeSVSubTablesReq(NULL, 0, &req);
24✔
444
  void   *pBuf = (*mallcFp)(bufLen);
24✔
445
  if (NULL == pBuf) {
24!
446
    return terrno;
×
447
  }
448
  if(tSerializeSVSubTablesReq(pBuf, bufLen, &req) < 0)   {
24!
449
    return TSDB_CODE_TSC_INVALID_INPUT;
×
450
  }
451

452
  *msg = pBuf;
24✔
453
  *msgLen = bufLen;
24✔
454

455
  return TSDB_CODE_SUCCESS;
24✔
456
}
457

458

459
int32_t queryProcessUseDBRsp(void *output, char *msg, int32_t msgSize) {
116,915✔
460
  SUseDbOutput *pOut = output;
116,915✔
461
  SUseDbRsp     usedbRsp = {0};
116,915✔
462
  int32_t       code = -1;
116,915✔
463

464
  if (NULL == output || NULL == msg || msgSize <= 0) {
116,915!
465
    code = TSDB_CODE_TSC_INVALID_INPUT;
×
466
    qError("invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
467
    goto PROCESS_USEDB_OVER;
×
468
  }
469

470
  if (tDeserializeSUseDbRsp(msg, msgSize, &usedbRsp) != 0) {
116,915!
471
    qError("invalid use db rsp msg, msgSize:%d", msgSize);
×
472
    code = TSDB_CODE_INVALID_MSG;
×
473
    goto PROCESS_USEDB_OVER;
×
474
  }
475

476
  if (usedbRsp.vgNum < 0) {
116,915!
477
    qError("invalid db[%s] vgroup number[%d]", usedbRsp.db, usedbRsp.vgNum);
×
478
    code = TSDB_CODE_TSC_INVALID_VALUE;
×
479
    goto PROCESS_USEDB_OVER;
×
480
  }
481

482
  qTrace("db:%s, usedbRsp received, numOfVgroups:%d", usedbRsp.db, usedbRsp.vgNum);
116,915✔
483
  for (int32_t i = 0; i < usedbRsp.vgNum; ++i) {
404,397✔
484
    SVgroupInfo *pInfo = taosArrayGet(usedbRsp.pVgroupInfos, i);
287,482✔
485
    qTrace("vgId:%d, numOfEps:%d inUse:%d ", pInfo->vgId, pInfo->epSet.numOfEps, pInfo->epSet.inUse);
287,482✔
486
    for (int32_t j = 0; j < pInfo->epSet.numOfEps; ++j) {
634,943✔
487
      qTrace("vgId:%d, index:%d epset:%s:%u", pInfo->vgId, j, pInfo->epSet.eps[j].fqdn, pInfo->epSet.eps[j].port);
347,461✔
488
    }
489
  }
490

491
  code = queryBuildUseDbOutput(pOut, &usedbRsp);
116,915✔
492

493
PROCESS_USEDB_OVER:
116,915✔
494

495
  if (code != 0) {
116,915!
496
    if (pOut) {
×
497
      if (pOut->dbVgroup) taosHashCleanup(pOut->dbVgroup->vgHash);
×
498
      taosMemoryFreeClear(pOut->dbVgroup);
×
499
    }
500
    qError("failed to process usedb rsp since %s", terrstr());
×
501
  }
502

503
  tFreeSUsedbRsp(&usedbRsp);
116,915✔
504
  return code;
116,915✔
505
}
506

507
static int32_t queryConvertTableMetaMsg(STableMetaRsp *pMetaMsg) {
169,731✔
508
  QUERY_PARAM_CHECK(pMetaMsg);
169,731!
509
  if (pMetaMsg->numOfTags < 0 || pMetaMsg->numOfTags > TSDB_MAX_TAGS) {
169,731!
510
    qError("invalid numOfTags[%d] in table meta rsp msg", pMetaMsg->numOfTags);
×
511
    return TSDB_CODE_TSC_INVALID_VALUE;
×
512
  }
513

514
  if (pMetaMsg->numOfColumns > TSDB_MAX_COLUMNS || pMetaMsg->numOfColumns <= 0) {
169,734!
515
    qError("invalid numOfColumns[%d] in table meta rsp msg", pMetaMsg->numOfColumns);
1!
516
    return TSDB_CODE_TSC_INVALID_VALUE;
×
517
  }
518

519
  if (pMetaMsg->tableType != TSDB_SUPER_TABLE && pMetaMsg->tableType != TSDB_CHILD_TABLE &&
169,733✔
520
      pMetaMsg->tableType != TSDB_NORMAL_TABLE && pMetaMsg->tableType != TSDB_SYSTEM_TABLE &&
19,612✔
521
      pMetaMsg->tableType != TSDB_VIRTUAL_NORMAL_TABLE && pMetaMsg->tableType != TSDB_VIRTUAL_CHILD_TABLE) {
98!
522
    qError("invalid tableType[%d] in table meta rsp msg", pMetaMsg->tableType);
×
523
    return TSDB_CODE_TSC_INVALID_VALUE;
×
524
  }
525

526
  if (pMetaMsg->sversion < 0) {
169,733!
527
    qError("invalid sversion[%d] in table meta rsp msg", pMetaMsg->sversion);
×
528
    return TSDB_CODE_TSC_INVALID_VALUE;
×
529
  }
530

531
  if (pMetaMsg->tversion < 0) {
169,733!
532
    qError("invalid tversion[%d] in table meta rsp msg", pMetaMsg->tversion);
×
533
    return TSDB_CODE_TSC_INVALID_VALUE;
×
534
  }
535

536
  if (pMetaMsg->pSchemas[0].colId != PRIMARYKEY_TIMESTAMP_COL_ID) {
169,733!
537
    qError("invalid colId[%" PRIi16 "] for the first column in table meta rsp msg", pMetaMsg->pSchemas[0].colId);
×
538
    return TSDB_CODE_TSC_INVALID_VALUE;
×
539
  }
540

541
  return TSDB_CODE_SUCCESS;
169,733✔
542
}
543

544
int32_t queryCreateCTableMetaFromMsg(STableMetaRsp *msg, SCTableMeta *pMeta) {
137,933✔
545
  QUERY_PARAM_CHECK(msg);
137,933!
546
  QUERY_PARAM_CHECK(pMeta);
137,933!
547
  pMeta->vgId = msg->vgId;
137,933✔
548
  pMeta->tableType = msg->tableType;
137,933✔
549
  pMeta->uid = msg->tuid;
137,933✔
550
  pMeta->suid = msg->suid;
137,933✔
551

552
  qDebug("ctb:%s, uid:0x%" PRIx64 " meta returned, type:%d vgId:%d db:%s suid:%" PRIx64, msg->tbName, pMeta->uid,
137,933✔
553
         pMeta->tableType, pMeta->vgId, msg->dbFName, pMeta->suid);
554

555
  return TSDB_CODE_SUCCESS;
137,937✔
556
}
557

558
int32_t queryCreateVCTableMetaFromMsg(STableMetaRsp *msg, SVCTableMeta **pMeta) {
235✔
559
  QUERY_PARAM_CHECK(msg);
235!
560
  QUERY_PARAM_CHECK(pMeta);
235!
561
  QUERY_PARAM_CHECK(msg->pColRefs);
235!
562

563
  int32_t pColRefSize = sizeof(SColRef) * msg->numOfColRefs;
235✔
564

565
  SVCTableMeta *pTableMeta = taosMemoryCalloc(1, sizeof(SVCTableMeta) + pColRefSize);
235!
566
  if (NULL == pTableMeta) {
235!
567
    qError("calloc size[%d] failed", (int32_t)sizeof(SVCTableMeta) + pColRefSize);
×
568
    return terrno;
×
569
  }
570

571
  pTableMeta->vgId = msg->vgId;
235✔
572
  pTableMeta->tableType = msg->tableType;
235✔
573
  pTableMeta->uid = msg->tuid;
235✔
574
  pTableMeta->suid = msg->suid;
235✔
575
  pTableMeta->numOfColRefs = msg->numOfColRefs;
235✔
576

577
  pTableMeta->colRef = (SColRef *)((char *)pTableMeta + sizeof(SVCTableMeta));
235✔
578
  memcpy(pTableMeta->colRef, msg->pColRefs, pColRefSize);
235✔
579

580
  qDebug("ctable %s uid %" PRIx64 " meta returned, type %d vgId:%d db %s suid %" PRIx64, msg->tbName, (pTableMeta)->uid,
235!
581
         (pTableMeta)->tableType, (pTableMeta)->vgId, msg->dbFName, (pTableMeta)->suid);
582

583
  *pMeta = pTableMeta;
235✔
584
  return TSDB_CODE_SUCCESS;
235✔
585
}
586

587
int32_t queryCreateTableMetaFromMsg(STableMetaRsp *msg, bool isStb, STableMeta **pMeta) {
192,810✔
588
  QUERY_PARAM_CHECK(msg);
192,810!
589
  QUERY_PARAM_CHECK(pMeta);
192,810!
590
  int32_t total = msg->numOfColumns + msg->numOfTags;
192,810✔
591
  int32_t metaSize = sizeof(STableMeta) + sizeof(SSchema) * total;
192,810✔
592
  int32_t schemaExtSize = (withExtSchema(msg->tableType) && msg->pSchemaExt) ? sizeof(SSchemaExt) * msg->numOfColumns : 0;
192,810✔
593
  int32_t pColRefSize = (hasRefCol(msg->tableType) && msg->pColRefs && !isStb) ? sizeof(SColRef) * msg->numOfColRefs : 0;
192,813!
594

595
  STableMeta *pTableMeta = taosMemoryCalloc(1, metaSize + schemaExtSize + pColRefSize);
192,811!
596
  if (NULL == pTableMeta) {
192,810!
597
    qError("calloc size[%d] failed", metaSize);
×
598
    return terrno;
×
599
  }
600
  SSchemaExt *pSchemaExt = (SSchemaExt *)((char *)pTableMeta + metaSize);
192,810✔
601
  SColRef    *pColRef = (SColRef *)((char *)pTableMeta + metaSize + schemaExtSize);
192,810✔
602

603
  pTableMeta->vgId = isStb ? 0 : msg->vgId;
192,810✔
604
  pTableMeta->tableType = isStb ? TSDB_SUPER_TABLE : msg->tableType;
192,810✔
605
  pTableMeta->uid = isStb ? msg->suid : msg->tuid;
192,810✔
606
  pTableMeta->suid = msg->suid;
192,810✔
607
  pTableMeta->sversion = msg->sversion;
192,810✔
608
  pTableMeta->tversion = msg->tversion;
192,810✔
609
  pTableMeta->virtualStb = msg->virtualStb;
192,810✔
610
  pTableMeta->numOfColRefs = msg->numOfColRefs;
192,810✔
611

612
  pTableMeta->tableInfo.numOfTags = msg->numOfTags;
192,810✔
613
  pTableMeta->tableInfo.precision = msg->precision;
192,810✔
614
  pTableMeta->tableInfo.numOfColumns = msg->numOfColumns;
192,810✔
615

616
  memcpy(pTableMeta->schema, msg->pSchemas, sizeof(SSchema) * total);
192,810✔
617
  if (withExtSchema(msg->tableType) && msg->pSchemaExt) {
192,810✔
618
    pTableMeta->schemaExt = pSchemaExt;
190,024✔
619
    memcpy(pSchemaExt, msg->pSchemaExt, schemaExtSize);
190,024✔
620
  } else {
621
    pTableMeta->schemaExt = NULL;
2,789✔
622
  }
623

624
  if (hasRefCol(msg->tableType) && msg->pColRefs && !isStb) {
192,813!
625
    pTableMeta->colRef = (SColRef *)((char *)pTableMeta + metaSize + schemaExtSize);
545✔
626
    memcpy(pTableMeta->colRef, msg->pColRefs, pColRefSize);
545✔
627
  } else {
628
    pTableMeta->colRef = NULL;
192,268✔
629
  }
630

631
  bool hasPK = (msg->numOfColumns > 1) && (pTableMeta->schema[1].flags & COL_IS_KEY);
192,813✔
632
  for (int32_t i = 0; i < msg->numOfColumns; ++i) {
2,818,074✔
633
    pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes;
2,625,261✔
634
    if (hasPK && (i > 0)) {
2,625,261✔
635
      if ((pTableMeta->schema[i].flags & COL_IS_KEY)) {
238,992✔
636
        ++pTableMeta->tableInfo.numOfPKs;
119,505✔
637
      } else {
638
        hasPK = false;
119,487✔
639
      }
640
    }
641
  }
642

643
  qDebug("tb:%s, uid:%" PRIx64 " meta returned, type:%d vgId:%d db:%s stb:%s suid:%" PRIx64
192,813✔
644
         " sver:%d tver:%d"
645
         " tagNum:%d colNum:%d precision:%d rowSize:%d",
646
         msg->tbName, pTableMeta->uid, pTableMeta->tableType, pTableMeta->vgId, msg->dbFName, msg->stbName,
647
         pTableMeta->suid, pTableMeta->sversion, pTableMeta->tversion, pTableMeta->tableInfo.numOfTags,
648
         pTableMeta->tableInfo.numOfColumns, pTableMeta->tableInfo.precision, pTableMeta->tableInfo.rowSize);
649

650
  *pMeta = pTableMeta;
192,812✔
651
  return TSDB_CODE_SUCCESS;
192,812✔
652
}
653

654
int32_t queryCreateTableMetaExFromMsg(STableMetaRsp *msg, bool isStb, STableMeta **pMeta) {
1,211✔
655
  QUERY_PARAM_CHECK(msg);
1,211!
656
  QUERY_PARAM_CHECK(pMeta);
1,211!
657
  int32_t total = msg->numOfColumns + msg->numOfTags;
1,211✔
658
  int32_t metaSize = sizeof(STableMeta) + sizeof(SSchema) * total;
1,211✔
659
  int32_t schemaExtSize = (withExtSchema(msg->tableType) && msg->pSchemaExt) ? sizeof(SSchemaExt) * msg->numOfColumns : 0;
1,211!
660
  int32_t pColRefSize = (hasRefCol(msg->tableType) && msg->pColRefs) ? sizeof(SColRef) * msg->numOfColRefs : 0;
1,211!
661
  int32_t tbNameSize = strlen(msg->tbName) + 1;
1,211✔
662

663
  STableMeta *pTableMeta = taosMemoryCalloc(1, metaSize + schemaExtSize + pColRefSize + tbNameSize);
1,211!
664
  if (NULL == pTableMeta) {
1,211!
665
    qError("calloc size[%d] failed", metaSize);
×
666
    return terrno;
×
667
  }
668
  SSchemaExt *pSchemaExt = (SSchemaExt *)((char *)pTableMeta + metaSize);
1,211✔
669
  SColRef    *pColRef = (SColRef *)((char *)pTableMeta + metaSize + schemaExtSize);
1,211✔
670

671
  pTableMeta->vgId = isStb ? 0 : msg->vgId;
1,211✔
672
  pTableMeta->tableType = isStb ? TSDB_SUPER_TABLE : msg->tableType;
1,211✔
673
  pTableMeta->uid = isStb ? msg->suid : msg->tuid;
1,211✔
674
  pTableMeta->suid = msg->suid;
1,211✔
675
  pTableMeta->sversion = msg->sversion;
1,211✔
676
  pTableMeta->tversion = msg->tversion;
1,211✔
677
  pTableMeta->virtualStb = msg->virtualStb;
1,211✔
678
  pTableMeta->numOfColRefs = msg->numOfColRefs;
1,211✔
679

680
  pTableMeta->tableInfo.numOfTags = msg->numOfTags;
1,211✔
681
  pTableMeta->tableInfo.precision = msg->precision;
1,211✔
682
  pTableMeta->tableInfo.numOfColumns = msg->numOfColumns;
1,211✔
683

684
  TAOS_MEMCPY(pTableMeta->schema, msg->pSchemas, sizeof(SSchema) * total);
1,211✔
685
  if (withExtSchema(msg->tableType) && msg->pSchemaExt) {
1,211!
686
    pTableMeta->schemaExt = pSchemaExt;
1,211✔
687
    TAOS_MEMCPY(pSchemaExt, msg->pSchemaExt, schemaExtSize);
1,211✔
688
  } else {
689
    pTableMeta->schemaExt = NULL;
×
690
  }
691

692
  if (hasRefCol(msg->tableType) && msg->pColRefs) {
1,211!
693
    pTableMeta->colRef = (SColRef *)((char *)pTableMeta + metaSize + schemaExtSize);
×
694
    memcpy(pTableMeta->colRef, msg->pColRefs, pColRefSize);
×
695
  } else {
696
    pTableMeta->colRef = NULL;
1,211✔
697
  }
698

699
  bool hasPK = (msg->numOfColumns > 1) && (pTableMeta->schema[1].flags & COL_IS_KEY);
1,211!
700
  for (int32_t i = 0; i < msg->numOfColumns; ++i) {
3,942✔
701
    pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes;
2,731✔
702
    if (hasPK && (i > 0)) {
2,731!
703
      if ((pTableMeta->schema[i].flags & COL_IS_KEY)) {
×
704
        ++pTableMeta->tableInfo.numOfPKs;
×
705
      } else {
706
        hasPK = false;
×
707
      }
708
    }
709
  }
710

711
  char *pTbName = (char *)pTableMeta + metaSize + schemaExtSize + pColRefSize;
1,211✔
712
  tstrncpy(pTbName, msg->tbName, tbNameSize);
1,211✔
713

714
  qDebug("tb:%s, uid:%" PRIx64 " meta returned, type:%d vgId:%d db:%s stb:%s suid:%" PRIx64
1,211!
715
         " sver:%d tver:%d"
716
         " tagNum:%d colNum:%d precision:%d rowSize:%d",
717
         msg->tbName, pTableMeta->uid, pTableMeta->tableType, pTableMeta->vgId, msg->dbFName, msg->stbName,
718
         pTableMeta->suid, pTableMeta->sversion, pTableMeta->tversion, pTableMeta->tableInfo.numOfTags,
719
         pTableMeta->tableInfo.numOfColumns, pTableMeta->tableInfo.precision, pTableMeta->tableInfo.rowSize);
720

721
  *pMeta = pTableMeta;
1,211✔
722
  return TSDB_CODE_SUCCESS;
1,211✔
723
}
724

725
int32_t queryProcessTableMetaRsp(void *output, char *msg, int32_t msgSize) {
168,518✔
726
  int32_t       code = 0;
168,518✔
727
  STableMetaRsp metaRsp = {0};
168,518✔
728

729
  if (NULL == output || NULL == msg || msgSize <= 0) {
168,518!
730
    qError("queryProcessTableMetaRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
731
    code = TSDB_CODE_TSC_INVALID_INPUT;
×
732
    goto PROCESS_META_OVER;
×
733
  }
734

735
  if (tDeserializeSTableMetaRsp(msg, msgSize, &metaRsp) != 0) {
168,519!
736
    code = TSDB_CODE_INVALID_MSG;
×
737
    goto PROCESS_META_OVER;
×
738
  }
739

740
  code = queryConvertTableMetaMsg(&metaRsp);
168,522✔
741
  if (code != TSDB_CODE_SUCCESS) {
168,521!
742
    goto PROCESS_META_OVER;
×
743
  }
744

745
  if (!IS_SYS_DBNAME(metaRsp.dbFName) &&
168,521!
746
      !tIsValidSchema(metaRsp.pSchemas, metaRsp.numOfColumns, metaRsp.numOfTags)) {
166,349!
747
    code = TSDB_CODE_TSC_INVALID_VALUE;
×
748
    goto PROCESS_META_OVER;
×
749
  }
750

751
  STableMetaOutput *pOut = output;
168,516✔
752
  tstrncpy(pOut->dbFName, metaRsp.dbFName, TSDB_DB_FNAME_LEN);
168,516✔
753
  pOut->dbId = metaRsp.dbId;
168,516✔
754

755
  if (metaRsp.tableType == TSDB_CHILD_TABLE) {
168,516✔
756
    SET_META_TYPE_BOTH_TABLE(pOut->metaType);
129,951✔
757

758
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
129,951✔
759
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
129,951✔
760

761
    pOut->ctbMeta.vgId = metaRsp.vgId;
129,951✔
762
    pOut->ctbMeta.tableType = metaRsp.tableType;
129,951✔
763
    pOut->ctbMeta.uid = metaRsp.tuid;
129,951✔
764
    pOut->ctbMeta.suid = metaRsp.suid;
129,951✔
765

766
    code = queryCreateTableMetaFromMsg(&metaRsp, true, &pOut->tbMeta);
129,951✔
767
  } else if (metaRsp.tableType == TSDB_VIRTUAL_CHILD_TABLE) {
38,565✔
768
    SET_META_TYPE_BOTH_VTABLE(pOut->metaType);
78✔
769

770
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
78✔
771
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
78✔
772

773
    code = queryCreateVCTableMetaFromMsg(&metaRsp, &pOut->vctbMeta);
78✔
774
    if (TSDB_CODE_SUCCESS != code) {
78!
775
      goto PROCESS_META_OVER;
×
776
    }
777
    code = queryCreateTableMetaFromMsg(&metaRsp, true, &pOut->tbMeta);
78✔
778
  } else {
779
    SET_META_TYPE_TABLE(pOut->metaType);
38,487✔
780
    tstrncpy(pOut->tbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
38,487✔
781
    code = queryCreateTableMetaFromMsg(&metaRsp, (metaRsp.tableType == TSDB_SUPER_TABLE), &pOut->tbMeta);
38,487✔
782
  }
783

784
PROCESS_META_OVER:
168,521✔
785
  if (code != 0) {
168,521!
786
    qError("failed to process table meta rsp since %s", tstrerror(code));
×
787
  }
788

789
  tFreeSTableMetaRsp(&metaRsp);
168,521✔
790
  return code;
168,518✔
791
}
792

793
static int32_t queryProcessTableNameRsp(void *output, char *msg, int32_t msgSize) {
1,211✔
794
  int32_t       code = 0;
1,211✔
795
  STableMetaRsp metaRsp = {0};
1,211✔
796

797
  if (NULL == output || NULL == msg || msgSize <= 0) {
1,211!
798
    qError("queryProcessTableNameRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
799
    code = TSDB_CODE_TSC_INVALID_INPUT;
×
800
    goto PROCESS_NAME_OVER;
×
801
  }
802

803
  if (tDeserializeSTableMetaRsp(msg, msgSize, &metaRsp) != 0) {
1,211!
804
    code = TSDB_CODE_INVALID_MSG;
×
805
    goto PROCESS_NAME_OVER;
×
806
  }
807

808
  code = queryConvertTableMetaMsg(&metaRsp);
1,211✔
809
  if (code != TSDB_CODE_SUCCESS) {
1,211!
810
    goto PROCESS_NAME_OVER;
×
811
  }
812

813
  if (!IS_SYS_DBNAME(metaRsp.dbFName) &&
1,211!
814
      !tIsValidSchema(metaRsp.pSchemas, metaRsp.numOfColumns, metaRsp.numOfTags)) {
1,211!
815
    code = TSDB_CODE_TSC_INVALID_VALUE;
×
816
    goto PROCESS_NAME_OVER;
×
817
  }
818

819
  STableMetaOutput *pOut = output;
1,211✔
820
  tstrncpy(pOut->dbFName, metaRsp.dbFName, TSDB_DB_FNAME_LEN);
1,211✔
821
  pOut->dbId = metaRsp.dbId;
1,211✔
822

823
  if (metaRsp.tableType == TSDB_CHILD_TABLE) {
1,211✔
824
    SET_META_TYPE_BOTH_TABLE(pOut->metaType);
317✔
825

826
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
317✔
827
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
317✔
828

829
    pOut->ctbMeta.vgId = metaRsp.vgId;
317✔
830
    pOut->ctbMeta.tableType = metaRsp.tableType;
317✔
831
    pOut->ctbMeta.uid = metaRsp.tuid;
317✔
832
    pOut->ctbMeta.suid = metaRsp.suid;
317✔
833

834
    code = queryCreateTableMetaExFromMsg(&metaRsp, true, &pOut->tbMeta);
317✔
835
  } else if (metaRsp.tableType == TSDB_VIRTUAL_CHILD_TABLE) {
894!
836
    SET_META_TYPE_BOTH_VTABLE(pOut->metaType);
×
837

838
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
×
839
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
×
840

841
    code = queryCreateVCTableMetaFromMsg(&metaRsp, &pOut->vctbMeta);
×
842
    if (TSDB_CODE_SUCCESS != code) {
×
843
      goto PROCESS_NAME_OVER;
×
844
    }
845

846
    code = queryCreateTableMetaExFromMsg(&metaRsp, true, &pOut->tbMeta);
×
847
  } else {
848
    SET_META_TYPE_TABLE(pOut->metaType);
894✔
849
    tstrncpy(pOut->tbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
894✔
850
    code = queryCreateTableMetaExFromMsg(&metaRsp, (metaRsp.tableType == TSDB_SUPER_TABLE), &pOut->tbMeta);
894✔
851
  }
852

853
PROCESS_NAME_OVER:
1,211✔
854
  if (code != 0) {
1,211!
855
    qError("failed to process table name rsp since %s", tstrerror(code));
×
856
  }
857

858
  tFreeSTableMetaRsp(&metaRsp);
1,211✔
859
  return code;
1,211✔
860
}
861

862
int32_t queryProcessQnodeListRsp(void *output, char *msg, int32_t msgSize) {
12,411✔
863
  SQnodeListRsp out = {0};
12,411✔
864
  int32_t       code = 0;
12,411✔
865

866
  if (NULL == output || NULL == msg || msgSize <= 0) {
12,411!
867
    qError("queryProcessQnodeListRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
868
    code = TSDB_CODE_TSC_INVALID_INPUT;
×
869
    return code;
×
870
  }
871

872
  out.qnodeList = (SArray *)output;
12,411✔
873
  if (tDeserializeSQnodeListRsp(msg, msgSize, &out) != 0) {
12,411!
874
    qError("invalid qnode list rsp msg, msgSize:%d", msgSize);
×
875
    code = TSDB_CODE_INVALID_MSG;
×
876
    return code;
×
877
  }
878

879
  return code;
12,411✔
880
}
881

882
int32_t queryProcessDnodeListRsp(void *output, char *msg, int32_t msgSize) {
354✔
883
  SDnodeListRsp out = {0};
354✔
884
  int32_t       code = 0;
354✔
885

886
  if (NULL == output || NULL == msg || msgSize <= 0) {
354!
887
    qError("queryProcessDnodeListRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
888
    code = TSDB_CODE_TSC_INVALID_INPUT;
×
889
    return code;
×
890
  }
891

892
  if (tDeserializeSDnodeListRsp(msg, msgSize, &out) != 0) {
354!
893
    qError("invalid dnode list rsp msg, msgSize:%d", msgSize);
×
894
    code = TSDB_CODE_INVALID_MSG;
×
895
    return code;
×
896
  }
897

898
  *(SArray **)output = out.dnodeList;
354✔
899

900
  return code;
354✔
901
}
902

903
int32_t queryProcessGetSerVerRsp(void *output, char *msg, int32_t msgSize) {
1✔
904
  SServerVerRsp out = {0};
1✔
905
  int32_t       code = 0;
1✔
906

907
  if (NULL == output || NULL == msg || msgSize <= 0) {
1!
908
    qError("queryProcessGetSerVerRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
909
    code = TSDB_CODE_TSC_INVALID_INPUT;
×
910
    return code;
×
911
  }
912

913
  if (tDeserializeSServerVerRsp(msg, msgSize, &out) != 0) {
1!
914
    qError("invalid svr ver rsp msg, msgSize:%d", msgSize);
×
915
    code = TSDB_CODE_INVALID_MSG;
×
916
    return code;
×
917
  }
918

919
  *(char **)output = taosStrdup(out.ver);
1!
920
  if (NULL == *(char **)output) {
1!
921
    return terrno;
×
922
  }
923

924
  return code;
1✔
925
}
926

927
int32_t queryProcessGetDbCfgRsp(void *output, char *msg, int32_t msgSize) {
5,621✔
928
  SDbCfgRsp out = {0};
5,621✔
929

930
  if (NULL == output || NULL == msg || msgSize <= 0) {
5,621!
931
    qError("queryProcessGetDbCfgRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
932
    return TSDB_CODE_TSC_INVALID_INPUT;
×
933
  }
934

935
  if (tDeserializeSDbCfgRsp(msg, msgSize, &out) != 0) {
5,621!
936
    qError("tDeserializeSDbCfgRsp failed, msgSize:%d, dbCfgRsp:%lu", msgSize, sizeof(out));
×
937
    return TSDB_CODE_INVALID_MSG;
×
938
  }
939

940
  memcpy(output, &out, sizeof(out));
5,621✔
941

942
  return TSDB_CODE_SUCCESS;
5,621✔
943
}
944

945
int32_t queryProcessGetIndexRsp(void *output, char *msg, int32_t msgSize) {
×
946
  SUserIndexRsp out = {0};
×
947

948
  if (NULL == output || NULL == msg || msgSize <= 0) {
×
949
    qError("queryProcessGetIndexRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
950
    return TSDB_CODE_TSC_INVALID_INPUT;
×
951
  }
952

953
  if (tDeserializeSUserIndexRsp(msg, msgSize, &out) != 0) {
×
954
    qError("tDeserializeSUserIndexRsp failed, msgSize:%d", msgSize);
×
955
    return TSDB_CODE_INVALID_MSG;
×
956
  }
957

958
  memcpy(output, &out, sizeof(out));
×
959

960
  return TSDB_CODE_SUCCESS;
×
961
}
962

963
int32_t queryProcessRetrieveFuncRsp(void *output, char *msg, int32_t msgSize) {
87✔
964
  SRetrieveFuncRsp out = {0};
87✔
965

966
  if (NULL == output || NULL == msg || msgSize <= 0) {
87!
967
    qError("queryProcessRetrieveFuncRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
968
    return TSDB_CODE_TSC_INVALID_INPUT;
×
969
  }
970

971
  if (tDeserializeSRetrieveFuncRsp(msg, msgSize, &out) != 0) {
87!
972
    qError("tDeserializeSRetrieveFuncRsp failed, msgSize:%d", msgSize);
×
973
    return TSDB_CODE_INVALID_MSG;
×
974
  }
975

976
  if (1 != out.numOfFuncs) {
87!
977
    qError("invalid func num returned, numOfFuncs:%d", out.numOfFuncs);
×
978
    return TSDB_CODE_INVALID_MSG;
×
979
  }
980

981
  SFuncInfo *funcInfo = taosArrayGet(out.pFuncInfos, 0);
87✔
982

983
  memcpy(output, funcInfo, sizeof(*funcInfo));
87✔
984
  taosArrayDestroy(out.pFuncInfos);
87✔
985
  taosArrayDestroy(out.pFuncExtraInfos);
87✔
986

987
  return TSDB_CODE_SUCCESS;
87✔
988
}
989

990
int32_t queryProcessGetUserAuthRsp(void *output, char *msg, int32_t msgSize) {
22,052✔
991
  if (NULL == output || NULL == msg || msgSize <= 0) {
22,052!
992
    qError("queryProcessGetUserAuthRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
993
    return TSDB_CODE_TSC_INVALID_INPUT;
×
994
  }
995

996
  if (tDeserializeSGetUserAuthRsp(msg, msgSize, (SGetUserAuthRsp *)output) != 0) {
22,052!
997
    qError("tDeserializeSGetUserAuthRsp failed, msgSize:%d", msgSize);
×
998
    return TSDB_CODE_INVALID_MSG;
×
999
  }
1000

1001
  return TSDB_CODE_SUCCESS;
22,051✔
1002
}
1003

1004
int32_t queryProcessGetTbIndexRsp(void *output, char *msg, int32_t msgSize) {
1✔
1005
  if (NULL == output || NULL == msg || msgSize <= 0) {
1!
1006
    qError("queryProcessGetTbIndexRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1007
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1008
  }
1009

1010
  STableIndexRsp *out = (STableIndexRsp *)output;
1✔
1011
  if (tDeserializeSTableIndexRsp(msg, msgSize, out) != 0) {
1!
1012
    qError("tDeserializeSTableIndexRsp failed, msgSize:%d", msgSize);
×
1013
    return TSDB_CODE_INVALID_MSG;
×
1014
  }
1015

1016
  return TSDB_CODE_SUCCESS;
1✔
1017
}
1018

1019
int32_t queryProcessGetTbCfgRsp(void *output, char *msg, int32_t msgSize) {
225✔
1020
  if (NULL == output || NULL == msg || msgSize <= 0) {
225!
1021
    qError("queryProcessGetTbCfgRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1022
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1023
  }
1024

1025
  STableCfgRsp *out = taosMemoryCalloc(1, sizeof(STableCfgRsp));
225!
1026
  if(out == NULL) {
225!
1027
    return terrno;
×
1028
  }
1029
  if (tDeserializeSTableCfgRsp(msg, msgSize, out) != 0) {
225!
1030
    qError("tDeserializeSTableCfgRsp failed, msgSize:%d", msgSize);
×
1031
    tFreeSTableCfgRsp(out);
×
1032
    taosMemoryFree(out);
×
1033
    return TSDB_CODE_INVALID_MSG;
×
1034
  }
1035

1036
  *(STableCfgRsp **)output = out;
225✔
1037

1038
  return TSDB_CODE_SUCCESS;
225✔
1039
}
1040

1041
int32_t queryProcessGetViewMetaRsp(void *output, char *msg, int32_t msgSize) {
313✔
1042
  if (NULL == output || NULL == msg || msgSize <= 0) {
313!
1043
    qError("queryProcessGetViewMetaRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1044
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1045
  }
1046

1047
  SViewMetaRsp *out = taosMemoryCalloc(1, sizeof(SViewMetaRsp));
313!
1048
  if (out == NULL) {
313!
1049
    return terrno;
×
1050
  }
1051
  if (tDeserializeSViewMetaRsp(msg, msgSize, out) != 0) {
313!
1052
    qError("tDeserializeSViewMetaRsp failed, msgSize:%d", msgSize);
×
1053
    tFreeSViewMetaRsp(out);
×
1054
    taosMemoryFree(out);
×
1055
    return TSDB_CODE_INVALID_MSG;
×
1056
  }
1057

1058
  qDebugL("view meta recved, dbFName:%s, view:%s, querySQL:%s", out->dbFName, out->name, out->querySql);
313✔
1059

1060
  *(SViewMetaRsp **)output = out;
313✔
1061

1062
  return TSDB_CODE_SUCCESS;
313✔
1063
}
1064

1065
int32_t queryProcessGetTbTSMARsp(void* output, char* msg, int32_t msgSize) {
855✔
1066
  if (NULL == output || NULL == msg || msgSize <= 0) {
855!
1067
    qError("queryProcessGetTbTSMARsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1068
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1069
  }
1070

1071
  if (tDeserializeTableTSMAInfoRsp(msg, msgSize, output) != 0) {
855!
1072
    qError("tDeserializeSViewMetaRsp failed, msgSize:%d", msgSize);
×
1073
    return TSDB_CODE_INVALID_MSG;
×
1074
  }
1075

1076
  return TSDB_CODE_SUCCESS;
855✔
1077
}
1078

1079
int32_t queryProcessStreamProgressRsp(void* output, char* msg, int32_t msgSize) {
4,401✔
1080
  if (!output || !msg || msgSize <= 0) {
4,401!
1081
    qError("queryProcessStreamProgressRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1082
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1083
  }
1084

1085
  if (tDeserializeSStreamProgressRsp(msg, msgSize, output) != 0) {
4,401!
1086
    qError("tDeserializeStreamProgressRsp failed, msgSize:%d", msgSize);
×
1087
    return TSDB_CODE_INVALID_MSG;
×
1088
  }
1089
  return TSDB_CODE_SUCCESS;
4,402✔
1090
}
1091

1092
int32_t queryProcessVSubTablesRsp(void* output, char* msg, int32_t msgSize) {
24✔
1093
  if (!output || !msg || msgSize <= 0) {
24!
1094
    qError("queryProcessVSubTablesRsp input error, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1095
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1096
  }
1097

1098
  SVSubTablesRsp* pRsp = (SVSubTablesRsp*)output;
24✔
1099
  int32_t code = tDeserializeSVSubTablesRsp(msg, msgSize, pRsp);
24✔
1100
  if (code != 0) {
24!
1101
    qError("tDeserializeSVSubTablesRsp failed, msgSize: %d, error:%d", msgSize, code);
×
1102
    return code;
×
1103
  }
1104
  
1105
  return TSDB_CODE_SUCCESS;
24✔
1106
}
1107

1108
void initQueryModuleMsgHandle() {
17,974✔
1109
  queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_META)] = queryBuildTableMetaReqMsg;
17,974✔
1110
  queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_NAME)] = queryBuildTableMetaReqMsg;
17,974✔
1111
  queryBuildMsg[TMSG_INDEX(TDMT_MND_TABLE_META)] = queryBuildTableMetaReqMsg;
17,974✔
1112
  queryBuildMsg[TMSG_INDEX(TDMT_MND_USE_DB)] = queryBuildUseDbMsg;
17,974✔
1113
  queryBuildMsg[TMSG_INDEX(TDMT_MND_QNODE_LIST)] = queryBuildQnodeListMsg;
17,974✔
1114
  queryBuildMsg[TMSG_INDEX(TDMT_MND_DNODE_LIST)] = queryBuildDnodeListMsg;
17,974✔
1115
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_DB_CFG)] = queryBuildGetDBCfgMsg;
17,974✔
1116
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_INDEX)] = queryBuildGetIndexMsg;
17,974✔
1117
  queryBuildMsg[TMSG_INDEX(TDMT_MND_RETRIEVE_FUNC)] = queryBuildRetrieveFuncMsg;
17,974✔
1118
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_USER_AUTH)] = queryBuildGetUserAuthMsg;
17,974✔
1119
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_TABLE_INDEX)] = queryBuildGetTbIndexMsg;
17,974✔
1120
  queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_CFG)] = queryBuildGetTbCfgMsg;
17,974✔
1121
  queryBuildMsg[TMSG_INDEX(TDMT_MND_TABLE_CFG)] = queryBuildGetTbCfgMsg;
17,974✔
1122
  queryBuildMsg[TMSG_INDEX(TDMT_MND_SERVER_VERSION)] = queryBuildGetSerVerMsg;
17,974✔
1123
  queryBuildMsg[TMSG_INDEX(TDMT_MND_VIEW_META)] = queryBuildGetViewMetaMsg;
17,974✔
1124
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_TABLE_TSMA)] = queryBuildGetTableTSMAMsg;
17,974✔
1125
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_TSMA)] = queryBuildGetTSMAMsg;
17,974✔
1126
  queryBuildMsg[TMSG_INDEX(TDMT_VND_GET_STREAM_PROGRESS)] = queryBuildGetStreamProgressMsg;
17,974✔
1127
  queryBuildMsg[TMSG_INDEX(TDMT_VND_VSUBTABLES_META)] = queryBuildVSubTablesMsg;
17,974✔
1128

1129
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_TABLE_META)] = queryProcessTableMetaRsp;
17,974✔
1130
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_TABLE_NAME)] = queryProcessTableNameRsp;
17,974✔
1131
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_TABLE_META)] = queryProcessTableMetaRsp;
17,974✔
1132
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_USE_DB)] = queryProcessUseDBRsp;
17,974✔
1133
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_QNODE_LIST)] = queryProcessQnodeListRsp;
17,974✔
1134
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_DNODE_LIST)] = queryProcessDnodeListRsp;
17,974✔
1135
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_DB_CFG)] = queryProcessGetDbCfgRsp;
17,974✔
1136
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_INDEX)] = queryProcessGetIndexRsp;
17,974✔
1137
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_RETRIEVE_FUNC)] = queryProcessRetrieveFuncRsp;
17,974✔
1138
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_USER_AUTH)] = queryProcessGetUserAuthRsp;
17,974✔
1139
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_TABLE_INDEX)] = queryProcessGetTbIndexRsp;
17,974✔
1140
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_TABLE_CFG)] = queryProcessGetTbCfgRsp;
17,974✔
1141
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_TABLE_CFG)] = queryProcessGetTbCfgRsp;
17,974✔
1142
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_SERVER_VERSION)] = queryProcessGetSerVerRsp;
17,974✔
1143
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_VIEW_META)] = queryProcessGetViewMetaRsp;
17,974✔
1144
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_TABLE_TSMA)] = queryProcessGetTbTSMARsp;
17,974✔
1145
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_TSMA)] = queryProcessGetTbTSMARsp;
17,974✔
1146
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_GET_STREAM_PROGRESS)] = queryProcessStreamProgressRsp;
17,974✔
1147
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_VSUBTABLES_META)] = queryProcessVSubTablesRsp;
17,974✔
1148
}
17,974✔
1149

1150
#pragma GCC diagnostic pop
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