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

taosdata / TDengine / #3661

17 Mar 2025 05:39AM UTC coverage: 62.007% (-0.03%) from 62.039%
#3661

push

travis-ci

web-flow
tests: add tdb ut (#30093)

* fix: compile warnings

* tests: add tdb ut

* test(tdb): fix return code

* test: recover ut

* fix: minor changes

* fix: enable test

* fix: ut errors

---------

Co-authored-by: Minglei Jin <mljin@taosdata.com>

153829 of 317582 branches covered (48.44%)

Branch coverage included in aggregate %.

240310 of 318051 relevant lines covered (75.56%)

19602636.8 hits per line

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

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

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

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

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

51
  if (usedbRsp->vgNum <= 0) {
223,648✔
52
    return TSDB_CODE_SUCCESS;
19,225✔
53
  }
54

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

61
  for (int32_t i = 0; i < usedbRsp->vgNum; ++i) {
735,313✔
62
    SVgroupInfo *pVgInfo = taosArrayGet(usedbRsp->pVgroupInfos, i);
530,890✔
63
    pOut->dbVgroup->numOfTable += pVgInfo->numOfTable;
530,890✔
64
    qDebug("the %dth vgroup, id:%d, epNum:%d, current:%s port:%u", i, pVgInfo->vgId, pVgInfo->epSet.numOfEps,
530,890✔
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))) {
530,889!
67
      return terrno;
×
68
    }
69
  }
70

71
  return TSDB_CODE_SUCCESS;
204,423✔
72
}
73

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

81
  STableInfoReq infoReq = {0};
236,499✔
82
  infoReq.option = pInput->option;
236,499✔
83
  infoReq.header.vgId = pInput->vgId;
236,499✔
84
  if (pInput->dbFName) {
236,499✔
85
    tstrncpy(infoReq.dbFName, pInput->dbFName, TSDB_DB_FNAME_LEN);
236,487✔
86
  }
87
  tstrncpy(infoReq.tbName, pInput->tbName, TSDB_TABLE_NAME_LEN);
236,499✔
88

89
  int32_t bufLen = tSerializeSTableInfoReq(NULL, 0, &infoReq);
236,499✔
90
  void   *pBuf = (*mallcFp)(bufLen);
236,493✔
91
  if (NULL == pBuf) {
236,516!
92
    return terrno;
×
93
  }
94
  int32_t ret = tSerializeSTableInfoReq(pBuf, bufLen, &infoReq);
236,516✔
95
  if (ret < 0) return ret;
236,525!
96

97
  *msg = pBuf;
236,525✔
98
  *msgLen = bufLen;
236,525✔
99

100
  return TSDB_CODE_SUCCESS;
236,525✔
101
}
102

103
int32_t queryBuildUseDbMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
210,915✔
104
  QUERY_PARAM_CHECK(input);
210,915!
105
  QUERY_PARAM_CHECK(msg);
210,915!
106
  QUERY_PARAM_CHECK(msgLen);
210,915!
107
  SBuildUseDBInput *pInput = input;
210,915✔
108

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

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

125
  *msg = pBuf;
210,915✔
126
  *msgLen = bufLen;
210,915✔
127

128
  return TSDB_CODE_SUCCESS;
210,915✔
129
}
130

131
int32_t queryBuildQnodeListMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
20,511✔
132
  QUERY_PARAM_CHECK(msg);
20,511!
133
  QUERY_PARAM_CHECK(msgLen);
20,511!
134

135
  SQnodeListReq qnodeListReq = {0};
20,511✔
136
  qnodeListReq.rowNum = -1;
20,511✔
137

138
  int32_t bufLen = tSerializeSQnodeListReq(NULL, 0, &qnodeListReq);
20,511✔
139
  void   *pBuf = (*mallcFp)(bufLen);
20,511✔
140
  if (NULL == pBuf) {
20,511!
141
    return terrno;
×
142
  }
143

144
  int32_t ret = tSerializeSQnodeListReq(pBuf, bufLen, &qnodeListReq);
20,511✔
145
  if (ret < 0) return ret;
20,511!
146

147
  *msg = pBuf;
20,511✔
148
  *msgLen = bufLen;
20,511✔
149

150
  return TSDB_CODE_SUCCESS;
20,511✔
151
}
152

153
int32_t queryBuildDnodeListMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
690✔
154
  QUERY_PARAM_CHECK(msg);
690!
155
  QUERY_PARAM_CHECK(msgLen);
690!
156

157
  SDnodeListReq dnodeListReq = {0};
690✔
158
  dnodeListReq.rowNum = -1;
690✔
159

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

168
  *msg = pBuf;
690✔
169
  *msgLen = bufLen;
690✔
170

171
  return TSDB_CODE_SUCCESS;
690✔
172
}
173

174
int32_t queryBuildGetSerVerMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
2✔
175
  QUERY_PARAM_CHECK(msg);
2!
176
  QUERY_PARAM_CHECK(msgLen);
2!
177

178
  SServerVerReq req = {0};
2✔
179

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

188
  *msg = pBuf;
2✔
189
  *msgLen = bufLen;
2✔
190

191
  return TSDB_CODE_SUCCESS;
2✔
192
}
193

194
int32_t queryBuildGetDBCfgMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
7,926✔
195
  QUERY_PARAM_CHECK(input);
7,926!
196
  QUERY_PARAM_CHECK(msg);
7,926!
197
  QUERY_PARAM_CHECK(msgLen);
7,926!
198

199
  SDbCfgReq dbCfgReq = {0};
7,926✔
200
  tstrncpy(dbCfgReq.db, input, TSDB_DB_FNAME_LEN);
7,926✔
201

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

210
  *msg = pBuf;
7,926✔
211
  *msgLen = bufLen;
7,926✔
212

213
  return TSDB_CODE_SUCCESS;
7,926✔
214
}
215

216
int32_t queryBuildGetIndexMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
2✔
217
  QUERY_PARAM_CHECK(input);
2!
218
  QUERY_PARAM_CHECK(msg);
2!
219
  QUERY_PARAM_CHECK(msgLen);
2!
220

221
  SUserIndexReq indexReq = {0};
2✔
222
  tstrncpy(indexReq.indexFName, input, TSDB_INDEX_FNAME_LEN);
2✔
223

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

232
  *msg = pBuf;
2✔
233
  *msgLen = bufLen;
2✔
234

235
  return TSDB_CODE_SUCCESS;
2✔
236
}
237

238
int32_t queryBuildRetrieveFuncMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen,
194✔
239
                                  void *(*mallcFp)(int64_t)) {
240
  QUERY_PARAM_CHECK(input);
194!
241
  QUERY_PARAM_CHECK(msg);
194!
242
  QUERY_PARAM_CHECK(msgLen);
194!
243

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

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

268
  taosArrayDestroy(funcReq.pFuncNames);
194✔
269

270
  *msg = pBuf;
194✔
271
  *msgLen = bufLen;
194✔
272

273
  return TSDB_CODE_SUCCESS;
194✔
274
}
275

276
int32_t queryBuildGetUserAuthMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
40,536✔
277
  QUERY_PARAM_CHECK(input);
40,536!
278
  QUERY_PARAM_CHECK(msg);
40,536!
279
  QUERY_PARAM_CHECK(msgLen);
40,536!
280

281
  SGetUserAuthReq req = {0};
40,536✔
282
  tstrncpy(req.user, input, TSDB_USER_LEN);
40,536✔
283

284
  int32_t bufLen = tSerializeSGetUserAuthReq(NULL, 0, &req);
40,536✔
285
  void   *pBuf = (*mallcFp)(bufLen);
40,535✔
286
  if (NULL == pBuf) {
40,535!
287
    return terrno;
×
288
  }
289
  int32_t ret = tSerializeSGetUserAuthReq(pBuf, bufLen, &req);
40,535✔
290
  if (ret < 0) return ret;
40,535!
291

292
  *msg = pBuf;
40,535✔
293
  *msgLen = bufLen;
40,535✔
294

295
  return TSDB_CODE_SUCCESS;
40,535✔
296
}
297

298
int32_t queryBuildGetTbIndexMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
14,721✔
299
  QUERY_PARAM_CHECK(input);
14,721!
300
  QUERY_PARAM_CHECK(msg);
14,721!
301
  QUERY_PARAM_CHECK(msgLen);
14,721!
302

303
  STableIndexReq indexReq = {0};
14,721✔
304
  tstrncpy(indexReq.tbFName, input, TSDB_TABLE_FNAME_LEN);
14,721✔
305

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

314
  *msg = pBuf;
14,721✔
315
  *msgLen = bufLen;
14,721✔
316

317
  return TSDB_CODE_SUCCESS;
14,721✔
318
}
319

320
int32_t queryBuildGetTbCfgMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
390✔
321
  QUERY_PARAM_CHECK(input);
390!
322
  QUERY_PARAM_CHECK(msg);
390!
323
  QUERY_PARAM_CHECK(msgLen);
390!
324

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

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

339
  *msg = pBuf;
390✔
340
  *msgLen = bufLen;
390✔
341

342
  return TSDB_CODE_SUCCESS;
390✔
343
}
344

345
int32_t queryBuildGetViewMetaMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
76,124✔
346
  QUERY_PARAM_CHECK(input);
76,124!
347
  QUERY_PARAM_CHECK(msg);
76,124!
348
  QUERY_PARAM_CHECK(msgLen);
76,124!
349

350
  SViewMetaReq req = {0};
76,124✔
351
  tstrncpy(req.fullname, input, TSDB_VIEW_FNAME_LEN);
76,124✔
352

353
  int32_t bufLen = tSerializeSViewMetaReq(NULL, 0, &req);
76,124✔
354
  void   *pBuf = (*mallcFp)(bufLen);
76,122✔
355
  if (NULL == pBuf) {
76,124!
356
    return terrno;
×
357
  }
358
  int32_t ret = tSerializeSViewMetaReq(pBuf, bufLen, &req);
76,124✔
359
  if (ret < 0) return ret;
76,125!
360

361
  *msg = pBuf;
76,125✔
362
  *msgLen = bufLen;
76,125✔
363

364
  return TSDB_CODE_SUCCESS;
76,125✔
365
}
366

367
int32_t queryBuildGetTableTSMAMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen,
2,092✔
368
                                  void *(*mallcFp)(int64_t)) {
369
  QUERY_PARAM_CHECK(input);
2,092!
370
  QUERY_PARAM_CHECK(msg);
2,092!
371
  QUERY_PARAM_CHECK(msgLen);
2,092!
372

373
  STableTSMAInfoReq req = {0};
2,092✔
374
  tstrncpy(req.name, input, TSDB_TABLE_FNAME_LEN);
2,092✔
375

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

384
  *msg = pBuf;
2,092✔
385
  *msgLen = bufLen;
2,092✔
386
  return TSDB_CODE_SUCCESS;
2,092✔
387
}
388

389
int32_t queryBuildGetTSMAMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen,
152✔
390
                                  void *(*mallcFp)(int64_t)) {
391
  QUERY_PARAM_CHECK(input);
152!
392
  QUERY_PARAM_CHECK(msg);
152!
393
  QUERY_PARAM_CHECK(msgLen);
152!
394

395
  STableTSMAInfoReq req = {0};
152✔
396
  req.fetchingWithTsmaName = true;
152✔
397
  tstrncpy(req.name, input, TSDB_TABLE_FNAME_LEN);
152✔
398

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

408
  *msg = pBuf;
152✔
409
  *msgLen = bufLen;
152✔
410
  return TSDB_CODE_SUCCESS;
152✔
411
}
412

413
int32_t queryBuildGetStreamProgressMsg(void* input, char** msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int64_t)) {
9,672✔
414
  QUERY_PARAM_CHECK(input);
9,672!
415
  QUERY_PARAM_CHECK(msg);
9,672!
416
  QUERY_PARAM_CHECK(msgLen);
9,672!
417

418
  int32_t len = tSerializeStreamProgressReq(NULL, 0, input);
9,672✔
419
  void* pBuf = (*mallcFp)(len);
9,672✔
420
  if (NULL == pBuf) {
9,672!
421
    return terrno;
×
422
  }
423

424
  int32_t ret = tSerializeStreamProgressReq(pBuf, len, input);
9,672✔
425
  if (ret < 0) return ret;
9,672!
426

427
  *msg = pBuf;
9,672✔
428
  *msgLen = len;
9,672✔
429
  return TSDB_CODE_SUCCESS;
9,672✔
430
}
431

432

433
int32_t queryBuildVSubTablesMsg(void* input, char** msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int64_t)) {
×
434
  QUERY_PARAM_CHECK(input);
×
435
  QUERY_PARAM_CHECK(msg);
×
436
  QUERY_PARAM_CHECK(msgLen);
×
437

438
  SVSubTablesReq req = {0};
×
439
  req.suid = *(int64_t*)input;
×
440

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

450
  *msg = pBuf;
×
451
  *msgLen = bufLen;
×
452

453
  return TSDB_CODE_SUCCESS;
×
454
}
455

456

457
int32_t queryProcessUseDBRsp(void *output, char *msg, int32_t msgSize) {
208,433✔
458
  SUseDbOutput *pOut = output;
208,433✔
459
  SUseDbRsp     usedbRsp = {0};
208,433✔
460
  int32_t       code = -1;
208,433✔
461

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

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

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

480
  qTrace("db:%s, usedbRsp received, numOfVgroups:%d", usedbRsp.db, usedbRsp.vgNum);
208,433✔
481
  for (int32_t i = 0; i < usedbRsp.vgNum; ++i) {
725,033✔
482
    SVgroupInfo *pInfo = taosArrayGet(usedbRsp.pVgroupInfos, i);
516,600✔
483
    qTrace("vgId:%d, numOfEps:%d inUse:%d ", pInfo->vgId, pInfo->epSet.numOfEps, pInfo->epSet.inUse);
516,600✔
484
    for (int32_t j = 0; j < pInfo->epSet.numOfEps; ++j) {
1,155,801✔
485
      qTrace("vgId:%d, index:%d epset:%s:%u", pInfo->vgId, j, pInfo->epSet.eps[j].fqdn, pInfo->epSet.eps[j].port);
639,201✔
486
    }
487
  }
488

489
  code = queryBuildUseDbOutput(pOut, &usedbRsp);
208,433✔
490

491
PROCESS_USEDB_OVER:
208,433✔
492

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

501
  tFreeSUsedbRsp(&usedbRsp);
208,433✔
502
  return code;
208,433✔
503
}
504

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

512
  if (pMetaMsg->numOfColumns > TSDB_MAX_COLUMNS || pMetaMsg->numOfColumns <= 0) {
165,613!
513
    qError("invalid numOfColumns[%d] in table meta rsp msg", pMetaMsg->numOfColumns);
×
514
    return TSDB_CODE_TSC_INVALID_VALUE;
×
515
  }
516

517
  if (pMetaMsg->tableType != TSDB_SUPER_TABLE && pMetaMsg->tableType != TSDB_CHILD_TABLE &&
165,618✔
518
      pMetaMsg->tableType != TSDB_NORMAL_TABLE && pMetaMsg->tableType != TSDB_SYSTEM_TABLE &&
38,398✔
519
      pMetaMsg->tableType != TSDB_VIRTUAL_NORMAL_TABLE && pMetaMsg->tableType != TSDB_VIRTUAL_CHILD_TABLE) {
81!
520
    qError("invalid tableType[%d] in table meta rsp msg", pMetaMsg->tableType);
×
521
    return TSDB_CODE_TSC_INVALID_VALUE;
×
522
  }
523

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

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

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

539
  return TSDB_CODE_SUCCESS;
165,618✔
540
}
541

542
int32_t queryCreateCTableMetaFromMsg(STableMetaRsp *msg, SCTableMeta *pMeta) {
246,632✔
543
  QUERY_PARAM_CHECK(msg);
246,632!
544
  QUERY_PARAM_CHECK(pMeta);
246,632!
545
  pMeta->vgId = msg->vgId;
246,632✔
546
  pMeta->tableType = msg->tableType;
246,632✔
547
  pMeta->uid = msg->tuid;
246,632✔
548
  pMeta->suid = msg->suid;
246,632✔
549

550
  qDebug("ctb:%s, uid:0x%" PRIx64 " meta returned, type:%d vgId:%d db:%s suid:%" PRIx64, msg->tbName, pMeta->uid,
246,632✔
551
         pMeta->tableType, pMeta->vgId, msg->dbFName, pMeta->suid);
552

553
  return TSDB_CODE_SUCCESS;
246,636✔
554
}
555

556
int32_t queryCreateVCTableMetaFromMsg(STableMetaRsp *msg, SVCTableMeta **pMeta) {
261✔
557
  QUERY_PARAM_CHECK(msg);
261!
558
  QUERY_PARAM_CHECK(pMeta);
261!
559
  QUERY_PARAM_CHECK(msg->pColRefs);
261!
560

561
  int32_t pColRefSize = sizeof(SColRef) * msg->numOfColRefs;
261✔
562

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

569
  pTableMeta->vgId = msg->vgId;
261✔
570
  pTableMeta->tableType = msg->tableType;
261✔
571
  pTableMeta->uid = msg->tuid;
261✔
572
  pTableMeta->suid = msg->suid;
261✔
573
  pTableMeta->numOfColRefs = msg->numOfColRefs;
261✔
574

575
  pTableMeta->colRef = (SColRef *)((char *)pTableMeta + sizeof(SVCTableMeta));
261✔
576
  memcpy(pTableMeta->colRef, msg->pColRefs, pColRefSize);
261✔
577

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

581
  *pMeta = pTableMeta;
261✔
582
  return TSDB_CODE_SUCCESS;
261✔
583
}
584

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

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

601
  pTableMeta->vgId = isStb ? 0 : msg->vgId;
209,021✔
602
  pTableMeta->tableType = isStb ? TSDB_SUPER_TABLE : msg->tableType;
209,021✔
603
  pTableMeta->uid = isStb ? msg->suid : msg->tuid;
209,021✔
604
  pTableMeta->suid = msg->suid;
209,021✔
605
  pTableMeta->sversion = msg->sversion;
209,021✔
606
  pTableMeta->tversion = msg->tversion;
209,021✔
607
  pTableMeta->virtualStb = msg->virtualStb;
209,021✔
608
  pTableMeta->numOfColRefs = msg->numOfColRefs;
209,021✔
609

610
  pTableMeta->tableInfo.numOfTags = msg->numOfTags;
209,021✔
611
  pTableMeta->tableInfo.precision = msg->precision;
209,021✔
612
  pTableMeta->tableInfo.numOfColumns = msg->numOfColumns;
209,021✔
613

614
  memcpy(pTableMeta->schema, msg->pSchemas, sizeof(SSchema) * total);
209,021✔
615
  if (withExtSchema(msg->tableType) && msg->pSchemaExt) {
209,021✔
616
    pTableMeta->schemaExt = pSchemaExt;
204,194✔
617
    memcpy(pSchemaExt, msg->pSchemaExt, schemaExtSize);
204,194✔
618
  } else {
619
    pTableMeta->schemaExt = NULL;
4,832✔
620
  }
621

622
  if (hasRefCol(msg->tableType) && msg->pColRefs && !isStb) {
209,026!
623
    pTableMeta->colRef = (SColRef *)((char *)pTableMeta + metaSize + schemaExtSize);
957✔
624
    memcpy(pTableMeta->colRef, msg->pColRefs, pColRefSize);
957✔
625
  } else {
626
    pTableMeta->colRef = NULL;
208,069✔
627
  }
628

629
  bool hasPK = (msg->numOfColumns > 1) && (pTableMeta->schema[1].flags & COL_IS_KEY);
209,026!
630
  for (int32_t i = 0; i < msg->numOfColumns; ++i) {
4,533,813✔
631
    pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes;
4,324,787✔
632
    if (hasPK && (i > 0)) {
4,324,787✔
633
      if ((pTableMeta->schema[i].flags & COL_IS_KEY)) {
157,297✔
634
        ++pTableMeta->tableInfo.numOfPKs;
78,668✔
635
      } else {
636
        hasPK = false;
78,629✔
637
      }
638
    }
639
  }
640

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

648
  *pMeta = pTableMeta;
209,022✔
649
  return TSDB_CODE_SUCCESS;
209,022✔
650
}
651

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

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

669
  pTableMeta->vgId = isStb ? 0 : msg->vgId;
2,435✔
670
  pTableMeta->tableType = isStb ? TSDB_SUPER_TABLE : msg->tableType;
2,435✔
671
  pTableMeta->uid = isStb ? msg->suid : msg->tuid;
2,435✔
672
  pTableMeta->suid = msg->suid;
2,435✔
673
  pTableMeta->sversion = msg->sversion;
2,435✔
674
  pTableMeta->tversion = msg->tversion;
2,435✔
675
  pTableMeta->virtualStb = msg->virtualStb;
2,435✔
676
  pTableMeta->numOfColRefs = msg->numOfColRefs;
2,435✔
677

678
  pTableMeta->tableInfo.numOfTags = msg->numOfTags;
2,435✔
679
  pTableMeta->tableInfo.precision = msg->precision;
2,435✔
680
  pTableMeta->tableInfo.numOfColumns = msg->numOfColumns;
2,435✔
681

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

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

697
  bool hasPK = (msg->numOfColumns > 1) && (pTableMeta->schema[1].flags & COL_IS_KEY);
2,435!
698
  for (int32_t i = 0; i < msg->numOfColumns; ++i) {
7,906✔
699
    pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes;
5,471✔
700
    if (hasPK && (i > 0)) {
5,471!
701
      if ((pTableMeta->schema[i].flags & COL_IS_KEY)) {
×
702
        ++pTableMeta->tableInfo.numOfPKs;
×
703
      } else {
704
        hasPK = false;
×
705
      }
706
    }
707
  }
708

709
  char *pTbName = (char *)pTableMeta + metaSize + schemaExtSize + pColRefSize;
2,435✔
710
  tstrncpy(pTbName, msg->tbName, tbNameSize);
2,435✔
711

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

719
  *pMeta = pTableMeta;
2,435✔
720
  return TSDB_CODE_SUCCESS;
2,435✔
721
}
722

723
int32_t queryProcessTableMetaRsp(void *output, char *msg, int32_t msgSize) {
163,180✔
724
  int32_t       code = 0;
163,180✔
725
  STableMetaRsp metaRsp = {0};
163,180✔
726

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

733
  if (tDeserializeSTableMetaRsp(msg, msgSize, &metaRsp) != 0) {
163,181!
734
    code = TSDB_CODE_INVALID_MSG;
×
735
    goto PROCESS_META_OVER;
×
736
  }
737

738
  code = queryConvertTableMetaMsg(&metaRsp);
163,180✔
739
  if (code != TSDB_CODE_SUCCESS) {
163,172!
740
    goto PROCESS_META_OVER;
×
741
  }
742

743
  if (!IS_SYS_DBNAME(metaRsp.dbFName) &&
163,172!
744
      !tIsValidSchema(metaRsp.pSchemas, metaRsp.numOfColumns, metaRsp.numOfTags)) {
159,339!
745
    code = TSDB_CODE_TSC_INVALID_VALUE;
×
746
    goto PROCESS_META_OVER;
×
747
  }
748

749
  STableMetaOutput *pOut = output;
163,175✔
750
  tstrncpy(pOut->dbFName, metaRsp.dbFName, TSDB_DB_FNAME_LEN);
163,175✔
751
  pOut->dbId = metaRsp.dbId;
163,175✔
752

753
  if (metaRsp.tableType == TSDB_CHILD_TABLE) {
163,175✔
754
    SET_META_TYPE_BOTH_TABLE(pOut->metaType);
95,918✔
755

756
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
95,918✔
757
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
95,918✔
758

759
    pOut->ctbMeta.vgId = metaRsp.vgId;
95,918✔
760
    pOut->ctbMeta.tableType = metaRsp.tableType;
95,918✔
761
    pOut->ctbMeta.uid = metaRsp.tuid;
95,918✔
762
    pOut->ctbMeta.suid = metaRsp.suid;
95,918✔
763

764
    code = queryCreateTableMetaFromMsg(&metaRsp, true, &pOut->tbMeta);
95,918✔
765
  } else if (metaRsp.tableType == TSDB_VIRTUAL_CHILD_TABLE) {
67,257✔
766
    SET_META_TYPE_BOTH_VTABLE(pOut->metaType);
41✔
767

768
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
41✔
769
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
41✔
770

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

782
PROCESS_META_OVER:
163,180✔
783
  if (code != 0) {
163,180!
784
    qError("failed to process table meta rsp since %s", tstrerror(code));
×
785
  }
786

787
  tFreeSTableMetaRsp(&metaRsp);
163,180✔
788
  return code;
163,175✔
789
}
790

791
static int32_t queryProcessTableNameRsp(void *output, char *msg, int32_t msgSize) {
2,435✔
792
  int32_t       code = 0;
2,435✔
793
  STableMetaRsp metaRsp = {0};
2,435✔
794

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

801
  if (tDeserializeSTableMetaRsp(msg, msgSize, &metaRsp) != 0) {
2,435!
802
    code = TSDB_CODE_INVALID_MSG;
×
803
    goto PROCESS_NAME_OVER;
×
804
  }
805

806
  code = queryConvertTableMetaMsg(&metaRsp);
2,435✔
807
  if (code != TSDB_CODE_SUCCESS) {
2,435!
808
    goto PROCESS_NAME_OVER;
×
809
  }
810

811
  if (!IS_SYS_DBNAME(metaRsp.dbFName) &&
2,435!
812
      !tIsValidSchema(metaRsp.pSchemas, metaRsp.numOfColumns, metaRsp.numOfTags)) {
2,435!
813
    code = TSDB_CODE_TSC_INVALID_VALUE;
×
814
    goto PROCESS_NAME_OVER;
×
815
  }
816

817
  STableMetaOutput *pOut = output;
2,435✔
818
  tstrncpy(pOut->dbFName, metaRsp.dbFName, TSDB_DB_FNAME_LEN);
2,435✔
819
  pOut->dbId = metaRsp.dbId;
2,435✔
820

821
  if (metaRsp.tableType == TSDB_CHILD_TABLE) {
2,435✔
822
    SET_META_TYPE_BOTH_TABLE(pOut->metaType);
659✔
823

824
    tstrncpy(pOut->ctbName, metaRsp.tbName, TSDB_TABLE_NAME_LEN);
659✔
825
    tstrncpy(pOut->tbName, metaRsp.stbName, TSDB_TABLE_NAME_LEN);
659✔
826

827
    pOut->ctbMeta.vgId = metaRsp.vgId;
659✔
828
    pOut->ctbMeta.tableType = metaRsp.tableType;
659✔
829
    pOut->ctbMeta.uid = metaRsp.tuid;
659✔
830
    pOut->ctbMeta.suid = metaRsp.suid;
659✔
831

832
    code = queryCreateTableMetaExFromMsg(&metaRsp, true, &pOut->tbMeta);
659✔
833
  } else if (metaRsp.tableType == TSDB_VIRTUAL_CHILD_TABLE) {
1,776!
834
    SET_META_TYPE_BOTH_VTABLE(pOut->metaType);
×
835

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

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

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

851
PROCESS_NAME_OVER:
2,435✔
852
  if (code != 0) {
2,435!
853
    qError("failed to process table name rsp since %s", tstrerror(code));
×
854
  }
855

856
  tFreeSTableMetaRsp(&metaRsp);
2,435✔
857
  return code;
2,435✔
858
}
859

860
int32_t queryProcessQnodeListRsp(void *output, char *msg, int32_t msgSize) {
20,511✔
861
  SQnodeListRsp out = {0};
20,511✔
862
  int32_t       code = 0;
20,511✔
863

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

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

877
  return code;
20,511✔
878
}
879

880
int32_t queryProcessDnodeListRsp(void *output, char *msg, int32_t msgSize) {
690✔
881
  SDnodeListRsp out = {0};
690✔
882
  int32_t       code = 0;
690✔
883

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

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

896
  *(SArray **)output = out.dnodeList;
690✔
897

898
  return code;
690✔
899
}
900

901
int32_t queryProcessGetSerVerRsp(void *output, char *msg, int32_t msgSize) {
2✔
902
  SServerVerRsp out = {0};
2✔
903
  int32_t       code = 0;
2✔
904

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

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

917
  *(char **)output = taosStrdup(out.ver);
2!
918
  if (NULL == *(char **)output) {
2!
919
    return terrno;
×
920
  }
921

922
  return code;
2✔
923
}
924

925
int32_t queryProcessGetDbCfgRsp(void *output, char *msg, int32_t msgSize) {
7,800✔
926
  SDbCfgRsp out = {0};
7,800✔
927

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

933
  if (tDeserializeSDbCfgRsp(msg, msgSize, &out) != 0) {
7,800!
934
    qError("tDeserializeSDbCfgRsp failed, msgSize:%d, dbCfgRsp:%lu", msgSize, sizeof(out));
×
935
    return TSDB_CODE_INVALID_MSG;
×
936
  }
937

938
  memcpy(output, &out, sizeof(out));
7,799✔
939

940
  return TSDB_CODE_SUCCESS;
7,799✔
941
}
942

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

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

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

956
  memcpy(output, &out, sizeof(out));
×
957

958
  return TSDB_CODE_SUCCESS;
×
959
}
960

961
int32_t queryProcessRetrieveFuncRsp(void *output, char *msg, int32_t msgSize) {
174✔
962
  SRetrieveFuncRsp out = {0};
174✔
963

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

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

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

979
  SFuncInfo *funcInfo = taosArrayGet(out.pFuncInfos, 0);
174✔
980

981
  memcpy(output, funcInfo, sizeof(*funcInfo));
174✔
982
  taosArrayDestroy(out.pFuncInfos);
174✔
983
  taosArrayDestroy(out.pFuncExtraInfos);
174✔
984

985
  return TSDB_CODE_SUCCESS;
174✔
986
}
987

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

994
  if (tDeserializeSGetUserAuthRsp(msg, msgSize, (SGetUserAuthRsp *)output) != 0) {
40,527✔
995
    qError("tDeserializeSGetUserAuthRsp failed, msgSize:%d", msgSize);
1!
996
    return TSDB_CODE_INVALID_MSG;
×
997
  }
998

999
  return TSDB_CODE_SUCCESS;
40,526✔
1000
}
1001

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

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

1014
  return TSDB_CODE_SUCCESS;
2✔
1015
}
1016

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

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

1034
  *(STableCfgRsp **)output = out;
390✔
1035

1036
  return TSDB_CODE_SUCCESS;
390✔
1037
}
1038

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

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

1056
  qDebugL("view meta recved, dbFName:%s, view:%s, querySQL:%s", out->dbFName, out->name, out->querySql);
621✔
1057

1058
  *(SViewMetaRsp **)output = out;
621✔
1059

1060
  return TSDB_CODE_SUCCESS;
621✔
1061
}
1062

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

1069
  if (tDeserializeTableTSMAInfoRsp(msg, msgSize, output) != 0) {
1,857!
1070
    qError("tDeserializeSViewMetaRsp failed, msgSize:%d", msgSize);
×
1071
    return TSDB_CODE_INVALID_MSG;
×
1072
  }
1073

1074
  return TSDB_CODE_SUCCESS;
1,857✔
1075
}
1076

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

1083
  if (tDeserializeSStreamProgressRsp(msg, msgSize, output) != 0) {
9,670!
1084
    qError("tDeserializeStreamProgressRsp failed, msgSize:%d", msgSize);
×
1085
    return TSDB_CODE_INVALID_MSG;
×
1086
  }
1087
  return TSDB_CODE_SUCCESS;
9,672✔
1088
}
1089

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

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

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

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

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