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

taosdata / TDengine / #3621

22 Feb 2025 11:44AM UTC coverage: 2.037% (-61.5%) from 63.573%
#3621

push

travis-ci

web-flow
Merge pull request #29874 from taosdata/merge/mainto3.0

merge: from main to 3.0 branch

4357 of 287032 branches covered (1.52%)

Branch coverage included in aggregate %.

0 of 174 new or added lines in 18 files covered. (0.0%)

213359 existing lines in 469 files now uncovered.

7260 of 283369 relevant lines covered (2.56%)

23737.72 hits per line

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

0.0
/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

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

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

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

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

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

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

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

UNCOV
60
  pRsp->withTbName = 1;
×
UNCOV
61
  pRsp->withSchema = 1;
×
UNCOV
62
  pRsp->blockData = taosArrayInit(0, sizeof(void*));
×
UNCOV
63
  TSDB_CHECK_NULL(pRsp->blockData, code, lino, END, terrno);\
×
64

UNCOV
65
  pRsp->blockDataLen = taosArrayInit(0, sizeof(int32_t));
×
UNCOV
66
  TSDB_CHECK_NULL(pRsp->blockDataLen, code, lino, END, terrno);
×
67

UNCOV
68
  pRsp->blockTbName = taosArrayInit(0, sizeof(void*));
×
UNCOV
69
  TSDB_CHECK_NULL(pRsp->blockTbName, code, lino, END, terrno);
×
70

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

74

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

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

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

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

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

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

UNCOV
147
  return 0;
×
148
}
149

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

UNCOV
159
  SMqDataRsp dataRsp = {0};
×
UNCOV
160
  code = tqInitDataRsp(&dataRsp, *pOffset);
×
UNCOV
161
  TSDB_CHECK_CODE(code, lino, end);
×
162

UNCOV
163
  code = qSetTaskId(pHandle->execHandle.task, consumerId, pRequest->reqId);
×
UNCOV
164
  TSDB_CHECK_CODE(code, lino, end);
×
165

UNCOV
166
  code = tqScanData(pTq, pHandle, &dataRsp, pOffset, pRequest);
×
UNCOV
167
  if (code != 0 && terrno != TSDB_CODE_WAL_LOG_NOT_EXIST) {
×
UNCOV
168
    goto end;
×
169
  }
170

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

184
  // reqOffset represents the current date offset, may be changed if wal not exists
UNCOV
185
  tOffsetCopy(&dataRsp.reqOffset, pOffset);
×
UNCOV
186
  code = tqSendDataRsp(pHandle, pMsg, pRequest, &dataRsp, TMQ_MSG_TYPE__POLL_DATA_RSP, vgId);
×
187

UNCOV
188
end:
×
189
  {
UNCOV
190
    char buf[TSDB_OFFSET_LEN] = {0};
×
UNCOV
191
    tFormatOffset(buf, TSDB_OFFSET_LEN, &dataRsp.rspOffset);
×
UNCOV
192
    if (code != 0){
×
UNCOV
193
      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",
×
194
              consumerId, pHandle->subKey, vgId, dataRsp.blockNum, buf, pRequest->reqId, tstrerror(code), lino);
195
    } else {
UNCOV
196
      tqDebug("tmq poll: consumer:0x%" PRIx64 ", subkey %s, vgId:%d, rsp block:%d, rsp offset type:%s,QID:0x%" PRIx64 " success",
×
197
              consumerId, pHandle->subKey, vgId, dataRsp.blockNum, buf, pRequest->reqId);
198
    }
199

UNCOV
200
    tDeleteMqDataRsp(&dataRsp);
×
UNCOV
201
    return code;
×
202
  }
203
}
204

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

UNCOV
223
static void tDeleteCommon(void* parm) {}
×
224

225
#define POLL_RSP_TYPE(pRequest,taosxRsp) \
226
taosxRsp.createTableNum > 0 ? TMQ_MSG_TYPE__POLL_DATA_META_RSP : \
227
(pRequest->rawData == 1 ? TMQ_MSG_TYPE__POLL_RAW_DATA_RSP : TMQ_MSG_TYPE__POLL_DATA_RSP)
228

UNCOV
229
static int32_t extractDataAndRspForDbStbSubscribe(STQ* pTq, STqHandle* pHandle, const SMqPollReq* pRequest,
×
230
                                                  SRpcMsg* pMsg, STqOffsetVal* offset) {
UNCOV
231
  int32_t         vgId = TD_VID(pTq->pVnode);
×
UNCOV
232
  SMqDataRsp      taosxRsp = {0};
×
UNCOV
233
  SMqBatchMetaRsp btMetaRsp = {0};
×
UNCOV
234
  int32_t         code = 0;
×
235

UNCOV
236
  TQ_ERR_GO_TO_END(tqInitTaosxRsp(&taosxRsp, *offset));
×
UNCOV
237
  if (offset->type != TMQ_OFFSET__LOG) {
×
UNCOV
238
    TQ_ERR_GO_TO_END(tqScanTaosx(pTq, pHandle, &taosxRsp, &btMetaRsp, offset, pRequest));
×
239

UNCOV
240
    if (taosArrayGetSize(btMetaRsp.batchMetaReq) > 0) {
×
UNCOV
241
      code = tqSendBatchMetaPollRsp(pHandle, pMsg, pRequest, &btMetaRsp, vgId);
×
UNCOV
242
      tqDebug("tmq poll: consumer:0x%" PRIx64 " subkey:%s vgId:%d, send meta offset type:%d,uid:%" PRId64 ",ts:%" PRId64,
×
243
              pRequest->consumerId, pHandle->subKey, vgId, btMetaRsp.rspOffset.type, btMetaRsp.rspOffset.uid,btMetaRsp.rspOffset.ts);
UNCOV
244
      goto END;
×
245
    }
246

UNCOV
247
    tqDebug("taosx poll: consumer:0x%" PRIx64 " subkey:%s vgId:%d, send data blockNum:%d, offset type:%d,uid:%" PRId64",ts:%" PRId64,
×
248
            pRequest->consumerId, pHandle->subKey, vgId, taosxRsp.blockNum, taosxRsp.rspOffset.type, taosxRsp.rspOffset.uid, taosxRsp.rspOffset.ts);
UNCOV
249
    if (taosxRsp.blockNum > 0) {
×
UNCOV
250
      code = tqSendDataRsp(pHandle, pMsg, pRequest, &taosxRsp, TMQ_MSG_TYPE__POLL_DATA_RSP, vgId);
×
UNCOV
251
      goto END;
×
252
    } else {
UNCOV
253
      tOffsetCopy(offset, &taosxRsp.rspOffset);
×
254
    }
255
  }
256

UNCOV
257
  if (offset->type == TMQ_OFFSET__LOG) {
×
UNCOV
258
    walReaderVerifyOffset(pHandle->pWalReader, offset);
×
UNCOV
259
    int64_t fetchVer = offset->version;
×
260

UNCOV
261
    uint64_t st = taosGetTimestampMs();
×
UNCOV
262
    int      totalRows = 0;
×
UNCOV
263
    int32_t  totalMetaRows = 0;
×
UNCOV
264
    while (1) {
×
UNCOV
265
      int32_t savedEpoch = atomic_load_32(&pHandle->epoch);
×
UNCOV
266
      if (savedEpoch > pRequest->epoch) {
×
267
        tqError("tmq poll: consumer:0x%" PRIx64 " (epoch %d) iter log, savedEpoch error, vgId:%d offset %" PRId64,
×
268
                pRequest->consumerId, pRequest->epoch, vgId, fetchVer);
269
        code = TSDB_CODE_TQ_INTERNAL_ERROR;
×
UNCOV
270
        goto END;
×
271
      }
272

UNCOV
273
      if (tqFetchLog(pTq, pHandle, &fetchVer, pRequest->reqId) < 0) {
×
UNCOV
274
        if (totalMetaRows > 0) {
×
UNCOV
275
          tqOffsetResetToLog(&btMetaRsp.rspOffset, fetchVer);
×
UNCOV
276
          code = tqSendBatchMetaPollRsp(pHandle, pMsg, pRequest, &btMetaRsp, vgId);
×
UNCOV
277
          goto END;
×
278
        }
UNCOV
279
        tqOffsetResetToLog(&taosxRsp.rspOffset, fetchVer);
×
UNCOV
280
        code = tqSendDataRsp(pHandle, pMsg, pRequest, &taosxRsp,
×
UNCOV
281
                             POLL_RSP_TYPE(pRequest, taosxRsp), vgId);
×
UNCOV
282
        goto END;
×
283
      }
284

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

289
      // process meta
UNCOV
290
      if (pHead->msgType != TDMT_VND_SUBMIT) {
×
UNCOV
291
        if (totalRows > 0) {
×
UNCOV
292
          tqOffsetResetToLog(&taosxRsp.rspOffset, fetchVer);
×
UNCOV
293
          code = tqSendDataRsp(pHandle, pMsg, pRequest, &taosxRsp,
×
UNCOV
294
                               POLL_RSP_TYPE(pRequest, taosxRsp), vgId);
×
UNCOV
295
          goto END;
×
296
        }
297

UNCOV
298
        if ((pRequest->sourceExcluded & TD_REQ_FROM_TAOX) != 0) {
×
UNCOV
299
          if (pHead->msgType == TDMT_VND_CREATE_TABLE) {
×
UNCOV
300
            PROCESS_EXCLUDED_MSG(SVCreateTbBatchReq, tDecodeSVCreateTbBatchReq, tDeleteSVCreateTbBatchReq)
×
UNCOV
301
          } else if (pHead->msgType == TDMT_VND_ALTER_TABLE) {
×
UNCOV
302
            PROCESS_EXCLUDED_MSG(SVAlterTbReq, tDecodeSVAlterTbReq, tDeleteCommon)
×
UNCOV
303
          } else if (pHead->msgType == TDMT_VND_CREATE_STB || pHead->msgType == TDMT_VND_ALTER_STB) {
×
UNCOV
304
            PROCESS_EXCLUDED_MSG(SVCreateStbReq, tDecodeSVCreateStbReq, tDeleteCommon)
×
UNCOV
305
          } else if (pHead->msgType == TDMT_VND_DELETE) {
×
UNCOV
306
            PROCESS_EXCLUDED_MSG(SDeleteRes, tDecodeDeleteRes, tDeleteCommon)
×
307
          }
308
        }
309

UNCOV
310
        tqDebug("fetch meta msg, ver:%" PRId64 ", vgId:%d, type:%s, enable batch meta:%d", pHead->version, vgId,
×
311
                TMSG_INFO(pHead->msgType), pRequest->enableBatchMeta);
UNCOV
312
        if (!pRequest->enableBatchMeta && !pRequest->useSnapshot) {
×
UNCOV
313
          SMqMetaRsp metaRsp = {0};
×
UNCOV
314
          tqOffsetResetToLog(&metaRsp.rspOffset, fetchVer + 1);
×
UNCOV
315
          metaRsp.resMsgType = pHead->msgType;
×
UNCOV
316
          metaRsp.metaRspLen = pHead->bodyLen;
×
UNCOV
317
          metaRsp.metaRsp = pHead->body;
×
UNCOV
318
          code = tqSendMetaPollRsp(pHandle, pMsg, pRequest, &metaRsp, vgId);
×
UNCOV
319
          goto END;
×
320
        }
321

UNCOV
322
        if (!btMetaRsp.batchMetaReq) {
×
UNCOV
323
          btMetaRsp.batchMetaReq = taosArrayInit(4, POINTER_BYTES);
×
UNCOV
324
          TQ_NULL_GO_TO_END(btMetaRsp.batchMetaReq);
×
UNCOV
325
          btMetaRsp.batchMetaLen = taosArrayInit(4, sizeof(int32_t));
×
UNCOV
326
          TQ_NULL_GO_TO_END(btMetaRsp.batchMetaLen);
×
327
        }
UNCOV
328
        fetchVer++;
×
329

UNCOV
330
        SMqMetaRsp tmpMetaRsp = {0};
×
UNCOV
331
        tmpMetaRsp.resMsgType = pHead->msgType;
×
UNCOV
332
        tmpMetaRsp.metaRspLen = pHead->bodyLen;
×
UNCOV
333
        tmpMetaRsp.metaRsp = pHead->body;
×
UNCOV
334
        uint32_t len = 0;
×
UNCOV
335
        tEncodeSize(tEncodeMqMetaRsp, &tmpMetaRsp, len, code);
×
UNCOV
336
        if (TSDB_CODE_SUCCESS != code) {
×
337
          tqError("tmq extract meta from log, tEncodeMqMetaRsp error");
×
338
          continue;
×
339
        }
UNCOV
340
        int32_t tLen = sizeof(SMqRspHead) + len;
×
UNCOV
341
        void*   tBuf = taosMemoryCalloc(1, tLen);
×
UNCOV
342
        TQ_NULL_GO_TO_END(tBuf);
×
UNCOV
343
        void*    metaBuff = POINTER_SHIFT(tBuf, sizeof(SMqRspHead));
×
UNCOV
344
        SEncoder encoder = {0};
×
UNCOV
345
        tEncoderInit(&encoder, metaBuff, len);
×
UNCOV
346
        code = tEncodeMqMetaRsp(&encoder, &tmpMetaRsp);
×
UNCOV
347
        tEncoderClear(&encoder);
×
348

UNCOV
349
        if (code < 0) {
×
350
          tqError("tmq extract meta from log, tEncodeMqMetaRsp error");
×
351
          continue;
×
352
        }
UNCOV
353
        TQ_NULL_GO_TO_END (taosArrayPush(btMetaRsp.batchMetaReq, &tBuf));
×
UNCOV
354
        TQ_NULL_GO_TO_END (taosArrayPush(btMetaRsp.batchMetaLen, &tLen));
×
UNCOV
355
        totalMetaRows++;
×
UNCOV
356
        if ((taosArrayGetSize(btMetaRsp.batchMetaReq) >= tmqRowSize) || (taosGetTimestampMs() - st > pRequest->timeout)) {
×
357
          tqOffsetResetToLog(&btMetaRsp.rspOffset, fetchVer);
×
358
          code = tqSendBatchMetaPollRsp(pHandle, pMsg, pRequest, &btMetaRsp, vgId);
×
359
          goto END;
×
360
        }
UNCOV
361
        continue;
×
362
      }
363

UNCOV
364
      if (totalMetaRows > 0) {
×
365
        tqOffsetResetToLog(&btMetaRsp.rspOffset, fetchVer);
×
366
        code = tqSendBatchMetaPollRsp(pHandle, pMsg, pRequest, &btMetaRsp, vgId);
×
367
        goto END;
×
368
      }
369

370
      // process data
UNCOV
371
      SPackedData submit = {
×
UNCOV
372
          .msgStr = POINTER_SHIFT(pHead->body, sizeof(SSubmitReq2Msg)),
×
UNCOV
373
          .msgLen = pHead->bodyLen - sizeof(SSubmitReq2Msg),
×
UNCOV
374
          .ver = pHead->version,
×
375
      };
376

UNCOV
377
      TQ_ERR_GO_TO_END(tqTaosxScanLog(pTq, pHandle, submit, &taosxRsp, &totalRows, pRequest));
×
378

UNCOV
379
      if ((pRequest->rawData == 0 && totalRows >= pRequest->minPollRows) ||
×
UNCOV
380
          (taosGetTimestampMs() - st > pRequest->timeout) ||
×
UNCOV
381
          (pRequest->rawData != 0 && (taosArrayGetSize(taosxRsp.blockData) > pRequest->minPollRows ||
×
UNCOV
382
                                      terrno == TSDB_CODE_TMQ_RAW_DATA_SPLIT))) {
×
383
//        tqDebug("start to send rsp, block num:%d, totalRows:%d, createTableNum:%d, terrno:%d",
384
//                (int)taosArrayGetSize(taosxRsp.blockData), totalRows, taosxRsp.createTableNum, terrno);
UNCOV
385
        tqOffsetResetToLog(&taosxRsp.rspOffset, terrno == TSDB_CODE_TMQ_RAW_DATA_SPLIT ? fetchVer : fetchVer + 1);
×
UNCOV
386
        code = tqSendDataRsp(pHandle, pMsg, pRequest, &taosxRsp,
×
UNCOV
387
                             POLL_RSP_TYPE(pRequest, taosxRsp), vgId);
×
UNCOV
388
        if (terrno == TSDB_CODE_TMQ_RAW_DATA_SPLIT){terrno = 0;}
×
UNCOV
389
        goto END;
×
390
      } else {
UNCOV
391
        fetchVer++;
×
392
      }
393
    }
394
  }
395

396
END:
×
UNCOV
397
  if (code != 0){
×
398
    tqError("tmq poll: tqTaosxScanLog error. consumerId:0x%" PRIx64 ", in vgId:%d, subkey %s", pRequest->consumerId, vgId,
×
399
            pRequest->subKey);
400
  }
UNCOV
401
  tDeleteMqBatchMetaRsp(&btMetaRsp);
×
UNCOV
402
  tDeleteSTaosxRsp(&taosxRsp);
×
UNCOV
403
  return code;
×
404
}
405

UNCOV
406
int32_t tqExtractDataForMq(STQ* pTq, STqHandle* pHandle, const SMqPollReq* pRequest, SRpcMsg* pMsg) {
×
UNCOV
407
  if (pTq == NULL || pHandle == NULL || pRequest == NULL || pMsg == NULL) {
×
408
    return TSDB_CODE_TMQ_INVALID_MSG;
×
409
  }
UNCOV
410
  int32_t      code = 0;
×
UNCOV
411
  STqOffsetVal reqOffset = {0};
×
UNCOV
412
  tOffsetCopy(&reqOffset, &pRequest->reqOffset);
×
413

414
  // reset the offset if needed
UNCOV
415
  if (IS_OFFSET_RESET_TYPE(pRequest->reqOffset.type)) {
×
UNCOV
416
    bool blockReturned = false;
×
UNCOV
417
    code = extractResetOffsetVal(&reqOffset, pTq, pHandle, pRequest, pMsg, &blockReturned);
×
UNCOV
418
    if (code != 0) {
×
UNCOV
419
      goto END;
×
420
    }
421

422
    // empty block returned, quit
UNCOV
423
    if (blockReturned) {
×
UNCOV
424
      goto END;
×
425
    }
UNCOV
426
  } else if (reqOffset.type == 0) {  // use the consumer specified offset
×
427
    uError("req offset type is 0");
×
428
    code = TSDB_CODE_TMQ_INVALID_MSG;
×
429
    goto END;
×
430
  }
431

UNCOV
432
  if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
×
UNCOV
433
    code = extractDataAndRspForNormalSubscribe(pTq, pHandle, pRequest, pMsg, &reqOffset);
×
434
  } else {
UNCOV
435
    code = extractDataAndRspForDbStbSubscribe(pTq, pHandle, pRequest, pMsg, &reqOffset);
×
436
  }
437

UNCOV
438
END:
×
UNCOV
439
  if (code != 0){
×
UNCOV
440
    uError("failed to extract data for mq, msg:%s", tstrerror(code));
×
441
  }
UNCOV
442
  tOffsetDestroy(&reqOffset);
×
UNCOV
443
  return code;
×
444
}
445

UNCOV
446
static void initMqRspHead(SMqRspHead* pMsgHead, int32_t type, int32_t epoch, int64_t consumerId, int64_t sver,
×
447
                          int64_t ever) {
UNCOV
448
  if (pMsgHead == NULL) {
×
449
    return;
×
450
  }
UNCOV
451
  pMsgHead->consumerId = consumerId;
×
UNCOV
452
  pMsgHead->epoch = epoch;
×
UNCOV
453
  pMsgHead->mqMsgType = type;
×
UNCOV
454
  pMsgHead->walsver = sver;
×
UNCOV
455
  pMsgHead->walever = ever;
×
456
}
457

UNCOV
458
int32_t tqSendBatchMetaPollRsp(STqHandle* pHandle, const SRpcMsg* pMsg, const SMqPollReq* pReq,
×
459
                               const SMqBatchMetaRsp* pRsp, int32_t vgId) {
UNCOV
460
  if (pHandle == NULL || pMsg == NULL || pReq == NULL || pRsp == NULL) {
×
461
    return TSDB_CODE_TMQ_INVALID_MSG;
×
462
  }
UNCOV
463
  int32_t len = 0;
×
UNCOV
464
  int32_t code = 0;
×
UNCOV
465
  tEncodeSize(tEncodeMqBatchMetaRsp, pRsp, len, code);
×
UNCOV
466
  if (code < 0) {
×
467
    return TAOS_GET_TERRNO(code);
×
468
  }
UNCOV
469
  int32_t tlen = sizeof(SMqRspHead) + len;
×
UNCOV
470
  void*   buf = rpcMallocCont(tlen);
×
UNCOV
471
  if (buf == NULL) {
×
472
    return TAOS_GET_TERRNO(terrno);
×
473
  }
474

UNCOV
475
  int64_t sver = 0, ever = 0;
×
UNCOV
476
  walReaderValidVersionRange(pHandle->execHandle.pTqReader->pWalReader, &sver, &ever);
×
UNCOV
477
  initMqRspHead(buf, TMQ_MSG_TYPE__POLL_BATCH_META_RSP, pReq->epoch, pReq->consumerId, sver, ever);
×
478

UNCOV
479
  void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
×
480

UNCOV
481
  SEncoder encoder = {0};
×
UNCOV
482
  tEncoderInit(&encoder, abuf, len);
×
UNCOV
483
  code = tEncodeMqBatchMetaRsp(&encoder, pRsp);
×
UNCOV
484
  tEncoderClear(&encoder);
×
UNCOV
485
  if (code < 0) {
×
486
    rpcFreeCont(buf);
×
487
    return TAOS_GET_TERRNO(code);
×
488
  }
UNCOV
489
  SRpcMsg resp = {.info = pMsg->info, .pCont = buf, .contLen = tlen, .code = 0};
×
490

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

UNCOV
495
  return 0;
×
496
}
497

UNCOV
498
int32_t tqSendMetaPollRsp(STqHandle* pHandle, const SRpcMsg* pMsg, const SMqPollReq* pReq, const SMqMetaRsp* pRsp,
×
499
                          int32_t vgId) {
UNCOV
500
  if (pHandle == NULL || pMsg == NULL || pReq == NULL || pRsp == NULL) {
×
501
    return TSDB_CODE_TMQ_INVALID_MSG;
×
502
  }
UNCOV
503
  int32_t len = 0;
×
UNCOV
504
  int32_t code = 0;
×
UNCOV
505
  tEncodeSize(tEncodeMqMetaRsp, pRsp, len, code);
×
UNCOV
506
  if (code < 0) {
×
507
    return TAOS_GET_TERRNO(code);
×
508
  }
UNCOV
509
  int32_t tlen = sizeof(SMqRspHead) + len;
×
UNCOV
510
  void*   buf = rpcMallocCont(tlen);
×
UNCOV
511
  if (buf == NULL) {
×
512
    return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
×
513
  }
514

UNCOV
515
  int64_t sver = 0, ever = 0;
×
UNCOV
516
  walReaderValidVersionRange(pHandle->execHandle.pTqReader->pWalReader, &sver, &ever);
×
UNCOV
517
  initMqRspHead(buf, TMQ_MSG_TYPE__POLL_META_RSP, pReq->epoch, pReq->consumerId, sver, ever);
×
518

UNCOV
519
  void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
×
520

UNCOV
521
  SEncoder encoder = {0};
×
UNCOV
522
  tEncoderInit(&encoder, abuf, len);
×
UNCOV
523
  code = tEncodeMqMetaRsp(&encoder, pRsp);
×
UNCOV
524
  tEncoderClear(&encoder);
×
UNCOV
525
  if (code < 0) {
×
526
    rpcFreeCont(buf);
×
527
    return TAOS_GET_TERRNO(code);
×
528
  }
529

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

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

UNCOV
536
  return 0;
×
537
}
538

UNCOV
539
int32_t tqDoSendDataRsp(const SRpcHandleInfo* pRpcHandleInfo, SMqDataRsp* pRsp, int32_t epoch, int64_t consumerId,
×
540
                        int32_t type, int64_t sver, int64_t ever) {
UNCOV
541
  if (pRpcHandleInfo == NULL || pRsp == NULL) {
×
542
    return TSDB_CODE_TMQ_INVALID_MSG;
×
543
  }
UNCOV
544
  int32_t len = 0;
×
UNCOV
545
  int32_t code = 0;
×
546

UNCOV
547
  if (type == TMQ_MSG_TYPE__POLL_RAW_DATA_RSP){
×
UNCOV
548
    pRsp->withSchema = 0;
×
549
  }
UNCOV
550
  if (type == TMQ_MSG_TYPE__POLL_DATA_RSP ||
×
UNCOV
551
      type == TMQ_MSG_TYPE__WALINFO_RSP ||
×
552
      type == TMQ_MSG_TYPE__POLL_RAW_DATA_RSP) {
UNCOV
553
    tEncodeSize(tEncodeMqDataRsp, pRsp, len, code);
×
UNCOV
554
  } else if (type == TMQ_MSG_TYPE__POLL_DATA_META_RSP) {
×
UNCOV
555
    tEncodeSize(tEncodeSTaosxRsp, pRsp, len, code);
×
556
  }
557

UNCOV
558
  if (code < 0) {
×
559
    return TAOS_GET_TERRNO(code);
×
560
  }
561

UNCOV
562
  int32_t tlen = sizeof(SMqRspHead) + len;
×
UNCOV
563
  void*   buf = rpcMallocCont(tlen);
×
UNCOV
564
  if (buf == NULL) {
×
565
    return terrno;
×
566
  }
567

UNCOV
568
  SMqRspHead* pHead = (SMqRspHead*)buf;
×
UNCOV
569
  initMqRspHead(pHead, type, epoch, consumerId, sver, ever);
×
570

UNCOV
571
  void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
×
572

UNCOV
573
  SEncoder encoder = {0};
×
UNCOV
574
  tEncoderInit(&encoder, abuf, len);
×
575

UNCOV
576
  if (type == TMQ_MSG_TYPE__POLL_DATA_RSP ||
×
UNCOV
577
      type == TMQ_MSG_TYPE__WALINFO_RSP ||
×
578
      type == TMQ_MSG_TYPE__POLL_RAW_DATA_RSP) {
UNCOV
579
    code = tEncodeMqDataRsp(&encoder, pRsp);
×
UNCOV
580
  } else if (type == TMQ_MSG_TYPE__POLL_DATA_META_RSP) {
×
UNCOV
581
    code = tEncodeSTaosxRsp(&encoder, pRsp);
×
582
  }
UNCOV
583
  tEncoderClear(&encoder);
×
UNCOV
584
  if (code < 0) {
×
585
    rpcFreeCont(buf);
×
586
    return TAOS_GET_TERRNO(code);
×
587
  }
UNCOV
588
  SRpcMsg rsp = {.info = *pRpcHandleInfo, .pCont = buf, .contLen = tlen, .code = 0};
×
589

UNCOV
590
  tmsgSendRsp(&rsp);
×
UNCOV
591
  return 0;
×
592
}
593

UNCOV
594
int32_t tqExtractDelDataBlock(const void* pData, int32_t len, int64_t ver, void** pRefBlock, int32_t type, EStreamType blockType) {
×
UNCOV
595
  int32_t     code = 0;
×
UNCOV
596
  int32_t     line = 0;
×
UNCOV
597
  SDecoder*   pCoder = &(SDecoder){0};
×
UNCOV
598
  SDeleteRes* pRes = &(SDeleteRes){0};
×
599

UNCOV
600
  *pRefBlock = NULL;
×
601

UNCOV
602
  pRes->uidList = taosArrayInit(0, sizeof(tb_uid_t));
×
UNCOV
603
  TSDB_CHECK_NULL(pRes->uidList, code, line, END, terrno)
×
604

UNCOV
605
  tDecoderInit(pCoder, (uint8_t*)pData, len);
×
UNCOV
606
  code = tDecodeDeleteRes(pCoder, pRes);
×
UNCOV
607
  TSDB_CHECK_CODE(code, line, END);
×
608

UNCOV
609
  int32_t numOfTables = taosArrayGetSize(pRes->uidList);
×
UNCOV
610
  if (numOfTables == 0 || pRes->affectedRows == 0) {
×
UNCOV
611
    goto END;
×
612
  }
613

UNCOV
614
  SSDataBlock* pDelBlock = NULL;
×
UNCOV
615
  code = createSpecialDataBlock(blockType, &pDelBlock);
×
UNCOV
616
  TSDB_CHECK_CODE(code, line, END);
×
617

UNCOV
618
  code = blockDataEnsureCapacity(pDelBlock, numOfTables);
×
UNCOV
619
  TSDB_CHECK_CODE(code, line, END);
×
620

UNCOV
621
  pDelBlock->info.rows = numOfTables;
×
UNCOV
622
  pDelBlock->info.version = ver;
×
623

UNCOV
624
  for (int32_t i = 0; i < numOfTables; i++) {
×
625
    // start key column
UNCOV
626
    SColumnInfoData* pStartCol = taosArrayGet(pDelBlock->pDataBlock, START_TS_COLUMN_INDEX);
×
UNCOV
627
    TSDB_CHECK_NULL(pStartCol, code, line, END, terrno)
×
UNCOV
628
    code = colDataSetVal(pStartCol, i, (const char*)&pRes->skey, false);  // end key column
×
UNCOV
629
    TSDB_CHECK_CODE(code, line, END);
×
UNCOV
630
    SColumnInfoData* pEndCol = taosArrayGet(pDelBlock->pDataBlock, END_TS_COLUMN_INDEX);
×
UNCOV
631
    TSDB_CHECK_NULL(pEndCol, code, line, END, terrno)
×
UNCOV
632
    code = colDataSetVal(pEndCol, i, (const char*)&pRes->ekey, false);
×
UNCOV
633
    TSDB_CHECK_CODE(code, line, END);
×
634
    // uid column
UNCOV
635
    SColumnInfoData* pUidCol = taosArrayGet(pDelBlock->pDataBlock, UID_COLUMN_INDEX);
×
UNCOV
636
    TSDB_CHECK_NULL(pUidCol, code, line, END, terrno)
×
637

UNCOV
638
    int64_t* pUid = taosArrayGet(pRes->uidList, i);
×
UNCOV
639
    code = colDataSetVal(pUidCol, i, (const char*)pUid, false);
×
UNCOV
640
    TSDB_CHECK_CODE(code, line, END);
×
UNCOV
641
    void* tmp = taosArrayGet(pDelBlock->pDataBlock, GROUPID_COLUMN_INDEX);
×
UNCOV
642
    TSDB_CHECK_NULL(tmp, code, line, END, terrno)
×
UNCOV
643
    colDataSetNULL(tmp, i);
×
UNCOV
644
    tmp = taosArrayGet(pDelBlock->pDataBlock, CALCULATE_START_TS_COLUMN_INDEX);
×
UNCOV
645
    TSDB_CHECK_NULL(tmp, code, line, END, terrno)
×
UNCOV
646
    colDataSetNULL(tmp, i);
×
UNCOV
647
    tmp = taosArrayGet(pDelBlock->pDataBlock, CALCULATE_END_TS_COLUMN_INDEX);
×
UNCOV
648
    TSDB_CHECK_NULL(tmp, code, line, END, terrno)
×
UNCOV
649
    colDataSetNULL(tmp, i);
×
UNCOV
650
    tmp = taosArrayGet(pDelBlock->pDataBlock, TABLE_NAME_COLUMN_INDEX);
×
UNCOV
651
    TSDB_CHECK_NULL(tmp, code, line, END, terrno)
×
UNCOV
652
    colDataSetNULL(tmp, i);
×
653
  }
654

UNCOV
655
  if (type == 0) {
×
UNCOV
656
    code = taosAllocateQitem(sizeof(SStreamRefDataBlock), DEF_QITEM, 0, pRefBlock);
×
UNCOV
657
    if (code) {
×
658
      blockDataCleanup(pDelBlock);
×
659
      taosMemoryFree(pDelBlock);
×
660
      return code;
×
661
    }
662

UNCOV
663
    ((SStreamRefDataBlock*)(*pRefBlock))->type = STREAM_INPUT__REF_DATA_BLOCK;
×
UNCOV
664
    ((SStreamRefDataBlock*)(*pRefBlock))->pBlock = pDelBlock;
×
UNCOV
665
  } else if (type == 1) {
×
UNCOV
666
    *pRefBlock = pDelBlock;
×
667
  } else {
668
    tqError("unknown type:%d", type);
×
669
    code = TSDB_CODE_TMQ_CONSUMER_ERROR;
×
670
  }
671

UNCOV
672
END:
×
UNCOV
673
  if (code != 0) {
×
674
    tqError("failed to extract delete data block, line:%d code:%d", line, code);
×
675
  }
UNCOV
676
  tDecoderClear(pCoder);
×
UNCOV
677
  taosArrayDestroy(pRes->uidList);
×
UNCOV
678
  return code;
×
679
}
680

UNCOV
681
int32_t tqGetStreamExecInfo(SVnode* pVnode, int64_t streamId, int64_t* pDelay, bool* fhFinished) {
×
UNCOV
682
  SStreamMeta* pMeta = pVnode->pTq->pStreamMeta;
×
UNCOV
683
  int32_t      numOfTasks = taosArrayGetSize(pMeta->pTaskList);
×
UNCOV
684
  int32_t      code = TSDB_CODE_SUCCESS;
×
685

UNCOV
686
  if (pDelay != NULL) {
×
UNCOV
687
    *pDelay = 0;
×
688
  }
689

UNCOV
690
  *fhFinished = false;
×
691

UNCOV
692
  if (numOfTasks <= 0) {
×
693
    return code;
×
694
  }
695

696
  // extract the required source task for a given stream, identified by streamId
UNCOV
697
  streamMetaRLock(pMeta);
×
698

UNCOV
699
  numOfTasks = taosArrayGetSize(pMeta->pTaskList);
×
700

UNCOV
701
  for (int32_t i = 0; i < numOfTasks; ++i) {
×
UNCOV
702
    SStreamTaskId* pId = taosArrayGet(pMeta->pTaskList, i);
×
UNCOV
703
    if (pId == NULL) {
×
UNCOV
704
      continue;
×
705
    }
UNCOV
706
    if (pId->streamId != streamId) {
×
UNCOV
707
      continue;
×
708
    }
709

UNCOV
710
    STaskId      id = {.streamId = pId->streamId, .taskId = pId->taskId};
×
UNCOV
711
    SStreamTask* pTask = NULL;
×
712

UNCOV
713
    code = streamMetaAcquireTaskUnsafe(pMeta, &id, &pTask);
×
UNCOV
714
    if (code != 0) {
×
715
      tqError("vgId:%d failed to acquire task:0x%x in retrieving progress", pMeta->vgId, pId->taskId);
×
716
      continue;
×
717
    }
718

UNCOV
719
    if (pTask->info.taskLevel != TASK_LEVEL__SOURCE) {
×
UNCOV
720
      streamMetaReleaseTask(pMeta, pTask);
×
UNCOV
721
      continue;
×
722
    }
723

724
    // here we get the required stream source task
UNCOV
725
    *fhFinished = !HAS_RELATED_FILLHISTORY_TASK(pTask);
×
726

UNCOV
727
    int64_t ver = walReaderGetCurrentVer(pTask->exec.pWalReader);
×
UNCOV
728
    if (ver == -1) {
×
UNCOV
729
      ver = pTask->chkInfo.processedVer;
×
730
    } else {
UNCOV
731
      ver--;
×
732
    }
733

UNCOV
734
    SVersionRange verRange = {0};
×
UNCOV
735
    walReaderValidVersionRange(pTask->exec.pWalReader, &verRange.minVer, &verRange.maxVer);
×
736

UNCOV
737
    SWalReader* pReader = walOpenReader(pTask->exec.pWalReader->pWal, NULL, 0);
×
UNCOV
738
    if (pReader == NULL) {
×
739
      tqError("failed to open wal reader to extract exec progress, vgId:%d", pMeta->vgId);
×
740
      streamMetaReleaseTask(pMeta, pTask);
×
741
      continue;
×
742
    }
743

UNCOV
744
    int64_t cur = 0;
×
UNCOV
745
    int64_t latest = 0;
×
746

UNCOV
747
    code = walFetchHead(pReader, ver);
×
UNCOV
748
    if (code == TSDB_CODE_SUCCESS) {
×
UNCOV
749
      cur = pReader->pHead->head.ingestTs;
×
750
    }
751

UNCOV
752
    if (ver == verRange.maxVer) {
×
UNCOV
753
      latest = cur;
×
754
    } else {
UNCOV
755
      code = walFetchHead(pReader, verRange.maxVer);
×
UNCOV
756
      if (code == TSDB_CODE_SUCCESS) {
×
UNCOV
757
        latest = pReader->pHead->head.ingestTs;
×
758
      }
759
    }
760

UNCOV
761
    if (pDelay != NULL) {  // delay in ms
×
UNCOV
762
      *pDelay = (latest - cur) / 1000;
×
763
    }
764

UNCOV
765
    walCloseReader(pReader);
×
UNCOV
766
    streamMetaReleaseTask(pMeta, pTask);
×
767
  }
768

UNCOV
769
  streamMetaRUnLock(pMeta);
×
770

UNCOV
771
  return TSDB_CODE_SUCCESS;
×
772
}
773

UNCOV
774
int32_t tqExtractDropCtbDataBlock(const void* data, int32_t len, int64_t ver, void** pRefBlock, int32_t type) {
×
UNCOV
775
  int32_t          code = 0;
×
UNCOV
776
  int32_t          lino = 0;
×
UNCOV
777
  SDecoder         dc = {0};
×
UNCOV
778
  SVDropTbBatchReq batchReq = {0};
×
UNCOV
779
  tDecoderInit(&dc, (uint8_t*)data, len);
×
UNCOV
780
  code = tDecodeSVDropTbBatchReq(&dc, &batchReq);
×
UNCOV
781
  TSDB_CHECK_CODE(code, lino, _exit);
×
UNCOV
782
  if (batchReq.nReqs <= 0) goto _exit;
×
783

UNCOV
784
  SSDataBlock* pBlock = NULL;
×
UNCOV
785
  code = createSpecialDataBlock(STREAM_DROP_CHILD_TABLE, &pBlock);
×
UNCOV
786
  TSDB_CHECK_CODE(code, lino, _exit);
×
787

UNCOV
788
  code = blockDataEnsureCapacity(pBlock, batchReq.nReqs);
×
UNCOV
789
  TSDB_CHECK_CODE(code, lino, _exit);
×
790

UNCOV
791
  pBlock->info.rows = batchReq.nReqs;
×
UNCOV
792
  pBlock->info.version = ver;
×
UNCOV
793
  for (int32_t i = 0; i < batchReq.nReqs; ++i) {
×
UNCOV
794
    SVDropTbReq* pReq = batchReq.pReqs + i;
×
UNCOV
795
    SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, UID_COLUMN_INDEX);
×
UNCOV
796
    TSDB_CHECK_NULL(pCol, code, lino, _exit, terrno);
×
UNCOV
797
    code = colDataSetVal(pCol, i, (const char* )&pReq->uid, false);
×
UNCOV
798
    TSDB_CHECK_CODE(code, lino, _exit);
×
799
  }
800

UNCOV
801
  code = taosAllocateQitem(sizeof(SStreamRefDataBlock), DEF_QITEM, 0, pRefBlock);
×
UNCOV
802
  TSDB_CHECK_CODE(code, lino, _exit);
×
UNCOV
803
  ((SStreamRefDataBlock*)(*pRefBlock))->type = STREAM_INPUT__REF_DATA_BLOCK;
×
UNCOV
804
  ((SStreamRefDataBlock*)(*pRefBlock))->pBlock = pBlock;
×
805

UNCOV
806
_exit:
×
UNCOV
807
  tDecoderClear(&dc);
×
UNCOV
808
  if (TSDB_CODE_SUCCESS != code) {
×
809
    tqError("faled to extract drop ctb data block, line:%d code:%s", lino, tstrerror(code));
×
810
    blockDataCleanup(pBlock);
×
811
    taosMemoryFree(pBlock);
×
812
  }
UNCOV
813
  return code;
×
814
}
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