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

taosdata / TDengine / #5010

29 Mar 2026 04:32AM UTC coverage: 72.292% (+0.03%) from 72.26%
#5010

push

travis-ci

web-flow
refactor: do some internal refactor for TDgpt. (#34955)

253774 of 351039 relevant lines covered (72.29%)

133420324.04 hits per line

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

81.63
/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) {
49,911,650✔
46
  int32_t code = 0;
49,911,650✔
47
  int32_t lino = 0;
49,911,650✔
48
  SSchemaWrapper* pSchema = NULL;
49,911,650✔
49
  
50
  size_t dataEncodeBufSize = blockGetEncodeSize(pBlock);
49,943,821✔
51
  int32_t dataStrLen = sizeof(SRetrieveTableRspForTmq) + dataEncodeBufSize;
50,027,648✔
52
  void*   buf = taosMemoryCalloc(1, dataStrLen);
50,027,648✔
53
  TSDB_CHECK_NULL(buf, code, lino, END, terrno);
49,865,550✔
54

55
  SRetrieveTableRspForTmq* pRetrieve = (SRetrieveTableRspForTmq*)buf;
49,865,550✔
56
  pRetrieve->version = RETRIEVE_TABLE_RSP_TMQ_VERSION;
49,865,550✔
57
  pRetrieve->precision = precision;
49,869,081✔
58
  pRetrieve->compressed = 0;
49,914,421✔
59
  pRetrieve->numOfRows = htobe64((int64_t)pBlock->info.rows);
49,906,328✔
60

61
  int32_t actualLen = blockEncode(pBlock, pRetrieve->data, dataEncodeBufSize, pSW->nCols);
49,972,537✔
62
  TSDB_CHECK_CONDITION(actualLen >= 0, code, lino, END, terrno);
49,887,216✔
63

64
  actualLen += sizeof(SRetrieveTableRspForTmq);
49,887,216✔
65
  TSDB_CHECK_NULL(taosArrayPush(pRsp->blockDataLen, &actualLen), code, lino, END, terrno);
99,895,899✔
66
  TSDB_CHECK_NULL(taosArrayPush(pRsp->blockData, &buf), code, lino, END, terrno);
100,014,702✔
67
  pSchema = tCloneSSchemaWrapper(pSW);
49,968,959✔
68
  TSDB_CHECK_NULL(pSchema, code, lino, END, terrno);
49,968,959✔
69
  TSDB_CHECK_NULL(taosArrayPush(pRsp->blockSchema, &pSchema), code, lino, END, terrno);
99,980,681✔
70
  pSchema = NULL;
50,011,722✔
71
  pRsp->blockDataElementFree = true;
50,011,722✔
72
  tqTrace("tqAddBlockDataToRsp add block data to block array, blockDataLen:%d, blockData:%p", dataStrLen, buf);
49,983,539✔
73

74
END:
49,983,539✔
75
  tDeleteSchemaWrapper(pSchema);
49,951,419✔
76
  if (code != TSDB_CODE_SUCCESS){
49,890,613✔
77
    taosMemoryFree(buf);
×
78
    tqError("%s failed at line %d with msg:%s", __func__, lino, tstrerror(code));
×
79
  }
80
  return code;
49,890,613✔
81
}
82

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

88
  TSDB_CHECK_NULL(pTq, code, lino, END, TSDB_CODE_INVALID_PARA);
46,680,200✔
89
  TSDB_CHECK_NULL(pRsp, code, lino, END, TSDB_CODE_INVALID_PARA);
46,680,200✔
90

91
  metaReaderDoInit(&mr, pTq->pVnode->pMeta, META_READER_LOCK);
46,680,200✔
92

93
  code = metaReaderGetTableEntryByUidCache(&mr, uid);
46,671,620✔
94
  TSDB_CHECK_CODE(code, lino, END);
46,651,019✔
95

96
  for (int32_t i = 0; i < n; i++) {
93,401,243✔
97
    char* tbName = taosStrdup(mr.me.name);
46,595,770✔
98
    TSDB_CHECK_NULL(tbName, code, lino, END, terrno);
46,676,149✔
99
    if(taosArrayPush(pRsp->blockTbName, &tbName) == NULL){
93,424,264✔
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);
46,748,115✔
104
  }
105

106
END:
46,805,792✔
107
  if (code != TSDB_CODE_SUCCESS) {
46,690,486✔
108
    tqError("%s failed at %d, failed to add tbName to response:%s, uid:%"PRId64, __FUNCTION__, lino, tstrerror(code), uid);
×
109
  }
110
  metaReaderClear(&mr);
46,690,486✔
111
  return code;
46,694,610✔
112
}
113

114
int32_t getDataBlock(qTaskInfo_t task, const STqHandle* pHandle, int32_t vgId, SSDataBlock** res) {
7,533,819✔
115
  if (task == NULL || pHandle == NULL || res == NULL) {
7,533,819✔
116
    return TSDB_CODE_INVALID_PARA;
×
117
  }
118
  uint64_t ts = 0;
7,536,608✔
119
  qStreamSetOpen(task);
7,534,927✔
120

121
  tqDebug("consumer:0x%" PRIx64 " vgId:%d, tmq one task start execute", pHandle->consumerId, vgId);
7,522,542✔
122
  int32_t code = qExecTask(task, res, &ts);
7,532,821✔
123
  if (code != TSDB_CODE_SUCCESS) {
7,540,849✔
124
    tqError("consumer:0x%" PRIx64 " vgId:%d, task exec error since %s", pHandle->consumerId, vgId, tstrerror(code));
×
125
  }
126

127
  tqDebug("consumer:0x%" PRIx64 " vgId:%d tmq one task end executed, pDataBlock:%p", pHandle->consumerId, vgId, *res);
7,540,879✔
128
  return code;
7,540,879✔
129
}
130

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

135
  if (IS_OFFSET_RESET_TYPE(pRequest->reqOffset.type) && pHandle->block != NULL) {
15,236✔
136
    blockDataDestroy(pHandle->block);
293✔
137
    pHandle->block = NULL;
293✔
138
  }
139
  if (pHandle->block == NULL) {
15,236✔
140
    if (pDataBlock == NULL) {
11,720✔
141
      goto END;
10,255✔
142
    }
143

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

148
    pHandle->block = NULL;
1,465✔
149

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

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

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

164
  pRsp->blockNum++;
4,981✔
165
  if (pDataBlock == NULL) {
4,981✔
166
    blockDataDestroy(pHandle->block);
1,172✔
167
    pHandle->block = NULL;
1,172✔
168
  } else {
169
    code = copyDataBlock(pHandle->block, pDataBlock);
3,809✔
170
    TSDB_CHECK_CODE(code, lino, END);
3,809✔
171

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

176
    pRsp->sleepTime = offset.ts - pHandle->blockTime;
3,809✔
177
    pHandle->blockTime = offset.ts;
3,809✔
178
    tOffsetDestroy(&offset);
3,809✔
179
  }
180

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

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

197
  int32_t vgId = TD_VID(pTq->pVnode);
7,795,684✔
198
  int32_t totalRows = 0;
7,799,053✔
199

200
  const STqExecHandle* pExec = &pHandle->execHandle;
7,799,053✔
201
  qTaskInfo_t          task = pExec->task;
7,797,453✔
202

203
  code = qStreamPrepareScan(task, pOffset, pHandle->execHandle.subType);
7,793,973✔
204
  TSDB_CHECK_CODE(code, lino, END);
7,794,988✔
205

206
  qStreamSetParams(task, pRequest->sourceExcluded, pRequest->minPollRows, pRequest->timeout, pRequest->enableReplay);
7,532,932✔
207
  do {
208
    SSDataBlock* pDataBlock = NULL;
7,519,041✔
209
    code = getDataBlock(task, pHandle, vgId, &pDataBlock);
7,521,024✔
210
    TSDB_CHECK_CODE(code, lino, END);
7,539,414✔
211

212
    if (pRequest->enableReplay) {
7,539,414✔
213
      code = tqProcessReplayRsp(pTq, pHandle, pRsp, pRequest, pDataBlock, task);
15,236✔
214
      TSDB_CHECK_CODE(code, lino, END);
15,236✔
215
      break;
15,236✔
216
    }
217
    if (pDataBlock == NULL) {
7,524,178✔
218
      break;
5,032,152✔
219
    }
220
    code = tqAddBlockDataToRsp(pDataBlock, pRsp, &pExec->execCol.pSW, pTq->pVnode->config.tsdbCfg.precision);
2,492,026✔
221
    TSDB_CHECK_CODE(code, lino, END);
2,491,709✔
222

223
    pRsp->blockNum++;
2,491,709✔
224
    totalRows += pDataBlock->info.rows;
2,491,075✔
225
  } while(0);
226

227
  tqDebug("consumer:0x%" PRIx64 " vgId:%d tmq task executed finished, total blocks:%d, totalRows:%d", pHandle->consumerId, vgId, pRsp->blockNum, totalRows);
7,538,720✔
228
  code = qStreamExtractOffset(task, &pRsp->rspOffset);
7,539,354✔
229

230
END:
7,801,105✔
231
  if (code != 0) {
7,801,105✔
232
    tqError("%s failed at %d, tmq task executed error msg:%s", __FUNCTION__, lino, tstrerror(code));
262,056✔
233
  }
234
  return code;
7,801,105✔
235
}
236

237
int32_t tqScanTaosx(STQ* pTq, const STqHandle* pHandle, SMqDataRsp* pRsp, SMqBatchMetaRsp* pBatchMetaRsp, STqOffsetVal* pOffset, const SMqPollReq* pRequest) {
44,487✔
238
  int32_t code = 0;
44,487✔
239
  int32_t lino = 0;
44,487✔
240
  char* tbName = NULL;
44,487✔
241
  const STqExecHandle* pExec = &pHandle->execHandle;
44,850✔
242
  qTaskInfo_t          task = pExec->task;
44,850✔
243
  code = qStreamPrepareScan(task, pOffset, pHandle->execHandle.subType);
44,850✔
244
  TSDB_CHECK_CODE(code, lino, END);
44,850✔
245

246
  qStreamSetParams(task, pRequest->sourceExcluded, pRequest->minPollRows, pRequest->timeout, false);
44,850✔
247

248
  int32_t rowCnt = 0;
44,169✔
249
  int64_t st = taosGetTimestampMs();
44,532✔
250
  while (1) {
1,488,153✔
251
    SSDataBlock* pDataBlock = NULL;
1,532,685✔
252
    uint64_t     ts = 0;
1,532,054✔
253
    tqDebug("tmqsnap task start to execute");
1,532,372✔
254
    code = qExecTask(task, &pDataBlock, &ts);
1,532,998✔
255
    TSDB_CHECK_CODE(code, lino, END);
1,533,629✔
256
    tqDebug("tmqsnap task execute end, get %p", pDataBlock);
1,533,629✔
257

258
    if (pDataBlock != NULL && pDataBlock->info.rows > 0) {
1,533,629✔
259
      if (pRsp->withTbName) {
766,801✔
260
        tbName = taosStrdup(qExtractTbnameFromTask(task));
766,801✔
261
        TSDB_CHECK_NULL(tbName, code, lino, END, terrno);
766,801✔
262
        TSDB_CHECK_NULL(taosArrayPush(pRsp->blockTbName, &tbName), code, lino, END, terrno);
1,533,602✔
263
        tqDebug("vgId:%d, add tbname:%s to rsp msg", pTq->pVnode->config.vgId, tbName);
766,801✔
264
        tbName = NULL;
766,801✔
265
      }
266

267
      code = tqAddBlockDataToRsp(pDataBlock, pRsp, qExtractSchemaFromTask(task), pTq->pVnode->config.tsdbCfg.precision);
766,801✔
268
      TSDB_CHECK_CODE(code, lino, END);
766,483✔
269

270
      pRsp->blockNum++;
766,483✔
271
      rowCnt += pDataBlock->info.rows;
766,165✔
272
      if (rowCnt <= pRequest->minPollRows && (taosGetTimestampMs() - st <= pRequest->timeout)) {
1,497,798✔
273
        continue;
731,633✔
274
      }
275
    }
276

277
    // get meta
278
    SMqBatchMetaRsp* tmp = qStreamExtractMetaMsg(task);
801,996✔
279
    if (taosArrayGetSize(tmp->batchMetaReq) > 0) {
801,996✔
280
      code = qStreamExtractOffset(task, &tmp->rspOffset);
2,431✔
281
      TSDB_CHECK_CODE(code, lino, END);
2,431✔
282
      *pBatchMetaRsp = *tmp;
2,431✔
283
      tqDebug("tmqsnap task get meta");
2,431✔
284
      break;
2,431✔
285
    }
286

287
    if (pDataBlock == NULL) {
799,565✔
288
      code = qStreamExtractOffset(task, pOffset);
764,397✔
289
      TSDB_CHECK_CODE(code, lino, END);
764,084✔
290

291
      if (pOffset->type == TMQ_OFFSET__SNAPSHOT_DATA) {
764,084✔
292
        continue;
756,833✔
293
      }
294

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

300
    if (pRsp->blockNum > 0) {
35,168✔
301
      tqDebug("tmqsnap task exec exited, get data");
34,850✔
302
      code = qStreamExtractOffset(task, &pRsp->rspOffset);
34,850✔
303
      break;
35,168✔
304
    }
305
  }
306
  tqDebug("%s:%d success", __FUNCTION__, lino);
44,850✔
307
END:
44,532✔
308
  if (code != 0){
44,850✔
309
    tqError("%s failed at %d, vgId:%d, task exec error since %s", __FUNCTION__ , lino, pTq->pVnode->config.vgId, tstrerror(code));
×
310
  }
311
  taosMemoryFree(tbName);
44,850✔
312
  return code;
44,850✔
313
}
314

315
static void tqProcessSubData(STQ* pTq, STqHandle* pHandle, SMqDataRsp* pRsp, int32_t* totalRows,
46,746,327✔
316
                             const SMqPollReq* pRequest, SArray* rawList){
317
  int32_t code = 0;
46,746,327✔
318
  int32_t lino = 0;
46,746,327✔
319
  SArray* pBlocks = NULL;
46,746,327✔
320
  SArray* pSchemas = NULL;
46,746,327✔
321

322
  STqExecHandle* pExec = &pHandle->execHandle;
46,746,327✔
323
  STqReader* pReader = pExec->pTqReader;
46,759,726✔
324

325
  pBlocks = taosArrayInit(0, sizeof(SSDataBlock));
46,754,846✔
326
  TSDB_CHECK_NULL(pBlocks, code, lino, END, terrno);
46,757,705✔
327
  pSchemas = taosArrayInit(0, sizeof(void*));
46,757,705✔
328
  TSDB_CHECK_NULL(pSchemas, code, lino, END, terrno);
46,771,157✔
329

330
  SSubmitTbData* pSubmitTbData = NULL;
46,771,157✔
331
  code = tqRetrieveTaosxBlock(pReader, pRsp, pBlocks, pSchemas, &pSubmitTbData, rawList, pHandle->fetchMeta);
46,769,548✔
332
  TSDB_CHECK_CODE(code, lino, END);
46,644,314✔
333
  bool tmp = (pSubmitTbData->flags & pRequest->sourceExcluded) != 0;
46,636,364✔
334
  TSDB_CHECK_CONDITION(!tmp, code, lino, END, TSDB_CODE_SUCCESS);
46,742,959✔
335

336
  if (pHandle->fetchMeta == ONLY_META){
46,742,959✔
337
    goto END;
948✔
338
  }
339

340
  int32_t blockNum = taosArrayGetSize(pBlocks) == 0 ? 1 : taosArrayGetSize(pBlocks);
46,761,063✔
341
  if (pRsp->withTbName) {
46,754,738✔
342
    int64_t uid = pExec->pTqReader->lastBlkUid;
46,746,192✔
343
    code = tqAddTbNameToRsp(pTq, uid, pRsp, blockNum);
46,752,043✔
344
    TSDB_CHECK_CODE(code, lino, END);
46,577,632✔
345
  }
346

347
  TSDB_CHECK_CONDITION(!tmp, code, lino, END, TSDB_CODE_SUCCESS);
46,581,070✔
348
  for (int32_t i = 0; i < blockNum; i++) {
93,313,250✔
349
    if (taosArrayGetSize(pBlocks) == 0){
46,564,426✔
350
      void* rawData = taosArrayGetP(rawList, pReader->nextBlk - 1);
×
351
      if (rawData == NULL) {
×
352
        continue;
×
353
      }
354
      if (tqAddRawDataToRsp(rawData, pRsp, pTq->pVnode->config.tsdbCfg.precision) != 0){
×
355
        tqError("vgId:%d, failed to add block to rsp msg", pTq->pVnode->config.vgId);
×
356
        continue;
×
357
      }
358
      *totalRows += *(uint32_t *)rawData + INT_BYTES; // bytes actually
×
359
    } else {
360
      SSDataBlock* pBlock = taosArrayGet(pBlocks, i);
46,612,361✔
361
      if (pBlock == NULL) {
46,673,707✔
362
        continue;
×
363
      }
364

365
      SSchemaWrapper* pSW = (SSchemaWrapper*)taosArrayGetP(pSchemas, i);
46,673,707✔
366
      if (tqAddBlockDataToRsp(pBlock, pRsp, pSW, pTq->pVnode->config.tsdbCfg.precision) != 0){
46,719,791✔
367
        tqError("vgId:%d, failed to add block to rsp msg", pTq->pVnode->config.vgId);
×
368
        continue;
×
369
      }
370
      *totalRows += pBlock->info.rows;
46,636,493✔
371
    }
372

373
    pRsp->blockNum++;
46,716,591✔
374
  }
375
  tqTrace("vgId:%d, process sub data success, response blocknum:%d, rows:%d", pTq->pVnode->config.vgId, pRsp->blockNum, *totalRows);
46,748,824✔
376
END:
46,757,722✔
377
  if (code != 0) {
46,609,909✔
378
    tqError("%s failed at %d, failed to process sub data:%s", __FUNCTION__, lino, tstrerror(code));
7,950✔
379
  }
380
  taosArrayDestroyEx(pBlocks, (FDelete)blockDataFreeRes);
46,609,909✔
381
  taosArrayDestroyP(pSchemas, (FDelete)tDeleteSchemaWrapper);
46,645,041✔
382
}
46,730,432✔
383

384
static void preProcessSubmitMsg(STqHandle* pHandle, const SMqPollReq* pRequest, SArray** rawList){
48,164,494✔
385
  STqExecHandle* pExec = &pHandle->execHandle;
48,164,494✔
386
  STqReader* pReader = pExec->pTqReader;
48,176,745✔
387
  int32_t blockSz = taosArrayGetSize(pReader->submit.aSubmitTbData);
48,180,056✔
388
  for (int32_t i = 0; i < blockSz; i++){
96,342,522✔
389
    SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, i);
48,164,963✔
390
    if (pSubmitTbData== NULL){
48,173,975✔
391
      taosArrayDestroy(*rawList);
×
392
      *rawList = NULL;
×
393
      return;
×
394
    }
395

396
    int64_t uid = pSubmitTbData->uid;
48,173,975✔
397
    if (pRequest->rawData) {
48,177,152✔
398
      if (taosHashGet(pRequest->uidHash, &uid, LONG_BYTES) != NULL) {
×
399
        tqDebug("poll rawdata split,uid:%" PRId64 " is already exists", uid);
×
400
        terrno = TSDB_CODE_TMQ_RAW_DATA_SPLIT;
×
401
        return;
×
402
      } else {
403
        int32_t code = taosHashPut(pRequest->uidHash, &uid, LONG_BYTES, &uid, LONG_BYTES);
×
404
        if (code != 0) {
×
405
          tqError("failed to add table uid to hash, code:%d, uid:%" PRId64, code, uid);
×
406
        }
407
      }
408
    }
409

410
    if (pSubmitTbData->pCreateTbReq == NULL){
48,178,774✔
411
      continue;
47,372,846✔
412
    }
413

414
    int64_t createTime = INT64_MAX;
796,251✔
415
    int64_t *cTime = (int64_t*)taosHashGet(pHandle->tableCreateTimeHash, &uid, LONG_BYTES);
797,591✔
416
    if (cTime != NULL){
798,596✔
417
      createTime = *cTime;
677✔
418
    } else{
419
      createTime = metaGetTableCreateTime(pReader->pVnode->pMeta, uid, 1);
797,919✔
420
      if (createTime != INT64_MAX){
794,234✔
421
        int32_t code = taosHashPut(pHandle->tableCreateTimeHash, &uid, LONG_BYTES, &createTime, LONG_BYTES);
796,579✔
422
        if (code != 0){
797,584✔
423
          tqError("failed to add table create time to hash,code:%d, uid:%"PRId64, code, uid);
×
424
        }
425
      }
426
    }
427
    if (pHandle->fetchMeta == WITH_DATA || pSubmitTbData->ctimeMs > createTime){
795,916✔
428
      tDestroySVSubmitCreateTbReq(pSubmitTbData->pCreateTbReq, TSDB_MSG_FLG_DECODE);
792,107✔
429
      taosMemoryFreeClear(pSubmitTbData->pCreateTbReq);
788,422✔
430
    } else{
431
      taosArrayDestroy(*rawList);
5,149✔
432
      *rawList = NULL;
5,149✔
433
    }
434
  }
435
}
436

437
int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SPackedData submit, SMqDataRsp* pRsp, int32_t* totalRows, const SMqPollReq* pRequest) {
48,192,545✔
438
  int32_t code = 0;
48,192,545✔
439
  int32_t lino = 0;
48,192,545✔
440
  SDecoder decoder = {0};
48,192,545✔
441
  STqExecHandle* pExec = &pHandle->execHandle;
48,193,196✔
442
  STqReader* pReader = pExec->pTqReader;
48,192,903✔
443
  SArray *rawList = NULL;
48,192,587✔
444
  if (pRequest->rawData){
48,192,799✔
445
    rawList = taosArrayInit(0, POINTER_BYTES);
×
446
    TSDB_CHECK_NULL(rawList, code, lino, END, terrno);
×
447
  }
448
  code = tqReaderSetSubmitMsg(pReader, submit.msgStr, submit.msgLen, submit.ver, rawList, &decoder);
48,193,095✔
449
  TSDB_CHECK_CODE(code, lino, END);
48,174,747✔
450
  preProcessSubmitMsg(pHandle, pRequest, &rawList);
48,174,747✔
451
  // data could not contains same uid data in rawdata mode
452
  if (pRequest->rawData != 0 && terrno == TSDB_CODE_TMQ_RAW_DATA_SPLIT){
48,159,874✔
453
    goto END;
×
454
  }
455

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

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

470
  if (pExec->subType == TOPIC_SUB_TYPE__TABLE) {
48,148,141✔
471
    while (tqNextBlockImpl(pReader, NULL)) {
24,756,345✔
472
      tqProcessSubData(pTq, pHandle, pRsp, totalRows, pRequest, rawList);
11,770,754✔
473
    }
474
  } else if (pExec->subType == TOPIC_SUB_TYPE__DB) {
35,159,526✔
475
    while (tqNextDataBlockFilterOut(pReader, pExec->execDb.pFilterOutTbUid)) {
70,031,828✔
476
      tqProcessSubData(pTq, pHandle, pRsp, totalRows, pRequest, rawList);
34,988,779✔
477
    }
478
  }
479

480
END:
48,098,880✔
481
  tDecoderClear(&decoder);
48,117,379✔
482
  tqReaderClearSubmitMsg(pReader);
48,157,613✔
483
  taosArrayDestroy(rawList);
48,180,707✔
484
  if (code != 0){
48,172,910✔
485
    tqError("%s failed at %d, failed to scan log:%s", __FUNCTION__, lino, tstrerror(code));
×
486
  }
487
  return code;
48,172,910✔
488
}
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