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

taosdata / TDengine / #4886

16 Dec 2025 01:13AM UTC coverage: 65.292% (+0.03%) from 65.258%
#4886

push

travis-ci

web-flow
fix: compile error (#33938)

178718 of 273721 relevant lines covered (65.29%)

103311111.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) {
60,110,333✔
46
  int32_t code = 0;
60,110,333✔
47
  int32_t lino = 0;
60,110,333✔
48
  SSchemaWrapper* pSchema = NULL;
60,110,333✔
49
  
50
  size_t dataEncodeBufSize = blockGetEncodeSize(pBlock);
60,117,551✔
51
  int32_t dataStrLen = sizeof(SRetrieveTableRspForTmq) + dataEncodeBufSize;
60,129,526✔
52
  void*   buf = taosMemoryCalloc(1, dataStrLen);
60,129,526✔
53
  TSDB_CHECK_NULL(buf, code, lino, END, terrno);
60,100,587✔
54

55
  SRetrieveTableRspForTmq* pRetrieve = (SRetrieveTableRspForTmq*)buf;
60,100,587✔
56
  pRetrieve->version = RETRIEVE_TABLE_RSP_TMQ_VERSION;
60,100,587✔
57
  pRetrieve->precision = precision;
60,091,632✔
58
  pRetrieve->compressed = 0;
60,108,240✔
59
  pRetrieve->numOfRows = htobe64((int64_t)pBlock->info.rows);
60,108,552✔
60

61
  int32_t actualLen = blockEncode(pBlock, pRetrieve->data, dataEncodeBufSize, pSW->nCols);
60,114,927✔
62
  TSDB_CHECK_CONDITION(actualLen >= 0, code, lino, END, terrno);
60,104,268✔
63

64
  actualLen += sizeof(SRetrieveTableRspForTmq);
60,104,268✔
65
  TSDB_CHECK_NULL(taosArrayPush(pRsp->blockDataLen, &actualLen), code, lino, END, terrno);
120,226,930✔
66
  TSDB_CHECK_NULL(taosArrayPush(pRsp->blockData, &buf), code, lino, END, terrno);
120,246,978✔
67
  pSchema = tCloneSSchemaWrapper(pSW);
60,123,112✔
68
  TSDB_CHECK_NULL(pSchema, code, lino, END, terrno);
60,123,112✔
69
  TSDB_CHECK_NULL(taosArrayPush(pRsp->blockSchema, &pSchema), code, lino, END, terrno);
120,248,248✔
70
  pSchema = NULL;
60,125,136✔
71
  pRsp->blockDataElementFree = true;
60,125,136✔
72
  tqTrace("tqAddBlockDataToRsp add block data to block array, blockDataLen:%d, blockData:%p", dataStrLen, buf);
60,119,991✔
73

74
END:
60,119,991✔
75
  tDeleteSchemaWrapper(pSchema);
60,123,976✔
76
  if (code != TSDB_CODE_SUCCESS){
60,095,931✔
77
    taosMemoryFree(buf);
×
78
    tqError("%s failed at line %d with msg:%s", __func__, lino, tstrerror(code));
×
79
  }
80
  return code;
60,095,931✔
81
}
82

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

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

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

93
  code = metaReaderGetTableEntryByUidCache(&mr, uid);
14,593,491✔
94
  TSDB_CHECK_CODE(code, lino, END);
14,577,430✔
95

96
  for (int32_t i = 0; i < n; i++) {
29,181,814✔
97
    char* tbName = taosStrdup(mr.me.name);
14,573,315✔
98
    TSDB_CHECK_NULL(tbName, code, lino, END, terrno);
14,584,054✔
99
    if(taosArrayPush(pRsp->blockTbName, &tbName) == NULL){
29,188,012✔
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,603,958✔
104
  }
105

106
END:
14,608,352✔
107
  if (code != TSDB_CODE_SUCCESS) {
14,595,370✔
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,595,370✔
111
  return code;
14,583,604✔
112
}
113

114
int32_t getDataBlock(qTaskInfo_t task, const STqHandle* pHandle, int32_t vgId, SSDataBlock** res) {
49,211,865✔
115
  if (task == NULL || pHandle == NULL || res == NULL) {
49,211,865✔
116
    return TSDB_CODE_INVALID_PARA;
×
117
  }
118
  uint64_t ts = 0;
49,217,358✔
119
  qStreamSetOpen(task);
49,216,387✔
120

121
  tqDebug("consumer:0x%" PRIx64 " vgId:%d, tmq one task start execute", pHandle->consumerId, vgId);
49,214,747✔
122
  int32_t code = qExecTask(task, res, &ts);
49,210,794✔
123
  if (code != TSDB_CODE_SUCCESS) {
49,217,934✔
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);
49,217,934✔
129
  return 0;
49,219,834✔
130
}
131

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

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

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

149
    pHandle->block = NULL;
145✔
150

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

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

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

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

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

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

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

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

198
  int32_t vgId = TD_VID(pTq->pVnode);
4,301,503✔
199
  int32_t totalRows = 0;
4,302,212✔
200

201
  const STqExecHandle* pExec = &pHandle->execHandle;
4,302,212✔
202
  qTaskInfo_t          task = pExec->task;
4,302,310✔
203

204
  code = qStreamPrepareScan(task, pOffset, pHandle->execHandle.subType);
4,302,238✔
205
  TSDB_CHECK_CODE(code, lino, END);
4,301,833✔
206

207
  qStreamSetSourceExcluded(task, pRequest->sourceExcluded);
4,263,909✔
208
  int64_t st = taosGetTimestampMs();
4,263,757✔
209
  while (1) {
44,953,114✔
210
    SSDataBlock* pDataBlock = NULL;
49,216,871✔
211
    code = getDataBlock(task, pHandle, vgId, &pDataBlock);
49,213,549✔
212
    TSDB_CHECK_CODE(code, lino, END);
49,216,513✔
213

214
    if (pRequest->enableReplay) {
49,216,513✔
215
      code = tqProcessReplayRsp(pTq, pHandle, pRsp, pRequest, pDataBlock, task);
957✔
216
      TSDB_CHECK_CODE(code, lino, END);
957✔
217
      break;
957✔
218
    }
219
    if (pDataBlock == NULL) {
49,218,313✔
220
      break;
3,813,450✔
221
    }
222
    code = tqAddBlockDataToRsp(pDataBlock, pRsp, &pExec->execCol.pSW, pTq->pVnode->config.tsdbCfg.precision);
45,404,863✔
223
    TSDB_CHECK_CODE(code, lino, END);
45,397,939✔
224

225
    pRsp->blockNum++;
45,397,939✔
226
    totalRows += pDataBlock->info.rows;
45,398,986✔
227
    if (totalRows >= pRequest->minPollRows || (taosGetTimestampMs() - st > pRequest->timeout)) {
90,485,351✔
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);
4,264,656✔
233
  code = qStreamExtractOffset(task, &pRsp->rspOffset);
4,264,656✔
234

235
END:
4,302,643✔
236
  if (code != 0) {
4,302,643✔
237
    tqError("%s failed at %d, tmq task executed error msg:%s", __FUNCTION__, lino, tstrerror(code));
37,987✔
238
  }
239
  return code;
4,302,643✔
240
}
241

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

251
  int32_t rowCnt = 0;
10,016✔
252
  int64_t st = taosGetTimestampMs();
10,016✔
253
  while (1) {
229,353✔
254
    SSDataBlock* pDataBlock = NULL;
239,369✔
255
    uint64_t     ts = 0;
239,369✔
256
    tqDebug("tmqsnap task start to execute");
239,369✔
257
    code = qExecTask(task, &pDataBlock, &ts);
239,457✔
258
    TSDB_CHECK_CODE(code, lino, END);
239,457✔
259
    tqDebug("tmqsnap task execute end, get %p", pDataBlock);
239,457✔
260

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

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

273
      pRsp->blockNum++;
115,756✔
274
      rowCnt += pDataBlock->info.rows;
115,756✔
275
      if (rowCnt <= pRequest->minPollRows && (taosGetTimestampMs() - st <= pRequest->timeout)) {
224,952✔
276
        continue;
109,152✔
277
      }
278
    }
279

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

290
    if (pDataBlock == NULL) {
129,152✔
291
      code = qStreamExtractOffset(task, pOffset);
122,460✔
292
      TSDB_CHECK_CODE(code, lino, END);
122,416✔
293

294
      if (pOffset->type == TMQ_OFFSET__SNAPSHOT_DATA) {
122,416✔
295
        continue;
120,245✔
296
      }
297

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

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

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

325
  STqExecHandle* pExec = &pHandle->execHandle;
14,647,674✔
326
  STqReader* pReader = pExec->pTqReader;
14,649,329✔
327

328
  pBlocks = taosArrayInit(0, sizeof(SSDataBlock));
14,649,569✔
329
  TSDB_CHECK_NULL(pBlocks, code, lino, END, terrno);
14,646,370✔
330
  pSchemas = taosArrayInit(0, sizeof(void*));
14,646,370✔
331
  TSDB_CHECK_NULL(pSchemas, code, lino, END, terrno);
14,649,057✔
332

333
  SSubmitTbData* pSubmitTbData = NULL;
14,649,057✔
334
  code = tqRetrieveTaosxBlock(pReader, pRsp, pBlocks, pSchemas, &pSubmitTbData, rawList, pHandle->fetchMeta);
14,649,106✔
335
  TSDB_CHECK_CODE(code, lino, END);
14,628,587✔
336
  bool tmp = (pSubmitTbData->flags & pRequest->sourceExcluded) != 0;
14,590,170✔
337
  TSDB_CHECK_CONDITION(!tmp, code, lino, END, TSDB_CODE_SUCCESS);
14,605,967✔
338

339
  if (pHandle->fetchMeta == ONLY_META){
14,603,741✔
340
    goto END;
636✔
341
  }
342

343
  int32_t blockNum = taosArrayGetSize(pBlocks) == 0 ? 1 : taosArrayGetSize(pBlocks);
14,607,260✔
344
  if (pRsp->withTbName) {
14,604,659✔
345
    int64_t uid = pExec->pTqReader->lastBlkUid;
14,603,794✔
346
    code = tqAddTbNameToRsp(pTq, uid, pRsp, blockNum);
14,605,901✔
347
    TSDB_CHECK_CODE(code, lino, END);
14,584,927✔
348
  }
349

350
  TSDB_CHECK_CONDITION(!tmp, code, lino, END, TSDB_CODE_SUCCESS);
14,587,255✔
351
  for (int32_t i = 0; i < blockNum; i++) {
29,183,800✔
352
    if (taosArrayGetSize(pBlocks) == 0){
14,572,143✔
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,596,615✔
364
      if (pBlock == NULL) {
14,591,119✔
365
        continue;
×
366
      }
367

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

376
    pRsp->blockNum++;
14,594,514✔
377
  }
378
  tqTrace("vgId:%d, process sub data success, response blocknum:%d, rows:%d", pTq->pVnode->config.vgId, pRsp->blockNum, *totalRows);
14,611,657✔
379
END:
14,652,936✔
380
  if (code != 0) {
14,619,029✔
381
    tqError("%s failed at %d, failed to process sub data:%s", __FUNCTION__, lino, tstrerror(code));
38,417✔
382
  }
383
  taosArrayDestroyEx(pBlocks, (FDelete)blockDataFreeRes);
14,619,029✔
384
  taosArrayDestroyP(pSchemas, (FDelete)tDeleteSchemaWrapper);
14,627,533✔
385
}
14,641,496✔
386

387
static void preProcessSubmitMsg(STqHandle* pHandle, const SMqPollReq* pRequest, SArray** rawList){
14,960,574✔
388
  STqExecHandle* pExec = &pHandle->execHandle;
14,960,574✔
389
  STqReader* pReader = pExec->pTqReader;
14,961,400✔
390
  int32_t blockSz = taosArrayGetSize(pReader->submit.aSubmitTbData);
14,961,483✔
391
  for (int32_t i = 0; i < blockSz; i++){
29,926,273✔
392
    SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, i);
14,963,540✔
393
    if (pSubmitTbData== NULL){
14,963,537✔
394
      taosArrayDestroy(*rawList);
×
395
      *rawList = NULL;
×
396
      return;
×
397
    }
398

399
    int64_t uid = pSubmitTbData->uid;
14,963,537✔
400
    if (pRequest->rawData) {
14,963,858✔
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,964,498✔
414
      continue;
14,952,774✔
415
    }
416

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

440
int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SPackedData submit, SMqDataRsp* pRsp, int32_t* totalRows, const SMqPollReq* pRequest) {
14,962,859✔
441
  int32_t code = 0;
14,962,859✔
442
  int32_t lino = 0;
14,962,859✔
443
  SDecoder decoder = {0};
14,962,859✔
444
  STqExecHandle* pExec = &pHandle->execHandle;
14,962,859✔
445
  STqReader* pReader = pExec->pTqReader;
14,962,859✔
446
  SArray *rawList = NULL;
14,962,908✔
447
  if (pRequest->rawData){
14,962,952✔
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,962,952✔
452
  TSDB_CHECK_CODE(code, lino, END);
14,961,988✔
453
  preProcessSubmitMsg(pHandle, pRequest, &rawList);
14,961,988✔
454
  // data could not contains same uid data in rawdata mode
455
  if (pRequest->rawData != 0 && terrno == TSDB_CODE_TMQ_RAW_DATA_SPLIT){
14,960,943✔
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,961,838✔
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,958,967✔
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,959,368✔
474
    while (tqNextBlockImpl(pReader, NULL)) {
5,801,249✔
475
      tqProcessSubData(pTq, pHandle, pRsp, totalRows, pRequest, rawList);
2,743,214✔
476
    }
477
  } else if (pExec->subType == TOPIC_SUB_TYPE__DB) {
11,900,925✔
478
    while (tqNextDataBlockFilterOut(pReader, pExec->execDb.pFilterOutTbUid)) {
23,778,843✔
479
      tqProcessSubData(pTq, pHandle, pRsp, totalRows, pRequest, rawList);
11,904,207✔
480
    }
481
  }
482

483
END:
14,929,382✔
484
  tDecoderClear(&decoder);
14,943,699✔
485
  tqReaderClearSubmitMsg(pReader);
14,960,247✔
486
  taosArrayDestroy(rawList);
14,962,387✔
487
  if (code != 0){
14,960,561✔
488
    tqError("%s failed at %d, failed to scan log:%s", __FUNCTION__, lino, tstrerror(code));
×
489
  }
490
  return code;
14,960,561✔
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