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

taosdata / TDengine / #4966

09 Feb 2026 01:16AM UTC coverage: 66.832% (-0.05%) from 66.884%
#4966

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

205639 of 307696 relevant lines covered (66.83%)

126955174.94 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) {
148,674,189✔
46
  int32_t code = 0;
148,674,189✔
47
  int32_t lino = 0;
148,674,189✔
48
  SSchemaWrapper* pSchema = NULL;
148,674,189✔
49
  
50
  size_t dataEncodeBufSize = blockGetEncodeSize(pBlock);
148,698,938✔
51
  int32_t dataStrLen = sizeof(SRetrieveTableRspForTmq) + dataEncodeBufSize;
148,756,916✔
52
  void*   buf = taosMemoryCalloc(1, dataStrLen);
148,756,916✔
53
  TSDB_CHECK_NULL(buf, code, lino, END, terrno);
148,673,634✔
54

55
  SRetrieveTableRspForTmq* pRetrieve = (SRetrieveTableRspForTmq*)buf;
148,673,634✔
56
  pRetrieve->version = RETRIEVE_TABLE_RSP_TMQ_VERSION;
148,673,634✔
57
  pRetrieve->precision = precision;
148,644,493✔
58
  pRetrieve->compressed = 0;
148,686,670✔
59
  pRetrieve->numOfRows = htobe64((int64_t)pBlock->info.rows);
148,697,735✔
60

61
  int32_t actualLen = blockEncode(pBlock, pRetrieve->data, dataEncodeBufSize, pSW->nCols);
148,702,775✔
62
  TSDB_CHECK_CONDITION(actualLen >= 0, code, lino, END, terrno);
148,676,894✔
63

64
  actualLen += sizeof(SRetrieveTableRspForTmq);
148,676,894✔
65
  TSDB_CHECK_NULL(taosArrayPush(pRsp->blockDataLen, &actualLen), code, lino, END, terrno);
297,419,429✔
66
  TSDB_CHECK_NULL(taosArrayPush(pRsp->blockData, &buf), code, lino, END, terrno);
297,489,602✔
67
  pSchema = tCloneSSchemaWrapper(pSW);
148,731,041✔
68
  TSDB_CHECK_NULL(pSchema, code, lino, END, terrno);
148,731,041✔
69
  TSDB_CHECK_NULL(taosArrayPush(pRsp->blockSchema, &pSchema), code, lino, END, terrno);
297,474,605✔
70
  pSchema = NULL;
148,743,564✔
71
  pRsp->blockDataElementFree = true;
148,743,564✔
72
  tqTrace("tqAddBlockDataToRsp add block data to block array, blockDataLen:%d, blockData:%p", dataStrLen, buf);
148,704,829✔
73

74
END:
148,704,829✔
75
  tDeleteSchemaWrapper(pSchema);
148,743,581✔
76
  if (code != TSDB_CODE_SUCCESS){
148,664,304✔
77
    taosMemoryFree(buf);
×
78
    tqError("%s failed at line %d with msg:%s", __func__, lino, tstrerror(code));
×
79
  }
80
  return code;
148,664,304✔
81
}
82

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

88
  TSDB_CHECK_NULL(pTq, code, lino, END, TSDB_CODE_INVALID_PARA);
42,847,085✔
89
  TSDB_CHECK_NULL(pRsp, code, lino, END, TSDB_CODE_INVALID_PARA);
42,847,085✔
90

91
  metaReaderDoInit(&mr, pTq->pVnode->pMeta, META_READER_LOCK);
42,847,085✔
92

93
  code = metaReaderGetTableEntryByUidCache(&mr, uid);
42,808,649✔
94
  TSDB_CHECK_CODE(code, lino, END);
42,775,458✔
95

96
  for (int32_t i = 0; i < n; i++) {
85,650,519✔
97
    char* tbName = taosStrdup(mr.me.name);
42,758,070✔
98
    TSDB_CHECK_NULL(tbName, code, lino, END, terrno);
42,794,066✔
99
    if(taosArrayPush(pRsp->blockTbName, &tbName) == NULL){
85,667,891✔
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);
42,873,825✔
104
  }
105

106
END:
42,892,158✔
107
  if (code != TSDB_CODE_SUCCESS) {
42,855,583✔
108
    tqError("%s failed at %d, failed to add tbName to response:%s, uid:%"PRId64, __FUNCTION__, lino, tstrerror(code), uid);
×
109
  }
110
  metaReaderClear(&mr);
42,855,583✔
111
  return code;
42,806,072✔
112
}
113

114
int32_t getDataBlock(qTaskInfo_t task, const STqHandle* pHandle, int32_t vgId, SSDataBlock** res) {
124,986,373✔
115
  if (task == NULL || pHandle == NULL || res == NULL) {
124,986,373✔
116
    return TSDB_CODE_INVALID_PARA;
×
117
  }
118
  uint64_t ts = 0;
125,002,619✔
119
  qStreamSetOpen(task);
125,000,517✔
120

121
  tqDebug("consumer:0x%" PRIx64 " vgId:%d, tmq one task start execute", pHandle->consumerId, vgId);
125,000,044✔
122
  int32_t code = qExecTask(task, res, &ts);
125,011,093✔
123
  if (code != TSDB_CODE_SUCCESS) {
125,010,976✔
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);
125,010,976✔
129
  return 0;
125,013,299✔
130
}
131

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

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

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

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

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

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

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

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

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

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

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

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

198
  int32_t vgId = TD_VID(pTq->pVnode);
21,141,801✔
199
  int32_t totalRows = 0;
21,141,658✔
200

201
  const STqExecHandle* pExec = &pHandle->execHandle;
21,141,658✔
202
  qTaskInfo_t          task = pExec->task;
21,141,995✔
203

204
  code = qStreamPrepareScan(task, pOffset, pHandle->execHandle.subType);
21,141,086✔
205
  TSDB_CHECK_CODE(code, lino, END);
21,138,753✔
206

207
  qStreamSetSourceExcluded(task, pRequest->sourceExcluded);
20,955,975✔
208
  int64_t st = taosGetTimestampMs();
20,955,458✔
209
  while (1) {
104,032,850✔
210
    SSDataBlock* pDataBlock = NULL;
124,988,308✔
211
    code = getDataBlock(task, pHandle, vgId, &pDataBlock);
124,987,946✔
212
    TSDB_CHECK_CODE(code, lino, END);
125,010,269✔
213

214
    if (pRequest->enableReplay) {
125,010,269✔
215
      code = tqProcessReplayRsp(pTq, pHandle, pRsp, pRequest, pDataBlock, task);
8,736✔
216
      TSDB_CHECK_CODE(code, lino, END);
8,736✔
217
      break;
8,736✔
218
    }
219
    if (pDataBlock == NULL) {
125,001,507✔
220
      break;
19,853,813✔
221
    }
222
    code = tqAddBlockDataToRsp(pDataBlock, pRsp, &pExec->execCol.pSW, pTq->pVnode->config.tsdbCfg.precision);
105,147,694✔
223
    TSDB_CHECK_CODE(code, lino, END);
105,134,915✔
224

225
    pRsp->blockNum++;
105,134,915✔
226
    totalRows += pDataBlock->info.rows;
105,136,175✔
227
    if (totalRows >= pRequest->minPollRows || (taosGetTimestampMs() - st > pRequest->timeout)) {
209,536,484✔
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);
20,960,846✔
233
  code = qStreamExtractOffset(task, &pRsp->rspOffset);
20,960,846✔
234

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

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

251
  int32_t rowCnt = 0;
45,451✔
252
  int64_t st = taosGetTimestampMs();
45,451✔
253
  while (1) {
1,414,076✔
254
    SSDataBlock* pDataBlock = NULL;
1,459,527✔
255
    uint64_t     ts = 0;
1,459,268✔
256
    tqDebug("tmqsnap task start to execute");
1,459,268✔
257
    code = qExecTask(task, &pDataBlock, &ts);
1,459,894✔
258
    TSDB_CHECK_CODE(code, lino, END);
1,459,527✔
259
    tqDebug("tmqsnap task execute end, get %p", pDataBlock);
1,459,527✔
260

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

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

273
      pRsp->blockNum++;
724,020✔
274
      rowCnt += pDataBlock->info.rows;
723,684✔
275
      if (rowCnt <= pRequest->minPollRows && (taosGetTimestampMs() - st <= pRequest->timeout)) {
1,415,658✔
276
        continue;
691,928✔
277
      }
278
    }
279

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

290
    if (pDataBlock == NULL) {
763,416✔
291
      code = qStreamExtractOffset(task, pOffset);
731,324✔
292
      TSDB_CHECK_CODE(code, lino, END);
731,324✔
293

294
      if (pOffset->type == TMQ_OFFSET__SNAPSHOT_DATA) {
731,324✔
295
        continue;
722,148✔
296
      }
297

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

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

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

325
  STqExecHandle* pExec = &pHandle->execHandle;
43,098,097✔
326
  STqReader* pReader = pExec->pTqReader;
43,107,671✔
327

328
  pBlocks = taosArrayInit(0, sizeof(SSDataBlock));
43,108,060✔
329
  TSDB_CHECK_NULL(pBlocks, code, lino, END, terrno);
43,105,422✔
330
  pSchemas = taosArrayInit(0, sizeof(void*));
43,105,422✔
331
  TSDB_CHECK_NULL(pSchemas, code, lino, END, terrno);
43,108,835✔
332

333
  SSubmitTbData* pSubmitTbData = NULL;
43,108,835✔
334
  code = tqRetrieveTaosxBlock(pReader, pRsp, pBlocks, pSchemas, &pSubmitTbData, rawList, pHandle->fetchMeta);
43,110,289✔
335
  TSDB_CHECK_CODE(code, lino, END);
43,037,531✔
336
  bool tmp = (pSubmitTbData->flags & pRequest->sourceExcluded) != 0;
42,837,852✔
337
  TSDB_CHECK_CONDITION(!tmp, code, lino, END, TSDB_CODE_SUCCESS);
42,902,571✔
338

339
  if (pHandle->fetchMeta == ONLY_META){
42,875,117✔
340
    goto END;
6,577✔
341
  }
342

343
  int32_t blockNum = taosArrayGetSize(pBlocks) == 0 ? 1 : taosArrayGetSize(pBlocks);
42,878,718✔
344
  if (pRsp->withTbName) {
42,877,994✔
345
    int64_t uid = pExec->pTqReader->lastBlkUid;
42,878,791✔
346
    code = tqAddTbNameToRsp(pTq, uid, pRsp, blockNum);
42,876,568✔
347
    TSDB_CHECK_CODE(code, lino, END);
42,802,986✔
348
  }
349

350
  TSDB_CHECK_CONDITION(!tmp, code, lino, END, TSDB_CODE_SUCCESS);
42,804,307✔
351
  for (int32_t i = 0; i < blockNum; i++) {
85,674,029✔
352
    if (taosArrayGetSize(pBlocks) == 0){
42,733,601✔
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);
42,833,191✔
364
      if (pBlock == NULL) {
42,810,318✔
365
        continue;
×
366
      }
367

368
      SSchemaWrapper* pSW = (SSchemaWrapper*)taosArrayGetP(pSchemas, i);
42,810,318✔
369
      if (tqAddBlockDataToRsp(pBlock, pRsp, pSW, pTq->pVnode->config.tsdbCfg.precision) != 0){
42,866,702✔
370
        tqError("vgId:%d, failed to add block to rsp msg", pTq->pVnode->config.vgId);
×
371
        continue;
×
372
      }
373
      *totalRows += pBlock->info.rows;
42,776,410✔
374
    }
375

376
    pRsp->blockNum++;
42,864,050✔
377
  }
378
  tqTrace("vgId:%d, process sub data success, response blocknum:%d, rows:%d", pTq->pVnode->config.vgId, pRsp->blockNum, *totalRows);
42,940,428✔
379
END:
43,174,138✔
380
  if (code != 0) {
43,005,086✔
381
    tqError("%s failed at %d, failed to process sub data:%s", __FUNCTION__, lino, tstrerror(code));
199,679✔
382
  }
383
  taosArrayDestroyEx(pBlocks, (FDelete)blockDataFreeRes);
43,005,086✔
384
  taosArrayDestroyP(pSchemas, (FDelete)tDeleteSchemaWrapper);
43,040,529✔
385
}
43,093,080✔
386

387
static void preProcessSubmitMsg(STqHandle* pHandle, const SMqPollReq* pRequest, SArray** rawList){
44,226,571✔
388
  STqExecHandle* pExec = &pHandle->execHandle;
44,226,571✔
389
  STqReader* pReader = pExec->pTqReader;
44,235,086✔
390
  int32_t blockSz = taosArrayGetSize(pReader->submit.aSubmitTbData);
44,236,497✔
391
  for (int32_t i = 0; i < blockSz; i++){
88,487,306✔
392
    SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, i);
44,246,181✔
393
    if (pSubmitTbData== NULL){
44,249,584✔
394
      taosArrayDestroy(*rawList);
×
395
      *rawList = NULL;
×
396
      return;
×
397
    }
398

399
    int64_t uid = pSubmitTbData->uid;
44,249,584✔
400
    if (pRequest->rawData) {
44,254,219✔
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){
44,255,361✔
414
      continue;
43,408,722✔
415
    }
416

417
    int64_t createTime = INT64_MAX;
842,749✔
418
    int64_t *cTime = (int64_t*)taosHashGet(pHandle->tableCreateTimeHash, &uid, LONG_BYTES);
843,060✔
419
    if (cTime != NULL){
843,060✔
420
      createTime = *cTime;
2,181✔
421
    } else{
422
      createTime = metaGetTableCreateTime(pReader->pVnodeMeta, uid, 1);
840,879✔
423
      if (createTime != INT64_MAX){
840,257✔
424
        int32_t code = taosHashPut(pHandle->tableCreateTimeHash, &uid, LONG_BYTES, &createTime, LONG_BYTES);
840,879✔
425
        if (code != 0){
840,879✔
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){
842,438✔
431
      tDestroySVSubmitCreateTbReq(pSubmitTbData->pCreateTbReq, TSDB_MSG_FLG_DECODE);
832,280✔
432
      taosMemoryFreeClear(pSubmitTbData->pCreateTbReq);
832,280✔
433
    } else{
434
      taosArrayDestroy(*rawList);
10,469✔
435
      *rawList = NULL;
10,469✔
436
    }
437
  }
438
}
439

440
int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SPackedData submit, SMqDataRsp* pRsp, int32_t* totalRows, const SMqPollReq* pRequest) {
44,239,878✔
441
  int32_t code = 0;
44,239,878✔
442
  int32_t lino = 0;
44,239,878✔
443
  SDecoder decoder = {0};
44,239,878✔
444
  STqExecHandle* pExec = &pHandle->execHandle;
44,242,537✔
445
  STqReader* pReader = pExec->pTqReader;
44,241,956✔
446
  SArray *rawList = NULL;
44,242,246✔
447
  if (pRequest->rawData){
44,242,537✔
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);
44,241,914✔
452
  TSDB_CHECK_CODE(code, lino, END);
44,234,760✔
453
  preProcessSubmitMsg(pHandle, pRequest, &rawList);
44,234,760✔
454
  // data could not contains same uid data in rawdata mode
455
  if (pRequest->rawData != 0 && terrno == TSDB_CODE_TMQ_RAW_DATA_SPLIT){
44,222,616✔
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){
44,235,770✔
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){
44,219,765✔
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) {
44,216,869✔
474
    while (tqNextBlockImpl(pReader, NULL)) {
22,684,987✔
475
      tqProcessSubData(pTq, pHandle, pRsp, totalRows, pRequest, rawList);
10,771,424✔
476
    }
477
  } else if (pExec->subType == TOPIC_SUB_TYPE__DB) {
32,301,024✔
478
    while (tqNextDataBlockFilterOut(pReader, pExec->execDb.pFilterOutTbUid)) {
64,578,092✔
479
      tqProcessSubData(pTq, pHandle, pRsp, totalRows, pRequest, rawList);
32,334,094✔
480
    }
481
  }
482

483
END:
44,137,279✔
484
  tDecoderClear(&decoder);
44,189,539✔
485
  tqReaderClearSubmitMsg(pReader);
44,213,927✔
486
  taosArrayDestroy(rawList);
44,233,238✔
487
  if (code != 0){
44,231,802✔
488
    tqError("%s failed at %d, failed to scan log:%s", __FUNCTION__, lino, tstrerror(code));
×
489
  }
490
  return code;
44,231,802✔
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