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

taosdata / TDengine / #3653

14 Mar 2025 08:10AM UTC coverage: 22.565% (-41.0%) from 63.596%
#3653

push

travis-ci

web-flow
feat(keep): support keep on super table level. (#30097)

* Feat: support use keep while create super table.

* Test(keep): add test for create super table with keep option.

* Feat(keep): Add tmsg for create keep.

* Feat(keep): support alter table option keep.

* Fix(keep): Add baisc test for alter table option.

* Fix(keep): memory leek.

* Feat(keep): add keep to metaEntry&metaCache and fix earliestTs with stn keep.

* Test(keep): add some cases for select with stb keep.

* Fix: fix ci core while alter stb.

* Feat(keep): delete expired data in super table level.

* Feat: remove get stb keep while query.

* Fix : build error.

* Revert "Fix : build error."

This reverts commit 0ed66e4e8.

* Revert "Feat(keep): delete expired data in super table level."

This reverts commit 36330f6b4.

* Fix : build errors.

* Feat : support restart taosd.

* Fix : alter table comment problems.

* Test : add tests for super table keep.

* Fix: change sdb stb reserve size.

* Test: add more tests.

* Feat: Disable normal tables and sub tables from setting the keep parameter

* Fix: add more checks to avoid unknown address.

* Docs: Add docs for stable keep.

* Fix: some review changes.

* Fix: review errors.

49248 of 302527 branches covered (16.28%)

Branch coverage included in aggregate %.

53 of 99 new or added lines in 12 files covered. (53.54%)

155872 existing lines in 443 files now uncovered.

87359 of 302857 relevant lines covered (28.84%)

570004.22 hits per line

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

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

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

51
  if (isLeader) {
20!
52
    tqScanWalAsync(pTq);
20✔
53
  }
54
}
20✔
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

78

UNCOV
79
END:
×
UNCOV
80
  if (code != 0){
×
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
  }
UNCOV
87
  return code;
×
88
}
89

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

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

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

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

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

UNCOV
151
  return 0;
×
152
}
153

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

UNCOV
163
  SMqDataRsp dataRsp = {0};
×
UNCOV
164
  code = tqInitDataRsp(&dataRsp, *pOffset);
×
UNCOV
165
  TSDB_CHECK_CODE(code, lino, end);
×
166

UNCOV
167
  code = qSetTaskId(pHandle->execHandle.task, consumerId, pRequest->reqId);
×
UNCOV
168
  TSDB_CHECK_CODE(code, lino, end);
×
169

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

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

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

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

UNCOV
204
    tDeleteMqDataRsp(&dataRsp);
×
UNCOV
205
    return code;
×
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

UNCOV
227
static void tDeleteCommon(void* parm) {}
×
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

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

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

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

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

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

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

UNCOV
295
END:
×
UNCOV
296
  taosArrayDestroy(pReq.pArray);
×
UNCOV
297
  return code;
×
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;
UNCOV
309
static int32_t extractDataAndRspForDbStbSubscribe(STQ* pTq, STqHandle* pHandle, const SMqPollReq* pRequest,
×
310
                                                  SRpcMsg* pMsg, STqOffsetVal* offset) {
UNCOV
311
  int32_t         vgId = TD_VID(pTq->pVnode);
×
UNCOV
312
  SMqDataRsp      taosxRsp = {0};
×
UNCOV
313
  SMqBatchMetaRsp btMetaRsp = {0};
×
UNCOV
314
  int32_t         code = 0;
×
315

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

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

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

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

UNCOV
341
    uint64_t st = taosGetTimestampMs();
×
UNCOV
342
    int      totalRows = 0;
×
UNCOV
343
    int32_t  totalMetaRows = 0;
×
UNCOV
344
    while (1) {
×
UNCOV
345
      int32_t savedEpoch = atomic_load_32(&pHandle->epoch);
×
UNCOV
346
      if (savedEpoch > pRequest->epoch) {
×
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;
×
UNCOV
350
        goto END;
×
351
      }
352

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

UNCOV
556
  return 0;
×
557
}
558

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

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

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

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

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

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

UNCOV
597
  return 0;
×
598
}
599

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

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

UNCOV
619
  if (code < 0) {
×
620
    return TAOS_GET_TERRNO(code);
×
621
  }
622

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

UNCOV
629
  SMqRspHead* pHead = (SMqRspHead*)buf;
×
UNCOV
630
  initMqRspHead(pHead, type, epoch, consumerId, sver, ever);
×
631

UNCOV
632
  void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
×
633

UNCOV
634
  SEncoder encoder = {0};
×
UNCOV
635
  tEncoderInit(&encoder, abuf, len);
×
636

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

UNCOV
651
  tmsgSendRsp(&rsp);
×
UNCOV
652
  return 0;
×
653
}
654

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

UNCOV
661
  *pRefBlock = NULL;
×
662

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

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

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

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

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

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

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

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

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

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

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

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

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

UNCOV
751
  *fhFinished = false;
×
752

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

UNCOV
830
  streamMetaRUnLock(pMeta);
×
831

UNCOV
832
  return TSDB_CODE_SUCCESS;
×
833
}
834

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

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

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

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

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

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