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

taosdata / TDengine / #3629

04 Mar 2025 01:45PM UTC coverage: 63.692% (-0.1%) from 63.79%
#3629

push

travis-ci

web-flow
Merge pull request #30007 from taosdata/revert-29951-docs/update-exception-handling-strategy

Revert "docs: update exception handling strategy"

149369 of 300378 branches covered (49.73%)

Branch coverage included in aggregate %.

233614 of 300930 relevant lines covered (77.63%)

18792670.99 hits per line

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

74.04
/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) {
43,052✔
24
  int32_t    code = TDB_CODE_SUCCESS;
43,052✔
25
  int32_t    lino = 0;
43,052✔
26
  tqDebug("%s called", __FUNCTION__ );
43,052!
27
  TSDB_CHECK_NULL(pRsp, code, lino, END, TSDB_CODE_INVALID_PARA);
43,052!
28

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

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

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

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

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

51
  if (isLeader) {
14,980✔
52
    tqScanWalAsync(pTq);
10,362✔
53
  }
54
}
14,980✔
55

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

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

69
  pRsp->blockDataLen = taosArrayInit(0, sizeof(int32_t));
10,851✔
70
  TSDB_CHECK_NULL(pRsp->blockDataLen, code, lino, END, terrno);
10,850!
71

72
  pRsp->blockTbName = taosArrayInit(0, sizeof(void*));
10,850✔
73
  TSDB_CHECK_NULL(pRsp->blockTbName, code, lino, END, terrno);
10,851!
74

75
  pRsp->blockSchema = taosArrayInit(0, sizeof(void*));
10,851✔
76
  TSDB_CHECK_NULL(pRsp->blockSchema, code, lino, END, terrno);
10,851!
77

78

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

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

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

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

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

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

151
  return 0;
1,666✔
152
}
153

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

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

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

170
  code = tqScanData(pTq, pHandle, &dataRsp, pOffset, pRequest);
42,319✔
171
  if (code != 0 && terrno != TSDB_CODE_WAL_LOG_NOT_EXIST) {
42,319✔
172
    goto end;
615✔
173
  }
174

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

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

192
end:
42,319✔
193
  {
194
    char buf[TSDB_OFFSET_LEN] = {0};
42,319✔
195
    tFormatOffset(buf, TSDB_OFFSET_LEN, &dataRsp.rspOffset);
42,319✔
196
    if (code != 0){
42,318✔
197
      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",
615!
198
              consumerId, pHandle->subKey, vgId, dataRsp.blockNum, buf, pRequest->reqId, tstrerror(code), lino);
199
    } else {
200
      tqDebug("tmq poll: consumer:0x%" PRIx64 ", subkey %s, vgId:%d, rsp block:%d, rsp offset type:%s, QID:0x%" PRIx64 " success",
41,703!
201
              consumerId, pHandle->subKey, vgId, dataRsp.blockNum, buf, pRequest->reqId);
202
    }
203

204
    tDeleteMqDataRsp(&dataRsp);
42,318✔
205
    return code;
42,319✔
206
  }
207
}
208

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

227
static void tDeleteCommon(void* parm) {}
405✔
228

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

233
static int32_t buildBatchMeta(SMqBatchMetaRsp *btMetaRsp, int16_t type, int32_t bodyLen, void* body){
3✔
234
  int32_t         code = 0;
3✔
235

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

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

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

269
END:
3✔
270
  return code;
3✔
271
}
272

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

295
END:
1✔
296
  taosArrayDestroy(pReq.pArray);
1✔
297
  return code;
1✔
298
}
299

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

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

316
  TQ_ERR_GO_TO_END(tqInitTaosxRsp(&taosxRsp, *offset));
10,851!
317
  if (offset->type != TMQ_OFFSET__LOG) {
10,851✔
318
    TQ_ERR_GO_TO_END(tqScanTaosx(pTq, pHandle, &taosxRsp, &btMetaRsp, offset, pRequest));
69!
319

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

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

337
  if (offset->type == TMQ_OFFSET__LOG) {
10,787!
338
    walReaderVerifyOffset(pHandle->pWalReader, offset);
10,787✔
339
    int64_t fetchVer = offset->version;
10,787✔
340

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

353
      if (tqFetchLog(pTq, pHandle, &fetchVer, pRequest->reqId) < 0) {
131,148✔
354
        if (totalMetaRows > 0) {
10,063✔
355
          SEND_BATCH_META_RSP
2✔
356
        }
357
        SEND_DATA_RSP
10,061✔
358
      }
359

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

364
      // process meta
365
      if (pHead->msgType != TDMT_VND_SUBMIT) {
121,704✔
366
        if (totalRows > 0) {
667✔
367
          SEND_DATA_RSP
35!
368
        }
369

370
        if ((pRequest->sourceExcluded & TD_REQ_FROM_TAOX) != 0) {
632✔
371
          if (pHead->msgType == TDMT_VND_CREATE_TABLE) {
629✔
372
            PROCESS_EXCLUDED_MSG(SVCreateTbBatchReq, tDecodeSVCreateTbBatchReq, tDeleteSVCreateTbBatchReq)
186!
373
          } else if (pHead->msgType == TDMT_VND_ALTER_TABLE) {
443✔
374
            PROCESS_EXCLUDED_MSG(SVAlterTbReq, tDecodeSVAlterTbReq, tDeleteCommon)
55!
375
          } else if (pHead->msgType == TDMT_VND_CREATE_STB || pHead->msgType == TDMT_VND_ALTER_STB) {
495✔
376
            PROCESS_EXCLUDED_MSG(SVCreateStbReq, tDecodeSVCreateStbReq, tDeleteCommon)
343!
377
          } else if (pHead->msgType == TDMT_VND_DELETE) {
45✔
378
            PROCESS_EXCLUDED_MSG(SDeleteRes, tDecodeDeleteRes, tDeleteCommon)
7!
379
          }
380
        }
381

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

405
      if (totalMetaRows > 0 && pHandle->fetchMeta != ONLY_META) {
121,037!
406
        SEND_BATCH_META_RSP
×
407
      }
408

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

416
      TQ_ERR_GO_TO_END(tqTaosxScanLog(pTq, pHandle, submit, &taosxRsp, &totalRows, pRequest));
121,037!
417

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

441
      if ((pRequest->rawData == 0 && totalRows >= pRequest->minPollRows) ||
120,755✔
442
          (taosGetTimestampMs() - st > pRequest->timeout) ||
120,359!
443
          (pRequest->rawData != 0 && (taosArrayGetSize(taosxRsp.blockData) > pRequest->minPollRows ||
120,473!
444
                                      terrno == TSDB_CODE_TMQ_RAW_DATA_SPLIT))) {
25!
445
        if (terrno == TSDB_CODE_TMQ_RAW_DATA_SPLIT){
566✔
446
          terrno = 0;
6✔
447
        } else{
448
          fetchVer++;
452✔
449
        }
450
        SEND_DATA_RSP
458✔
451
      } else {
452
        fetchVer++;
120,159✔
453
      }
454
    }
455
  }
456

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

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

475
  // reset the offset if needed
476
  if (IS_OFFSET_RESET_TYPE(pRequest->reqOffset.type)) {
53,865✔
477
    bool blockReturned = false;
2,537✔
478
    code = extractResetOffsetVal(&reqOffset, pTq, pHandle, pRequest, pMsg, &blockReturned);
2,537✔
479
    if (code != 0) {
2,535✔
480
      goto END;
694✔
481
    }
482

483
    // empty block returned, quit
484
    if (blockReturned) {
1,895✔
485
      goto END;
54✔
486
    }
487
  } else if (reqOffset.type == 0) {  // use the consumer specified offset
51,328!
488
    uError("req offset type is 0");
×
489
    code = TSDB_CODE_TMQ_INVALID_MSG;
×
490
    goto END;
×
491
  }
492

493
  if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
53,169✔
494
    code = extractDataAndRspForNormalSubscribe(pTq, pHandle, pRequest, pMsg, &reqOffset);
42,319✔
495
  } else {
496
    code = extractDataAndRspForDbStbSubscribe(pTq, pHandle, pRequest, pMsg, &reqOffset);
10,850✔
497
  }
498

499
END:
53,860✔
500
  if (code != 0){
53,860✔
501
    uError("failed to extract data for mq, msg:%s", tstrerror(code));
1,255!
502
  }
503
  tOffsetDestroy(&reqOffset);
53,860✔
504
  return code;
53,861✔
505
}
506

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

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

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

540
  void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
17✔
541

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

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

556
  return 0;
17✔
557
}
558

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

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

580
  void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
228✔
581

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

591
  SRpcMsg resp = {.info = pMsg->info, .pCont = buf, .contLen = tlen, .code = 0};
228✔
592

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

597
  return 0;
228✔
598
}
599

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

608
  if (type == TMQ_MSG_TYPE__POLL_RAW_DATA_RSP){
34,354✔
609
    pRsp->withSchema = 0;
45✔
610
  }
611
  if (type == TMQ_MSG_TYPE__POLL_DATA_RSP ||
34,354✔
612
      type == TMQ_MSG_TYPE__WALINFO_RSP ||
71✔
613
      type == TMQ_MSG_TYPE__POLL_RAW_DATA_RSP) {
614
    tEncodeSize(tEncodeMqDataRsp, pRsp, len, code);
34,328!
615
  } else if (type == TMQ_MSG_TYPE__POLL_DATA_META_RSP) {
26!
616
    tEncodeSize(tEncodeSTaosxRsp, pRsp, len, code);
26!
617
  }
618

619
  if (code < 0) {
34,351!
620
    return TAOS_GET_TERRNO(code);
×
621
  }
622

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

629
  SMqRspHead* pHead = (SMqRspHead*)buf;
34,354✔
630
  initMqRspHead(pHead, type, epoch, consumerId, sver, ever);
34,354✔
631

632
  void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
34,353✔
633

634
  SEncoder encoder = {0};
34,353✔
635
  tEncoderInit(&encoder, abuf, len);
34,353✔
636

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

651
  tmsgSendRsp(&rsp);
34,351✔
652
  return 0;
34,354✔
653
}
654

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

661
  *pRefBlock = NULL;
11,501✔
662

663
  pRes->uidList = taosArrayInit(0, sizeof(tb_uid_t));
11,501✔
664
  TSDB_CHECK_NULL(pRes->uidList, code, line, END, terrno)
11,502!
665

666
  tDecoderInit(pCoder, (uint8_t*)pData, len);
11,502✔
667
  code = tDecodeDeleteRes(pCoder, pRes);
11,502✔
668
  TSDB_CHECK_CODE(code, line, END);
11,501!
669

670
  int32_t numOfTables = taosArrayGetSize(pRes->uidList);
11,501✔
671
  if (numOfTables == 0 || pRes->affectedRows == 0) {
11,501✔
672
    goto END;
9,116✔
673
  }
674

675
  SSDataBlock* pDelBlock = NULL;
2,385✔
676
  code = createSpecialDataBlock(blockType, &pDelBlock);
2,385✔
677
  TSDB_CHECK_CODE(code, line, END);
2,383!
678

679
  code = blockDataEnsureCapacity(pDelBlock, numOfTables);
2,383✔
680
  TSDB_CHECK_CODE(code, line, END);
2,385!
681

682
  pDelBlock->info.rows = numOfTables;
2,385✔
683
  pDelBlock->info.version = ver;
2,385✔
684

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

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

716
  if (type == 0) {
2,383✔
717
    code = taosAllocateQitem(sizeof(SStreamRefDataBlock), DEF_QITEM, 0, pRefBlock);
2,376✔
718
    if (code) {
2,377!
719
      blockDataCleanup(pDelBlock);
×
720
      taosMemoryFree(pDelBlock);
×
721
      return code;
×
722
    }
723

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

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

742
int32_t tqGetStreamExecInfo(SVnode* pVnode, int64_t streamId, int64_t* pDelay, bool* fhFinished) {
6,184✔
743
  SStreamMeta* pMeta = pVnode->pTq->pStreamMeta;
6,184✔
744
  int32_t      numOfTasks = taosArrayGetSize(pMeta->pTaskList);
6,184✔
745
  int32_t      code = TSDB_CODE_SUCCESS;
6,186✔
746

747
  if (pDelay != NULL) {
6,186!
748
    *pDelay = 0;
6,186✔
749
  }
750

751
  *fhFinished = false;
6,186✔
752

753
  if (numOfTasks <= 0) {
6,186!
754
    return code;
×
755
  }
756

757
  // extract the required source task for a given stream, identified by streamId
758
  streamMetaRLock(pMeta);
6,186✔
759

760
  numOfTasks = taosArrayGetSize(pMeta->pTaskList);
6,185✔
761

762
  for (int32_t i = 0; i < numOfTasks; ++i) {
37,892✔
763
    SStreamTaskId* pId = taosArrayGet(pMeta->pTaskList, i);
31,706✔
764
    if (pId == NULL) {
31,707!
765
      continue;
25,533✔
766
    }
767
    if (pId->streamId != streamId) {
31,707✔
768
      continue;
19,347✔
769
    }
770

771
    STaskId      id = {.streamId = pId->streamId, .taskId = pId->taskId};
12,360✔
772
    SStreamTask* pTask = NULL;
12,360✔
773

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

780
    if (pTask->info.taskLevel != TASK_LEVEL__SOURCE) {
12,372✔
781
      streamMetaReleaseTask(pMeta, pTask);
6,186✔
782
      continue;
6,186✔
783
    }
784

785
    // here we get the required stream source task
786
    *fhFinished = !HAS_RELATED_FILLHISTORY_TASK(pTask);
6,186✔
787

788
    int64_t ver = walReaderGetCurrentVer(pTask->exec.pWalReader);
6,186✔
789
    if (ver == -1) {
6,186✔
790
      ver = pTask->chkInfo.processedVer;
1,295✔
791
    } else {
792
      ver--;
4,891✔
793
    }
794

795
    SVersionRange verRange = {0};
6,186✔
796
    walReaderValidVersionRange(pTask->exec.pWalReader, &verRange.minVer, &verRange.maxVer);
6,186✔
797

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

805
    int64_t cur = 0;
6,186✔
806
    int64_t latest = 0;
6,186✔
807

808
    code = walFetchHead(pReader, ver);
6,186✔
809
    if (code == TSDB_CODE_SUCCESS) {
6,185!
810
      cur = pReader->pHead->head.ingestTs;
6,185✔
811
    }
812

813
    if (ver == verRange.maxVer) {
6,185✔
814
      latest = cur;
2,664✔
815
    } else {
816
      code = walFetchHead(pReader, verRange.maxVer);
3,521✔
817
      if (code == TSDB_CODE_SUCCESS) {
3,519!
818
        latest = pReader->pHead->head.ingestTs;
3,519✔
819
      }
820
    }
821

822
    if (pDelay != NULL) {  // delay in ms
6,183!
823
      *pDelay = (latest - cur) / 1000;
6,183✔
824
    }
825

826
    walCloseReader(pReader);
6,183✔
827
    streamMetaReleaseTask(pMeta, pTask);
6,185✔
828
  }
829

830
  streamMetaRUnLock(pMeta);
6,186✔
831

832
  return TSDB_CODE_SUCCESS;
6,186✔
833
}
834

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

845
  SSDataBlock* pBlock = NULL;
185✔
846
  code = createSpecialDataBlock(STREAM_DROP_CHILD_TABLE, &pBlock);
185✔
847
  TSDB_CHECK_CODE(code, lino, _exit);
185!
848

849
  code = blockDataEnsureCapacity(pBlock, batchReq.nReqs);
185✔
850
  TSDB_CHECK_CODE(code, lino, _exit);
185!
851

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

862
  code = taosAllocateQitem(sizeof(SStreamRefDataBlock), DEF_QITEM, 0, pRefBlock);
185✔
863
  TSDB_CHECK_CODE(code, lino, _exit);
185!
864
  ((SStreamRefDataBlock*)(*pRefBlock))->type = STREAM_INPUT__REF_DATA_BLOCK;
185✔
865
  ((SStreamRefDataBlock*)(*pRefBlock))->pBlock = pBlock;
185✔
866

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