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

taosdata / TDengine / #4945

30 Jan 2026 06:19AM UTC coverage: 66.87% (+0.02%) from 66.849%
#4945

push

travis-ci

web-flow
merge: from main to 3.0 #34453

1126 of 2018 new or added lines in 72 files covered. (55.8%)

13708 existing lines in 159 files now uncovered.

205277 of 306978 relevant lines covered (66.87%)

126353544.65 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) {
138,789,847✔
46
  int32_t code = 0;
138,789,847✔
47
  int32_t lino = 0;
138,789,847✔
48
  SSchemaWrapper* pSchema = NULL;
138,789,847✔
49
  
50
  size_t dataEncodeBufSize = blockGetEncodeSize(pBlock);
138,801,370✔
51
  int32_t dataStrLen = sizeof(SRetrieveTableRspForTmq) + dataEncodeBufSize;
138,828,367✔
52
  void*   buf = taosMemoryCalloc(1, dataStrLen);
138,828,367✔
53
  TSDB_CHECK_NULL(buf, code, lino, END, terrno);
138,748,413✔
54

55
  SRetrieveTableRspForTmq* pRetrieve = (SRetrieveTableRspForTmq*)buf;
138,748,413✔
56
  pRetrieve->version = RETRIEVE_TABLE_RSP_TMQ_VERSION;
138,748,413✔
57
  pRetrieve->precision = precision;
138,735,379✔
58
  pRetrieve->compressed = 0;
138,766,570✔
59
  pRetrieve->numOfRows = htobe64((int64_t)pBlock->info.rows);
138,776,991✔
60

61
  int32_t actualLen = blockEncode(pBlock, pRetrieve->data, dataEncodeBufSize, pSW->nCols);
138,789,235✔
62
  TSDB_CHECK_CONDITION(actualLen >= 0, code, lino, END, terrno);
138,756,129✔
63

64
  actualLen += sizeof(SRetrieveTableRspForTmq);
138,756,129✔
65
  TSDB_CHECK_NULL(taosArrayPush(pRsp->blockDataLen, &actualLen), code, lino, END, terrno);
277,567,667✔
66
  TSDB_CHECK_NULL(taosArrayPush(pRsp->blockData, &buf), code, lino, END, terrno);
277,628,138✔
67
  pSchema = tCloneSSchemaWrapper(pSW);
138,801,334✔
68
  TSDB_CHECK_NULL(pSchema, code, lino, END, terrno);
138,801,334✔
69
  TSDB_CHECK_NULL(taosArrayPush(pRsp->blockSchema, &pSchema), code, lino, END, terrno);
277,609,107✔
70
  pSchema = NULL;
138,807,773✔
71
  pRsp->blockDataElementFree = true;
138,807,773✔
72
  tqTrace("tqAddBlockDataToRsp add block data to block array, blockDataLen:%d, blockData:%p", dataStrLen, buf);
138,781,424✔
73

74
END:
138,781,424✔
75
  tDeleteSchemaWrapper(pSchema);
138,800,801✔
76
  if (code != TSDB_CODE_SUCCESS){
138,740,589✔
77
    taosMemoryFree(buf);
×
78
    tqError("%s failed at line %d with msg:%s", __func__, lino, tstrerror(code));
×
79
  }
80
  return code;
138,740,589✔
81
}
82

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

88
  TSDB_CHECK_NULL(pTq, code, lino, END, TSDB_CODE_INVALID_PARA);
41,725,878✔
89
  TSDB_CHECK_NULL(pRsp, code, lino, END, TSDB_CODE_INVALID_PARA);
41,725,878✔
90

91
  metaReaderDoInit(&mr, pTq->pVnode->pMeta, META_READER_LOCK);
41,725,878✔
92

93
  code = metaReaderGetTableEntryByUidCache(&mr, uid);
41,712,308✔
94
  TSDB_CHECK_CODE(code, lino, END);
41,678,852✔
95

96
  for (int32_t i = 0; i < n; i++) {
83,430,987✔
97
    char* tbName = taosStrdup(mr.me.name);
41,665,035✔
98
    TSDB_CHECK_NULL(tbName, code, lino, END, terrno);
41,680,052✔
99
    if(taosArrayPush(pRsp->blockTbName, &tbName) == NULL){
83,430,781✔
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);
41,750,729✔
104
  }
105

106
END:
41,764,527✔
107
  if (code != TSDB_CODE_SUCCESS) {
41,738,348✔
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);
41,738,348✔
111
  return code;
41,694,132✔
112
}
113

114
int32_t getDataBlock(qTaskInfo_t task, const STqHandle* pHandle, int32_t vgId, SSDataBlock** res) {
117,081,974✔
115
  if (task == NULL || pHandle == NULL || res == NULL) {
117,081,974✔
116
    return TSDB_CODE_INVALID_PARA;
×
117
  }
118
  uint64_t ts = 0;
117,098,703✔
119
  qStreamSetOpen(task);
117,093,919✔
120

121
  tqDebug("consumer:0x%" PRIx64 " vgId:%d, tmq one task start execute", pHandle->consumerId, vgId);
117,098,229✔
122
  int32_t code = qExecTask(task, res, &ts);
117,104,887✔
123
  if (code != TSDB_CODE_SUCCESS) {
117,108,490✔
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);
117,108,490✔
129
  return 0;
117,106,820✔
130
}
131

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

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

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

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

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

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

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

165
  pRsp->blockNum++;
7,344✔
166
  if (pDataBlock == NULL) {
7,344✔
167
    blockDataDestroy(pHandle->block);
1,088✔
168
    pHandle->block = NULL;
1,088✔
169
  } else {
170
    code = copyDataBlock(pHandle->block, pDataBlock);
6,256✔
171
    TSDB_CHECK_CODE(code, lino, END);
6,256✔
172

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

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

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

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

198
  int32_t vgId = TD_VID(pTq->pVnode);
21,867,764✔
199
  int32_t totalRows = 0;
21,868,393✔
200

201
  const STqExecHandle* pExec = &pHandle->execHandle;
21,868,393✔
202
  qTaskInfo_t          task = pExec->task;
21,869,707✔
203

204
  code = qStreamPrepareScan(task, pOffset, pHandle->execHandle.subType);
21,869,064✔
205
  TSDB_CHECK_CODE(code, lino, END);
21,864,546✔
206

207
  qStreamSetSourceExcluded(task, pRequest->sourceExcluded);
21,696,925✔
208
  int64_t st = taosGetTimestampMs();
21,695,963✔
209
  while (1) {
95,379,584✔
210
    SSDataBlock* pDataBlock = NULL;
117,075,547✔
211
    code = getDataBlock(task, pHandle, vgId, &pDataBlock);
117,073,189✔
212
    TSDB_CHECK_CODE(code, lino, END);
117,103,479✔
213

214
    if (pRequest->enableReplay) {
117,103,479✔
215
      code = tqProcessReplayRsp(pTq, pHandle, pRsp, pRequest, pDataBlock, task);
8,704✔
216
      TSDB_CHECK_CODE(code, lino, END);
8,704✔
217
      break;
8,704✔
218
    }
219
    if (pDataBlock == NULL) {
117,097,444✔
220
      break;
20,735,861✔
221
    }
222
    code = tqAddBlockDataToRsp(pDataBlock, pRsp, &pExec->execCol.pSW, pTq->pVnode->config.tsdbCfg.precision);
96,361,583✔
223
    TSDB_CHECK_CODE(code, lino, END);
96,348,168✔
224

225
    pRsp->blockNum++;
96,348,168✔
226
    totalRows += pDataBlock->info.rows;
96,345,436✔
227
    if (totalRows >= pRequest->minPollRows || (taosGetTimestampMs() - st > pRequest->timeout)) {
191,971,767✔
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);
21,702,641✔
233
  code = qStreamExtractOffset(task, &pRsp->rspOffset);
21,702,947✔
234

235
END:
21,870,262✔
236
  if (code != 0) {
21,870,262✔
237
    tqError("%s failed at %d, tmq task executed error msg:%s", __FUNCTION__, lino, tstrerror(code));
167,621✔
238
  }
239
  return code;
21,870,262✔
240
}
241

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

251
  int32_t rowCnt = 0;
43,342✔
252
  int64_t st = taosGetTimestampMs();
43,342✔
253
  while (1) {
1,397,169✔
254
    SSDataBlock* pDataBlock = NULL;
1,440,511✔
255
    uint64_t     ts = 0;
1,440,511✔
256
    tqDebug("tmqsnap task start to execute");
1,440,796✔
257
    code = qExecTask(task, &pDataBlock, &ts);
1,440,796✔
258
    TSDB_CHECK_CODE(code, lino, END);
1,440,796✔
259
    tqDebug("tmqsnap task execute end, get %p", pDataBlock);
1,440,796✔
260

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

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

273
      pRsp->blockNum++;
701,270✔
274
      rowCnt += pDataBlock->info.rows;
701,270✔
275
      if (rowCnt <= pRequest->minPollRows && (taosGetTimestampMs() - st <= pRequest->timeout)) {
1,373,324✔
276
        continue;
672,054✔
277
      }
278
    }
279

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

290
    if (pDataBlock == NULL) {
764,579✔
291
      code = qStreamExtractOffset(task, pOffset);
735,363✔
292
      TSDB_CHECK_CODE(code, lino, END);
735,363✔
293

294
      if (pOffset->type == TMQ_OFFSET__SNAPSHOT_DATA) {
735,363✔
295
        continue;
725,400✔
296
      }
297

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

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

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

325
  STqExecHandle* pExec = &pHandle->execHandle;
41,970,604✔
326
  STqReader* pReader = pExec->pTqReader;
41,983,104✔
327

328
  pBlocks = taosArrayInit(0, sizeof(SSDataBlock));
41,982,226✔
329
  TSDB_CHECK_NULL(pBlocks, code, lino, END, terrno);
41,976,420✔
330
  pSchemas = taosArrayInit(0, sizeof(void*));
41,976,420✔
331
  TSDB_CHECK_NULL(pSchemas, code, lino, END, terrno);
41,980,953✔
332

333
  SSubmitTbData* pSubmitTbData = NULL;
41,980,953✔
334
  code = tqRetrieveTaosxBlock(pReader, pRsp, pBlocks, pSchemas, &pSubmitTbData, rawList, pHandle->fetchMeta);
41,982,470✔
335
  TSDB_CHECK_CODE(code, lino, END);
41,921,568✔
336
  bool tmp = (pSubmitTbData->flags & pRequest->sourceExcluded) != 0;
41,727,872✔
337
  TSDB_CHECK_CONDITION(!tmp, code, lino, END, TSDB_CODE_SUCCESS);
41,783,932✔
338

339
  if (pHandle->fetchMeta == ONLY_META){
41,756,584✔
340
    goto END;
6,555✔
341
  }
342

343
  int32_t blockNum = taosArrayGetSize(pBlocks) == 0 ? 1 : taosArrayGetSize(pBlocks);
41,755,580✔
344
  if (pRsp->withTbName) {
41,753,507✔
345
    int64_t uid = pExec->pTqReader->lastBlkUid;
41,755,251✔
346
    code = tqAddTbNameToRsp(pTq, uid, pRsp, blockNum);
41,754,396✔
347
    TSDB_CHECK_CODE(code, lino, END);
41,701,949✔
348
  }
349

350
  TSDB_CHECK_CONDITION(!tmp, code, lino, END, TSDB_CODE_SUCCESS);
41,701,939✔
351
  for (int32_t i = 0; i < blockNum; i++) {
83,449,443✔
352
    if (taosArrayGetSize(pBlocks) == 0){
41,665,216✔
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);
41,708,187✔
364
      if (pBlock == NULL) {
41,715,097✔
365
        continue;
×
366
      }
367

368
      SSchemaWrapper* pSW = (SSchemaWrapper*)taosArrayGetP(pSchemas, i);
41,715,097✔
369
      if (tqAddBlockDataToRsp(pBlock, pRsp, pSW, pTq->pVnode->config.tsdbCfg.precision) != 0){
41,744,472✔
370
        tqError("vgId:%d, failed to add block to rsp msg", pTq->pVnode->config.vgId);
×
371
        continue;
×
372
      }
373
      *totalRows += pBlock->info.rows;
41,667,496✔
374
    }
375

376
    pRsp->blockNum++;
41,740,357✔
377
  }
378
  tqTrace("vgId:%d, process sub data success, response blocknum:%d, rows:%d", pTq->pVnode->config.vgId, pRsp->blockNum, *totalRows);
41,784,227✔
379
END:
42,011,826✔
380
  if (code != 0) {
41,896,928✔
381
    tqError("%s failed at %d, failed to process sub data:%s", __FUNCTION__, lino, tstrerror(code));
193,696✔
382
  }
383
  taosArrayDestroyEx(pBlocks, (FDelete)blockDataFreeRes);
41,896,928✔
384
  taosArrayDestroyP(pSchemas, (FDelete)tDeleteSchemaWrapper);
41,919,464✔
385
}
41,963,490✔
386

387
static void preProcessSubmitMsg(STqHandle* pHandle, const SMqPollReq* pRequest, SArray** rawList){
43,084,738✔
388
  STqExecHandle* pExec = &pHandle->execHandle;
43,084,738✔
389
  STqReader* pReader = pExec->pTqReader;
43,091,716✔
390
  int32_t blockSz = taosArrayGetSize(pReader->submit.aSubmitTbData);
43,093,520✔
391
  for (int32_t i = 0; i < blockSz; i++){
86,184,433✔
392
    SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, i);
43,103,944✔
393
    if (pSubmitTbData== NULL){
43,110,509✔
394
      taosArrayDestroy(*rawList);
×
395
      *rawList = NULL;
×
396
      return;
×
397
    }
398

399
    int64_t uid = pSubmitTbData->uid;
43,110,509✔
400
    if (pRequest->rawData) {
43,110,315✔
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){
43,113,540✔
414
      continue;
42,513,090✔
415
    }
416

417
    int64_t createTime = INT64_MAX;
596,759✔
418
    int64_t *cTime = (int64_t*)taosHashGet(pHandle->tableCreateTimeHash, &uid, LONG_BYTES);
596,759✔
419
    if (cTime != NULL){
597,068✔
420
      createTime = *cTime;
616✔
421
    } else{
422
      createTime = metaGetTableCreateTime(pReader->pVnodeMeta, uid, 1);
596,452✔
423
      if (createTime != INT64_MAX){
595,525✔
424
        int32_t code = taosHashPut(pHandle->tableCreateTimeHash, &uid, LONG_BYTES, &createTime, LONG_BYTES);
595,525✔
425
        if (code != 0){
596,143✔
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){
596,759✔
431
      tDestroySVSubmitCreateTbReq(pSubmitTbData->pCreateTbReq, TSDB_MSG_FLG_DECODE);
586,641✔
432
      taosMemoryFreeClear(pSubmitTbData->pCreateTbReq);
585,405✔
433
    } else{
434
      taosArrayDestroy(*rawList);
10,427✔
435
      *rawList = NULL;
10,427✔
436
    }
437
  }
438
}
439

440
int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SPackedData submit, SMqDataRsp* pRsp, int32_t* totalRows, const SMqPollReq* pRequest) {
43,096,416✔
441
  int32_t code = 0;
43,096,416✔
442
  int32_t lino = 0;
43,096,416✔
443
  SDecoder decoder = {0};
43,096,416✔
444
  STqExecHandle* pExec = &pHandle->execHandle;
43,097,602✔
445
  STqReader* pReader = pExec->pTqReader;
43,097,602✔
446
  SArray *rawList = NULL;
43,097,602✔
447
  if (pRequest->rawData){
43,097,887✔
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);
43,097,317✔
452
  TSDB_CHECK_CODE(code, lino, END);
43,095,161✔
453
  preProcessSubmitMsg(pHandle, pRequest, &rawList);
43,095,161✔
454
  // data could not contains same uid data in rawdata mode
455
  if (pRequest->rawData != 0 && terrno == TSDB_CODE_TMQ_RAW_DATA_SPLIT){
43,075,793✔
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){
43,089,402✔
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){
43,076,363✔
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) {
43,074,298✔
474
    while (tqNextBlockImpl(pReader, NULL)) {
21,979,015✔
475
      tqProcessSubData(pTq, pHandle, pRsp, totalRows, pRequest, rawList);
10,425,582✔
476
    }
477
  } else if (pExec->subType == TOPIC_SUB_TYPE__DB) {
31,521,031✔
478
    while (tqNextDataBlockFilterOut(pReader, pExec->execDb.pFilterOutTbUid)) {
63,009,898✔
479
      tqProcessSubData(pTq, pHandle, pRsp, totalRows, pRequest, rawList);
31,554,612✔
480
    }
481
  }
482

483
END:
42,984,736✔
484
  tDecoderClear(&decoder);
43,028,137✔
485
  tqReaderClearSubmitMsg(pReader);
43,085,689✔
486
  taosArrayDestroy(rawList);
43,088,587✔
487
  if (code != 0){
43,088,023✔
488
    tqError("%s failed at %d, failed to scan log:%s", __FUNCTION__, lino, tstrerror(code));
×
489
  }
490
  return code;
43,088,023✔
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