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

taosdata / TDengine / #4906

30 Dec 2025 10:52AM UTC coverage: 65.514% (+0.09%) from 65.423%
#4906

push

travis-ci

web-flow
enh: drop multi-stream (#33962)

60 of 106 new or added lines in 4 files covered. (56.6%)

4080 existing lines in 123 files now uncovered.

193840 of 295877 relevant lines covered (65.51%)

120444601.14 hits per line

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

81.49
/source/dnode/vnode/src/tq/tqScan.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 "tq.h"
17
static int32_t tqAddRawDataToRsp(const void* rawData, SMqDataRsp* pRsp, int8_t precision) {
×
18
  int32_t    code = TDB_CODE_SUCCESS;
×
19
  int32_t    lino = 0;
×
20
  void*      buf = NULL;
×
21

22
  int32_t dataStrLen = sizeof(SRetrieveTableRspForTmq) + *(uint32_t *)rawData + INT_BYTES;
×
23
  buf = taosMemoryCalloc(1, dataStrLen);
×
24
  TSDB_CHECK_NULL(buf, code, lino, END, terrno);
×
25

26
  SRetrieveTableRspForTmq* pRetrieve = (SRetrieveTableRspForTmq*)buf;
×
27
  pRetrieve->version = RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION;
×
28
  pRetrieve->precision = precision;
×
29
  pRetrieve->compressed = 0;
×
30

31
  memcpy(pRetrieve->data, rawData, *(uint32_t *)rawData + INT_BYTES);
×
32
  TSDB_CHECK_NULL(taosArrayPush(pRsp->blockDataLen, &dataStrLen), code, lino, END, terrno);
×
33
  TSDB_CHECK_NULL(taosArrayPush(pRsp->blockData, &buf), code, lino, END, terrno);
×
34
  pRsp->blockDataElementFree = true;
×
35

36
  tqTrace("tqAddRawDataToRsp add block data to block array, blockDataLen:%d, blockData:%p", dataStrLen, buf);
×
37
  END:
×
38
  if (code != TSDB_CODE_SUCCESS) {
×
39
    taosMemoryFree(buf);
×
40
    tqError("%s failed at %d, failed to add block data to response:%s", __FUNCTION__, lino, tstrerror(code));
×
41
  }
42
  return code;
×
43
}
44

45
static int32_t tqAddBlockDataToRsp(const SSDataBlock* pBlock, SMqDataRsp* pRsp, const SSchemaWrapper* pSW, int8_t precision) {
153,119,839✔
46
  int32_t code = 0;
153,119,839✔
47
  int32_t lino = 0;
153,119,839✔
48
  SSchemaWrapper* pSchema = NULL;
153,119,839✔
49
  
50
  size_t dataEncodeBufSize = blockGetEncodeSize(pBlock);
153,139,358✔
51
  int32_t dataStrLen = sizeof(SRetrieveTableRspForTmq) + dataEncodeBufSize;
153,177,075✔
52
  void*   buf = taosMemoryCalloc(1, dataStrLen);
153,177,075✔
53
  TSDB_CHECK_NULL(buf, code, lino, END, terrno);
153,102,404✔
54

55
  SRetrieveTableRspForTmq* pRetrieve = (SRetrieveTableRspForTmq*)buf;
153,102,404✔
56
  pRetrieve->version = RETRIEVE_TABLE_RSP_TMQ_VERSION;
153,102,404✔
57
  pRetrieve->precision = precision;
153,118,752✔
58
  pRetrieve->compressed = 0;
153,126,996✔
59
  pRetrieve->numOfRows = htobe64((int64_t)pBlock->info.rows);
153,103,934✔
60

61
  int32_t actualLen = blockEncode(pBlock, pRetrieve->data, dataEncodeBufSize, pSW->nCols);
153,144,953✔
62
  TSDB_CHECK_CONDITION(actualLen >= 0, code, lino, END, terrno);
153,113,943✔
63

64
  actualLen += sizeof(SRetrieveTableRspForTmq);
153,113,943✔
65
  TSDB_CHECK_NULL(taosArrayPush(pRsp->blockDataLen, &actualLen), code, lino, END, terrno);
306,276,804✔
66
  TSDB_CHECK_NULL(taosArrayPush(pRsp->blockData, &buf), code, lino, END, terrno);
306,321,069✔
67
  pSchema = tCloneSSchemaWrapper(pSW);
153,141,928✔
68
  TSDB_CHECK_NULL(pSchema, code, lino, END, terrno);
153,141,928✔
69
  TSDB_CHECK_NULL(taosArrayPush(pRsp->blockSchema, &pSchema), code, lino, END, terrno);
306,298,653✔
70
  pSchema = NULL;
153,156,725✔
71
  pRsp->blockDataElementFree = true;
153,156,725✔
72
  tqTrace("tqAddBlockDataToRsp add block data to block array, blockDataLen:%d, blockData:%p", dataStrLen, buf);
153,134,528✔
73

74
END:
153,134,528✔
75
  tDeleteSchemaWrapper(pSchema);
153,133,160✔
76
  if (code != TSDB_CODE_SUCCESS){
153,071,351✔
77
    taosMemoryFree(buf);
×
78
    tqError("%s failed at line %d with msg:%s", __func__, lino, tstrerror(code));
×
79
  }
80
  return code;
153,071,351✔
81
}
82

83
static int32_t tqAddTbNameToRsp(const STQ* pTq, int64_t uid, SMqDataRsp* pRsp, int32_t n) {
36,028,175✔
84
  int32_t    code = TDB_CODE_SUCCESS;
36,028,175✔
85
  int32_t    lino = 0;
36,028,175✔
86
  SMetaReader mr = {0};
36,028,175✔
87

88
  TSDB_CHECK_NULL(pTq, code, lino, END, TSDB_CODE_INVALID_PARA);
36,037,156✔
89
  TSDB_CHECK_NULL(pRsp, code, lino, END, TSDB_CODE_INVALID_PARA);
36,037,156✔
90

91
  metaReaderDoInit(&mr, pTq->pVnode->pMeta, META_READER_LOCK);
36,037,156✔
92

93
  code = metaReaderGetTableEntryByUidCache(&mr, uid);
36,019,397✔
94
  TSDB_CHECK_CODE(code, lino, END);
36,002,692✔
95

96
  for (int32_t i = 0; i < n; i++) {
72,057,993✔
97
    char* tbName = taosStrdup(mr.me.name);
35,965,277✔
98
    TSDB_CHECK_NULL(tbName, code, lino, END, terrno);
36,003,316✔
99
    if(taosArrayPush(pRsp->blockTbName, &tbName) == NULL){
72,057,924✔
100
      tqError("failed to push tbName to blockTbName:%s, uid:%"PRId64, tbName, uid);
×
101
      continue;
×
102
    }
103
    tqTrace("add tbName to response success tbname:%s, uid:%"PRId64, tbName, uid);
36,054,608✔
104
  }
105

106
END:
36,093,048✔
107
  if (code != TSDB_CODE_SUCCESS) {
36,016,159✔
UNCOV
108
    tqError("%s failed at %d, failed to add tbName to response:%s, uid:%"PRId64, __FUNCTION__, lino, tstrerror(code), uid);
×
109
  }
110
  metaReaderClear(&mr);
36,016,159✔
111
  return code;
36,031,668✔
112
}
113

114
int32_t getDataBlock(qTaskInfo_t task, const STqHandle* pHandle, int32_t vgId, SSDataBlock** res) {
137,443,166✔
115
  if (task == NULL || pHandle == NULL || res == NULL) {
137,443,166✔
116
    return TSDB_CODE_INVALID_PARA;
×
117
  }
118
  uint64_t ts = 0;
137,462,258✔
119
  qStreamSetOpen(task);
137,463,405✔
120

121
  tqDebug("consumer:0x%" PRIx64 " vgId:%d, tmq one task start execute", pHandle->consumerId, vgId);
137,460,085✔
122
  int32_t code = qExecTask(task, res, &ts);
137,468,915✔
123
  if (code != TSDB_CODE_SUCCESS) {
137,462,240✔
124
    tqError("consumer:0x%" PRIx64 " vgId:%d, task exec error since %s", pHandle->consumerId, vgId, tstrerror(code));
×
125
    return code;
×
126
  }
127

128
  tqDebug("consumer:0x%" PRIx64 " vgId:%d tmq one task end executed, pDataBlock:%p", pHandle->consumerId, vgId, *res);
137,462,240✔
129
  return 0;
137,467,645✔
130
}
131

132
static int32_t tqProcessReplayRsp(STQ* pTq, STqHandle* pHandle, SMqDataRsp* pRsp, const SMqPollReq* pRequest, SSDataBlock* pDataBlock, qTaskInfo_t task){
8,151✔
133
  int32_t code = 0;
8,151✔
134
  int32_t lino = 0;
8,151✔
135

136
  if (IS_OFFSET_RESET_TYPE(pRequest->reqOffset.type) && pHandle->block != NULL) {
8,151✔
137
    blockDataDestroy(pHandle->block);
247✔
138
    pHandle->block = NULL;
247✔
139
  }
140
  if (pHandle->block == NULL) {
8,151✔
141
    if (pDataBlock == NULL) {
2,717✔
142
      goto END;
1,482✔
143
    }
144

145
    STqOffsetVal offset = {0};
1,235✔
146
    code = qStreamExtractOffset(task, &offset);
1,235✔
147
    TSDB_CHECK_CODE(code, lino, END);
1,235✔
148

149
    pHandle->block = NULL;
1,235✔
150

151
    code = createOneDataBlock(pDataBlock, true, &pHandle->block);
1,235✔
152
    TSDB_CHECK_CODE(code, lino, END);
1,235✔
153

154
    pHandle->blockTime = offset.ts;
1,235✔
155
    tOffsetDestroy(&offset);
1,235✔
156
    int32_t vgId = TD_VID(pTq->pVnode);
1,235✔
157
    code = getDataBlock(task, pHandle, vgId, &pDataBlock);
1,235✔
158
    TSDB_CHECK_CODE(code, lino, END);
1,235✔
159
  }
160

161
  const STqExecHandle* pExec = &pHandle->execHandle;
6,669✔
162
  code = tqAddBlockDataToRsp(pHandle->block, pRsp, &pExec->execCol.pSW, pTq->pVnode->config.tsdbCfg.precision);
6,669✔
163
  TSDB_CHECK_CODE(code, lino, END);
6,669✔
164

165
  pRsp->blockNum++;
6,669✔
166
  if (pDataBlock == NULL) {
6,669✔
167
    blockDataDestroy(pHandle->block);
988✔
168
    pHandle->block = NULL;
988✔
169
  } else {
170
    code = copyDataBlock(pHandle->block, pDataBlock);
5,681✔
171
    TSDB_CHECK_CODE(code, lino, END);
5,681✔
172

173
    STqOffsetVal offset = {0};
5,681✔
174
    code = qStreamExtractOffset(task, &offset);
5,681✔
175
    TSDB_CHECK_CODE(code, lino, END);
5,681✔
176

177
    pRsp->sleepTime = offset.ts - pHandle->blockTime;
5,681✔
178
    pHandle->blockTime = offset.ts;
5,681✔
179
    tOffsetDestroy(&offset);
5,681✔
180
  }
181

182
END:
8,151✔
183
  if (code != TSDB_CODE_SUCCESS) {
8,151✔
184
    tqError("%s failed at %d, failed to process replay response:%s", __FUNCTION__, lino, tstrerror(code));
×
185
  }
186
  return code;
8,151✔
187
}
188

189
int32_t tqScanData(STQ* pTq, STqHandle* pHandle, SMqDataRsp* pRsp, STqOffsetVal* pOffset, const SMqPollReq* pRequest) {
23,923,055✔
190
  int32_t code = 0;
23,923,055✔
191
  int32_t lino = 0;
23,923,055✔
192
  TSDB_CHECK_NULL(pRsp, code, lino, END, TSDB_CODE_INVALID_PARA);
23,923,055✔
193
  TSDB_CHECK_NULL(pTq, code, lino, END, TSDB_CODE_INVALID_PARA);
23,923,055✔
194
  TSDB_CHECK_NULL(pHandle, code, lino, END, TSDB_CODE_INVALID_PARA);
23,923,055✔
195
  TSDB_CHECK_NULL(pOffset, code, lino, END, TSDB_CODE_INVALID_PARA);
23,923,055✔
196
  TSDB_CHECK_NULL(pRequest, code, lino, END, TSDB_CODE_INVALID_PARA);
23,923,055✔
197

198
  int32_t vgId = TD_VID(pTq->pVnode);
23,923,055✔
199
  int32_t totalRows = 0;
23,924,228✔
200

201
  const STqExecHandle* pExec = &pHandle->execHandle;
23,924,228✔
202
  qTaskInfo_t          task = pExec->task;
23,923,280✔
203

204
  code = qStreamPrepareScan(task, pOffset, pHandle->execHandle.subType);
23,922,339✔
205
  TSDB_CHECK_CODE(code, lino, END);
23,921,711✔
206

207
  qStreamSetSourceExcluded(task, pRequest->sourceExcluded);
23,731,955✔
208
  int64_t st = taosGetTimestampMs();
23,732,955✔
209
  while (1) {
113,731,060✔
210
    SSDataBlock* pDataBlock = NULL;
137,464,015✔
211
    code = getDataBlock(task, pHandle, vgId, &pDataBlock);
137,455,980✔
212
    TSDB_CHECK_CODE(code, lino, END);
137,468,309✔
213

214
    if (pRequest->enableReplay) {
137,468,309✔
215
      code = tqProcessReplayRsp(pTq, pHandle, pRsp, pRequest, pDataBlock, task);
8,151✔
216
      TSDB_CHECK_CODE(code, lino, END);
8,151✔
217
      break;
8,151✔
218
    }
219
    if (pDataBlock == NULL) {
137,463,267✔
220
      break;
21,036,430✔
221
    }
222
    code = tqAddBlockDataToRsp(pDataBlock, pRsp, &pExec->execCol.pSW, pTq->pVnode->config.tsdbCfg.precision);
116,426,837✔
223
    TSDB_CHECK_CODE(code, lino, END);
116,408,229✔
224

225
    pRsp->blockNum++;
116,408,229✔
226
    totalRows += pDataBlock->info.rows;
116,411,372✔
227
    if (totalRows >= pRequest->minPollRows || (taosGetTimestampMs() - st > pRequest->timeout)) {
232,158,315✔
228
      break;
229
    }
230
  }
231

232
  tqDebug("consumer:0x%" PRIx64 " vgId:%d tmq task executed finished, total blocks:%d, totalRows:%d", pHandle->consumerId, vgId, pRsp->blockNum, totalRows);
23,734,776✔
233
  code = qStreamExtractOffset(task, &pRsp->rspOffset);
23,734,776✔
234

235
END:
23,924,532✔
236
  if (code != 0) {
23,924,532✔
237
    tqError("%s failed at %d, tmq task executed error msg:%s", __FUNCTION__, lino, tstrerror(code));
189,756✔
238
  }
239
  return code;
23,924,532✔
240
}
241

242
int32_t tqScanTaosx(STQ* pTq, const STqHandle* pHandle, SMqDataRsp* pRsp, SMqBatchMetaRsp* pBatchMetaRsp, STqOffsetVal* pOffset, const SMqPollReq* pRequest) {
42,677✔
243
  int32_t code = 0;
42,677✔
244
  int32_t lino = 0;
42,677✔
245
  char* tbName = NULL;
42,677✔
246
  const STqExecHandle* pExec = &pHandle->execHandle;
42,677✔
247
  qTaskInfo_t          task = pExec->task;
42,677✔
248
  code = qStreamPrepareScan(task, pOffset, pHandle->execHandle.subType);
42,677✔
249
  TSDB_CHECK_CODE(code, lino, END);
42,677✔
250

251
  int32_t rowCnt = 0;
42,677✔
252
  int64_t st = taosGetTimestampMs();
42,677✔
253
  while (1) {
1,339,532✔
254
    SSDataBlock* pDataBlock = NULL;
1,382,209✔
255
    uint64_t     ts = 0;
1,381,659✔
256
    tqDebug("tmqsnap task start to execute");
1,382,209✔
257
    code = qExecTask(task, &pDataBlock, &ts);
1,383,013✔
258
    TSDB_CHECK_CODE(code, lino, END);
1,382,209✔
259
    tqDebug("tmqsnap task execute end, get %p", pDataBlock);
1,382,209✔
260

261
    if (pDataBlock != NULL && pDataBlock->info.rows > 0) {
1,382,209✔
262
      if (pRsp->withTbName) {
686,532✔
263
        tbName = taosStrdup(qExtractTbnameFromTask(task));
686,532✔
264
        TSDB_CHECK_NULL(tbName, code, lino, END, terrno);
686,532✔
265
        TSDB_CHECK_NULL(taosArrayPush(pRsp->blockTbName, &tbName), code, lino, END, terrno);
1,373,064✔
266
        tqDebug("vgId:%d, add tbname:%s to rsp msg", pTq->pVnode->config.vgId, tbName);
686,532✔
267
        tbName = NULL;
686,532✔
268
      }
269

270
      code = tqAddBlockDataToRsp(pDataBlock, pRsp, qExtractSchemaFromTask(task), pTq->pVnode->config.tsdbCfg.precision);
686,532✔
271
      TSDB_CHECK_CODE(code, lino, END);
686,257✔
272

273
      pRsp->blockNum++;
686,257✔
274
      rowCnt += pDataBlock->info.rows;
686,257✔
275
      if (rowCnt <= pRequest->minPollRows && (taosGetTimestampMs() - st <= pRequest->timeout)) {
1,342,676✔
276
        continue;
656,694✔
277
      }
278
    }
279

280
    // get meta
281
    SMqBatchMetaRsp* tmp = qStreamExtractMetaMsg(task);
725,515✔
282
    if (taosArrayGetSize(tmp->batchMetaReq) > 0) {
725,515✔
283
      code = qStreamExtractOffset(task, &tmp->rspOffset);
4,059✔
284
      TSDB_CHECK_CODE(code, lino, END);
4,059✔
285
      *pBatchMetaRsp = *tmp;
4,059✔
286
      tqDebug("tmqsnap task get meta");
4,059✔
287
      break;
4,059✔
288
    }
289

290
    if (pDataBlock == NULL) {
721,181✔
291
      code = qStreamExtractOffset(task, pOffset);
691,343✔
292
      TSDB_CHECK_CODE(code, lino, END);
691,618✔
293

294
      if (pOffset->type == TMQ_OFFSET__SNAPSHOT_DATA) {
691,618✔
295
        continue;
682,838✔
296
      }
297

298
      tqDebug("tmqsnap vgId: %d, tsdb consume over, switch to wal, ver %" PRId64, TD_VID(pTq->pVnode), pHandle->snapshotVer + 1);
8,780✔
299
      code = qStreamExtractOffset(task, &pRsp->rspOffset);
8,780✔
300
      break;
8,780✔
301
    }
302

303
    if (pRsp->blockNum > 0) {
29,838✔
304
      tqDebug("tmqsnap task exec exited, get data");
29,838✔
305
      code = qStreamExtractOffset(task, &pRsp->rspOffset);
29,838✔
306
      break;
29,838✔
307
    }
308
  }
309
  tqDebug("%s:%d success", __FUNCTION__, lino);
42,677✔
310
END:
42,402✔
311
  if (code != 0){
42,677✔
312
    tqError("%s failed at %d, vgId:%d, task exec error since %s", __FUNCTION__ , lino, pTq->pVnode->config.vgId, tstrerror(code));
×
313
  }
314
  taosMemoryFree(tbName);
42,677✔
315
  return code;
42,677✔
316
}
317

318
static void tqProcessSubData(STQ* pTq, STqHandle* pHandle, SMqDataRsp* pRsp, int32_t* totalRows,
36,265,836✔
319
                             const SMqPollReq* pRequest, SArray* rawList){
320
  int32_t code = 0;
36,265,836✔
321
  int32_t lino = 0;
36,265,836✔
322
  SArray* pBlocks = NULL;
36,265,836✔
323
  SArray* pSchemas = NULL;
36,265,836✔
324

325
  STqExecHandle* pExec = &pHandle->execHandle;
36,265,836✔
326
  STqReader* pReader = pExec->pTqReader;
36,271,639✔
327

328
  pBlocks = taosArrayInit(0, sizeof(SSDataBlock));
36,269,164✔
329
  TSDB_CHECK_NULL(pBlocks, code, lino, END, terrno);
36,272,917✔
330
  pSchemas = taosArrayInit(0, sizeof(void*));
36,272,917✔
331
  TSDB_CHECK_NULL(pSchemas, code, lino, END, terrno);
36,275,089✔
332

333
  SSubmitTbData* pSubmitTbData = NULL;
36,275,089✔
334
  code = tqRetrieveTaosxBlock(pReader, pRsp, pBlocks, pSchemas, &pSubmitTbData, rawList, pHandle->fetchMeta);
36,271,618✔
335
  TSDB_CHECK_CODE(code, lino, END);
36,215,264✔
336
  bool tmp = (pSubmitTbData->flags & pRequest->sourceExcluded) != 0;
36,031,202✔
337
  TSDB_CHECK_CONDITION(!tmp, code, lino, END, TSDB_CODE_SUCCESS);
36,084,666✔
338

339
  if (pHandle->fetchMeta == ONLY_META){
36,057,742✔
340
    goto END;
6,413✔
341
  }
342

343
  int32_t blockNum = taosArrayGetSize(pBlocks) == 0 ? 1 : taosArrayGetSize(pBlocks);
36,057,493✔
344
  if (pRsp->withTbName) {
36,056,346✔
345
    int64_t uid = pExec->pTqReader->lastBlkUid;
36,054,753✔
346
    code = tqAddTbNameToRsp(pTq, uid, pRsp, blockNum);
36,056,953✔
347
    TSDB_CHECK_CODE(code, lino, END);
35,983,067✔
348
  }
349

350
  TSDB_CHECK_CONDITION(!tmp, code, lino, END, TSDB_CODE_SUCCESS);
35,979,767✔
351
  for (int32_t i = 0; i < blockNum; i++) {
72,011,983✔
352
    if (taosArrayGetSize(pBlocks) == 0){
35,963,163✔
353
      void* rawData = taosArrayGetP(rawList, pReader->nextBlk - 1);
×
354
      if (rawData == NULL) {
×
355
        continue;
×
356
      }
357
      if (tqAddRawDataToRsp(rawData, pRsp, pTq->pVnode->config.tsdbCfg.precision) != 0){
×
358
        tqError("vgId:%d, failed to add block to rsp msg", pTq->pVnode->config.vgId);
×
359
        continue;
×
360
      }
361
      *totalRows += *(uint32_t *)rawData + INT_BYTES; // bytes actually
×
362
    } else {
363
      SSDataBlock* pBlock = taosArrayGet(pBlocks, i);
36,028,606✔
364
      if (pBlock == NULL) {
36,002,559✔
365
        continue;
×
366
      }
367

368
      SSchemaWrapper* pSW = (SSchemaWrapper*)taosArrayGetP(pSchemas, i);
36,002,559✔
369
      if (tqAddBlockDataToRsp(pBlock, pRsp, pSW, pTq->pVnode->config.tsdbCfg.precision) != 0){
36,049,461✔
370
        tqError("vgId:%d, failed to add block to rsp msg", pTq->pVnode->config.vgId);
×
371
        continue;
×
372
      }
373
      *totalRows += pBlock->info.rows;
35,996,434✔
374
    }
375

376
    pRsp->blockNum++;
36,032,151✔
377
  }
378
  tqTrace("vgId:%d, process sub data success, response blocknum:%d, rows:%d", pTq->pVnode->config.vgId, pRsp->blockNum, *totalRows);
36,048,820✔
379
END:
36,266,219✔
380
  if (code != 0) {
36,182,180✔
381
    tqError("%s failed at %d, failed to process sub data:%s", __FUNCTION__, lino, tstrerror(code));
184,062✔
382
  }
383
  taosArrayDestroyEx(pBlocks, (FDelete)blockDataFreeRes);
36,182,180✔
384
  taosArrayDestroyP(pSchemas, (FDelete)tDeleteSchemaWrapper);
36,205,342✔
385
}
36,252,689✔
386

387
static void preProcessSubmitMsg(STqHandle* pHandle, const SMqPollReq* pRequest, SArray** rawList){
37,309,996✔
388
  STqExecHandle* pExec = &pHandle->execHandle;
37,309,996✔
389
  STqReader* pReader = pExec->pTqReader;
37,314,671✔
390
  int32_t blockSz = taosArrayGetSize(pReader->submit.aSubmitTbData);
37,313,571✔
391
  for (int32_t i = 0; i < blockSz; i++){
74,654,351✔
392
    SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, i);
37,333,932✔
393
    if (pSubmitTbData== NULL){
37,334,710✔
394
      taosArrayDestroy(*rawList);
×
395
      *rawList = NULL;
×
396
      return;
×
397
    }
398

399
    int64_t uid = pSubmitTbData->uid;
37,334,710✔
400
    if (pRequest->rawData) {
37,338,788✔
401
      if (taosHashGet(pRequest->uidHash, &uid, LONG_BYTES) != NULL) {
×
402
        tqDebug("poll rawdata split,uid:%" PRId64 " is already exists", uid);
×
403
        terrno = TSDB_CODE_TMQ_RAW_DATA_SPLIT;
×
404
        return;
×
405
      } else {
406
        int32_t code = taosHashPut(pRequest->uidHash, &uid, LONG_BYTES, &uid, LONG_BYTES);
×
407
        if (code != 0) {
×
408
          tqError("failed to add table uid to hash, code:%d, uid:%" PRId64, code, uid);
×
409
        }
410
      }
411
    }
412

413
    if (pSubmitTbData->pCreateTbReq == NULL){
37,338,731✔
414
      continue;
37,258,262✔
415
    }
416

417
    int64_t createTime = INT64_MAX;
72,244✔
418
    int64_t *cTime = (int64_t*)taosHashGet(pHandle->tableCreateTimeHash, &uid, LONG_BYTES);
72,244✔
419
    if (cTime != NULL){
72,244✔
420
      createTime = *cTime;
599✔
421
    } else{
422
      createTime = metaGetTableCreateTime(pReader->pVnodeMeta, uid, 1);
71,645✔
423
      if (createTime != INT64_MAX){
71,645✔
424
        int32_t code = taosHashPut(pHandle->tableCreateTimeHash, &uid, LONG_BYTES, &createTime, LONG_BYTES);
71,645✔
425
        if (code != 0){
71,645✔
426
          tqError("failed to add table create time to hash,code:%d, uid:%"PRId64, code, uid);
×
427
        }
428
      }
429
    }
430
    if (pHandle->fetchMeta == WITH_DATA || pSubmitTbData->ctimeMs > createTime){
72,244✔
431
      tDestroySVSubmitCreateTbReq(pSubmitTbData->pCreateTbReq, TSDB_MSG_FLG_DECODE);
62,046✔
432
      taosMemoryFreeClear(pSubmitTbData->pCreateTbReq);
62,046✔
433
    } else{
434
      taosArrayDestroy(*rawList);
10,198✔
435
      *rawList = NULL;
10,198✔
436
    }
437
  }
438
}
439

440
int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SPackedData submit, SMqDataRsp* pRsp, int32_t* totalRows, const SMqPollReq* pRequest) {
37,321,120✔
441
  int32_t code = 0;
37,321,120✔
442
  int32_t lino = 0;
37,321,120✔
443
  SDecoder decoder = {0};
37,321,120✔
444
  STqExecHandle* pExec = &pHandle->execHandle;
37,321,120✔
445
  STqReader* pReader = pExec->pTqReader;
37,321,120✔
446
  SArray *rawList = NULL;
37,321,120✔
447
  if (pRequest->rawData){
37,321,367✔
448
    rawList = taosArrayInit(0, POINTER_BYTES);
×
449
    TSDB_CHECK_NULL(rawList, code, lino, END, terrno);
×
450
  }
451
  code = tqReaderSetSubmitMsg(pReader, submit.msgStr, submit.msgLen, submit.ver, rawList, &decoder);
37,321,642✔
452
  TSDB_CHECK_CODE(code, lino, END);
37,312,825✔
453
  preProcessSubmitMsg(pHandle, pRequest, &rawList);
37,312,825✔
454
  // data could not contains same uid data in rawdata mode
455
  if (pRequest->rawData != 0 && terrno == TSDB_CODE_TMQ_RAW_DATA_SPLIT){
37,315,516✔
456
    goto END;
×
457
  }
458

459
  // this submit data is metadata and previous data is rawdata
460
  if (pRequest->rawData != 0 && *totalRows > 0 && pRsp->createTableNum == 0 && rawList == NULL){
37,315,791✔
461
    tqDebug("poll rawdata split,vgId:%d, this wal submit data contains metadata and previous data is data", pTq->pVnode->config.vgId);
×
462
    terrno = TSDB_CODE_TMQ_RAW_DATA_SPLIT;
×
463
    goto END;
×
464
  }
465

466
  // this submit data is rawdata and previous data is metadata
467
  if (pRequest->rawData != 0 && pRsp->createTableNum > 0 && rawList != NULL){
37,312,538✔
468
    tqDebug("poll rawdata split,vgId:%d, this wal submit data is data and previous data is metadata", pTq->pVnode->config.vgId);
×
469
    terrno = TSDB_CODE_TMQ_RAW_DATA_SPLIT;
×
470
    goto END;
×
471
  }
472

473
  if (pExec->subType == TOPIC_SUB_TYPE__TABLE) {
37,310,556✔
474
    while (tqNextBlockImpl(pReader, NULL)) {
20,917,516✔
475
      tqProcessSubData(pTq, pHandle, pRsp, totalRows, pRequest, rawList);
9,927,674✔
476
    }
477
  } else if (pExec->subType == TOPIC_SUB_TYPE__DB) {
26,317,336✔
478
    while (tqNextDataBlockFilterOut(pReader, pExec->execDb.pFilterOutTbUid)) {
52,588,680✔
479
      tqProcessSubData(pTq, pHandle, pRsp, totalRows, pRequest, rawList);
26,341,633✔
480
    }
481
  }
482

483
END:
37,264,996✔
484
  tDecoderClear(&decoder);
37,292,252✔
485
  tqReaderClearSubmitMsg(pReader);
37,307,938✔
486
  taosArrayDestroy(rawList);
37,318,492✔
487
  if (code != 0){
37,316,056✔
488
    tqError("%s failed at %d, failed to scan log:%s", __FUNCTION__, lino, tstrerror(code));
×
489
  }
490
  return code;
37,316,056✔
491
}
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