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

taosdata / TDengine / #4506

15 Jul 2025 12:33AM UTC coverage: 62.026% (-0.7%) from 62.706%
#4506

push

travis-ci

web-flow
docs: update stream docs (#31874)

155391 of 320094 branches covered (48.55%)

Branch coverage included in aggregate %.

240721 of 318525 relevant lines covered (75.57%)

6529048.03 hits per line

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

51.97
/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) {
155,318✔
32
  QUERY_PARAM_CHECK(pOut);
155,318!
33
  QUERY_PARAM_CHECK(usedbRsp);
155,318!
34
  memcpy(pOut->db, usedbRsp->db, TSDB_DB_FNAME_LEN);
155,318✔
35
  pOut->dbId = usedbRsp->uid;
155,318✔
36

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

42
  pOut->dbVgroup->vgVersion = usedbRsp->vgVersion;
155,322✔
43
  pOut->dbVgroup->hashMethod = usedbRsp->hashMethod;
155,322✔
44
  pOut->dbVgroup->hashPrefix = usedbRsp->hashPrefix;
155,322✔
45
  pOut->dbVgroup->hashSuffix = usedbRsp->hashSuffix;
155,322✔
46
  pOut->dbVgroup->stateTs = usedbRsp->stateTs;
155,322✔
47
  pOut->dbVgroup->flags = usedbRsp->flags;
155,322✔
48

49
  qDebug("db:%s, get %d vgroup, vgVersion:%d, stateTs:%" PRId64, usedbRsp->db, usedbRsp->vgNum, usedbRsp->vgVersion,
155,322✔
50
         usedbRsp->stateTs);
51

52
  if (usedbRsp->vgNum <= 0) {
155,320✔
53
    return TSDB_CODE_SUCCESS;
8,851✔
54
  }
55

56
  pOut->dbVgroup->vgHash =
292,938✔
57
      taosHashInit(usedbRsp->vgNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
146,469✔
58
  if (NULL == pOut->dbVgroup->vgHash) {
146,469!
59
    return terrno;
×
60
  }
61

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

72
  return TSDB_CODE_SUCCESS;
146,469✔
73
}
74

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

82
  STableInfoReq infoReq = {0};
148,765✔
83
  infoReq.option = pInput->option;
148,765✔
84
  infoReq.header.vgId = pInput->vgId;
148,765✔
85
  infoReq.autoCreateCtb = pInput->autoCreateCtb;
148,765✔
86

87
  if (pInput->dbFName) {
148,765!
88
    tstrncpy(infoReq.dbFName, pInput->dbFName, TSDB_DB_FNAME_LEN);
148,766✔
89
  }
90
  tstrncpy(infoReq.tbName, pInput->tbName, TSDB_TABLE_NAME_LEN);
148,765✔
91

92
  int32_t bufLen = tSerializeSTableInfoReq(NULL, 0, &infoReq);
148,765✔
93
  void   *pBuf = (*mallcFp)(bufLen);
148,756✔
94
  if (NULL == pBuf) {
148,762!
95
    return terrno;
×
96
  }
97
  int32_t ret = tSerializeSTableInfoReq(pBuf, bufLen, &infoReq);
148,762✔
98
  if (ret < 0) return ret;
148,763!
99

100
  *msg = pBuf;
148,763✔
101
  *msgLen = bufLen;
148,763✔
102

103
  return TSDB_CODE_SUCCESS;
148,763✔
104
}
105

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

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

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

128
  *msg = pBuf;
148,582✔
129
  *msgLen = bufLen;
148,582✔
130

131
  return TSDB_CODE_SUCCESS;
148,582✔
132
}
133

134
int32_t queryBuildQnodeListMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
11,824✔
135
  QUERY_PARAM_CHECK(msg);
11,824!
136
  QUERY_PARAM_CHECK(msgLen);
11,824!
137

138
  SQnodeListReq qnodeListReq = {0};
11,824✔
139
  qnodeListReq.rowNum = -1;
11,824✔
140

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

147
  int32_t ret = tSerializeSQnodeListReq(pBuf, bufLen, &qnodeListReq);
11,824✔
148
  if (ret < 0) return ret;
11,824!
149

150
  *msg = pBuf;
11,824✔
151
  *msgLen = bufLen;
11,824✔
152

153
  return TSDB_CODE_SUCCESS;
11,824✔
154
}
155

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

160
  SDnodeListReq dnodeListReq = {0};
363✔
161
  dnodeListReq.rowNum = -1;
363✔
162

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

171
  *msg = pBuf;
363✔
172
  *msgLen = bufLen;
363✔
173

174
  return TSDB_CODE_SUCCESS;
363✔
175
}
176

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

181
  SServerVerReq req = {0};
1✔
182

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

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

194
  return TSDB_CODE_SUCCESS;
1✔
195
}
196

197
int32_t queryBuildGetDBCfgMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
6,313✔
198
  QUERY_PARAM_CHECK(input);
6,313!
199
  QUERY_PARAM_CHECK(msg);
6,313!
200
  QUERY_PARAM_CHECK(msgLen);
6,313!
201

202
  SDbCfgReq dbCfgReq = {0};
6,313✔
203
  tstrncpy(dbCfgReq.db, input, TSDB_DB_FNAME_LEN);
6,313✔
204

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

213
  *msg = pBuf;
6,313✔
214
  *msgLen = bufLen;
6,313✔
215

216
  return TSDB_CODE_SUCCESS;
6,313✔
217
}
218

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

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

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

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

238
  return TSDB_CODE_SUCCESS;
1✔
239
}
240

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

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

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

271
  taosArrayDestroy(funcReq.pFuncNames);
97✔
272

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

276
  return TSDB_CODE_SUCCESS;
97✔
277
}
278

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

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

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

295
  *msg = pBuf;
22,184✔
296
  *msgLen = bufLen;
22,184✔
297

298
  return TSDB_CODE_SUCCESS;
22,184✔
299
}
300

301
int32_t queryBuildGetTbIndexMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
1,411✔
302
  QUERY_PARAM_CHECK(input);
1,411!
303
  QUERY_PARAM_CHECK(msg);
1,411!
304
  QUERY_PARAM_CHECK(msgLen);
1,411!
305

306
  STableIndexReq indexReq = {0};
1,411✔
307
  tstrncpy(indexReq.tbFName, input, TSDB_TABLE_FNAME_LEN);
1,411✔
308

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

317
  *msg = pBuf;
1,411✔
318
  *msgLen = bufLen;
1,411✔
319

320
  return TSDB_CODE_SUCCESS;
1,411✔
321
}
322

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

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

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

342
  *msg = pBuf;
246✔
343
  *msgLen = bufLen;
246✔
344

345
  return TSDB_CODE_SUCCESS;
246✔
346
}
347

348
int32_t queryBuildGetViewMetaMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
43,987✔
349
  QUERY_PARAM_CHECK(input);
43,987!
350
  QUERY_PARAM_CHECK(msg);
43,987!
351
  QUERY_PARAM_CHECK(msgLen);
43,987!
352

353
  SViewMetaReq req = {0};
43,987✔
354
  tstrncpy(req.fullname, input, TSDB_VIEW_FNAME_LEN);
43,987✔
355

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

364
  *msg = pBuf;
43,987✔
365
  *msgLen = bufLen;
43,987✔
366

367
  return TSDB_CODE_SUCCESS;
43,987✔
368
}
369

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

376
  STableTSMAInfoReq req = {0};
1,119✔
377
  tstrncpy(req.name, input, TSDB_TABLE_FNAME_LEN);
1,119✔
378

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

387
  *msg = pBuf;
1,119✔
388
  *msgLen = bufLen;
1,119✔
389
  return TSDB_CODE_SUCCESS;
1,119✔
390
}
391

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

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

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

411
  *msg = pBuf;
60✔
412
  *msgLen = bufLen;
60✔
413
  return TSDB_CODE_SUCCESS;
60✔
414
}
415

416
int32_t queryBuildGetStreamProgressMsg(void* input, char** msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int64_t)) {
5,474✔
417
  QUERY_PARAM_CHECK(input);
5,474!
418
  QUERY_PARAM_CHECK(msg);
5,474!
419
  QUERY_PARAM_CHECK(msgLen);
5,474!
420

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

427
  int32_t ret = tSerializeStreamProgressReq(pBuf, len, input);
5,474✔
428
  if (ret < 0) return ret;
5,474!
429

430
  *msg = pBuf;
5,474✔
431
  *msgLen = len;
5,474✔
432
  return TSDB_CODE_SUCCESS;
5,474✔
433
}
434

435

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

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

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

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

456
  return TSDB_CODE_SUCCESS;
24✔
457
}
458

459
int32_t queryBuildVStbRefDBsMsg(void* input, char** msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int64_t)) {
9,988✔
460
  QUERY_PARAM_CHECK(input);
9,988!
461
  QUERY_PARAM_CHECK(msg);
9,988!
462
  QUERY_PARAM_CHECK(msgLen);
9,988!
463

464
  SVStbRefDbsReq req = {0};
9,988✔
465
  req.suid = *(int64_t*)input;
9,988✔
466

467
  int32_t bufLen = tSerializeSVStbRefDbsReq(NULL, 0, &req);
9,988✔
468
  void   *pBuf = (*mallcFp)(bufLen);
9,988✔
469
  if (NULL == pBuf) {
9,988!
470
    return terrno;
×
471
  }
472
  if(tSerializeSVStbRefDbsReq(pBuf, bufLen, &req) < 0)   {
9,988!
473
    return TSDB_CODE_TSC_INVALID_INPUT;
×
474
  }
475

476
  *msg = pBuf;
9,988✔
477
  *msgLen = bufLen;
9,988✔
478

479
  return TSDB_CODE_SUCCESS;
9,988✔
480
}
481

482
int32_t queryProcessUseDBRsp(void *output, char *msg, int32_t msgSize) {
147,784✔
483
  SUseDbOutput *pOut = output;
147,784✔
484
  SUseDbRsp     usedbRsp = {0};
147,784✔
485
  int32_t       code = -1;
147,784✔
486

487
  if (NULL == output || NULL == msg || msgSize <= 0) {
147,784!
488
    code = TSDB_CODE_TSC_INVALID_INPUT;
×
489
    qError("invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
490
    goto PROCESS_USEDB_OVER;
×
491
  }
492

493
  if (tDeserializeSUseDbRsp(msg, msgSize, &usedbRsp) != 0) {
147,784!
494
    qError("invalid use db rsp msg, msgSize:%d", msgSize);
×
495
    code = TSDB_CODE_INVALID_MSG;
×
496
    goto PROCESS_USEDB_OVER;
×
497
  }
498

499
  if (usedbRsp.vgNum < 0) {
147,784!
500
    qError("invalid db[%s] vgroup number[%d]", usedbRsp.db, usedbRsp.vgNum);
×
501
    code = TSDB_CODE_TSC_INVALID_VALUE;
×
502
    goto PROCESS_USEDB_OVER;
×
503
  }
504

505
  qTrace("db:%s, usedbRsp received, numOfVgroups:%d", usedbRsp.db, usedbRsp.vgNum);
147,784✔
506
  for (int32_t i = 0; i < usedbRsp.vgNum; ++i) {
488,768✔
507
    SVgroupInfo *pInfo = taosArrayGet(usedbRsp.pVgroupInfos, i);
340,984✔
508
    qTrace("vgId:%d, numOfEps:%d inUse:%d ", pInfo->vgId, pInfo->epSet.numOfEps, pInfo->epSet.inUse);
340,984✔
509
    for (int32_t j = 0; j < pInfo->epSet.numOfEps; ++j) {
744,875✔
510
      qTrace("vgId:%d, index:%d epset:%s:%u", pInfo->vgId, j, pInfo->epSet.eps[j].fqdn, pInfo->epSet.eps[j].port);
403,891✔
511
    }
512
  }
513

514
  code = queryBuildUseDbOutput(pOut, &usedbRsp);
147,784✔
515

516
PROCESS_USEDB_OVER:
147,784✔
517

518
  if (code != 0) {
147,784!
519
    if (pOut) {
×
520
      if (pOut->dbVgroup) taosHashCleanup(pOut->dbVgroup->vgHash);
×
521
      taosMemoryFreeClear(pOut->dbVgroup);
×
522
    }
523
    qError("failed to process usedb rsp since %s", terrstr());
×
524
  }
525

526
  tFreeSUsedbRsp(&usedbRsp);
147,784✔
527
  return code;
147,784✔
528
}
529

530
static int32_t queryConvertTableMetaMsg(STableMetaRsp *pMetaMsg) {
88,177✔
531
  QUERY_PARAM_CHECK(pMetaMsg);
88,177!
532
  if (pMetaMsg->numOfTags < 0 || pMetaMsg->numOfTags > TSDB_MAX_TAGS) {
88,177!
533
    qError("invalid numOfTags[%d] in table meta rsp msg", pMetaMsg->numOfTags);
×
534
    return TSDB_CODE_TSC_INVALID_VALUE;
×
535
  }
536

537
  if (pMetaMsg->numOfColumns > TSDB_MAX_COLUMNS || pMetaMsg->numOfColumns <= 0) {
88,178!
538
    qError("invalid numOfColumns[%d] in table meta rsp msg", pMetaMsg->numOfColumns);
×
539
    return TSDB_CODE_TSC_INVALID_VALUE;
×
540
  }
541

542
  if (pMetaMsg->tableType != TSDB_SUPER_TABLE && pMetaMsg->tableType != TSDB_CHILD_TABLE &&
88,178✔
543
      pMetaMsg->tableType != TSDB_NORMAL_TABLE && pMetaMsg->tableType != TSDB_SYSTEM_TABLE &&
37,237✔
544
      pMetaMsg->tableType != TSDB_VIRTUAL_NORMAL_TABLE && pMetaMsg->tableType != TSDB_VIRTUAL_CHILD_TABLE) {
286!
545
    qError("invalid tableType[%d] in table meta rsp msg", pMetaMsg->tableType);
×
546
    return TSDB_CODE_TSC_INVALID_VALUE;
×
547
  }
548

549
  if (pMetaMsg->sversion < 0) {
88,178!
550
    qError("invalid sversion[%d] in table meta rsp msg", pMetaMsg->sversion);
×
551
    return TSDB_CODE_TSC_INVALID_VALUE;
×
552
  }
553

554
  if (pMetaMsg->tversion < 0) {
88,178!
555
    qError("invalid tversion[%d] in table meta rsp msg", pMetaMsg->tversion);
×
556
    return TSDB_CODE_TSC_INVALID_VALUE;
×
557
  }
558

559
  if (pMetaMsg->rversion < 0) {
88,178!
560
    qError("invalid rversion[%d] in table meta rsp msg", pMetaMsg->rversion);
×
561
    return TSDB_CODE_TSC_INVALID_VALUE;
×
562
  }
563

564
  if (pMetaMsg->pSchemas[0].colId != PRIMARYKEY_TIMESTAMP_COL_ID) {
88,178!
565
    qError("invalid colId[%" PRIi16 "] for the first column in table meta rsp msg", pMetaMsg->pSchemas[0].colId);
×
566
    return TSDB_CODE_TSC_INVALID_VALUE;
×
567
  }
568

569
  return TSDB_CODE_SUCCESS;
88,178✔
570
}
571

572
int32_t queryCreateCTableMetaFromMsg(STableMetaRsp *msg, SCTableMeta *pMeta) {
143,118✔
573
  QUERY_PARAM_CHECK(msg);
143,118!
574
  QUERY_PARAM_CHECK(pMeta);
143,118!
575
  pMeta->vgId = msg->vgId;
143,118✔
576
  pMeta->tableType = msg->tableType;
143,118✔
577
  pMeta->uid = msg->tuid;
143,118✔
578
  pMeta->suid = msg->suid;
143,118✔
579

580
  qDebug("ctb:%s, uid:0x%" PRIx64 " meta returned, type:%d vgId:%d db:%s suid:%" PRIx64, msg->tbName, pMeta->uid,
143,118✔
581
         pMeta->tableType, pMeta->vgId, msg->dbFName, pMeta->suid);
582

583
  return TSDB_CODE_SUCCESS;
143,125✔
584
}
585

586
int32_t queryCreateVCTableMetaFromMsg(STableMetaRsp *msg, SVCTableMeta **pMeta) {
299✔
587
  QUERY_PARAM_CHECK(msg);
299!
588
  QUERY_PARAM_CHECK(pMeta);
299!
589
  QUERY_PARAM_CHECK(msg->pColRefs);
299!
590

591
  int32_t pColRefSize = sizeof(SColRef) * msg->numOfColRefs;
299✔
592

593
  SVCTableMeta *pTableMeta = taosMemoryCalloc(1, sizeof(SVCTableMeta) + pColRefSize);
299!
594
  if (NULL == pTableMeta) {
299!
595
    qError("calloc size[%d] failed", (int32_t)sizeof(SVCTableMeta) + pColRefSize);
×
596
    return terrno;
×
597
  }
598

599
  pTableMeta->vgId = msg->vgId;
299✔
600
  pTableMeta->tableType = msg->tableType;
299✔
601
  pTableMeta->uid = msg->tuid;
299✔
602
  pTableMeta->suid = msg->suid;
299✔
603
  pTableMeta->numOfColRefs = msg->numOfColRefs;
299✔
604
  pTableMeta->rversion = msg->rversion;
299✔
605

606
  pTableMeta->colRef = (SColRef *)((char *)pTableMeta + sizeof(SVCTableMeta));
299✔
607
  memcpy(pTableMeta->colRef, msg->pColRefs, pColRefSize);
299✔
608

609
  qDebug("ctable %s uid %" PRIx64 " meta returned, type %d vgId:%d db %s suid %" PRIx64, msg->tbName, (pTableMeta)->uid,
299!
610
         (pTableMeta)->tableType, (pTableMeta)->vgId, msg->dbFName, (pTableMeta)->suid);
611

612
  *pMeta = pTableMeta;
299✔
613
  return TSDB_CODE_SUCCESS;
299✔
614
}
615

616
int32_t queryCreateTableMetaFromMsg(STableMetaRsp *msg, bool isStb, STableMeta **pMeta) {
114,982✔
617
  QUERY_PARAM_CHECK(msg);
114,982!
618
  QUERY_PARAM_CHECK(pMeta);
114,982!
619
  int32_t total = msg->numOfColumns + msg->numOfTags;
114,982✔
620
  int32_t metaSize = sizeof(STableMeta) + sizeof(SSchema) * total;
114,982✔
621
  int32_t schemaExtSize = (withExtSchema(msg->tableType) && msg->pSchemaExt) ? sizeof(SSchemaExt) * msg->numOfColumns : 0;
114,982✔
622
  int32_t pColRefSize = (hasRefCol(msg->tableType) && msg->pColRefs && !isStb) ? sizeof(SColRef) * msg->numOfColRefs : 0;
114,983!
623

624
  STableMeta *pTableMeta = taosMemoryCalloc(1, metaSize + schemaExtSize + pColRefSize);
114,981!
625
  if (NULL == pTableMeta) {
114,983!
626
    qError("calloc size[%d] failed", metaSize);
×
627
    return terrno;
×
628
  }
629
  SSchemaExt *pSchemaExt = (SSchemaExt *)((char *)pTableMeta + metaSize);
114,983✔
630
  SColRef    *pColRef = (SColRef *)((char *)pTableMeta + metaSize + schemaExtSize);
114,983✔
631

632
  pTableMeta->vgId = isStb ? 0 : msg->vgId;
114,983✔
633
  pTableMeta->tableType = isStb ? TSDB_SUPER_TABLE : msg->tableType;
114,983✔
634
  pTableMeta->uid = isStb ? msg->suid : msg->tuid;
114,983✔
635
  pTableMeta->suid = msg->suid;
114,983✔
636
  pTableMeta->sversion = msg->sversion;
114,983✔
637
  pTableMeta->tversion = msg->tversion;
114,983✔
638
  pTableMeta->rversion = msg->rversion;
114,983✔
639
  if (msg->virtualStb) {
114,983✔
640
    pTableMeta->virtualStb = 1;
236✔
641
    pTableMeta->numOfColRefs = 0;
236✔
642
  } else {
643
    if (msg->tableType == TSDB_VIRTUAL_CHILD_TABLE && isStb) {
114,747✔
644
      pTableMeta->virtualStb = 1;
164✔
645
      pTableMeta->numOfColRefs = 0;
164✔
646
    } else {
647
      pTableMeta->virtualStb = 0;
114,583✔
648
      pTableMeta->numOfColRefs = msg->numOfColRefs;
114,583✔
649
    }
650
  }
651

652
  pTableMeta->tableInfo.numOfTags = msg->numOfTags;
114,983✔
653
  pTableMeta->tableInfo.precision = msg->precision;
114,983✔
654
  pTableMeta->tableInfo.numOfColumns = msg->numOfColumns;
114,983✔
655

656
  memcpy(pTableMeta->schema, msg->pSchemas, sizeof(SSchema) * total);
114,983✔
657
  if (withExtSchema(msg->tableType) && msg->pSchemaExt) {
114,983✔
658
    pTableMeta->schemaExt = pSchemaExt;
111,377✔
659
    memcpy(pSchemaExt, msg->pSchemaExt, schemaExtSize);
111,377✔
660
  } else {
661
    pTableMeta->schemaExt = NULL;
3,607✔
662
  }
663

664
  if (hasRefCol(msg->tableType) && msg->pColRefs && !isStb) {
114,984!
665
    pTableMeta->colRef = (SColRef *)((char *)pTableMeta + metaSize + schemaExtSize);
624✔
666
    memcpy(pTableMeta->colRef, msg->pColRefs, pColRefSize);
624✔
667
  } else {
668
    pTableMeta->colRef = NULL;
114,360✔
669
  }
670

671
  bool hasPK = (msg->numOfColumns > 1) && (pTableMeta->schema[1].flags & COL_IS_KEY);
114,984!
672
  for (int32_t i = 0; i < msg->numOfColumns; ++i) {
3,083,894✔
673
    pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes;
2,968,910✔
674
    if (hasPK && (i > 0)) {
2,968,910✔
675
      if ((pTableMeta->schema[i].flags & COL_IS_KEY)) {
744✔
676
        ++pTableMeta->tableInfo.numOfPKs;
395✔
677
      } else {
678
        hasPK = false;
349✔
679
      }
680
    }
681
  }
682

683
  qDebug("tb:%s, uid:%" PRIx64 " meta returned, type:%d vgId:%d db:%s stb:%s suid:%" PRIx64
114,984✔
684
         " sver:%d tver:%d"
685
         " tagNum:%d colNum:%d precision:%d rowSize:%d",
686
         msg->tbName, pTableMeta->uid, pTableMeta->tableType, pTableMeta->vgId, msg->dbFName, msg->stbName,
687
         pTableMeta->suid, pTableMeta->sversion, pTableMeta->tversion, pTableMeta->tableInfo.numOfTags,
688
         pTableMeta->tableInfo.numOfColumns, pTableMeta->tableInfo.precision, pTableMeta->tableInfo.rowSize);
689

690
  *pMeta = pTableMeta;
114,984✔
691
  return TSDB_CODE_SUCCESS;
114,984✔
692
}
693

694
int32_t queryCreateTableMetaExFromMsg(STableMetaRsp *msg, bool isStb, STableMeta **pMeta) {
1,219✔
695
  QUERY_PARAM_CHECK(msg);
1,219!
696
  QUERY_PARAM_CHECK(pMeta);
1,219!
697
  int32_t total = msg->numOfColumns + msg->numOfTags;
1,219✔
698
  int32_t metaSize = sizeof(STableMeta) + sizeof(SSchema) * total;
1,219✔
699
  int32_t schemaExtSize = (withExtSchema(msg->tableType) && msg->pSchemaExt) ? sizeof(SSchemaExt) * msg->numOfColumns : 0;
1,219!
700
  int32_t pColRefSize = (hasRefCol(msg->tableType) && msg->pColRefs) ? sizeof(SColRef) * msg->numOfColRefs : 0;
1,219!
701
  int32_t tbNameSize = strlen(msg->tbName) + 1;
1,219✔
702

703
  STableMeta *pTableMeta = taosMemoryCalloc(1, metaSize + schemaExtSize + pColRefSize + tbNameSize);
1,219!
704
  if (NULL == pTableMeta) {
1,219!
705
    qError("calloc size[%d] failed", metaSize);
×
706
    return terrno;
×
707
  }
708
  SSchemaExt *pSchemaExt = (SSchemaExt *)((char *)pTableMeta + metaSize);
1,219✔
709
  SColRef    *pColRef = (SColRef *)((char *)pTableMeta + metaSize + schemaExtSize);
1,219✔
710

711
  pTableMeta->vgId = isStb ? 0 : msg->vgId;
1,219✔
712
  pTableMeta->tableType = isStb ? TSDB_SUPER_TABLE : msg->tableType;
1,219✔
713
  pTableMeta->uid = isStb ? msg->suid : msg->tuid;
1,219✔
714
  pTableMeta->suid = msg->suid;
1,219✔
715
  pTableMeta->sversion = msg->sversion;
1,219✔
716
  pTableMeta->tversion = msg->tversion;
1,219✔
717
  pTableMeta->rversion = msg->rversion;
1,219✔
718
  pTableMeta->virtualStb = msg->virtualStb;
1,219✔
719
  pTableMeta->numOfColRefs = msg->numOfColRefs;
1,219✔
720

721
  pTableMeta->tableInfo.numOfTags = msg->numOfTags;
1,219✔
722
  pTableMeta->tableInfo.precision = msg->precision;
1,219✔
723
  pTableMeta->tableInfo.numOfColumns = msg->numOfColumns;
1,219✔
724

725
  TAOS_MEMCPY(pTableMeta->schema, msg->pSchemas, sizeof(SSchema) * total);
1,219✔
726
  if (withExtSchema(msg->tableType) && msg->pSchemaExt) {
1,219!
727
    pTableMeta->schemaExt = pSchemaExt;
1,219✔
728
    TAOS_MEMCPY(pSchemaExt, msg->pSchemaExt, schemaExtSize);
1,219✔
729
  } else {
730
    pTableMeta->schemaExt = NULL;
×
731
  }
732

733
  if (hasRefCol(msg->tableType) && msg->pColRefs) {
1,219!
734
    pTableMeta->colRef = (SColRef *)((char *)pTableMeta + metaSize + schemaExtSize);
×
735
    memcpy(pTableMeta->colRef, msg->pColRefs, pColRefSize);
×
736
  } else {
737
    pTableMeta->colRef = NULL;
1,219✔
738
  }
739

740
  bool hasPK = (msg->numOfColumns > 1) && (pTableMeta->schema[1].flags & COL_IS_KEY);
1,219!
741
  for (int32_t i = 0; i < msg->numOfColumns; ++i) {
3,954✔
742
    pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes;
2,735✔
743
    if (hasPK && (i > 0)) {
2,735!
744
      if ((pTableMeta->schema[i].flags & COL_IS_KEY)) {
×
745
        ++pTableMeta->tableInfo.numOfPKs;
×
746
      } else {
747
        hasPK = false;
×
748
      }
749
    }
750
  }
751

752
  char *pTbName = (char *)pTableMeta + metaSize + schemaExtSize + pColRefSize;
1,219✔
753
  tstrncpy(pTbName, msg->tbName, tbNameSize);
1,219✔
754

755
  qDebug("tb:%s, uid:%" PRIx64 " meta returned, type:%d vgId:%d db:%s stb:%s suid:%" PRIx64
1,219!
756
         " sver:%d tver:%d"
757
         " tagNum:%d colNum:%d precision:%d rowSize:%d",
758
         msg->tbName, pTableMeta->uid, pTableMeta->tableType, pTableMeta->vgId, msg->dbFName, msg->stbName,
759
         pTableMeta->suid, pTableMeta->sversion, pTableMeta->tversion, pTableMeta->tableInfo.numOfTags,
760
         pTableMeta->tableInfo.numOfColumns, pTableMeta->tableInfo.precision, pTableMeta->tableInfo.rowSize);
761

762
  *pMeta = pTableMeta;
1,219✔
763
  return TSDB_CODE_SUCCESS;
1,219✔
764
}
765

766
int32_t queryProcessTableMetaRsp(void *output, char *msg, int32_t msgSize) {
86,960✔
767
  int32_t       code = 0;
86,960✔
768
  STableMetaRsp metaRsp = {0};
86,960✔
769

770
  if (NULL == output || NULL == msg || msgSize <= 0) {
86,960!
771
    qError("queryProcessTableMetaRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
772
    code = TSDB_CODE_TSC_INVALID_INPUT;
×
773
    goto PROCESS_META_OVER;
×
774
  }
775

776
  if (tDeserializeSTableMetaRsp(msg, msgSize, &metaRsp) != 0) {
86,960!
777
    code = TSDB_CODE_INVALID_MSG;
×
778
    goto PROCESS_META_OVER;
×
779
  }
780

781
  code = queryConvertTableMetaMsg(&metaRsp);
86,958✔
782
  if (code != TSDB_CODE_SUCCESS) {
86,958!
783
    goto PROCESS_META_OVER;
×
784
  }
785

786
  if (!IS_SYS_DBNAME(metaRsp.dbFName) &&
86,958!
787
      !tIsValidSchema(metaRsp.pSchemas, metaRsp.numOfColumns, metaRsp.numOfTags)) {
84,142!
788
    code = TSDB_CODE_TSC_INVALID_VALUE;
×
789
    goto PROCESS_META_OVER;
×
790
  }
791

792
  STableMetaOutput *pOut = output;
86,958✔
793
  tstrncpy(pOut->dbFName, metaRsp.dbFName, TSDB_DB_FNAME_LEN);
86,958✔
794
  pOut->dbId = metaRsp.dbId;
86,958✔
795

796
  if (metaRsp.tableType == TSDB_CHILD_TABLE) {
86,958✔
797
    SET_META_TYPE_BOTH_TABLE(pOut->metaType);
15,540✔
798

799
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
15,540✔
800
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
15,540✔
801

802
    pOut->ctbMeta.vgId = metaRsp.vgId;
15,540✔
803
    pOut->ctbMeta.tableType = metaRsp.tableType;
15,540✔
804
    pOut->ctbMeta.uid = metaRsp.tuid;
15,540✔
805
    pOut->ctbMeta.suid = metaRsp.suid;
15,540✔
806

807
    code = queryCreateTableMetaFromMsg(&metaRsp, true, &pOut->tbMeta);
15,540✔
808
  } else if (metaRsp.tableType == TSDB_VIRTUAL_CHILD_TABLE) {
71,418✔
809
    SET_META_TYPE_BOTH_VTABLE(pOut->metaType);
164✔
810

811
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
164✔
812
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
164✔
813

814
    code = queryCreateVCTableMetaFromMsg(&metaRsp, &pOut->vctbMeta);
164✔
815
    if (TSDB_CODE_SUCCESS != code) {
164!
816
      goto PROCESS_META_OVER;
×
817
    }
818
    code = queryCreateTableMetaFromMsg(&metaRsp, true, &pOut->tbMeta);
164✔
819
  } else {
820
    SET_META_TYPE_TABLE(pOut->metaType);
71,254✔
821
    tstrncpy(pOut->tbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
71,254✔
822
    code = queryCreateTableMetaFromMsg(&metaRsp, (metaRsp.tableType == TSDB_SUPER_TABLE), &pOut->tbMeta);
71,254✔
823
  }
824

825
PROCESS_META_OVER:
86,960✔
826
  if (code != 0) {
86,960!
827
    qError("failed to process table meta rsp since %s", tstrerror(code));
×
828
  }
829

830
  tFreeSTableMetaRsp(&metaRsp);
86,960✔
831
  return code;
86,959✔
832
}
833

834
static int32_t queryProcessTableNameRsp(void *output, char *msg, int32_t msgSize) {
1,219✔
835
  int32_t       code = 0;
1,219✔
836
  STableMetaRsp metaRsp = {0};
1,219✔
837

838
  if (NULL == output || NULL == msg || msgSize <= 0) {
1,219!
839
    qError("queryProcessTableNameRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
840
    code = TSDB_CODE_TSC_INVALID_INPUT;
×
841
    goto PROCESS_NAME_OVER;
×
842
  }
843

844
  if (tDeserializeSTableMetaRsp(msg, msgSize, &metaRsp) != 0) {
1,219!
845
    code = TSDB_CODE_INVALID_MSG;
×
846
    goto PROCESS_NAME_OVER;
×
847
  }
848

849
  code = queryConvertTableMetaMsg(&metaRsp);
1,219✔
850
  if (code != TSDB_CODE_SUCCESS) {
1,219!
851
    goto PROCESS_NAME_OVER;
×
852
  }
853

854
  if (!IS_SYS_DBNAME(metaRsp.dbFName) &&
1,219!
855
      !tIsValidSchema(metaRsp.pSchemas, metaRsp.numOfColumns, metaRsp.numOfTags)) {
1,219!
856
    code = TSDB_CODE_TSC_INVALID_VALUE;
×
857
    goto PROCESS_NAME_OVER;
×
858
  }
859

860
  STableMetaOutput *pOut = output;
1,219✔
861
  tstrncpy(pOut->dbFName, metaRsp.dbFName, TSDB_DB_FNAME_LEN);
1,219✔
862
  pOut->dbId = metaRsp.dbId;
1,219✔
863

864
  if (metaRsp.tableType == TSDB_CHILD_TABLE) {
1,219✔
865
    SET_META_TYPE_BOTH_TABLE(pOut->metaType);
333✔
866

867
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
333✔
868
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
333✔
869

870
    pOut->ctbMeta.vgId = metaRsp.vgId;
333✔
871
    pOut->ctbMeta.tableType = metaRsp.tableType;
333✔
872
    pOut->ctbMeta.uid = metaRsp.tuid;
333✔
873
    pOut->ctbMeta.suid = metaRsp.suid;
333✔
874

875
    code = queryCreateTableMetaExFromMsg(&metaRsp, true, &pOut->tbMeta);
333✔
876
  } else if (metaRsp.tableType == TSDB_VIRTUAL_CHILD_TABLE) {
886!
877
    SET_META_TYPE_BOTH_VTABLE(pOut->metaType);
×
878

879
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
×
880
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
×
881

882
    code = queryCreateVCTableMetaFromMsg(&metaRsp, &pOut->vctbMeta);
×
883
    if (TSDB_CODE_SUCCESS != code) {
×
884
      goto PROCESS_NAME_OVER;
×
885
    }
886

887
    code = queryCreateTableMetaExFromMsg(&metaRsp, true, &pOut->tbMeta);
×
888
  } else {
889
    SET_META_TYPE_TABLE(pOut->metaType);
886✔
890
    tstrncpy(pOut->tbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
886✔
891
    code = queryCreateTableMetaExFromMsg(&metaRsp, (metaRsp.tableType == TSDB_SUPER_TABLE), &pOut->tbMeta);
886✔
892
  }
893

894
PROCESS_NAME_OVER:
1,219✔
895
  if (code != 0) {
1,219!
896
    qError("failed to process table name rsp since %s", tstrerror(code));
×
897
  }
898

899
  tFreeSTableMetaRsp(&metaRsp);
1,219✔
900
  return code;
1,219✔
901
}
902

903
int32_t queryProcessQnodeListRsp(void *output, char *msg, int32_t msgSize) {
11,824✔
904
  SQnodeListRsp out = {0};
11,824✔
905
  int32_t       code = 0;
11,824✔
906

907
  if (NULL == output || NULL == msg || msgSize <= 0) {
11,824!
908
    qError("queryProcessQnodeListRsp: 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
  out.qnodeList = (SArray *)output;
11,824✔
914
  if (tDeserializeSQnodeListRsp(msg, msgSize, &out) != 0) {
11,824!
915
    qError("invalid qnode list rsp msg, msgSize:%d", msgSize);
×
916
    code = TSDB_CODE_INVALID_MSG;
×
917
    return code;
×
918
  }
919

920
  return code;
11,824✔
921
}
922

923
int32_t queryProcessDnodeListRsp(void *output, char *msg, int32_t msgSize) {
363✔
924
  SDnodeListRsp out = {0};
363✔
925
  int32_t       code = 0;
363✔
926

927
  if (NULL == output || NULL == msg || msgSize <= 0) {
363!
928
    qError("queryProcessDnodeListRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
929
    code = TSDB_CODE_TSC_INVALID_INPUT;
×
930
    return code;
×
931
  }
932

933
  if (tDeserializeSDnodeListRsp(msg, msgSize, &out) != 0) {
363!
934
    qError("invalid dnode list rsp msg, msgSize:%d", msgSize);
×
935
    code = TSDB_CODE_INVALID_MSG;
×
936
    return code;
×
937
  }
938

939
  *(SArray **)output = out.dnodeList;
363✔
940

941
  return code;
363✔
942
}
943

944
int32_t queryProcessGetSerVerRsp(void *output, char *msg, int32_t msgSize) {
1✔
945
  SServerVerRsp out = {0};
1✔
946
  int32_t       code = 0;
1✔
947

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

954
  if (tDeserializeSServerVerRsp(msg, msgSize, &out) != 0) {
1!
955
    qError("invalid svr ver rsp msg, msgSize:%d", msgSize);
×
956
    code = TSDB_CODE_INVALID_MSG;
×
957
    return code;
×
958
  }
959

960
  *(char **)output = taosStrdup(out.ver);
1!
961
  if (NULL == *(char **)output) {
1!
962
    return terrno;
×
963
  }
964

965
  return code;
1✔
966
}
967

968
int32_t queryProcessGetDbCfgRsp(void *output, char *msg, int32_t msgSize) {
5,477✔
969
  SDbCfgRsp out = {0};
5,477✔
970

971
  if (NULL == output || NULL == msg || msgSize <= 0) {
5,477!
972
    qError("queryProcessGetDbCfgRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
973
    return TSDB_CODE_TSC_INVALID_INPUT;
×
974
  }
975

976
  if (tDeserializeSDbCfgRsp(msg, msgSize, &out) != 0) {
5,477!
977
    qError("tDeserializeSDbCfgRsp failed, msgSize:%d, dbCfgRsp:%lu", msgSize, sizeof(out));
×
978
    return TSDB_CODE_INVALID_MSG;
×
979
  }
980

981
  memcpy(output, &out, sizeof(out));
5,476✔
982

983
  return TSDB_CODE_SUCCESS;
5,476✔
984
}
985

986
int32_t queryProcessGetIndexRsp(void *output, char *msg, int32_t msgSize) {
×
987
  SUserIndexRsp out = {0};
×
988

989
  if (NULL == output || NULL == msg || msgSize <= 0) {
×
990
    qError("queryProcessGetIndexRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
991
    return TSDB_CODE_TSC_INVALID_INPUT;
×
992
  }
993

994
  if (tDeserializeSUserIndexRsp(msg, msgSize, &out) != 0) {
×
995
    qError("tDeserializeSUserIndexRsp failed, msgSize:%d", msgSize);
×
996
    return TSDB_CODE_INVALID_MSG;
×
997
  }
998

999
  memcpy(output, &out, sizeof(out));
×
1000

1001
  return TSDB_CODE_SUCCESS;
×
1002
}
1003

1004
int32_t queryProcessRetrieveFuncRsp(void *output, char *msg, int32_t msgSize) {
87✔
1005
  SRetrieveFuncRsp out = {0};
87✔
1006

1007
  if (NULL == output || NULL == msg || msgSize <= 0) {
87!
1008
    qError("queryProcessRetrieveFuncRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1009
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1010
  }
1011

1012
  if (tDeserializeSRetrieveFuncRsp(msg, msgSize, &out) != 0) {
87!
1013
    qError("tDeserializeSRetrieveFuncRsp failed, msgSize:%d", msgSize);
×
1014
    return TSDB_CODE_INVALID_MSG;
×
1015
  }
1016

1017
  if (1 != out.numOfFuncs) {
87!
1018
    qError("invalid func num returned, numOfFuncs:%d", out.numOfFuncs);
×
1019
    return TSDB_CODE_INVALID_MSG;
×
1020
  }
1021

1022
  SFuncInfo *funcInfo = taosArrayGet(out.pFuncInfos, 0);
87✔
1023

1024
  memcpy(output, funcInfo, sizeof(*funcInfo));
87✔
1025
  taosArrayDestroy(out.pFuncInfos);
87✔
1026
  taosArrayDestroy(out.pFuncExtraInfos);
87✔
1027

1028
  return TSDB_CODE_SUCCESS;
87✔
1029
}
1030

1031
int32_t queryProcessGetUserAuthRsp(void *output, char *msg, int32_t msgSize) {
22,172✔
1032
  if (NULL == output || NULL == msg || msgSize <= 0) {
22,172!
1033
    qError("queryProcessGetUserAuthRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1034
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1035
  }
1036

1037
  if (tDeserializeSGetUserAuthRsp(msg, msgSize, (SGetUserAuthRsp *)output) != 0) {
22,172!
1038
    qError("tDeserializeSGetUserAuthRsp failed, msgSize:%d", msgSize);
×
1039
    return TSDB_CODE_INVALID_MSG;
×
1040
  }
1041

1042
  return TSDB_CODE_SUCCESS;
22,172✔
1043
}
1044

1045
int32_t queryProcessGetTbIndexRsp(void *output, char *msg, int32_t msgSize) {
1✔
1046
  if (NULL == output || NULL == msg || msgSize <= 0) {
1!
1047
    qError("queryProcessGetTbIndexRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1048
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1049
  }
1050

1051
  STableIndexRsp *out = (STableIndexRsp *)output;
1✔
1052
  if (tDeserializeSTableIndexRsp(msg, msgSize, out) != 0) {
1!
1053
    qError("tDeserializeSTableIndexRsp failed, msgSize:%d", msgSize);
×
1054
    return TSDB_CODE_INVALID_MSG;
×
1055
  }
1056

1057
  return TSDB_CODE_SUCCESS;
1✔
1058
}
1059

1060
int32_t queryProcessGetTbCfgRsp(void *output, char *msg, int32_t msgSize) {
246✔
1061
  if (NULL == output || NULL == msg || msgSize <= 0) {
246!
1062
    qError("queryProcessGetTbCfgRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1063
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1064
  }
1065

1066
  STableCfgRsp *out = taosMemoryCalloc(1, sizeof(STableCfgRsp));
246!
1067
  if(out == NULL) {
246!
1068
    return terrno;
×
1069
  }
1070
  if (tDeserializeSTableCfgRsp(msg, msgSize, out) != 0) {
246!
1071
    qError("tDeserializeSTableCfgRsp failed, msgSize:%d", msgSize);
×
1072
    tFreeSTableCfgRsp(out);
×
1073
    taosMemoryFree(out);
×
1074
    return TSDB_CODE_INVALID_MSG;
×
1075
  }
1076

1077
  *(STableCfgRsp **)output = out;
246✔
1078

1079
  return TSDB_CODE_SUCCESS;
246✔
1080
}
1081

1082
int32_t queryProcessGetViewMetaRsp(void *output, char *msg, int32_t msgSize) {
316✔
1083
  if (NULL == output || NULL == msg || msgSize <= 0) {
316!
1084
    qError("queryProcessGetViewMetaRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1085
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1086
  }
1087

1088
  SViewMetaRsp *out = taosMemoryCalloc(1, sizeof(SViewMetaRsp));
316!
1089
  if (out == NULL) {
316!
1090
    return terrno;
×
1091
  }
1092
  if (tDeserializeSViewMetaRsp(msg, msgSize, out) != 0) {
316!
1093
    qError("tDeserializeSViewMetaRsp failed, msgSize:%d", msgSize);
×
1094
    tFreeSViewMetaRsp(out);
×
1095
    taosMemoryFree(out);
×
1096
    return TSDB_CODE_INVALID_MSG;
×
1097
  }
1098

1099
  qDebugL("view meta recved, dbFName:%s, view:%s, querySQL:%s", out->dbFName, out->name, out->querySql);
316✔
1100

1101
  *(SViewMetaRsp **)output = out;
316✔
1102

1103
  return TSDB_CODE_SUCCESS;
316✔
1104
}
1105

1106
int32_t queryProcessGetTbTSMARsp(void* output, char* msg, int32_t msgSize) {
1,033✔
1107
  if (NULL == output || NULL == msg || msgSize <= 0) {
1,033!
1108
    qError("queryProcessGetTbTSMARsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1109
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1110
  }
1111

1112
  if (tDeserializeTableTSMAInfoRsp(msg, msgSize, output) != 0) {
1,033!
1113
    qError("tDeserializeSViewMetaRsp failed, msgSize:%d", msgSize);
×
1114
    return TSDB_CODE_INVALID_MSG;
×
1115
  }
1116

1117
  return TSDB_CODE_SUCCESS;
1,033✔
1118
}
1119

1120
int32_t queryProcessStreamProgressRsp(void* output, char* msg, int32_t msgSize) {
5,473✔
1121
  if (!output || !msg || msgSize <= 0) {
5,473!
1122
    qError("queryProcessStreamProgressRsp: invalid input param, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1123
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1124
  }
1125

1126
  if (tDeserializeSStreamProgressRsp(msg, msgSize, output) != 0) {
5,473!
1127
    qError("tDeserializeStreamProgressRsp failed, msgSize:%d", msgSize);
×
1128
    return TSDB_CODE_INVALID_MSG;
×
1129
  }
1130
  return TSDB_CODE_SUCCESS;
5,473✔
1131
}
1132

1133
int32_t queryProcessVSubTablesRsp(void* output, char* msg, int32_t msgSize) {
24✔
1134
  if (!output || !msg || msgSize <= 0) {
24!
1135
    qError("queryProcessVSubTablesRsp input error, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1136
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1137
  }
1138

1139
  SVSubTablesRsp* pRsp = (SVSubTablesRsp*)output;
24✔
1140
  int32_t code = tDeserializeSVSubTablesRsp(msg, msgSize, pRsp);
24✔
1141
  if (code != 0) {
24!
1142
    qError("tDeserializeSVSubTablesRsp failed, msgSize: %d, error:%d", msgSize, code);
×
1143
    return code;
×
1144
  }
1145
  
1146
  return TSDB_CODE_SUCCESS;
24✔
1147
}
1148

1149
int32_t queryProcessVStbRefDbsRsp(void* output, char* msg, int32_t msgSize) {
9,987✔
1150
  if (!output || !msg || msgSize <= 0) {
9,987!
1151
    qError("queryProcessVStbRefDbsRsp input error, output:%p, msg:%p, msgSize:%d", output, msg, msgSize);
×
1152
    return TSDB_CODE_TSC_INVALID_INPUT;
×
1153
  }
1154

1155
  SVStbRefDbsRsp * pRsp = (SVStbRefDbsRsp*)output;
9,987✔
1156
  int32_t code = tDeserializeSVStbRefDbsRsp(msg, msgSize, pRsp);
9,987✔
1157
  if (code != 0) {
9,986✔
1158
    qError("tDeserializeSVStbRefDbsRsp failed, msgSize: %d, error:%d", msgSize, code);
1!
1159
    return code;
×
1160
  }
1161

1162
  return TSDB_CODE_SUCCESS;
9,985✔
1163
}
1164

1165
void initQueryModuleMsgHandle() {
17,080✔
1166
  queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_META)] = queryBuildTableMetaReqMsg;
17,080✔
1167
  queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_NAME)] = queryBuildTableMetaReqMsg;
17,080✔
1168
  queryBuildMsg[TMSG_INDEX(TDMT_MND_TABLE_META)] = queryBuildTableMetaReqMsg;
17,080✔
1169
  queryBuildMsg[TMSG_INDEX(TDMT_MND_USE_DB)] = queryBuildUseDbMsg;
17,080✔
1170
  queryBuildMsg[TMSG_INDEX(TDMT_MND_QNODE_LIST)] = queryBuildQnodeListMsg;
17,080✔
1171
  queryBuildMsg[TMSG_INDEX(TDMT_MND_DNODE_LIST)] = queryBuildDnodeListMsg;
17,080✔
1172
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_DB_CFG)] = queryBuildGetDBCfgMsg;
17,080✔
1173
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_INDEX)] = queryBuildGetIndexMsg;
17,080✔
1174
  queryBuildMsg[TMSG_INDEX(TDMT_MND_RETRIEVE_FUNC)] = queryBuildRetrieveFuncMsg;
17,080✔
1175
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_USER_AUTH)] = queryBuildGetUserAuthMsg;
17,080✔
1176
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_TABLE_INDEX)] = queryBuildGetTbIndexMsg;
17,080✔
1177
  queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_CFG)] = queryBuildGetTbCfgMsg;
17,080✔
1178
  queryBuildMsg[TMSG_INDEX(TDMT_MND_TABLE_CFG)] = queryBuildGetTbCfgMsg;
17,080✔
1179
  queryBuildMsg[TMSG_INDEX(TDMT_MND_SERVER_VERSION)] = queryBuildGetSerVerMsg;
17,080✔
1180
  queryBuildMsg[TMSG_INDEX(TDMT_MND_VIEW_META)] = queryBuildGetViewMetaMsg;
17,080✔
1181
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_TABLE_TSMA)] = queryBuildGetTableTSMAMsg;
17,080✔
1182
  queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_TSMA)] = queryBuildGetTSMAMsg;
17,080✔
1183
  queryBuildMsg[TMSG_INDEX(TDMT_VND_GET_STREAM_PROGRESS)] = queryBuildGetStreamProgressMsg;
17,080✔
1184
  queryBuildMsg[TMSG_INDEX(TDMT_VND_VSUBTABLES_META)] = queryBuildVSubTablesMsg;
17,080✔
1185
  queryBuildMsg[TMSG_INDEX(TDMT_VND_VSTB_REF_DBS)] = queryBuildVStbRefDBsMsg;
17,080✔
1186

1187
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_TABLE_META)] = queryProcessTableMetaRsp;
17,080✔
1188
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_TABLE_NAME)] = queryProcessTableNameRsp;
17,080✔
1189
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_TABLE_META)] = queryProcessTableMetaRsp;
17,080✔
1190
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_USE_DB)] = queryProcessUseDBRsp;
17,080✔
1191
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_QNODE_LIST)] = queryProcessQnodeListRsp;
17,080✔
1192
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_DNODE_LIST)] = queryProcessDnodeListRsp;
17,080✔
1193
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_DB_CFG)] = queryProcessGetDbCfgRsp;
17,080✔
1194
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_INDEX)] = queryProcessGetIndexRsp;
17,080✔
1195
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_RETRIEVE_FUNC)] = queryProcessRetrieveFuncRsp;
17,080✔
1196
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_USER_AUTH)] = queryProcessGetUserAuthRsp;
17,080✔
1197
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_TABLE_INDEX)] = queryProcessGetTbIndexRsp;
17,080✔
1198
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_TABLE_CFG)] = queryProcessGetTbCfgRsp;
17,080✔
1199
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_TABLE_CFG)] = queryProcessGetTbCfgRsp;
17,080✔
1200
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_SERVER_VERSION)] = queryProcessGetSerVerRsp;
17,080✔
1201
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_VIEW_META)] = queryProcessGetViewMetaRsp;
17,080✔
1202
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_TABLE_TSMA)] = queryProcessGetTbTSMARsp;
17,080✔
1203
  queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_TSMA)] = queryProcessGetTbTSMARsp;
17,080✔
1204
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_GET_STREAM_PROGRESS)] = queryProcessStreamProgressRsp;
17,080✔
1205
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_VSUBTABLES_META)] = queryProcessVSubTablesRsp;
17,080✔
1206
  queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_VSTB_REF_DBS)] = queryProcessVStbRefDbsRsp;
17,080✔
1207
}
17,080✔
1208

1209
#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