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

taosdata / TDengine / #4889

18 Dec 2025 07:22AM UTC coverage: 65.487% (+0.2%) from 65.281%
#4889

push

travis-ci

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

9 of 13 new or added lines in 3 files covered. (69.23%)

594 existing lines in 113 files now uncovered.

182473 of 278642 relevant lines covered (65.49%)

105098310.46 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) {
56,982,833✔
46
  int32_t code = 0;
56,982,833✔
47
  int32_t lino = 0;
56,982,833✔
48
  SSchemaWrapper* pSchema = NULL;
56,982,833✔
49
  
50
  size_t dataEncodeBufSize = blockGetEncodeSize(pBlock);
56,984,714✔
51
  int32_t dataStrLen = sizeof(SRetrieveTableRspForTmq) + dataEncodeBufSize;
56,989,936✔
52
  void*   buf = taosMemoryCalloc(1, dataStrLen);
56,989,936✔
53
  TSDB_CHECK_NULL(buf, code, lino, END, terrno);
56,976,667✔
54

55
  SRetrieveTableRspForTmq* pRetrieve = (SRetrieveTableRspForTmq*)buf;
56,976,667✔
56
  pRetrieve->version = RETRIEVE_TABLE_RSP_TMQ_VERSION;
56,976,667✔
57
  pRetrieve->precision = precision;
56,976,172✔
58
  pRetrieve->compressed = 0;
56,978,221✔
59
  pRetrieve->numOfRows = htobe64((int64_t)pBlock->info.rows);
56,979,912✔
60

61
  int32_t actualLen = blockEncode(pBlock, pRetrieve->data, dataEncodeBufSize, pSW->nCols);
56,982,495✔
62
  TSDB_CHECK_CONDITION(actualLen >= 0, code, lino, END, terrno);
56,978,132✔
63

64
  actualLen += sizeof(SRetrieveTableRspForTmq);
56,978,132✔
65
  TSDB_CHECK_NULL(taosArrayPush(pRsp->blockDataLen, &actualLen), code, lino, END, terrno);
113,964,440✔
66
  TSDB_CHECK_NULL(taosArrayPush(pRsp->blockData, &buf), code, lino, END, terrno);
113,972,015✔
67
  pSchema = tCloneSSchemaWrapper(pSW);
56,985,756✔
68
  TSDB_CHECK_NULL(pSchema, code, lino, END, terrno);
56,985,756✔
69
  TSDB_CHECK_NULL(taosArrayPush(pRsp->blockSchema, &pSchema), code, lino, END, terrno);
113,971,910✔
70
  pSchema = NULL;
56,986,154✔
71
  pRsp->blockDataElementFree = true;
56,986,154✔
72
  tqTrace("tqAddBlockDataToRsp add block data to block array, blockDataLen:%d, blockData:%p", dataStrLen, buf);
56,983,301✔
73

74
END:
56,983,301✔
75
  tDeleteSchemaWrapper(pSchema);
56,985,697✔
76
  if (code != TSDB_CODE_SUCCESS){
56,976,196✔
77
    taosMemoryFree(buf);
×
78
    tqError("%s failed at line %d with msg:%s", __func__, lino, tstrerror(code));
×
79
  }
80
  return code;
56,976,196✔
81
}
82

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

88
  TSDB_CHECK_NULL(pTq, code, lino, END, TSDB_CODE_INVALID_PARA);
14,173,458✔
89
  TSDB_CHECK_NULL(pRsp, code, lino, END, TSDB_CODE_INVALID_PARA);
14,173,458✔
90

91
  metaReaderDoInit(&mr, pTq->pVnode->pMeta, META_READER_LOCK);
14,173,458✔
92

93
  code = metaReaderGetTableEntryByUidCache(&mr, uid);
14,169,827✔
94
  TSDB_CHECK_CODE(code, lino, END);
14,168,227✔
95

96
  for (int32_t i = 0; i < n; i++) {
28,344,569✔
97
    char* tbName = taosStrdup(mr.me.name);
14,167,005✔
98
    TSDB_CHECK_NULL(tbName, code, lino, END, terrno);
14,168,563✔
99
    if(taosArrayPush(pRsp->blockTbName, &tbName) == NULL){
28,344,039✔
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);
14,175,476✔
104
  }
105

106
END:
14,177,433✔
107
  if (code != TSDB_CODE_SUCCESS) {
14,173,061✔
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);
14,173,061✔
111
  return code;
14,167,549✔
112
}
113

114
int32_t getDataBlock(qTaskInfo_t task, const STqHandle* pHandle, int32_t vgId, SSDataBlock** res) {
46,082,000✔
115
  if (task == NULL || pHandle == NULL || res == NULL) {
46,082,000✔
116
    return TSDB_CODE_INVALID_PARA;
×
117
  }
118
  uint64_t ts = 0;
46,087,627✔
119
  qStreamSetOpen(task);
46,075,113✔
120

121
  tqDebug("consumer:0x%" PRIx64 " vgId:%d, tmq one task start execute", pHandle->consumerId, vgId);
46,085,050✔
122
  int32_t code = qExecTask(task, res, &ts);
46,086,805✔
123
  if (code != TSDB_CODE_SUCCESS) {
46,083,075✔
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);
46,083,075✔
129
  return 0;
46,088,925✔
130
}
131

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

136
  if (IS_OFFSET_RESET_TYPE(pRequest->reqOffset.type) && pHandle->block != NULL) {
891✔
137
    blockDataDestroy(pHandle->block);
27✔
138
    pHandle->block = NULL;
27✔
139
  }
140
  if (pHandle->block == NULL) {
891✔
141
    if (pDataBlock == NULL) {
297✔
142
      goto END;
162✔
143
    }
144

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

149
    pHandle->block = NULL;
135✔
150

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

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

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

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

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

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

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

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

198
  int32_t vgId = TD_VID(pTq->pVnode);
3,839,115✔
199
  int32_t totalRows = 0;
3,838,954✔
200

201
  const STqExecHandle* pExec = &pHandle->execHandle;
3,838,954✔
202
  qTaskInfo_t          task = pExec->task;
3,839,220✔
203

204
  code = qStreamPrepareScan(task, pOffset, pHandle->execHandle.subType);
3,839,073✔
205
  TSDB_CHECK_CODE(code, lino, END);
3,838,316✔
206

207
  qStreamSetSourceExcluded(task, pRequest->sourceExcluded);
3,796,279✔
208
  int64_t st = taosGetTimestampMs();
3,796,087✔
209
  while (1) {
42,289,503✔
210
    SSDataBlock* pDataBlock = NULL;
46,085,590✔
211
    code = getDataBlock(task, pHandle, vgId, &pDataBlock);
46,082,545✔
212
    TSDB_CHECK_CODE(code, lino, END);
46,088,582✔
213

214
    if (pRequest->enableReplay) {
46,088,582✔
215
      code = tqProcessReplayRsp(pTq, pHandle, pRsp, pRequest, pDataBlock, task);
891✔
216
      TSDB_CHECK_CODE(code, lino, END);
891✔
217
      break;
891✔
218
    }
219
    if (pDataBlock == NULL) {
46,088,121✔
220
      break;
3,388,871✔
221
    }
222
    code = tqAddBlockDataToRsp(pDataBlock, pRsp, &pExec->execCol.pSW, pTq->pVnode->config.tsdbCfg.precision);
42,699,250✔
223
    TSDB_CHECK_CODE(code, lino, END);
42,695,523✔
224

225
    pRsp->blockNum++;
42,695,523✔
226
    totalRows += pDataBlock->info.rows;
42,695,206✔
227
    if (totalRows >= pRequest->minPollRows || (taosGetTimestampMs() - st > pRequest->timeout)) {
85,080,092✔
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);
3,797,630✔
233
  code = qStreamExtractOffset(task, &pRsp->rspOffset);
3,797,630✔
234

235
END:
3,839,667✔
236
  if (code != 0) {
3,839,667✔
237
    tqError("%s failed at %d, tmq task executed error msg:%s", __FUNCTION__, lino, tstrerror(code));
42,037✔
238
  }
239
  return code;
3,839,667✔
240
}
241

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

251
  int32_t rowCnt = 0;
9,611✔
252
  int64_t st = taosGetTimestampMs();
9,694✔
253
  while (1) {
222,519✔
254
    SSDataBlock* pDataBlock = NULL;
232,213✔
255
    uint64_t     ts = 0;
232,213✔
256
    tqDebug("tmqsnap task start to execute");
232,213✔
257
    code = qExecTask(task, &pDataBlock, &ts);
232,256✔
258
    TSDB_CHECK_CODE(code, lino, END);
232,256✔
259
    tqDebug("tmqsnap task execute end, get %p", pDataBlock);
232,256✔
260

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

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

273
      pRsp->blockNum++;
113,012✔
274
      rowCnt += pDataBlock->info.rows;
113,012✔
275
      if (rowCnt <= pRequest->minPollRows && (taosGetTimestampMs() - st <= pRequest->timeout)) {
219,448✔
276
        continue;
106,479✔
277
      }
278
    }
279

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

290
    if (pDataBlock == NULL) {
124,720✔
291
      code = qStreamExtractOffset(task, pOffset);
118,187✔
292
      TSDB_CHECK_CODE(code, lino, END);
118,187✔
293

294
      if (pOffset->type == TMQ_OFFSET__SNAPSHOT_DATA) {
118,187✔
295
        continue;
116,083✔
296
      }
297

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

303
    if (pRsp->blockNum > 0) {
6,533✔
304
      tqDebug("tmqsnap task exec exited, get data");
6,533✔
305
      code = qStreamExtractOffset(task, &pRsp->rspOffset);
6,533✔
306
      break;
6,533✔
307
    }
308
  }
309
  tqDebug("%s:%d success", __FUNCTION__, lino);
9,694✔
310
END:
9,694✔
311
  if (code != 0){
9,694✔
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);
9,694✔
315
  return code;
9,694✔
316
}
317

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

325
  STqExecHandle* pExec = &pHandle->execHandle;
14,215,720✔
326
  STqReader* pReader = pExec->pTqReader;
14,216,549✔
327

328
  pBlocks = taosArrayInit(0, sizeof(SSDataBlock));
14,216,662✔
329
  TSDB_CHECK_NULL(pBlocks, code, lino, END, terrno);
14,213,994✔
330
  pSchemas = taosArrayInit(0, sizeof(void*));
14,213,994✔
331
  TSDB_CHECK_NULL(pSchemas, code, lino, END, terrno);
14,216,095✔
332

333
  SSubmitTbData* pSubmitTbData = NULL;
14,216,095✔
334
  code = tqRetrieveTaosxBlock(pReader, pRsp, pBlocks, pSchemas, &pSubmitTbData, rawList, pHandle->fetchMeta);
14,216,181✔
335
  TSDB_CHECK_CODE(code, lino, END);
14,209,203✔
336
  bool tmp = (pSubmitTbData->flags & pRequest->sourceExcluded) != 0;
14,172,639✔
337
  TSDB_CHECK_CONDITION(!tmp, code, lino, END, TSDB_CODE_SUCCESS);
14,179,549✔
338

339
  if (pHandle->fetchMeta == ONLY_META){
14,177,641✔
340
    goto END;
564✔
341
  }
342

343
  int32_t blockNum = taosArrayGetSize(pBlocks) == 0 ? 1 : taosArrayGetSize(pBlocks);
14,177,884✔
344
  if (pRsp->withTbName) {
14,177,180✔
345
    int64_t uid = pExec->pTqReader->lastBlkUid;
14,177,309✔
346
    code = tqAddTbNameToRsp(pTq, uid, pRsp, blockNum);
14,177,223✔
347
    TSDB_CHECK_CODE(code, lino, END);
14,168,800✔
348
  }
349

350
  TSDB_CHECK_CONDITION(!tmp, code, lino, END, TSDB_CODE_SUCCESS);
14,168,626✔
351
  for (int32_t i = 0; i < blockNum; i++) {
28,346,237✔
352
    if (taosArrayGetSize(pBlocks) == 0){
14,164,880✔
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);
14,172,343✔
364
      if (pBlock == NULL) {
14,169,331✔
365
        continue;
×
366
      }
367

368
      SSchemaWrapper* pSW = (SSchemaWrapper*)taosArrayGetP(pSchemas, i);
14,169,331✔
369
      if (tqAddBlockDataToRsp(pBlock, pRsp, pSW, pTq->pVnode->config.tsdbCfg.precision) != 0){
14,175,182✔
370
        tqError("vgId:%d, failed to add block to rsp msg", pTq->pVnode->config.vgId);
×
371
        continue;
×
372
      }
373
      *totalRows += pBlock->info.rows;
14,167,770✔
374
    }
375

376
    pRsp->blockNum++;
14,176,313✔
377
  }
378
  tqTrace("vgId:%d, process sub data success, response blocknum:%d, rows:%d", pTq->pVnode->config.vgId, pRsp->blockNum, *totalRows);
14,181,357✔
379
END:
14,220,393✔
380
  if (code != 0) {
14,205,459✔
381
    tqError("%s failed at %d, failed to process sub data:%s", __FUNCTION__, lino, tstrerror(code));
36,564✔
382
  }
383
  taosArrayDestroyEx(pBlocks, (FDelete)blockDataFreeRes);
14,205,459✔
384
  taosArrayDestroyP(pSchemas, (FDelete)tDeleteSchemaWrapper);
14,208,491✔
385
}
14,214,312✔
386

387
static void preProcessSubmitMsg(STqHandle* pHandle, const SMqPollReq* pRequest, SArray** rawList){
14,519,654✔
388
  STqExecHandle* pExec = &pHandle->execHandle;
14,519,654✔
389
  STqReader* pReader = pExec->pTqReader;
14,520,352✔
390
  int32_t blockSz = taosArrayGetSize(pReader->submit.aSubmitTbData);
14,520,293✔
391
  for (int32_t i = 0; i < blockSz; i++){
29,042,562✔
392
    SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, i);
14,522,419✔
393
    if (pSubmitTbData== NULL){
14,520,773✔
394
      taosArrayDestroy(*rawList);
×
395
      *rawList = NULL;
×
396
      return;
×
397
    }
398

399
    int64_t uid = pSubmitTbData->uid;
14,520,773✔
400
    if (pRequest->rawData) {
14,522,927✔
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){
14,522,972✔
414
      continue;
14,509,428✔
415
    }
416

417
    int64_t createTime = INT64_MAX;
12,737✔
418
    int64_t *cTime = (int64_t*)taosHashGet(pHandle->tableCreateTimeHash, &uid, LONG_BYTES);
12,737✔
419
    if (cTime != NULL){
12,764✔
420
      createTime = *cTime;
497✔
421
    } else{
422
      createTime = metaGetTableCreateTime(pReader->pVnodeMeta, uid, 1);
12,267✔
423
      if (createTime != INT64_MAX){
12,240✔
424
        int32_t code = taosHashPut(pHandle->tableCreateTimeHash, &uid, LONG_BYTES, &createTime, LONG_BYTES);
12,267✔
425
        if (code != 0){
12,267✔
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){
12,737✔
431
      tDestroySVSubmitCreateTbReq(pSubmitTbData->pCreateTbReq, TSDB_MSG_FLG_DECODE);
11,862✔
432
      taosMemoryFreeClear(pSubmitTbData->pCreateTbReq);
11,862✔
433
    } else{
434
      taosArrayDestroy(*rawList);
902✔
435
      *rawList = NULL;
902✔
436
    }
437
  }
438
}
439

440
int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SPackedData submit, SMqDataRsp* pRsp, int32_t* totalRows, const SMqPollReq* pRequest) {
14,520,770✔
441
  int32_t code = 0;
14,520,770✔
442
  int32_t lino = 0;
14,520,770✔
443
  SDecoder decoder = {0};
14,520,770✔
444
  STqExecHandle* pExec = &pHandle->execHandle;
14,520,813✔
445
  STqReader* pReader = pExec->pTqReader;
14,520,726✔
446
  SArray *rawList = NULL;
14,520,726✔
447
  if (pRequest->rawData){
14,520,683✔
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);
14,520,856✔
452
  TSDB_CHECK_CODE(code, lino, END);
14,519,720✔
453
  preProcessSubmitMsg(pHandle, pRequest, &rawList);
14,519,720✔
454
  // data could not contains same uid data in rawdata mode
455
  if (pRequest->rawData != 0 && terrno == TSDB_CODE_TMQ_RAW_DATA_SPLIT){
14,519,167✔
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){
14,520,166✔
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){
14,518,661✔
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) {
14,518,616✔
474
    while (tqNextBlockImpl(pReader, NULL)) {
5,511,432✔
475
      tqProcessSubData(pTq, pHandle, pRsp, totalRows, pRequest, rawList);
2,603,438✔
476
    }
477
  } else if (pExec->subType == TOPIC_SUB_TYPE__DB) {
11,610,260✔
478
    while (tqNextDataBlockFilterOut(pReader, pExec->execDb.pFilterOutTbUid)) {
23,216,141✔
479
      tqProcessSubData(pTq, pHandle, pRsp, totalRows, pRequest, rawList);
11,612,927✔
480
    }
481
  }
482

483
END:
14,508,849✔
484
  tDecoderClear(&decoder);
14,513,475✔
485
  tqReaderClearSubmitMsg(pReader);
14,517,617✔
486
  taosArrayDestroy(rawList);
14,519,945✔
487
  if (code != 0){
14,519,257✔
488
    tqError("%s failed at %d, failed to scan log:%s", __FUNCTION__, lino, tstrerror(code));
×
489
  }
490
  return code;
14,519,257✔
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