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

taosdata / TDengine / #4959

09 Feb 2026 01:16AM UTC coverage: 66.863% (+0.02%) from 66.842%
#4959

push

travis-ci

web-flow
docs: add support for recording STMT to CSV files (#34276)

* docs: add support for recording STMT to CSV files

* docs: update version for STMT recording feature in CSV files

205736 of 307696 relevant lines covered (66.86%)

128357780.92 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) {
146,298,704✔
46
  int32_t code = 0;
146,298,704✔
47
  int32_t lino = 0;
146,298,704✔
48
  SSchemaWrapper* pSchema = NULL;
146,298,704✔
49
  
50
  size_t dataEncodeBufSize = blockGetEncodeSize(pBlock);
146,300,649✔
51
  int32_t dataStrLen = sizeof(SRetrieveTableRspForTmq) + dataEncodeBufSize;
146,321,654✔
52
  void*   buf = taosMemoryCalloc(1, dataStrLen);
146,321,654✔
53
  TSDB_CHECK_NULL(buf, code, lino, END, terrno);
146,281,896✔
54

55
  SRetrieveTableRspForTmq* pRetrieve = (SRetrieveTableRspForTmq*)buf;
146,281,896✔
56
  pRetrieve->version = RETRIEVE_TABLE_RSP_TMQ_VERSION;
146,281,896✔
57
  pRetrieve->precision = precision;
146,276,140✔
58
  pRetrieve->compressed = 0;
146,288,523✔
59
  pRetrieve->numOfRows = htobe64((int64_t)pBlock->info.rows);
146,290,202✔
60

61
  int32_t actualLen = blockEncode(pBlock, pRetrieve->data, dataEncodeBufSize, pSW->nCols);
146,301,951✔
62
  TSDB_CHECK_CONDITION(actualLen >= 0, code, lino, END, terrno);
146,273,531✔
63

64
  actualLen += sizeof(SRetrieveTableRspForTmq);
146,273,531✔
65
  TSDB_CHECK_NULL(taosArrayPush(pRsp->blockDataLen, &actualLen), code, lino, END, terrno);
292,578,865✔
66
  TSDB_CHECK_NULL(taosArrayPush(pRsp->blockData, &buf), code, lino, END, terrno);
292,613,766✔
67
  pSchema = tCloneSSchemaWrapper(pSW);
146,298,549✔
68
  TSDB_CHECK_NULL(pSchema, code, lino, END, terrno);
146,298,549✔
69
  TSDB_CHECK_NULL(taosArrayPush(pRsp->blockSchema, &pSchema), code, lino, END, terrno);
292,605,919✔
70
  pSchema = NULL;
146,307,370✔
71
  pRsp->blockDataElementFree = true;
146,307,370✔
72
  tqTrace("tqAddBlockDataToRsp add block data to block array, blockDataLen:%d, blockData:%p", dataStrLen, buf);
146,289,489✔
73

74
END:
146,289,489✔
75
  tDeleteSchemaWrapper(pSchema);
146,303,237✔
76
  if (code != TSDB_CODE_SUCCESS){
146,255,928✔
77
    taosMemoryFree(buf);
×
78
    tqError("%s failed at line %d with msg:%s", __func__, lino, tstrerror(code));
×
79
  }
80
  return code;
146,255,928✔
81
}
82

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

88
  TSDB_CHECK_NULL(pTq, code, lino, END, TSDB_CODE_INVALID_PARA);
44,730,236✔
89
  TSDB_CHECK_NULL(pRsp, code, lino, END, TSDB_CODE_INVALID_PARA);
44,730,236✔
90

91
  metaReaderDoInit(&mr, pTq->pVnode->pMeta, META_READER_LOCK);
44,730,236✔
92

93
  code = metaReaderGetTableEntryByUidCache(&mr, uid);
44,720,290✔
94
  TSDB_CHECK_CODE(code, lino, END);
44,704,440✔
95

96
  for (int32_t i = 0; i < n; i++) {
89,447,902✔
97
    char* tbName = taosStrdup(mr.me.name);
44,698,728✔
98
    TSDB_CHECK_NULL(tbName, code, lino, END, terrno);
44,708,510✔
99
    if(taosArrayPush(pRsp->blockTbName, &tbName) == NULL){
89,452,548✔
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);
44,744,038✔
104
  }
105

106
END:
44,749,146✔
107
  if (code != TSDB_CODE_SUCCESS) {
44,731,717✔
108
    tqError("%s failed at %d, failed to add tbName to response:%s, uid:%"PRId64, __FUNCTION__, lino, tstrerror(code), uid);
×
109
  }
110
  metaReaderClear(&mr);
44,731,717✔
111
  return code;
44,718,709✔
112
}
113

114
int32_t getDataBlock(qTaskInfo_t task, const STqHandle* pHandle, int32_t vgId, SSDataBlock** res) {
121,820,396✔
115
  if (task == NULL || pHandle == NULL || res == NULL) {
121,820,396✔
116
    return TSDB_CODE_INVALID_PARA;
×
117
  }
118
  uint64_t ts = 0;
121,838,302✔
119
  qStreamSetOpen(task);
121,833,102✔
120

121
  tqDebug("consumer:0x%" PRIx64 " vgId:%d, tmq one task start execute", pHandle->consumerId, vgId);
121,832,156✔
122
  int32_t code = qExecTask(task, res, &ts);
121,848,158✔
123
  if (code != TSDB_CODE_SUCCESS) {
121,851,944✔
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);
121,851,944✔
129
  return 0;
121,846,624✔
130
}
131

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

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

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

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

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

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

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

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

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

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

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

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

198
  int32_t vgId = TD_VID(pTq->pVnode);
22,210,074✔
199
  int32_t totalRows = 0;
22,211,087✔
200

201
  const STqExecHandle* pExec = &pHandle->execHandle;
22,211,087✔
202
  qTaskInfo_t          task = pExec->task;
22,211,748✔
203

204
  code = qStreamPrepareScan(task, pOffset, pHandle->execHandle.subType);
22,211,388✔
205
  TSDB_CHECK_CODE(code, lino, END);
22,209,370✔
206

207
  qStreamSetSourceExcluded(task, pRequest->sourceExcluded);
22,014,906✔
208
  int64_t st = taosGetTimestampMs();
22,013,909✔
209
  while (1) {
99,809,568✔
210
    SSDataBlock* pDataBlock = NULL;
121,823,477✔
211
    code = getDataBlock(task, pHandle, vgId, &pDataBlock);
121,821,509✔
212
    TSDB_CHECK_CODE(code, lino, END);
121,845,919✔
213

214
    if (pRequest->enableReplay) {
121,845,919✔
215
      code = tqProcessReplayRsp(pTq, pHandle, pRsp, pRequest, pDataBlock, task);
8,992✔
216
      TSDB_CHECK_CODE(code, lino, END);
8,992✔
217
      break;
8,992✔
218
    }
219
    if (pDataBlock == NULL) {
121,839,377✔
220
      break;
21,029,746✔
221
    }
222
    code = tqAddBlockDataToRsp(pDataBlock, pRsp, &pExec->execCol.pSW, pTq->pVnode->config.tsdbCfg.precision);
100,809,631✔
223
    TSDB_CHECK_CODE(code, lino, END);
100,792,366✔
224

225
    pRsp->blockNum++;
100,792,366✔
226
    totalRows += pDataBlock->info.rows;
100,794,483✔
227
    if (totalRows >= pRequest->minPollRows || (taosGetTimestampMs() - st > pRequest->timeout)) {
200,833,570✔
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);
22,018,643✔
233
  code = qStreamExtractOffset(task, &pRsp->rspOffset);
22,018,643✔
234

235
END:
22,212,757✔
236
  if (code != 0) {
22,212,757✔
237
    tqError("%s failed at %d, tmq task executed error msg:%s", __FUNCTION__, lino, tstrerror(code));
194,114✔
238
  }
239
  return code;
22,212,760✔
240
}
241

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

251
  int32_t rowCnt = 0;
47,474✔
252
  int64_t st = taosGetTimestampMs();
47,474✔
253
  while (1) {
1,477,115✔
254
    SSDataBlock* pDataBlock = NULL;
1,524,589✔
255
    uint64_t     ts = 0;
1,524,589✔
256
    tqDebug("tmqsnap task start to execute");
1,524,589✔
257
    code = qExecTask(task, &pDataBlock, &ts);
1,524,589✔
258
    TSDB_CHECK_CODE(code, lino, END);
1,524,589✔
259
    tqDebug("tmqsnap task execute end, get %p", pDataBlock);
1,524,589✔
260

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

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

273
      pRsp->blockNum++;
757,028✔
274
      rowCnt += pDataBlock->info.rows;
757,330✔
275
      if (rowCnt <= pRequest->minPollRows && (taosGetTimestampMs() - st <= pRequest->timeout)) {
1,480,876✔
276
        continue;
723,819✔
277
      }
278
    }
279

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

290
    if (pDataBlock == NULL) {
796,695✔
291
      code = qStreamExtractOffset(task, pOffset);
763,184✔
292
      TSDB_CHECK_CODE(code, lino, END);
763,184✔
293

294
      if (pOffset->type == TMQ_OFFSET__SNAPSHOT_DATA) {
763,184✔
295
        continue;
753,598✔
296
      }
297

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

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

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

325
  STqExecHandle* pExec = &pHandle->execHandle;
44,973,900✔
326
  STqReader* pReader = pExec->pTqReader;
44,980,945✔
327

328
  pBlocks = taosArrayInit(0, sizeof(SSDataBlock));
44,979,521✔
329
  TSDB_CHECK_NULL(pBlocks, code, lino, END, terrno);
44,983,084✔
330
  pSchemas = taosArrayInit(0, sizeof(void*));
44,983,084✔
331
  TSDB_CHECK_NULL(pSchemas, code, lino, END, terrno);
44,984,331✔
332

333
  SSubmitTbData* pSubmitTbData = NULL;
44,984,331✔
334
  code = tqRetrieveTaosxBlock(pReader, pRsp, pBlocks, pSchemas, &pSubmitTbData, rawList, pHandle->fetchMeta);
44,984,331✔
335
  TSDB_CHECK_CODE(code, lino, END);
44,958,042✔
336
  bool tmp = (pSubmitTbData->flags & pRequest->sourceExcluded) != 0;
44,753,881✔
337
  TSDB_CHECK_CONDITION(!tmp, code, lino, END, TSDB_CODE_SUCCESS);
44,778,092✔
338

339
  if (pHandle->fetchMeta == ONLY_META){
44,749,154✔
340
    goto END;
6,939✔
341
  }
342

343
  int32_t blockNum = taosArrayGetSize(pBlocks) == 0 ? 1 : taosArrayGetSize(pBlocks);
44,745,672✔
344
  if (pRsp->withTbName) {
44,744,704✔
345
    int64_t uid = pExec->pTqReader->lastBlkUid;
44,745,051✔
346
    code = tqAddTbNameToRsp(pTq, uid, pRsp, blockNum);
44,744,145✔
347
    TSDB_CHECK_CODE(code, lino, END);
44,722,096✔
348
  }
349

350
  TSDB_CHECK_CONDITION(!tmp, code, lino, END, TSDB_CODE_SUCCESS);
44,722,051✔
351
  for (int32_t i = 0; i < blockNum; i++) {
89,460,059✔
352
    if (taosArrayGetSize(pBlocks) == 0){
44,704,545✔
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);
44,725,283✔
364
      if (pBlock == NULL) {
44,714,883✔
365
        continue;
×
366
      }
367

368
      SSchemaWrapper* pSW = (SSchemaWrapper*)taosArrayGetP(pSchemas, i);
44,714,883✔
369
      if (tqAddBlockDataToRsp(pBlock, pRsp, pSW, pTq->pVnode->config.tsdbCfg.precision) != 0){
44,735,378✔
370
        tqError("vgId:%d, failed to add block to rsp msg", pTq->pVnode->config.vgId);
×
371
        continue;
×
372
      }
373
      *totalRows += pBlock->info.rows;
44,705,808✔
374
    }
375

376
    pRsp->blockNum++;
44,735,631✔
377
  }
378
  tqTrace("vgId:%d, process sub data success, response blocknum:%d, rows:%d", pTq->pVnode->config.vgId, pRsp->blockNum, *totalRows);
44,755,514✔
379
END:
44,995,552✔
380
  if (code != 0) {
44,943,510✔
381
    tqError("%s failed at %d, failed to process sub data:%s", __FUNCTION__, lino, tstrerror(code));
204,161✔
382
  }
383
  taosArrayDestroyEx(pBlocks, (FDelete)blockDataFreeRes);
44,943,510✔
384
  taosArrayDestroyP(pSchemas, (FDelete)tDeleteSchemaWrapper);
44,951,917✔
385
}
44,973,997✔
386

387
static void preProcessSubmitMsg(STqHandle* pHandle, const SMqPollReq* pRequest, SArray** rawList){
46,141,331✔
388
  STqExecHandle* pExec = &pHandle->execHandle;
46,141,331✔
389
  STqReader* pReader = pExec->pTqReader;
46,150,084✔
390
  int32_t blockSz = taosArrayGetSize(pReader->submit.aSubmitTbData);
46,151,639✔
391
  for (int32_t i = 0; i < blockSz; i++){
92,318,714✔
392
    SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, i);
46,166,843✔
393
    if (pSubmitTbData== NULL){
46,169,226✔
394
      taosArrayDestroy(*rawList);
×
395
      *rawList = NULL;
×
396
      return;
×
397
    }
398

399
    int64_t uid = pSubmitTbData->uid;
46,169,226✔
400
    if (pRequest->rawData) {
46,171,942✔
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){
46,174,227✔
414
      continue;
45,286,504✔
415
    }
416

417
    int64_t createTime = INT64_MAX;
885,868✔
418
    int64_t *cTime = (int64_t*)taosHashGet(pHandle->tableCreateTimeHash, &uid, LONG_BYTES);
885,868✔
419
    if (cTime != NULL){
885,868✔
420
      createTime = *cTime;
4,154✔
421
    } else{
422
      createTime = metaGetTableCreateTime(pReader->pVnodeMeta, uid, 1);
881,714✔
423
      if (createTime != INT64_MAX){
881,395✔
424
        int32_t code = taosHashPut(pHandle->tableCreateTimeHash, &uid, LONG_BYTES, &createTime, LONG_BYTES);
881,714✔
425
        if (code != 0){
881,714✔
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){
885,549✔
431
      tDestroySVSubmitCreateTbReq(pSubmitTbData->pCreateTbReq, TSDB_MSG_FLG_DECODE);
874,870✔
432
      taosMemoryFreeClear(pSubmitTbData->pCreateTbReq);
874,232✔
433
    } else{
434
      taosArrayDestroy(*rawList);
10,679✔
435
      *rawList = NULL;
10,679✔
436
    }
437
  }
438
}
439

440
int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SPackedData submit, SMqDataRsp* pRsp, int32_t* totalRows, const SMqPollReq* pRequest) {
46,155,129✔
441
  int32_t code = 0;
46,155,129✔
442
  int32_t lino = 0;
46,155,129✔
443
  SDecoder decoder = {0};
46,155,129✔
444
  STqExecHandle* pExec = &pHandle->execHandle;
46,155,431✔
445
  STqReader* pReader = pExec->pTqReader;
46,155,129✔
446
  SArray *rawList = NULL;
46,155,431✔
447
  if (pRequest->rawData){
46,155,778✔
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);
46,155,778✔
452
  TSDB_CHECK_CODE(code, lino, END);
46,148,741✔
453
  preProcessSubmitMsg(pHandle, pRequest, &rawList);
46,148,741✔
454
  // data could not contains same uid data in rawdata mode
455
  if (pRequest->rawData != 0 && terrno == TSDB_CODE_TMQ_RAW_DATA_SPLIT){
46,142,467✔
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){
46,150,271✔
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){
46,145,748✔
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) {
46,140,251✔
474
    while (tqNextBlockImpl(pReader, NULL)) {
23,580,789✔
475
      tqProcessSubData(pTq, pHandle, pRsp, totalRows, pRequest, rawList);
11,198,008✔
476
    }
477
  } else if (pExec->subType == TOPIC_SUB_TYPE__DB) {
33,752,783✔
478
    while (tqNextDataBlockFilterOut(pReader, pExec->execDb.pFilterOutTbUid)) {
67,519,974✔
479
      tqProcessSubData(pTq, pHandle, pRsp, totalRows, pRequest, rawList);
33,780,804✔
480
    }
481
  }
482

483
END:
46,115,384✔
484
  tDecoderClear(&decoder);
46,133,001✔
485
  tqReaderClearSubmitMsg(pReader);
46,145,458✔
486
  taosArrayDestroy(rawList);
46,151,308✔
487
  if (code != 0){
46,150,016✔
488
    tqError("%s failed at %d, failed to scan log:%s", __FUNCTION__, lino, tstrerror(code));
×
489
  }
490
  return code;
46,150,016✔
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