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

taosdata / TDengine / #4180

27 May 2025 10:49AM UTC coverage: 63.267% (+0.4%) from 62.885%
#4180

push

travis-ci

web-flow
TD-35056 (#31227)

158426 of 318644 branches covered (49.72%)

Branch coverage included in aggregate %.

243945 of 317346 relevant lines covered (76.87%)

18276423.81 hits per line

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

69.92
/source/dnode/vnode/src/tq/tqStreamTask.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
#include "vnd.h"
18

19
#define SCAN_WAL_IDLE_DURATION    250  // idle for 500ms to do next wal scan
20
#define SCAN_WAL_WAIT_COUNT       2
21

22
typedef struct SBuildScanWalMsgParam {
23
  int64_t metaId;
24
  SMsgCb  msgCb;
25
} SBuildScanWalMsgParam;
26

27
static int32_t doScanWalForAllTasks(SStreamMeta* pStreamMeta, int32_t* pNumOfTasks);
28
static int32_t setWalReaderStartOffset(SStreamTask* pTask, int32_t vgId);
29
static bool    handleFillhistoryScanComplete(SStreamTask* pTask, int64_t ver);
30
static bool    taskReadyForDataFromWal(SStreamTask* pTask);
31
static int32_t doPutDataIntoInputQ(SStreamTask* pTask, int64_t maxVer, int32_t* numOfItems, bool* pSucc);
32

33
// extract data blocks(submit/delete) from WAL, and add them into the input queue for all the sources tasks.
34
int32_t tqScanWal(STQ* pTq) {
206,013✔
35
  SStreamMeta* pMeta = pTq->pStreamMeta;
206,013✔
36
  int32_t      vgId = pMeta->vgId;
206,013✔
37
  int64_t      st = taosGetTimestampMs();
206,557✔
38
  int32_t      numOfTasks = 0;
206,557✔
39
  int64_t      el = 0;
206,557✔
40
  int32_t      code = 0;
206,557✔
41

42
  int32_t old = atomic_val_compare_exchange_32(&pMeta->scanInfo.scanSentinel, 0, 1);
206,557✔
43
  if (old == 0) {
206,490!
44
    tqDebug("vgId:%d try to scan wal to extract data", vgId);
206,525✔
45
  } else {
46
    tqDebug("vgId:%d already in wal scan, abort", vgId);
×
47
    return code;
×
48
  }
49

50
  // the scan wal interval less than 200, not scan, actually.
51
  if ((pMeta->scanInfo.lastScanTs > 0) && (st - pMeta->scanInfo.lastScanTs < 200)) {
206,528✔
52
    tqDebug("vgId:%d scan wal less than 200ms, do nothing", vgId);
1!
53
    atomic_store_32(&pMeta->scanInfo.scanSentinel, 0);
1✔
54
    return code;
1✔
55
  }
56

57
  // check all tasks
58
  code = doScanWalForAllTasks(pMeta, &numOfTasks);
206,527✔
59

60
  pMeta->scanInfo.lastScanTs = taosGetTimestampMs();
206,217✔
61
  el = (pMeta->scanInfo.lastScanTs - st);
206,217✔
62

63
  if (code) {
206,217!
64
    tqError("vgId:%d failed to scan wal for all tasks, try next time, elapsed time:%" PRId64 "ms code:%s", vgId, el,
×
65
            tstrerror(code));
66
  } else {
67
    tqDebug("vgId:%d scan wal for stream tasks completed, elapsed time:%" PRId64 "ms", vgId, el);
206,217✔
68
  }
69

70
  atomic_store_32(&pMeta->scanInfo.scanSentinel, 0);
206,218✔
71
  return code;
206,503✔
72
}
73

74
static bool waitEnoughDuration(SStreamMeta* pMeta) {
2,643,472✔
75
  if ((++pMeta->scanInfo.tickCounter) >= SCAN_WAL_WAIT_COUNT) {
2,643,472✔
76
    pMeta->scanInfo.tickCounter = 0;
1,318,658✔
77
    return true;
1,318,658✔
78
  }
79

80
  return false;
1,324,814✔
81
}
82

83
static void doStartScanWal(void* param, void* tmrId) {
2,668,139✔
84
  int32_t                vgId = 0;
2,668,139✔
85
  int32_t                code = 0;
2,668,139✔
86
  int32_t                numOfTasks = 0;
2,668,139✔
87
  tmr_h                  pTimer = NULL;
2,668,139✔
88
  int32_t                numOfItems = 0;
2,668,139✔
89
  STQ*                   pTq = NULL;
2,668,139✔
90
  SBuildScanWalMsgParam* pParam = (SBuildScanWalMsgParam*)param;
2,668,139✔
91

92
  tqTrace("start to do scan wal in tmr, metaRid:%" PRId64, pParam->metaId);
2,668,139✔
93

94
  SStreamMeta* pMeta = taosAcquireRef(streamMetaRefPool, pParam->metaId);
2,668,139✔
95
  if (pMeta == NULL) {
2,668,139!
96
    tqError("metaRid:%" PRId64 " not valid now, stream meta has been freed", pParam->metaId);
×
97
    taosMemoryFree(pParam);
×
98
    return;
1,337,526✔
99
  }
100

101
  pTq = pMeta->ahandle;
2,668,139✔
102
  vgId = pMeta->vgId;
2,668,139✔
103
  code = streamTimerGetInstance(&pTimer);
2,668,139✔
104
  if (code) {
2,668,139!
105
    tqFatal("vgId:%d failed to get tmr ctrl during sched scan wal, not scan wal, code:%s", vgId, tstrerror(code));
×
106
    taosMemoryFree(pParam);
×
107
    return;
×
108
  }
109

110
  if (pMeta->closeFlag) {
2,668,139✔
111
    code = taosReleaseRef(streamMetaRefPool, pParam->metaId);
12,683✔
112
    if (code == TSDB_CODE_SUCCESS) {
12,683!
113
      tqInfo("vgId:%d jump out of scan wal timer since closed", vgId);
12,683!
114
    } else {
115
      tqError("vgId:%d failed to release ref for streamMeta, rid:%" PRId64 " code:%s", vgId, pParam->metaId,
×
116
              tstrerror(code));
117
    }
118

119
    taosMemoryFree(pParam);
12,683!
120
    return;
12,683✔
121
  }
122

123
  if (pMeta->role != NODE_ROLE_LEADER) {
2,655,456✔
124
    tqDebug("vgId:%d not leader, role:%d not scan wal anymore", vgId, pMeta->role);
29!
125

126
    code = taosReleaseRef(streamMetaRefPool, pParam->metaId);
29✔
127
    if (code == TSDB_CODE_SUCCESS) {
29!
128
      tqDebug("vgId:%d jump out of scan wal timer since not leader", vgId);
29!
129
    } else {
130
      tqError("vgId:%d failed to release ref for streamMeta, rid:%" PRId64 " code:%s", vgId, pParam->metaId,
×
131
              tstrerror(code));
132
    }
133

134
    taosMemFree(pParam);
29✔
135
    return;
29✔
136
  }
137

138
  if (pMeta->startInfo.startAllTasks) {
2,655,427✔
139
    tqDebug("vgId:%d in restart procedure, not ready to scan wal", vgId);
11,955✔
140
    goto _end;
11,955✔
141
  }
142

143
  numOfItems = tmsgGetQueueSize(&pTq->pVnode->msgCb, pMeta->vgId, STREAM_QUEUE);
2,643,472✔
144
  bool tooMany = (numOfItems > tsThresholdItemsInStreamQueue);
2,643,472✔
145

146
  if (!waitEnoughDuration(pMeta) || tooMany) {
2,643,472!
147
    if (tooMany) {
1,324,814!
148
      tqDebug("vgId:%d %d items (threshold: %d) in stream_queue, not scan wal now", vgId, numOfItems,
×
149
              tsThresholdItemsInStreamQueue);
150
    }
151

152
    streamTmrStart(doStartScanWal, SCAN_WAL_IDLE_DURATION, pParam, pTimer, &pMeta->scanInfo.scanTimer, vgId,
1,324,814✔
153
                   "scan-wal");
154
    code = taosReleaseRef(streamMetaRefPool, pParam->metaId);
1,324,814✔
155
    if (code) {
1,324,814!
156
      tqError("vgId:%d failed to release ref for streamMeta, rid:%" PRId64 " code:%s", vgId, pParam->metaId,
×
157
              tstrerror(code));
158
    }
159
    return;
1,324,814✔
160
  }
161

162
  // failed to lock, try 500ms later
163
  code = streamMetaTryRlock(pMeta);
1,318,658✔
164
  if (code == 0) {
1,318,658✔
165
    numOfTasks = taosArrayGetSize(pMeta->pTaskList);
1,318,310✔
166
    streamMetaRUnLock(pMeta);
1,318,310✔
167
  } else {
168
    numOfTasks = 0;
348✔
169
  }
170

171
  if (numOfTasks > 0) {
1,318,658✔
172
    tqDebug("vgId:%d create msg to start wal scan, numOfTasks:%d", vgId, numOfTasks);
206,640✔
173

174
#if 0
175
  //  wait for the vnode is freed, and invalid read may occur.
176
  taosMsleep(10000);
177
#endif
178

179
    code = streamTaskSchedTask(&pParam->msgCb, vgId, 0, 0, STREAM_EXEC_T_EXTRACT_WAL_DATA, false);
206,640✔
180
    if (code) {
206,640!
181
      tqError("vgId:%d failed sched task to scan wal, code:%s", vgId, tstrerror(code));
×
182
    }
183
  }
184

185
_end:
1,318,658✔
186
  streamTmrStart(doStartScanWal, SCAN_WAL_IDLE_DURATION, pParam, pTimer, &pMeta->scanInfo.scanTimer, vgId, "scan-wal");
1,330,613✔
187
  tqTrace("vgId:%d try scan-wal will start in %dms", vgId, SCAN_WAL_IDLE_DURATION*SCAN_WAL_WAIT_COUNT);
1,330,613✔
188

189
  code = taosReleaseRef(streamMetaRefPool, pParam->metaId);
1,330,613✔
190
  if (code) {
1,330,613!
191
    tqError("vgId:%d failed to release ref for streamMeta, rid:%" PRId64 " code:%s", vgId, pParam->metaId,
×
192
            tstrerror(code));
193
  }
194
}
195

196
void tqScanWalAsync(STQ* pTq) {
12,707✔
197
  SStreamMeta*           pMeta = pTq->pStreamMeta;
12,707✔
198
  int32_t                code = 0;
12,707✔
199
  int32_t                vgId = TD_VID(pTq->pVnode);
12,707✔
200
  tmr_h                  pTimer = NULL;
12,707✔
201
  SBuildScanWalMsgParam* pParam = NULL;
12,707✔
202

203
  // 1. the vnode should be the leader.
204
  // 2. the stream isn't disabled
205
  if ((pMeta->role != NODE_ROLE_LEADER) || tsDisableStream) {
12,707!
206
    tqInfo("vgId:%d follower node or stream disabled, not scan wal", vgId);
×
207
    return;
×
208
  }
209

210
  pParam = taosMemoryMalloc(sizeof(SBuildScanWalMsgParam));
12,712!
211
  if (pParam == NULL) {
12,712!
212
    tqError("vgId:%d failed to start scan wal, stream not executes, code:%s", vgId, tstrerror(code));
×
213
    return;
×
214
  }
215

216
  pParam->metaId = pMeta->rid;
12,712✔
217
  pParam->msgCb = pTq->pVnode->msgCb;
12,712✔
218

219
  code = streamTimerGetInstance(&pTimer);
12,712✔
220
  if (code) {
12,712!
221
    tqFatal("vgId:%d failed to get tmr ctrl during sched scan wal", vgId);
×
222
    taosMemoryFree(pParam);
×
223
  } else {
224
    streamTmrStart(doStartScanWal, SCAN_WAL_IDLE_DURATION, pParam, pTimer, &pMeta->scanInfo.scanTimer, vgId,
12,712✔
225
                   "scan-wal");
226
  }
227
}
228

229
int32_t tqStopStreamAllTasksAsync(SStreamMeta* pMeta, SMsgCb* pMsgCb) {
6,255✔
230
  return streamTaskSchedTask(pMsgCb, pMeta->vgId, 0, 0, STREAM_EXEC_T_STOP_ALL_TASKS, false);
6,255✔
231
}
232

233
int32_t setWalReaderStartOffset(SStreamTask* pTask, int32_t vgId) {
219,664✔
234
  // seek the stored version and extract data from WAL
235
  int64_t firstVer = walReaderGetValidFirstVer(pTask->exec.pWalReader);
219,664✔
236
  if (pTask->chkInfo.nextProcessVer < firstVer) {
219,842✔
237
    tqWarn("vgId:%d s-task:%s ver:%" PRId64 " earlier than the first ver of wal range %" PRId64 ", forward to %" PRId64,
5!
238
           vgId, pTask->id.idStr, pTask->chkInfo.nextProcessVer, firstVer, firstVer);
239

240
    pTask->chkInfo.nextProcessVer = firstVer;
5✔
241

242
    // todo need retry if failed
243
    int32_t code = walReaderSeekVer(pTask->exec.pWalReader, pTask->chkInfo.nextProcessVer);
5✔
244
    if (code != TSDB_CODE_SUCCESS) {
5!
245
      return code;
×
246
    }
247

248
    // append the data for the stream
249
    tqDebug("vgId:%d s-task:%s wal reader seek to ver:%" PRId64, vgId, pTask->id.idStr, pTask->chkInfo.nextProcessVer);
5!
250
  } else {
251
    int64_t currentVer = walReaderGetCurrentVer(pTask->exec.pWalReader);
219,837✔
252
    if (currentVer == -1) {  // we only seek the read for the first time
219,447✔
253
      int32_t code = walReaderSeekVer(pTask->exec.pWalReader, pTask->chkInfo.nextProcessVer);
4,237✔
254
      if (code != TSDB_CODE_SUCCESS) {  // no data in wal, quit
4,232!
255
        return code;
×
256
      }
257

258
      // append the data for the stream
259
      tqDebug("vgId:%d s-task:%s wal reader initial seek to ver:%" PRId64, vgId, pTask->id.idStr,
4,232✔
260
              pTask->chkInfo.nextProcessVer);
261
    }
262
  }
263

264
  int64_t skipToVer = walReaderGetSkipToVersion(pTask->exec.pWalReader);
219,448✔
265
  if (skipToVer != 0 && skipToVer > pTask->chkInfo.nextProcessVer) {
219,549✔
266
    int32_t code = walReaderSeekVer(pTask->exec.pWalReader, skipToVer);
132✔
267
    if (code != TSDB_CODE_SUCCESS) {  // no data in wal, quit
133!
268
      return code;
×
269
    }
270

271
    tqDebug("vgId:%d s-task:%s wal reader jump to ver:%" PRId64, vgId, pTask->id.idStr, skipToVer);
133✔
272
  }
273

274
  return TSDB_CODE_SUCCESS;
219,497✔
275
}
276

277
// todo handle memory error
278
bool handleFillhistoryScanComplete(SStreamTask* pTask, int64_t ver) {
389,469✔
279
  const char* id = pTask->id.idStr;
389,469✔
280
  int64_t     maxVer = pTask->step2Range.maxVer;
389,469✔
281

282
  if ((pTask->info.fillHistory == 1) && ver > maxVer) {
389,469✔
283
    if (!pTask->status.appendTranstateBlock) {
678!
284
      qWarn("s-task:%s fill-history scan WAL, nextProcessVer:%" PRId64 " out of the maximum ver:%" PRId64
678!
285
            ", not scan wal anymore, add transfer-state block into inputQ",
286
            id, ver, maxVer);
287

288
      double el = (taosGetTimestampMs() - pTask->execInfo.step2Start) / 1000.0;
678✔
289
      qDebug("s-task:%s scan-history from WAL stage(step 2) ended, range:%" PRId64 "-%" PRId64 ", elapsed time:%.2fs",
678✔
290
             id, pTask->step2Range.minVer, maxVer, el);
291
      int32_t code = streamTaskPutTranstateIntoInputQ(pTask);
678✔
292
      if (code) {
678!
293
        qError("s-task:%s failed to put trans-state into inputQ", id);
×
294
      }
295

296
      return true;
678✔
297
    } else {
298
      qWarn("s-task:%s fill-history scan WAL, nextProcessVer:%" PRId64 " out of the ver range:%" PRId64 "-%" PRId64
×
299
            ", not scan wal",
300
            id, ver, pTask->step2Range.minVer, maxVer);
301
    }
302
  }
303

304
  return false;
388,441✔
305
}
306

307
bool taskReadyForDataFromWal(SStreamTask* pTask) {
587,141✔
308
  // non-source or fill-history tasks don't need to response the WAL scan action.
309
  SSTaskBasicInfo* pInfo = &pTask->info;
587,141✔
310
  if ((pInfo->taskLevel != TASK_LEVEL__SOURCE) || (pTask->status.downstreamReady == 0)) {
587,141✔
311
    return false;
279,464✔
312
  }
313

314
  if (pInfo->trigger == STREAM_TRIGGER_FORCE_WINDOW_CLOSE) {
307,677✔
315
    return false;
36,634✔
316
  }
317

318
  if (pInfo->fillHistory == STREAM_RECALCUL_TASK) {
271,043!
319
    return false;
×
320
  }
321

322
  // not in ready state, do not handle the data from wal
323
  SStreamTaskState pState = streamTaskGetStatus(pTask);
271,043✔
324
  if (pState.state != TASK_STATUS__READY) {
271,023✔
325
    tqTrace("s-task:%s not ready for submit block in wal, status:%s", pTask->id.idStr, pState.name);
43,045✔
326
    return false;
43,045✔
327
  }
328

329
  // fill-history task has entered into the last phase, no need to do anything
330
  if ((pInfo->fillHistory == STREAM_HISTORY_TASK) && pTask->status.appendTranstateBlock) {
227,978✔
331
    // the maximum version of data in the WAL has reached already, the step2 is done
332
    tqDebug("s-task:%s fill-history reach the maximum ver:%" PRId64 ", not scan wal anymore", pTask->id.idStr,
7,747✔
333
            pTask->dataRange.range.maxVer);
334
    return false;
7,747✔
335
  }
336

337
  // check whether input queue is full or not
338
  if (streamQueueIsFull(pTask->inputq.queue)) {
220,231✔
339
    tqTrace("s-task:%s input queue is full, launch task without scanning wal", pTask->id.idStr);
151!
340
    int32_t code = streamTrySchedExec(pTask, false);
151✔
341
    if (code) {
1!
342
      tqError("s-task:%s failed to start task while inputQ is full", pTask->id.idStr);
×
343
    }
344
    return false;
1✔
345
  }
346

347
  // the input queue of downstream task is full, so the output is blocked, stopped for a while
348
  if (pTask->inputq.status == TASK_INPUT_STATUS__BLOCKED) {
220,100!
349
    tqDebug("s-task:%s inputQ is blocked, do nothing", pTask->id.idStr);
×
350
    return false;
×
351
  }
352

353
  return true;
220,100✔
354
}
355

356
int32_t doPutDataIntoInputQ(SStreamTask* pTask, int64_t maxVer, int32_t* numOfItems, bool* pSucc) {
219,704✔
357
  const char* id = pTask->id.idStr;
219,704✔
358
  int32_t     numOfNewItems = 0;
219,704✔
359
  int32_t     code = 0;
219,704✔
360
  *pSucc = false;
219,704✔
361

362
  while (1) {
170,147✔
363
    if ((pTask->info.fillHistory == 1) && pTask->status.appendTranstateBlock) {
389,851!
364
      *numOfItems += numOfNewItems;
×
365
      return numOfNewItems > 0;
×
366
    }
367

368
    SStreamQueueItem* pItem = NULL;
389,851✔
369
    code = extractMsgFromWal(pTask->exec.pWalReader, (void**)&pItem, maxVer, id);
389,851✔
370
    if (code != TSDB_CODE_SUCCESS || pItem == NULL) {  // failed, continue
389,301✔
371
      int64_t currentVer = walReaderGetCurrentVer(pTask->exec.pWalReader);
218,927✔
372
      bool    itemInFillhistory = handleFillhistoryScanComplete(pTask, currentVer);
219,027✔
373
      if (itemInFillhistory) {
218,836✔
374
        numOfNewItems += 1;
460✔
375
      }
376
      break;
218,836✔
377
    }
378

379
    if (pItem != NULL) {
170,374✔
380
      code = streamTaskPutDataIntoInputQ(pTask, pItem);
170,373✔
381
      if (code == TSDB_CODE_SUCCESS) {
170,398✔
382
        numOfNewItems += 1;
170,383✔
383
        int64_t ver = walReaderGetCurrentVer(pTask->exec.pWalReader);
170,383✔
384
        pTask->chkInfo.nextProcessVer = ver;
170,370✔
385
        tqDebug("s-task:%s set ver:%" PRId64 " for reader after extract data from WAL", id, ver);
170,370✔
386

387
        bool itemInFillhistory = handleFillhistoryScanComplete(pTask, ver);
170,370✔
388
        if (itemInFillhistory) {
170,364✔
389
          break;
218✔
390
        }
391
      } else {
392
        if (code == TSDB_CODE_OUT_OF_MEMORY) {
15!
393
          tqError("s-task:%s failed to put data into inputQ, since out of memory", id);
×
394
        } else {
395
          tqTrace("s-task:%s append input queue failed, code:inputQ is full, ver:%" PRId64, id,
15!
396
                  pTask->chkInfo.nextProcessVer);
397
          code = walReaderSeekVer(pTask->exec.pWalReader, pTask->chkInfo.nextProcessVer);
15✔
398
          if (code) {
15!
399
            tqError("s-task:%s failed to seek ver to:%" PRId64 " in wal", id, pTask->chkInfo.nextProcessVer);
×
400
          }
401

402
          code = 0;  // reset the error code
15✔
403
        }
404

405
        break;
15✔
406
      }
407
    }
408
  }
409

410
  *numOfItems += numOfNewItems;
219,069✔
411
  *pSucc = (numOfNewItems > 0);
219,069✔
412
  return code;
219,069✔
413
}
414

415
int32_t doScanWalForAllTasks(SStreamMeta* pStreamMeta, int32_t* pNumOfTasks) {
206,305✔
416
  int32_t vgId = pStreamMeta->vgId;
206,305✔
417
  SArray* pTaskList = NULL;
206,305✔
418
  int32_t numOfTasks = 0;
206,305✔
419

420
  // clone the task list, to avoid the task update during scan wal files
421
  streamMetaWLock(pStreamMeta);
206,305✔
422
  pTaskList = taosArrayDup(pStreamMeta->pTaskList, NULL);
206,476✔
423
  streamMetaWUnLock(pStreamMeta);
206,482✔
424
  if (pTaskList == NULL) {
206,362!
425
    tqError("vgId:%d failed to create task list dup, code:%s", vgId, tstrerror(terrno));
×
426
    return terrno;
×
427
  }
428

429
  // update the new task number
430
  numOfTasks = taosArrayGetSize(pTaskList);
206,362✔
431
  if (pNumOfTasks != NULL) {
206,095!
432
    *pNumOfTasks = numOfTasks;
206,183✔
433
  }
434

435
  tqDebug("vgId:%d start to check wal to extract new submit block for %d tasks", vgId, numOfTasks);
206,095✔
436

437
  for (int32_t i = 0; i < numOfTasks; ++i) {
799,247✔
438
    STaskId* pTaskId = taosArrayGet(pTaskList, i);
592,362✔
439
    if (pTaskId == NULL) {
590,543!
440
      continue;
372,785✔
441
    }
442

443
    SStreamTask* pTask = NULL;
590,543✔
444
    int32_t      code = streamMetaAcquireTask(pStreamMeta, pTaskId->streamId, pTaskId->taskId, &pTask);
590,543✔
445
    if (pTask == NULL || code != 0) {
592,834!
446
      continue;
5,128✔
447
    }
448

449
    if (!taskReadyForDataFromWal(pTask)) {
587,706✔
450
      streamMetaReleaseTask(pStreamMeta, pTask);
367,428✔
451
      continue;
367,638✔
452
    }
453

454
    // seek the stored version and extract data from WAL
455
    code = setWalReaderStartOffset(pTask, vgId);
219,947✔
456
    if (code != TSDB_CODE_SUCCESS) {
219,460!
457
      streamMetaReleaseTask(pStreamMeta, pTask);
×
458
      continue;
×
459
    }
460

461
    int32_t numOfItems = streamQueueGetNumOfItems(pTask->inputq.queue);
219,460✔
462
    int64_t maxVer = (pTask->info.fillHistory == 1) ? pTask->step2Range.maxVer : INT64_MAX;
219,858✔
463

464
    streamMutexLock(&pTask->lock);
219,858✔
465

466
    SStreamTaskState state = streamTaskGetStatus(pTask);
220,132✔
467
    if (state.state != TASK_STATUS__READY) {
220,004!
468
      tqDebug("s-task:%s not ready for submit block from wal, status:%s", pTask->id.idStr, state.name);
×
469
      streamMutexUnlock(&pTask->lock);
×
470
      streamMetaReleaseTask(pStreamMeta, pTask);
×
471
      continue;
19✔
472
    }
473

474
    bool hasNewData = false;
220,004✔
475
    code = doPutDataIntoInputQ(pTask, maxVer, &numOfItems, &hasNewData);
220,004✔
476
    streamMutexUnlock(&pTask->lock);
219,072✔
477

478
    TAOS_UNUSED(code);
479

480
    if ((numOfItems > 0) || hasNewData) {
220,220!
481
      code = streamTrySchedExec(pTask, false);
15,863✔
482
      if (code != TSDB_CODE_SUCCESS) {
15,866!
483
        streamMetaReleaseTask(pStreamMeta, pTask);
×
484
        taosArrayDestroy(pTaskList);
×
485
        return code;
×
486
      }
487
    }
488

489
    streamMetaReleaseTask(pStreamMeta, pTask);
220,223✔
490
  }
491

492
  taosArrayDestroy(pTaskList);
206,885✔
493
  return TSDB_CODE_SUCCESS;
206,342✔
494
}
495

496
void streamMetaFreeTQDuringScanWalError(STQ* pTq) {
×
497
  SBuildScanWalMsgParam* p = taosMemoryCalloc(1, sizeof(SBuildScanWalMsgParam));
×
498
  p->metaId = pTq->pStreamMeta->rid;
×
499

500
  doStartScanWal(p, 0);
×
501
}
×
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