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

taosdata / TDengine / #3720

26 Mar 2025 06:20AM UTC coverage: 30.242% (-31.7%) from 61.936%
#3720

push

travis-ci

web-flow
feat(taosBenchmark): supports decimal data type (#30456)

* feat: taosBenchmark supports decimal data type

* build: decimal script not use pytest.sh

* fix: fix typo for decimal script

* test: insertBasic.py debug

71234 of 313946 branches covered (22.69%)

Branch coverage included in aggregate %.

38 of 423 new or added lines in 8 files covered. (8.98%)

120240 existing lines in 447 files now uncovered.

118188 of 312400 relevant lines covered (37.83%)

1450220.33 hits per line

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

15.8
/source/dnode/vnode/src/tq/tqUtil.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

18
static int32_t tqSendMetaPollRsp(STqHandle* pHandle, const SRpcMsg* pMsg, const SMqPollReq* pReq,
19
                                 const SMqMetaRsp* pRsp, int32_t vgId);
20
static int32_t tqSendBatchMetaPollRsp(STqHandle* pHandle, const SRpcMsg* pMsg, const SMqPollReq* pReq,
21
                                      const SMqBatchMetaRsp* pRsp, int32_t vgId);
22

23
int32_t tqInitDataRsp(SMqDataRsp* pRsp, STqOffsetVal pOffset) {
35✔
24
  int32_t    code = TDB_CODE_SUCCESS;
35✔
25
  int32_t    lino = 0;
35✔
26
  tqDebug("%s called", __FUNCTION__ );
35!
27
  TSDB_CHECK_NULL(pRsp, code, lino, END, TSDB_CODE_INVALID_PARA);
35!
28

29
  pRsp->blockData = taosArrayInit(0, sizeof(void*));
35✔
30
  TSDB_CHECK_NULL(pRsp->blockData, code, lino, END, terrno);
35!
31

32
  pRsp->blockDataLen = taosArrayInit(0, sizeof(int32_t));
35✔
33
  TSDB_CHECK_NULL(pRsp->blockDataLen, code, lino, END, terrno);
35!
34

35
  tOffsetCopy(&pRsp->reqOffset, &pOffset);
35✔
36
  tOffsetCopy(&pRsp->rspOffset, &pOffset);
35✔
37
  pRsp->withTbName = 0;
35✔
38
  pRsp->withSchema = false;
35✔
39

40
END:
35✔
41
  if (code != 0){
35!
42
    tqError("%s failed at:%d, code:%s", __FUNCTION__ , lino, tstrerror(code));
×
43
  }
44
  return code;
35✔
45
}
46

47
void tqUpdateNodeStage(STQ* pTq, bool isLeader) {
1,022✔
48
  SSyncState state = syncGetState(pTq->pVnode->sync);
1,022✔
49
  streamMetaUpdateStageRole(pTq->pStreamMeta, state.term, isLeader);
1,022✔
50

51
  if (isLeader) {
1,022✔
52
    tqScanWalAsync(pTq);
216✔
53
  }
54
}
1,022✔
55

UNCOV
56
static int32_t tqInitTaosxRsp(SMqDataRsp* pRsp, STqOffsetVal pOffset) {
×
UNCOV
57
  int32_t    code = TDB_CODE_SUCCESS;
×
UNCOV
58
  int32_t    lino = 0;
×
UNCOV
59
  tqDebug("%s called", __FUNCTION__ );
×
UNCOV
60
  TSDB_CHECK_NULL(pRsp, code, lino, END, TSDB_CODE_INVALID_PARA);
×
UNCOV
61
  tOffsetCopy(&pRsp->reqOffset, &pOffset);
×
UNCOV
62
  tOffsetCopy(&pRsp->rspOffset, &pOffset);
×
63

UNCOV
64
  pRsp->withTbName = 1;
×
UNCOV
65
  pRsp->withSchema = 1;
×
UNCOV
66
  pRsp->blockData = taosArrayInit(0, sizeof(void*));
×
UNCOV
67
  TSDB_CHECK_NULL(pRsp->blockData, code, lino, END, terrno);\
×
68

UNCOV
69
  pRsp->blockDataLen = taosArrayInit(0, sizeof(int32_t));
×
UNCOV
70
  TSDB_CHECK_NULL(pRsp->blockDataLen, code, lino, END, terrno);
×
71

UNCOV
72
  pRsp->blockTbName = taosArrayInit(0, sizeof(void*));
×
UNCOV
73
  TSDB_CHECK_NULL(pRsp->blockTbName, code, lino, END, terrno);
×
74

UNCOV
75
  pRsp->blockSchema = taosArrayInit(0, sizeof(void*));
×
UNCOV
76
  TSDB_CHECK_NULL(pRsp->blockSchema, code, lino, END, terrno);
×
77

UNCOV
78
END:
×
UNCOV
79
  if (code != 0){
×
80
    tqError("%s failed at:%d, code:%s", __FUNCTION__ , lino, tstrerror(code));
×
81
    taosArrayDestroy(pRsp->blockData);
×
82
    taosArrayDestroy(pRsp->blockDataLen);
×
83
    taosArrayDestroy(pRsp->blockTbName);
×
84
    taosArrayDestroy(pRsp->blockSchema);
×
85
  }
UNCOV
86
  return code;
×
87
}
88

89
static int32_t extractResetOffsetVal(STqOffsetVal* pOffsetVal, STQ* pTq, STqHandle* pHandle, const SMqPollReq* pRequest,
12✔
90
                                     SRpcMsg* pMsg, bool* pBlockReturned) {
91
  if (pOffsetVal == NULL || pTq == NULL || pHandle == NULL || pRequest == NULL || pMsg == NULL || pBlockReturned == NULL) {
12!
92
    return TSDB_CODE_INVALID_PARA;
×
93
  }
94
  uint64_t   consumerId = pRequest->consumerId;
12✔
95
  STqOffset* pOffset = NULL;
12✔
96
  int32_t    code = tqMetaGetOffset(pTq, pRequest->subKey, &pOffset);
12✔
97
  int32_t    vgId = TD_VID(pTq->pVnode);
12✔
98

99
  *pBlockReturned = false;
12✔
100
  // In this vnode, data has been polled by consumer for this topic, so let's continue from the last offset value.
101
  if (code == 0) {
12✔
102
    tOffsetCopy(pOffsetVal, &pOffset->val);
3✔
103

104
    char formatBuf[TSDB_OFFSET_LEN] = {0};
3✔
105
    tFormatOffset(formatBuf, TSDB_OFFSET_LEN, pOffsetVal);
3✔
106
    tqDebug("tmq poll: consumer:0x%" PRIx64
3!
107
                ", subkey %s, vgId:%d, existed offset found, offset reset to %s and continue.QID:0x%" PRIx64,
108
            consumerId, pHandle->subKey, vgId, formatBuf, pRequest->reqId);
109
    return 0;
3✔
110
  } else {
111
    // no poll occurs in this vnode for this topic, let's seek to the right offset value.
112
    if (pRequest->reqOffset.type == TMQ_OFFSET__RESET_EARLIEST) {
9!
113
      if (pRequest->useSnapshot) {
9!
UNCOV
114
        tqDebug("tmq poll: consumer:0x%" PRIx64 ", subkey:%s, vgId:%d, (earliest) set offset to be snapshot",
×
115
                consumerId, pHandle->subKey, vgId);
UNCOV
116
        if (pHandle->fetchMeta) {
×
117
          tqOffsetResetToMeta(pOffsetVal, 0);
118
        } else {
UNCOV
119
          SValue val = {0};
×
UNCOV
120
          tqOffsetResetToData(pOffsetVal, 0, 0, val);
×
121
        }
122
      } else {
123
        walRefFirstVer(pTq->pVnode->pWal, pHandle->pRef);
9✔
124
        tqOffsetResetToLog(pOffsetVal, pHandle->pRef->refVer);
9✔
125
      }
UNCOV
126
    } else if (pRequest->reqOffset.type == TMQ_OFFSET__RESET_LATEST) {
×
UNCOV
127
      walRefLastVer(pTq->pVnode->pWal, pHandle->pRef);
×
UNCOV
128
      SMqDataRsp dataRsp = {0};
×
UNCOV
129
      tqOffsetResetToLog(pOffsetVal, pHandle->pRef->refVer + 1);
×
130

UNCOV
131
      code = tqInitDataRsp(&dataRsp, *pOffsetVal);
×
UNCOV
132
      if (code != 0) {
×
133
        return code;
×
134
      }
UNCOV
135
      tqDebug("tmq poll: consumer:0x%" PRIx64 ", subkey %s, vgId:%d, (latest) offset reset to %" PRId64, consumerId,
×
136
              pHandle->subKey, vgId, dataRsp.rspOffset.version);
UNCOV
137
      code = tqSendDataRsp(pHandle, pMsg, pRequest, &dataRsp, (pRequest->rawData == 1) ? TMQ_MSG_TYPE__POLL_RAW_DATA_RSP : TMQ_MSG_TYPE__POLL_DATA_RSP, vgId);
×
UNCOV
138
      tDeleteMqDataRsp(&dataRsp);
×
139

UNCOV
140
      *pBlockReturned = true;
×
UNCOV
141
      return code;
×
UNCOV
142
    } else if (pRequest->reqOffset.type == TMQ_OFFSET__RESET_NONE) {
×
UNCOV
143
      tqError("tmq poll: subkey:%s, no offset committed for consumer:0x%" PRIx64
×
144
                  " in vg %d, subkey %s, reset none failed",
145
              pHandle->subKey, consumerId, vgId, pRequest->subKey);
UNCOV
146
      return TSDB_CODE_TQ_NO_COMMITTED_OFFSET;
×
147
    }
148
  }
149

150
  return 0;
9✔
151
}
152

153
static int32_t extractDataAndRspForNormalSubscribe(STQ* pTq, STqHandle* pHandle, const SMqPollReq* pRequest,
29✔
154
                                                   SRpcMsg* pMsg, STqOffsetVal* pOffset) {
155
  int32_t    code = TDB_CODE_SUCCESS;
29✔
156
  int32_t    lino = 0;
29✔
157
  tqDebug("%s called", __FUNCTION__ );
29!
158
  uint64_t consumerId = pRequest->consumerId;
29✔
159
  int32_t  vgId = TD_VID(pTq->pVnode);
29✔
160
  terrno = 0;
29✔
161

162
  SMqDataRsp dataRsp = {0};
29✔
163
  code = tqInitDataRsp(&dataRsp, *pOffset);
29✔
164
  TSDB_CHECK_CODE(code, lino, end);
29!
165

166
  code = qSetTaskId(pHandle->execHandle.task, consumerId, pRequest->reqId);
29✔
167
  TSDB_CHECK_CODE(code, lino, end);
29!
168

169
  code = tqScanData(pTq, pHandle, &dataRsp, pOffset, pRequest);
29✔
170
  if (code != 0 && terrno != TSDB_CODE_WAL_LOG_NOT_EXIST) {
29!
UNCOV
171
    goto end;
×
172
  }
173

174
  //   till now, all data has been transferred to consumer, new data needs to push client once arrived.
175
  if (terrno == TSDB_CODE_WAL_LOG_NOT_EXIST && dataRsp.blockNum == 0) {
29!
176
    // lock
177
    taosWLockLatch(&pTq->lock);
12✔
178
    int64_t ver = walGetCommittedVer(pTq->pVnode->pWal);
12✔
179
    if (dataRsp.rspOffset.version > ver) {  // check if there are data again to avoid lost data
12✔
180
      code = tqRegisterPushHandle(pTq, pHandle, pMsg);
7✔
181
      taosWUnLockLatch(&pTq->lock);
7✔
182
      goto end;
7✔
183
    }
184
    taosWUnLockLatch(&pTq->lock);
5✔
185
  }
186

187
  // reqOffset represents the current date offset, may be changed if wal not exists
188
  tOffsetCopy(&dataRsp.reqOffset, pOffset);
22✔
189
  code = tqSendDataRsp(pHandle, pMsg, pRequest, &dataRsp, TMQ_MSG_TYPE__POLL_DATA_RSP, vgId);
22✔
190

191
end:
29✔
192
  {
193
    char buf[TSDB_OFFSET_LEN] = {0};
29✔
194
    tFormatOffset(buf, TSDB_OFFSET_LEN, &dataRsp.rspOffset);
29✔
195
    if (code != 0){
29!
UNCOV
196
      tqError("tmq poll: consumer:0x%" PRIx64 ", subkey %s, vgId:%d, rsp block:%d, rsp offset type:%s, QID:0x%" PRIx64 " error msg:%s, line:%d",
×
197
              consumerId, pHandle->subKey, vgId, dataRsp.blockNum, buf, pRequest->reqId, tstrerror(code), lino);
198
    } else {
199
      tqDebug("tmq poll: consumer:0x%" PRIx64 ", subkey %s, vgId:%d, rsp block:%d, rsp offset type:%s, QID:0x%" PRIx64 " success",
29!
200
              consumerId, pHandle->subKey, vgId, dataRsp.blockNum, buf, pRequest->reqId);
201
    }
202

203
    tDeleteMqDataRsp(&dataRsp);
29✔
204
    return code;
29✔
205
  }
206
}
207

208
#define PROCESS_EXCLUDED_MSG(TYPE, DECODE_FUNC, DELETE_FUNC)                                               \
209
  SDecoder decoder = {0};                                                                                  \
210
  TYPE     req = {0};                                                                                      \
211
  void*    data = POINTER_SHIFT(pHead->body, sizeof(SMsgHead));                                            \
212
  int32_t  len = pHead->bodyLen - sizeof(SMsgHead);                                                        \
213
  tDecoderInit(&decoder, data, len);                                                                       \
214
  if (DECODE_FUNC(&decoder, &req) == 0 && (req.source & TD_REQ_FROM_TAOX) != 0) {                          \
215
    tqDebug("tmq poll: consumer:0x%" PRIx64 " (epoch %d) iter log, jump meta for, vgId:%d offset %" PRId64 \
216
            " msgType %d",                                                                                 \
217
            pRequest->consumerId, pRequest->epoch, vgId, fetchVer, pHead->msgType);                        \
218
    fetchVer++;                                                                                            \
219
    DELETE_FUNC(&req);                                                                                     \
220
    tDecoderClear(&decoder);                                                                               \
221
    continue;                                                                                              \
222
  }                                                                                                        \
223
  DELETE_FUNC(&req);                                                                                       \
224
  tDecoderClear(&decoder);
225

UNCOV
226
static void tDeleteCommon(void* parm) {}
×
227

228
#define POLL_RSP_TYPE(pRequest,taosxRsp) \
229
taosxRsp.createTableNum > 0 ? TMQ_MSG_TYPE__POLL_DATA_META_RSP : \
230
(pRequest->rawData == 1 ? TMQ_MSG_TYPE__POLL_RAW_DATA_RSP : TMQ_MSG_TYPE__POLL_DATA_RSP)
231

UNCOV
232
static int32_t buildBatchMeta(SMqBatchMetaRsp *btMetaRsp, int16_t type, int32_t bodyLen, void* body){
×
UNCOV
233
  int32_t         code = 0;
×
234

UNCOV
235
  if (!btMetaRsp->batchMetaReq) {
×
UNCOV
236
    btMetaRsp->batchMetaReq = taosArrayInit(4, POINTER_BYTES);
×
UNCOV
237
    TQ_NULL_GO_TO_END(btMetaRsp->batchMetaReq);
×
UNCOV
238
    btMetaRsp->batchMetaLen = taosArrayInit(4, sizeof(int32_t));
×
UNCOV
239
    TQ_NULL_GO_TO_END(btMetaRsp->batchMetaLen);
×
240
  }
241

UNCOV
242
  SMqMetaRsp tmpMetaRsp = {0};
×
UNCOV
243
  tmpMetaRsp.resMsgType = type;
×
UNCOV
244
  tmpMetaRsp.metaRspLen = bodyLen;
×
UNCOV
245
  tmpMetaRsp.metaRsp = body;
×
UNCOV
246
  uint32_t len = 0;
×
UNCOV
247
  tEncodeSize(tEncodeMqMetaRsp, &tmpMetaRsp, len, code);
×
UNCOV
248
  if (TSDB_CODE_SUCCESS != code) {
×
249
    tqError("tmq extract meta from log, tEncodeMqMetaRsp error");
×
250
    goto END;
×
251
  }
UNCOV
252
  int32_t tLen = sizeof(SMqRspHead) + len;
×
UNCOV
253
  void*   tBuf = taosMemoryCalloc(1, tLen);
×
UNCOV
254
  TQ_NULL_GO_TO_END(tBuf);
×
UNCOV
255
  void*    metaBuff = POINTER_SHIFT(tBuf, sizeof(SMqRspHead));
×
UNCOV
256
  SEncoder encoder = {0};
×
UNCOV
257
  tEncoderInit(&encoder, metaBuff, len);
×
UNCOV
258
  code = tEncodeMqMetaRsp(&encoder, &tmpMetaRsp);
×
UNCOV
259
  tEncoderClear(&encoder);
×
260

UNCOV
261
  if (code < 0) {
×
262
    tqError("tmq extract meta from log, tEncodeMqMetaRsp error");
×
263
    goto END;
×
264
  }
UNCOV
265
  TQ_NULL_GO_TO_END (taosArrayPush(btMetaRsp->batchMetaReq, &tBuf));
×
UNCOV
266
  TQ_NULL_GO_TO_END (taosArrayPush(btMetaRsp->batchMetaLen, &tLen));
×
267

UNCOV
268
END:
×
UNCOV
269
  return code;
×
270
}
271

UNCOV
272
static int32_t buildCreateTbBatchReqBinary(SMqDataRsp *taosxRsp, void** pBuf, int32_t *len){
×
UNCOV
273
  int32_t code = 0;
×
UNCOV
274
  SVCreateTbBatchReq pReq = {0};
×
UNCOV
275
  pReq.nReqs = taosArrayGetSize(taosxRsp->createTableReq);
×
UNCOV
276
  pReq.pArray = taosArrayInit(1, sizeof(struct SVCreateTbReq));
×
UNCOV
277
  TQ_NULL_GO_TO_END(pReq.pArray);
×
UNCOV
278
  for (int i = 0; i < taosArrayGetSize(taosxRsp->createTableReq); i++){
×
UNCOV
279
    void   *createTableReq = taosArrayGetP(taosxRsp->createTableReq, i);
×
UNCOV
280
    TQ_NULL_GO_TO_END(taosArrayPush(pReq.pArray, createTableReq));
×
281
  }
UNCOV
282
  tEncodeSize(tEncodeSVCreateTbBatchReq, &pReq, *len, code);
×
UNCOV
283
  if (code < 0) {
×
284
    goto END;
×
285
  }
UNCOV
286
  *len += sizeof(SMsgHead);
×
UNCOV
287
  *pBuf = taosMemoryMalloc(*len);
×
UNCOV
288
  TQ_NULL_GO_TO_END(pBuf);
×
UNCOV
289
  SEncoder coder = {0};
×
UNCOV
290
  tEncoderInit(&coder, POINTER_SHIFT(*pBuf, sizeof(SMsgHead)), *len);
×
UNCOV
291
  code = tEncodeSVCreateTbBatchReq(&coder, &pReq);
×
UNCOV
292
  tEncoderClear(&coder);
×
293

UNCOV
294
END:
×
UNCOV
295
  taosArrayDestroy(pReq.pArray);
×
UNCOV
296
  return code;
×
297
}
298

299
#define SEND_BATCH_META_RSP \
300
tqOffsetResetToLog(&btMetaRsp.rspOffset, fetchVer);\
301
code = tqSendBatchMetaPollRsp(pHandle, pMsg, pRequest, &btMetaRsp, vgId);\
302
goto END;
303

304
#define SEND_DATA_RSP \
305
tqOffsetResetToLog(&taosxRsp.rspOffset, fetchVer);\
306
code = tqSendDataRsp(pHandle, pMsg, pRequest, &taosxRsp, POLL_RSP_TYPE(pRequest, taosxRsp), vgId);\
307
goto END;
UNCOV
308
static int32_t extractDataAndRspForDbStbSubscribe(STQ* pTq, STqHandle* pHandle, const SMqPollReq* pRequest,
×
309
                                                  SRpcMsg* pMsg, STqOffsetVal* offset) {
UNCOV
310
  int32_t         vgId = TD_VID(pTq->pVnode);
×
UNCOV
311
  SMqDataRsp      taosxRsp = {0};
×
UNCOV
312
  SMqBatchMetaRsp btMetaRsp = {0};
×
UNCOV
313
  int32_t         code = 0;
×
314

UNCOV
315
  TQ_ERR_GO_TO_END(tqInitTaosxRsp(&taosxRsp, *offset));
×
UNCOV
316
  if (offset->type != TMQ_OFFSET__LOG) {
×
UNCOV
317
    TQ_ERR_GO_TO_END(tqScanTaosx(pTq, pHandle, &taosxRsp, &btMetaRsp, offset, pRequest));
×
318

UNCOV
319
    if (taosArrayGetSize(btMetaRsp.batchMetaReq) > 0) {
×
UNCOV
320
      code = tqSendBatchMetaPollRsp(pHandle, pMsg, pRequest, &btMetaRsp, vgId);
×
UNCOV
321
      tqDebug("tmq poll: consumer:0x%" PRIx64 " subkey:%s vgId:%d, send meta offset type:%d,uid:%" PRId64 ",ts:%" PRId64,
×
322
              pRequest->consumerId, pHandle->subKey, vgId, btMetaRsp.rspOffset.type, btMetaRsp.rspOffset.uid,btMetaRsp.rspOffset.ts);
UNCOV
323
      goto END;
×
324
    }
325

UNCOV
326
    tqDebug("taosx poll: consumer:0x%" PRIx64 " subkey:%s vgId:%d, send data blockNum:%d, offset type:%d,uid:%" PRId64",ts:%" PRId64,
×
327
            pRequest->consumerId, pHandle->subKey, vgId, taosxRsp.blockNum, taosxRsp.rspOffset.type, taosxRsp.rspOffset.uid, taosxRsp.rspOffset.ts);
UNCOV
328
    if (taosxRsp.blockNum > 0) {
×
UNCOV
329
      code = tqSendDataRsp(pHandle, pMsg, pRequest, &taosxRsp, TMQ_MSG_TYPE__POLL_DATA_RSP, vgId);
×
UNCOV
330
      goto END;
×
331
    } else {
UNCOV
332
      tOffsetCopy(offset, &taosxRsp.rspOffset);
×
333
    }
334
  }
335

UNCOV
336
  if (offset->type == TMQ_OFFSET__LOG) {
×
UNCOV
337
    walReaderVerifyOffset(pHandle->pWalReader, offset);
×
UNCOV
338
    int64_t fetchVer = offset->version;
×
339

UNCOV
340
    uint64_t st = taosGetTimestampMs();
×
UNCOV
341
    int      totalRows = 0;
×
UNCOV
342
    int32_t  totalMetaRows = 0;
×
UNCOV
343
    while (1) {
×
UNCOV
344
      int32_t savedEpoch = atomic_load_32(&pHandle->epoch);
×
UNCOV
345
      if (savedEpoch > pRequest->epoch) {
×
346
        tqError("tmq poll: consumer:0x%" PRIx64 " (epoch %d) iter log, savedEpoch error, vgId:%d offset %" PRId64,
×
347
                pRequest->consumerId, pRequest->epoch, vgId, fetchVer);
348
        code = TSDB_CODE_TQ_INTERNAL_ERROR;
×
UNCOV
349
        goto END;
×
350
      }
351

UNCOV
352
      if (tqFetchLog(pTq, pHandle, &fetchVer, pRequest->reqId) < 0) {
×
UNCOV
353
        if (totalMetaRows > 0) {
×
UNCOV
354
          SEND_BATCH_META_RSP
×
355
        }
UNCOV
356
        SEND_DATA_RSP
×
357
      }
358

UNCOV
359
      SWalCont* pHead = &pHandle->pWalReader->pHead->head;
×
UNCOV
360
      tqDebug("tmq poll: consumer:0x%" PRIx64 " (epoch %d) iter log, vgId:%d offset %" PRId64 " msgType %s",
×
361
              pRequest->consumerId, pRequest->epoch, vgId, fetchVer, TMSG_INFO(pHead->msgType));
362

363
      // process meta
UNCOV
364
      if (pHead->msgType != TDMT_VND_SUBMIT) {
×
UNCOV
365
        if (totalRows > 0) {
×
UNCOV
366
          SEND_DATA_RSP
×
367
        }
368

UNCOV
369
        if ((pRequest->sourceExcluded & TD_REQ_FROM_TAOX) != 0) {
×
UNCOV
370
          if (pHead->msgType == TDMT_VND_CREATE_TABLE) {
×
UNCOV
371
            PROCESS_EXCLUDED_MSG(SVCreateTbBatchReq, tDecodeSVCreateTbBatchReq, tDeleteSVCreateTbBatchReq)
×
UNCOV
372
          } else if (pHead->msgType == TDMT_VND_ALTER_TABLE) {
×
UNCOV
373
            PROCESS_EXCLUDED_MSG(SVAlterTbReq, tDecodeSVAlterTbReq, tDeleteCommon)
×
UNCOV
374
          } else if (pHead->msgType == TDMT_VND_CREATE_STB || pHead->msgType == TDMT_VND_ALTER_STB) {
×
UNCOV
375
            PROCESS_EXCLUDED_MSG(SVCreateStbReq, tDecodeSVCreateStbReq, tDeleteCommon)
×
UNCOV
376
          } else if (pHead->msgType == TDMT_VND_DELETE) {
×
UNCOV
377
            PROCESS_EXCLUDED_MSG(SDeleteRes, tDecodeDeleteRes, tDeleteCommon)
×
378
          }
379
        }
380

UNCOV
381
        tqDebug("fetch meta msg, ver:%" PRId64 ", vgId:%d, type:%s, enable batch meta:%d", pHead->version, vgId,
×
382
                TMSG_INFO(pHead->msgType), pRequest->enableBatchMeta);
UNCOV
383
        if (!pRequest->enableBatchMeta && !pRequest->useSnapshot) {
×
UNCOV
384
          SMqMetaRsp metaRsp = {0};
×
UNCOV
385
          tqOffsetResetToLog(&metaRsp.rspOffset, fetchVer + 1);
×
UNCOV
386
          metaRsp.resMsgType = pHead->msgType;
×
UNCOV
387
          metaRsp.metaRspLen = pHead->bodyLen;
×
UNCOV
388
          metaRsp.metaRsp = pHead->body;
×
UNCOV
389
          code = tqSendMetaPollRsp(pHandle, pMsg, pRequest, &metaRsp, vgId);
×
UNCOV
390
          goto END;
×
391
        }
UNCOV
392
        code = buildBatchMeta(&btMetaRsp, pHead->msgType, pHead->bodyLen, pHead->body);
×
UNCOV
393
        fetchVer++;
×
UNCOV
394
        if (code != 0){
×
395
          goto END;
×
396
        }
UNCOV
397
        totalMetaRows++;
×
UNCOV
398
        if ((taosArrayGetSize(btMetaRsp.batchMetaReq) >= tmqRowSize) || (taosGetTimestampMs() - st > pRequest->timeout)) {
×
399
          SEND_BATCH_META_RSP
×
400
        }
UNCOV
401
        continue;
×
402
      }
403

UNCOV
404
      if (totalMetaRows > 0 && pHandle->fetchMeta != ONLY_META) {
×
405
        SEND_BATCH_META_RSP
×
406
      }
407

408
      // process data
UNCOV
409
      SPackedData submit = {
×
UNCOV
410
          .msgStr = POINTER_SHIFT(pHead->body, sizeof(SSubmitReq2Msg)),
×
UNCOV
411
          .msgLen = pHead->bodyLen - sizeof(SSubmitReq2Msg),
×
UNCOV
412
          .ver = pHead->version,
×
413
      };
414

UNCOV
415
      TQ_ERR_GO_TO_END(tqTaosxScanLog(pTq, pHandle, submit, &taosxRsp, &totalRows, pRequest));
×
416

UNCOV
417
      if (pHandle->fetchMeta == ONLY_META && taosArrayGetSize(taosxRsp.createTableReq) > 0){
×
UNCOV
418
        int32_t len = 0;
×
UNCOV
419
        void *pBuf = NULL;
×
UNCOV
420
        code = buildCreateTbBatchReqBinary(&taosxRsp, &pBuf, &len);
×
UNCOV
421
        if (code == 0){
×
UNCOV
422
          code = buildBatchMeta(&btMetaRsp, TDMT_VND_CREATE_TABLE, len, pBuf);
×
423
        }
UNCOV
424
        taosMemoryFree(pBuf);
×
UNCOV
425
        taosArrayDestroyP(taosxRsp.createTableReq, NULL);
×
UNCOV
426
        taosxRsp.createTableReq = NULL;
×
UNCOV
427
        fetchVer++;
×
UNCOV
428
        if (code != 0){
×
UNCOV
429
          goto END;
×
430
        }
UNCOV
431
        totalMetaRows++;
×
UNCOV
432
        if ((taosArrayGetSize(btMetaRsp.batchMetaReq) >= tmqRowSize) ||
×
UNCOV
433
            (taosGetTimestampMs() - st > pRequest->timeout) ||
×
UNCOV
434
            (!pRequest->enableBatchMeta && !pRequest->useSnapshot)) {
×
UNCOV
435
          SEND_BATCH_META_RSP
×
436
        }
437
        continue;
×
438
      }
439

UNCOV
440
      if ((pRequest->rawData == 0 && totalRows >= pRequest->minPollRows) ||
×
UNCOV
441
          (taosGetTimestampMs() - st > pRequest->timeout) ||
×
UNCOV
442
          (pRequest->rawData != 0 && (taosArrayGetSize(taosxRsp.blockData) > pRequest->minPollRows ||
×
UNCOV
443
                                      terrno == TSDB_CODE_TMQ_RAW_DATA_SPLIT))) {
×
UNCOV
444
        if (terrno == TSDB_CODE_TMQ_RAW_DATA_SPLIT){
×
UNCOV
445
          terrno = 0;
×
446
        } else{
UNCOV
447
          fetchVer++;
×
448
        }
UNCOV
449
        SEND_DATA_RSP
×
450
      } else {
UNCOV
451
        fetchVer++;
×
452
      }
453
    }
454
  }
455

456
END:
×
UNCOV
457
  if (code != 0){
×
458
    tqError("tmq poll: tqTaosxScanLog error. consumerId:0x%" PRIx64 ", in vgId:%d, subkey %s", pRequest->consumerId, vgId,
×
459
            pRequest->subKey);
460
  }
UNCOV
461
  tDeleteMqBatchMetaRsp(&btMetaRsp);
×
UNCOV
462
  tDeleteSTaosxRsp(&taosxRsp);
×
UNCOV
463
  return code;
×
464
}
465

466
int32_t tqExtractDataForMq(STQ* pTq, STqHandle* pHandle, const SMqPollReq* pRequest, SRpcMsg* pMsg) {
29✔
467
  if (pTq == NULL || pHandle == NULL || pRequest == NULL || pMsg == NULL) {
29!
468
    return TSDB_CODE_TMQ_INVALID_MSG;
×
469
  }
470
  int32_t      code = 0;
29✔
471
  STqOffsetVal reqOffset = {0};
29✔
472
  tOffsetCopy(&reqOffset, &pRequest->reqOffset);
29✔
473

474
  // reset the offset if needed
475
  if (IS_OFFSET_RESET_TYPE(pRequest->reqOffset.type)) {
29✔
476
    bool blockReturned = false;
12✔
477
    code = extractResetOffsetVal(&reqOffset, pTq, pHandle, pRequest, pMsg, &blockReturned);
12✔
478
    if (code != 0) {
12!
UNCOV
479
      goto END;
×
480
    }
481

482
    // empty block returned, quit
483
    if (blockReturned) {
12!
UNCOV
484
      goto END;
×
485
    }
486
  } else if (reqOffset.type == 0) {  // use the consumer specified offset
17!
487
    uError("req offset type is 0");
×
488
    code = TSDB_CODE_TMQ_INVALID_MSG;
×
489
    goto END;
×
490
  }
491

492
  if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
29!
493
    code = extractDataAndRspForNormalSubscribe(pTq, pHandle, pRequest, pMsg, &reqOffset);
29✔
494
  } else {
UNCOV
495
    code = extractDataAndRspForDbStbSubscribe(pTq, pHandle, pRequest, pMsg, &reqOffset);
×
496
  }
497

498
END:
29✔
499
  if (code != 0){
29!
UNCOV
500
    uError("failed to extract data for mq, msg:%s", tstrerror(code));
×
501
  }
502
  tOffsetDestroy(&reqOffset);
29✔
503
  return code;
29✔
504
}
505

506
static void initMqRspHead(SMqRspHead* pMsgHead, int32_t type, int32_t epoch, int64_t consumerId, int64_t sver,
28✔
507
                          int64_t ever) {
508
  if (pMsgHead == NULL) {
28!
509
    return;
×
510
  }
511
  pMsgHead->consumerId = consumerId;
28✔
512
  pMsgHead->epoch = epoch;
28✔
513
  pMsgHead->mqMsgType = type;
28✔
514
  pMsgHead->walsver = sver;
28✔
515
  pMsgHead->walever = ever;
28✔
516
}
517

UNCOV
518
int32_t tqSendBatchMetaPollRsp(STqHandle* pHandle, const SRpcMsg* pMsg, const SMqPollReq* pReq,
×
519
                               const SMqBatchMetaRsp* pRsp, int32_t vgId) {
UNCOV
520
  if (pHandle == NULL || pMsg == NULL || pReq == NULL || pRsp == NULL) {
×
521
    return TSDB_CODE_TMQ_INVALID_MSG;
×
522
  }
UNCOV
523
  int32_t len = 0;
×
UNCOV
524
  int32_t code = 0;
×
UNCOV
525
  tEncodeSize(tEncodeMqBatchMetaRsp, pRsp, len, code);
×
UNCOV
526
  if (code < 0) {
×
527
    return TAOS_GET_TERRNO(code);
×
528
  }
UNCOV
529
  int32_t tlen = sizeof(SMqRspHead) + len;
×
UNCOV
530
  void*   buf = rpcMallocCont(tlen);
×
UNCOV
531
  if (buf == NULL) {
×
532
    return TAOS_GET_TERRNO(terrno);
×
533
  }
534

UNCOV
535
  int64_t sver = 0, ever = 0;
×
UNCOV
536
  walReaderValidVersionRange(pHandle->execHandle.pTqReader->pWalReader, &sver, &ever);
×
UNCOV
537
  initMqRspHead(buf, TMQ_MSG_TYPE__POLL_BATCH_META_RSP, pReq->epoch, pReq->consumerId, sver, ever);
×
538

UNCOV
539
  void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
×
540

UNCOV
541
  SEncoder encoder = {0};
×
UNCOV
542
  tEncoderInit(&encoder, abuf, len);
×
UNCOV
543
  code = tEncodeMqBatchMetaRsp(&encoder, pRsp);
×
UNCOV
544
  tEncoderClear(&encoder);
×
UNCOV
545
  if (code < 0) {
×
546
    rpcFreeCont(buf);
×
547
    return TAOS_GET_TERRNO(code);
×
548
  }
UNCOV
549
  SRpcMsg resp = {.info = pMsg->info, .pCont = buf, .contLen = tlen, .code = 0};
×
550

UNCOV
551
  tmsgSendRsp(&resp);
×
UNCOV
552
  tqDebug("vgId:%d, from consumer:0x%" PRIx64 " (epoch %d) send rsp, res msg type: batch meta, size:%ld offset type:%d",
×
553
          vgId, pReq->consumerId, pReq->epoch, taosArrayGetSize(pRsp->batchMetaReq), pRsp->rspOffset.type);
554

UNCOV
555
  return 0;
×
556
}
557

UNCOV
558
int32_t tqSendMetaPollRsp(STqHandle* pHandle, const SRpcMsg* pMsg, const SMqPollReq* pReq, const SMqMetaRsp* pRsp,
×
559
                          int32_t vgId) {
UNCOV
560
  if (pHandle == NULL || pMsg == NULL || pReq == NULL || pRsp == NULL) {
×
561
    return TSDB_CODE_TMQ_INVALID_MSG;
×
562
  }
UNCOV
563
  int32_t len = 0;
×
UNCOV
564
  int32_t code = 0;
×
UNCOV
565
  tEncodeSize(tEncodeMqMetaRsp, pRsp, len, code);
×
UNCOV
566
  if (code < 0) {
×
567
    return TAOS_GET_TERRNO(code);
×
568
  }
UNCOV
569
  int32_t tlen = sizeof(SMqRspHead) + len;
×
UNCOV
570
  void*   buf = rpcMallocCont(tlen);
×
UNCOV
571
  if (buf == NULL) {
×
572
    return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
×
573
  }
574

UNCOV
575
  int64_t sver = 0, ever = 0;
×
UNCOV
576
  walReaderValidVersionRange(pHandle->execHandle.pTqReader->pWalReader, &sver, &ever);
×
UNCOV
577
  initMqRspHead(buf, TMQ_MSG_TYPE__POLL_META_RSP, pReq->epoch, pReq->consumerId, sver, ever);
×
578

UNCOV
579
  void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
×
580

UNCOV
581
  SEncoder encoder = {0};
×
UNCOV
582
  tEncoderInit(&encoder, abuf, len);
×
UNCOV
583
  code = tEncodeMqMetaRsp(&encoder, pRsp);
×
UNCOV
584
  tEncoderClear(&encoder);
×
UNCOV
585
  if (code < 0) {
×
586
    rpcFreeCont(buf);
×
587
    return TAOS_GET_TERRNO(code);
×
588
  }
589

UNCOV
590
  SRpcMsg resp = {.info = pMsg->info, .pCont = buf, .contLen = tlen, .code = 0};
×
591

UNCOV
592
  tmsgSendRsp(&resp);
×
UNCOV
593
  tqDebug("vgId:%d, from consumer:0x%" PRIx64 " (epoch %d) send rsp, res msg type %d, offset type:%d", vgId,
×
594
          pReq->consumerId, pReq->epoch, pRsp->resMsgType, pRsp->rspOffset.type);
595

UNCOV
596
  return 0;
×
597
}
598

599
int32_t tqDoSendDataRsp(const SRpcHandleInfo* pRpcHandleInfo, SMqDataRsp* pRsp, int32_t epoch, int64_t consumerId,
28✔
600
                        int32_t type, int64_t sver, int64_t ever) {
601
  if (pRpcHandleInfo == NULL || pRsp == NULL) {
28!
602
    return TSDB_CODE_TMQ_INVALID_MSG;
×
603
  }
604
  int32_t len = 0;
28✔
605
  int32_t code = 0;
28✔
606

607
  if (type == TMQ_MSG_TYPE__POLL_RAW_DATA_RSP){
28!
UNCOV
608
    pRsp->withSchema = 0;
×
609
  }
610
  if (type == TMQ_MSG_TYPE__POLL_DATA_RSP ||
28!
UNCOV
611
      type == TMQ_MSG_TYPE__WALINFO_RSP ||
×
612
      type == TMQ_MSG_TYPE__POLL_RAW_DATA_RSP) {
613
    tEncodeSize(tEncodeMqDataRsp, pRsp, len, code);
28!
UNCOV
614
  } else if (type == TMQ_MSG_TYPE__POLL_DATA_META_RSP) {
×
UNCOV
615
    tEncodeSize(tEncodeSTaosxRsp, pRsp, len, code);
×
616
  }
617

618
  if (code < 0) {
28!
619
    return TAOS_GET_TERRNO(code);
×
620
  }
621

622
  int32_t tlen = sizeof(SMqRspHead) + len;
28✔
623
  void*   buf = rpcMallocCont(tlen);
28✔
624
  if (buf == NULL) {
28!
625
    return terrno;
×
626
  }
627

628
  SMqRspHead* pHead = (SMqRspHead*)buf;
28✔
629
  initMqRspHead(pHead, type, epoch, consumerId, sver, ever);
28✔
630

631
  void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
28✔
632

633
  SEncoder encoder = {0};
28✔
634
  tEncoderInit(&encoder, abuf, len);
28✔
635

636
  if (type == TMQ_MSG_TYPE__POLL_DATA_RSP ||
28!
UNCOV
637
      type == TMQ_MSG_TYPE__WALINFO_RSP ||
×
638
      type == TMQ_MSG_TYPE__POLL_RAW_DATA_RSP) {
639
    code = tEncodeMqDataRsp(&encoder, pRsp);
28✔
UNCOV
640
  } else if (type == TMQ_MSG_TYPE__POLL_DATA_META_RSP) {
×
UNCOV
641
    code = tEncodeSTaosxRsp(&encoder, pRsp);
×
642
  }
643
  tEncoderClear(&encoder);
28✔
644
  if (code < 0) {
28!
645
    rpcFreeCont(buf);
×
646
    return TAOS_GET_TERRNO(code);
×
647
  }
648
  SRpcMsg rsp = {.info = *pRpcHandleInfo, .pCont = buf, .contLen = tlen, .code = 0};
28✔
649

650
  tmsgSendRsp(&rsp);
28✔
651
  return 0;
28✔
652
}
653

UNCOV
654
int32_t tqExtractDelDataBlock(const void* pData, int32_t len, int64_t ver, void** pRefBlock, int32_t type, EStreamType blockType) {
×
UNCOV
655
  int32_t     code = 0;
×
UNCOV
656
  int32_t     line = 0;
×
UNCOV
657
  SDecoder*   pCoder = &(SDecoder){0};
×
UNCOV
658
  SDeleteRes* pRes = &(SDeleteRes){0};
×
659

UNCOV
660
  *pRefBlock = NULL;
×
661

UNCOV
662
  pRes->uidList = taosArrayInit(0, sizeof(tb_uid_t));
×
UNCOV
663
  TSDB_CHECK_NULL(pRes->uidList, code, line, END, terrno)
×
664

UNCOV
665
  tDecoderInit(pCoder, (uint8_t*)pData, len);
×
UNCOV
666
  code = tDecodeDeleteRes(pCoder, pRes);
×
UNCOV
667
  TSDB_CHECK_CODE(code, line, END);
×
668

UNCOV
669
  int32_t numOfTables = taosArrayGetSize(pRes->uidList);
×
UNCOV
670
  if (numOfTables == 0 || pRes->affectedRows == 0) {
×
UNCOV
671
    goto END;
×
672
  }
673

UNCOV
674
  SSDataBlock* pDelBlock = NULL;
×
UNCOV
675
  code = createSpecialDataBlock(blockType, &pDelBlock);
×
UNCOV
676
  TSDB_CHECK_CODE(code, line, END);
×
677

UNCOV
678
  code = blockDataEnsureCapacity(pDelBlock, numOfTables);
×
UNCOV
679
  TSDB_CHECK_CODE(code, line, END);
×
680

UNCOV
681
  pDelBlock->info.rows = numOfTables;
×
UNCOV
682
  pDelBlock->info.version = ver;
×
683

UNCOV
684
  for (int32_t i = 0; i < numOfTables; i++) {
×
685
    // start key column
UNCOV
686
    SColumnInfoData* pStartCol = taosArrayGet(pDelBlock->pDataBlock, START_TS_COLUMN_INDEX);
×
UNCOV
687
    TSDB_CHECK_NULL(pStartCol, code, line, END, terrno)
×
UNCOV
688
    code = colDataSetVal(pStartCol, i, (const char*)&pRes->skey, false);  // end key column
×
UNCOV
689
    TSDB_CHECK_CODE(code, line, END);
×
UNCOV
690
    SColumnInfoData* pEndCol = taosArrayGet(pDelBlock->pDataBlock, END_TS_COLUMN_INDEX);
×
UNCOV
691
    TSDB_CHECK_NULL(pEndCol, code, line, END, terrno)
×
UNCOV
692
    code = colDataSetVal(pEndCol, i, (const char*)&pRes->ekey, false);
×
UNCOV
693
    TSDB_CHECK_CODE(code, line, END);
×
694
    // uid column
UNCOV
695
    SColumnInfoData* pUidCol = taosArrayGet(pDelBlock->pDataBlock, UID_COLUMN_INDEX);
×
UNCOV
696
    TSDB_CHECK_NULL(pUidCol, code, line, END, terrno)
×
697

UNCOV
698
    int64_t* pUid = taosArrayGet(pRes->uidList, i);
×
UNCOV
699
    code = colDataSetVal(pUidCol, i, (const char*)pUid, false);
×
UNCOV
700
    TSDB_CHECK_CODE(code, line, END);
×
UNCOV
701
    void* tmp = taosArrayGet(pDelBlock->pDataBlock, GROUPID_COLUMN_INDEX);
×
UNCOV
702
    TSDB_CHECK_NULL(tmp, code, line, END, terrno)
×
UNCOV
703
    colDataSetNULL(tmp, i);
×
UNCOV
704
    tmp = taosArrayGet(pDelBlock->pDataBlock, CALCULATE_START_TS_COLUMN_INDEX);
×
UNCOV
705
    TSDB_CHECK_NULL(tmp, code, line, END, terrno)
×
UNCOV
706
    colDataSetNULL(tmp, i);
×
UNCOV
707
    tmp = taosArrayGet(pDelBlock->pDataBlock, CALCULATE_END_TS_COLUMN_INDEX);
×
UNCOV
708
    TSDB_CHECK_NULL(tmp, code, line, END, terrno)
×
UNCOV
709
    colDataSetNULL(tmp, i);
×
UNCOV
710
    tmp = taosArrayGet(pDelBlock->pDataBlock, TABLE_NAME_COLUMN_INDEX);
×
UNCOV
711
    TSDB_CHECK_NULL(tmp, code, line, END, terrno)
×
UNCOV
712
    colDataSetNULL(tmp, i);
×
713
  }
714

UNCOV
715
  if (type == 0) {
×
UNCOV
716
    code = taosAllocateQitem(sizeof(SStreamRefDataBlock), DEF_QITEM, 0, pRefBlock);
×
UNCOV
717
    if (code) {
×
718
      blockDataCleanup(pDelBlock);
×
719
      taosMemoryFree(pDelBlock);
×
720
      return code;
×
721
    }
722

UNCOV
723
    ((SStreamRefDataBlock*)(*pRefBlock))->type = STREAM_INPUT__REF_DATA_BLOCK;
×
UNCOV
724
    ((SStreamRefDataBlock*)(*pRefBlock))->pBlock = pDelBlock;
×
UNCOV
725
  } else if (type == 1) {
×
UNCOV
726
    *pRefBlock = pDelBlock;
×
727
  } else {
728
    tqError("unknown type:%d", type);
×
729
    code = TSDB_CODE_TMQ_CONSUMER_ERROR;
×
730
  }
731

UNCOV
732
END:
×
UNCOV
733
  if (code != 0) {
×
734
    tqError("failed to extract delete data block, line:%d code:%d", line, code);
×
735
  }
UNCOV
736
  tDecoderClear(pCoder);
×
UNCOV
737
  taosArrayDestroy(pRes->uidList);
×
UNCOV
738
  return code;
×
739
}
740

UNCOV
741
int32_t tqGetStreamExecInfo(SVnode* pVnode, int64_t streamId, int64_t* pDelay, bool* fhFinished) {
×
UNCOV
742
  SStreamMeta* pMeta = pVnode->pTq->pStreamMeta;
×
UNCOV
743
  int32_t      numOfTasks = taosArrayGetSize(pMeta->pTaskList);
×
UNCOV
744
  int32_t      code = TSDB_CODE_SUCCESS;
×
745

UNCOV
746
  if (pDelay != NULL) {
×
UNCOV
747
    *pDelay = 0;
×
748
  }
749

UNCOV
750
  *fhFinished = false;
×
751

UNCOV
752
  if (numOfTasks <= 0) {
×
753
    return code;
×
754
  }
755

756
  // extract the required source task for a given stream, identified by streamId
UNCOV
757
  streamMetaRLock(pMeta);
×
758

UNCOV
759
  numOfTasks = taosArrayGetSize(pMeta->pTaskList);
×
760

UNCOV
761
  for (int32_t i = 0; i < numOfTasks; ++i) {
×
UNCOV
762
    SStreamTaskId* pId = taosArrayGet(pMeta->pTaskList, i);
×
UNCOV
763
    if (pId == NULL) {
×
UNCOV
764
      continue;
×
765
    }
UNCOV
766
    if (pId->streamId != streamId) {
×
UNCOV
767
      continue;
×
768
    }
769

UNCOV
770
    STaskId      id = {.streamId = pId->streamId, .taskId = pId->taskId};
×
UNCOV
771
    SStreamTask* pTask = NULL;
×
772

UNCOV
773
    code = streamMetaAcquireTaskUnsafe(pMeta, &id, &pTask);
×
UNCOV
774
    if (code != 0) {
×
775
      tqError("vgId:%d failed to acquire task:0x%x in retrieving progress", pMeta->vgId, pId->taskId);
×
776
      continue;
×
777
    }
778

UNCOV
779
    if (pTask->info.taskLevel != TASK_LEVEL__SOURCE) {
×
UNCOV
780
      streamMetaReleaseTask(pMeta, pTask);
×
UNCOV
781
      continue;
×
782
    }
783

784
    // here we get the required stream source task
UNCOV
785
    *fhFinished = !HAS_RELATED_FILLHISTORY_TASK(pTask);
×
786

UNCOV
787
    int64_t ver = walReaderGetCurrentVer(pTask->exec.pWalReader);
×
UNCOV
788
    if (ver == -1) {
×
UNCOV
789
      ver = pTask->chkInfo.processedVer;
×
790
    } else {
UNCOV
791
      ver--;
×
792
    }
793

UNCOV
794
    SVersionRange verRange = {0};
×
UNCOV
795
    walReaderValidVersionRange(pTask->exec.pWalReader, &verRange.minVer, &verRange.maxVer);
×
796

UNCOV
797
    SWalReader* pReader = walOpenReader(pTask->exec.pWalReader->pWal, NULL, 0);
×
UNCOV
798
    if (pReader == NULL) {
×
799
      tqError("failed to open wal reader to extract exec progress, vgId:%d", pMeta->vgId);
×
800
      streamMetaReleaseTask(pMeta, pTask);
×
801
      continue;
×
802
    }
803

UNCOV
804
    int64_t cur = 0;
×
UNCOV
805
    int64_t latest = 0;
×
806

UNCOV
807
    code = walFetchHead(pReader, ver);
×
UNCOV
808
    if (code == TSDB_CODE_SUCCESS) {
×
UNCOV
809
      cur = pReader->pHead->head.ingestTs;
×
810
    }
811

UNCOV
812
    if (ver == verRange.maxVer) {
×
UNCOV
813
      latest = cur;
×
814
    } else {
UNCOV
815
      code = walFetchHead(pReader, verRange.maxVer);
×
UNCOV
816
      if (code == TSDB_CODE_SUCCESS) {
×
UNCOV
817
        latest = pReader->pHead->head.ingestTs;
×
818
      }
819
    }
820

UNCOV
821
    if (pDelay != NULL) {  // delay in ms
×
UNCOV
822
      *pDelay = (latest - cur) / 1000;
×
823
    }
824

UNCOV
825
    walCloseReader(pReader);
×
UNCOV
826
    streamMetaReleaseTask(pMeta, pTask);
×
827
  }
828

UNCOV
829
  streamMetaRUnLock(pMeta);
×
830

UNCOV
831
  return TSDB_CODE_SUCCESS;
×
832
}
833

UNCOV
834
int32_t tqExtractDropCtbDataBlock(const void* data, int32_t len, int64_t ver, void** pRefBlock, int32_t type) {
×
UNCOV
835
  int32_t          code = 0;
×
UNCOV
836
  int32_t          lino = 0;
×
UNCOV
837
  SDecoder         dc = {0};
×
UNCOV
838
  SVDropTbBatchReq batchReq = {0};
×
UNCOV
839
  tDecoderInit(&dc, (uint8_t*)data, len);
×
UNCOV
840
  code = tDecodeSVDropTbBatchReq(&dc, &batchReq);
×
UNCOV
841
  TSDB_CHECK_CODE(code, lino, _exit);
×
UNCOV
842
  if (batchReq.nReqs <= 0) goto _exit;
×
843

UNCOV
844
  SSDataBlock* pBlock = NULL;
×
UNCOV
845
  code = createSpecialDataBlock(STREAM_DROP_CHILD_TABLE, &pBlock);
×
UNCOV
846
  TSDB_CHECK_CODE(code, lino, _exit);
×
847

UNCOV
848
  code = blockDataEnsureCapacity(pBlock, batchReq.nReqs);
×
UNCOV
849
  TSDB_CHECK_CODE(code, lino, _exit);
×
850

UNCOV
851
  pBlock->info.rows = batchReq.nReqs;
×
UNCOV
852
  pBlock->info.version = ver;
×
UNCOV
853
  for (int32_t i = 0; i < batchReq.nReqs; ++i) {
×
UNCOV
854
    SVDropTbReq* pReq = batchReq.pReqs + i;
×
UNCOV
855
    SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, UID_COLUMN_INDEX);
×
UNCOV
856
    TSDB_CHECK_NULL(pCol, code, lino, _exit, terrno);
×
UNCOV
857
    code = colDataSetVal(pCol, i, (const char* )&pReq->uid, false);
×
UNCOV
858
    TSDB_CHECK_CODE(code, lino, _exit);
×
859
  }
860

UNCOV
861
  code = taosAllocateQitem(sizeof(SStreamRefDataBlock), DEF_QITEM, 0, pRefBlock);
×
UNCOV
862
  TSDB_CHECK_CODE(code, lino, _exit);
×
UNCOV
863
  ((SStreamRefDataBlock*)(*pRefBlock))->type = STREAM_INPUT__REF_DATA_BLOCK;
×
UNCOV
864
  ((SStreamRefDataBlock*)(*pRefBlock))->pBlock = pBlock;
×
865

UNCOV
866
_exit:
×
UNCOV
867
  tDecoderClear(&dc);
×
UNCOV
868
  if (TSDB_CODE_SUCCESS != code) {
×
869
    tqError("faled to extract drop ctb data block, line:%d code:%s", lino, tstrerror(code));
×
870
    blockDataCleanup(pBlock);
×
871
    taosMemoryFree(pBlock);
×
872
  }
UNCOV
873
  return code;
×
874
}
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