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

taosdata / TDengine / #4258

10 Jun 2025 06:25AM UTC coverage: 62.983% (+0.1%) from 62.872%
#4258

push

travis-ci

GitHub
add server port and mqttport in configuration file (#31277)

157807 of 318982 branches covered (49.47%)

Branch coverage included in aggregate %.

243299 of 317865 relevant lines covered (76.54%)

17887576.03 hits per line

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

67.62
/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) {
199,218✔
35
  SStreamMeta* pMeta = pTq->pStreamMeta;
199,218✔
36
  int32_t      vgId = pMeta->vgId;
199,218✔
37
  int64_t      st = taosGetTimestampMs();
199,400✔
38
  int32_t      numOfTasks = 0;
199,400✔
39
  int64_t      el = 0;
199,400✔
40
  int32_t      code = 0;
199,400✔
41

42
  int32_t old = atomic_val_compare_exchange_32(&pMeta->scanInfo.scanSentinel, 0, 1);
199,400✔
43
  if (old == 0) {
199,413!
44
    tqDebug("vgId:%d try to scan wal to extract data", vgId);
199,435✔
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)) {
199,434✔
52
    tqDebug("vgId:%d scan wal less than 200ms, do nothing", vgId);
4!
53
    atomic_store_32(&pMeta->scanInfo.scanSentinel, 0);
4✔
54
    return code;
4✔
55
  }
56

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

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

63
  if (code) {
199,256!
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);
199,256✔
68
  }
69

70
  atomic_store_32(&pMeta->scanInfo.scanSentinel, 0);
199,257✔
71
  return code;
199,446✔
72
}
73

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

80
  return false;
1,258,154✔
81
}
82

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

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

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

101
  pTq = pMeta->ahandle;
2,534,901✔
102
  vgId = pMeta->vgId;
2,534,901✔
103
  code = streamTimerGetInstance(&pTimer);
2,534,901✔
104
  if (code) {
2,534,901!
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,534,901✔
111
    code = taosReleaseRef(streamMetaRefPool, pParam->metaId);
12,008✔
112
    if (code == TSDB_CODE_SUCCESS) {
12,008!
113
      tqInfo("vgId:%d jump out of scan wal timer since closed", vgId);
12,008!
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,008!
120
    return;
12,008✔
121
  }
122

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

126
    code = taosReleaseRef(streamMetaRefPool, pParam->metaId);
37✔
127
    if (code == TSDB_CODE_SUCCESS) {
37!
128
      tqDebug("vgId:%d jump out of scan wal timer since not leader", vgId);
37!
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);
37✔
135
    return;
37✔
136
  }
137

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

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

146
  if (!waitEnoughDuration(pMeta) || tooMany) {
2,510,561!
147
    if (tooMany) {
1,258,154!
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,258,154✔
153
                   "scan-wal");
154
    code = taosReleaseRef(streamMetaRefPool, pParam->metaId);
1,258,154✔
155
    if (code) {
1,258,154!
156
      tqError("vgId:%d failed to release ref for streamMeta, rid:%" PRId64 " code:%s", vgId, pParam->metaId,
×
157
              tstrerror(code));
158
    }
159
    return;
1,258,154✔
160
  }
161

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

171
  if (numOfTasks > 0) {
1,252,407✔
172
    tqDebug("vgId:%d create msg to start wal scan, numOfTasks:%d", vgId, numOfTasks);
199,513✔
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);
199,513✔
180
    if (code) {
199,513✔
181
      tqError("vgId:%d failed sched task to scan wal, code:%s", vgId, tstrerror(code));
4!
182
    }
183
  }
184

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

189
  code = taosReleaseRef(streamMetaRefPool, pParam->metaId);
1,264,702✔
190
  if (code) {
1,264,702!
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,042✔
197
  SStreamMeta*           pMeta = pTq->pStreamMeta;
12,042✔
198
  int32_t                code = 0;
12,042✔
199
  int32_t                vgId = TD_VID(pTq->pVnode);
12,042✔
200
  tmr_h                  pTimer = NULL;
12,042✔
201
  SBuildScanWalMsgParam* pParam = NULL;
12,042✔
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,042!
206
    tqInfo("vgId:%d follower node or stream disabled, not scan wal", vgId);
×
207
    return;
×
208
  }
209

210
  pParam = taosMemoryMalloc(sizeof(SBuildScanWalMsgParam));
12,045!
211
  if (pParam == NULL) {
12,044!
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,044✔
217
  pParam->msgCb = pTq->pVnode->msgCb;
12,044✔
218

219
  code = streamTimerGetInstance(&pTimer);
12,044✔
220
  if (code) {
12,044!
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,044✔
225
                   "scan-wal");
226
  }
227
}
228

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

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

240
    pTask->chkInfo.nextProcessVer = firstVer;
×
241

242
    // todo need retry if failed
243
    int32_t code = walReaderSeekVer(pTask->exec.pWalReader, pTask->chkInfo.nextProcessVer);
×
244
    if (code != TSDB_CODE_SUCCESS) {
×
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);
×
250
  } else {
251
    int64_t currentVer = walReaderGetCurrentVer(pTask->exec.pWalReader);
213,527✔
252
    if (currentVer == -1) {  // we only seek the read for the first time
213,323✔
253
      int32_t code = walReaderSeekVer(pTask->exec.pWalReader, pTask->chkInfo.nextProcessVer);
4,208✔
254
      if (code != TSDB_CODE_SUCCESS) {  // no data in wal, quit
4,201!
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,201✔
260
              pTask->chkInfo.nextProcessVer);
261
    }
262
  }
263

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

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

274
  return TSDB_CODE_SUCCESS;
213,192✔
275
}
276

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

282
  if ((pTask->info.fillHistory == 1) && ver > maxVer) {
342,701✔
283
    if (!pTask->status.appendTranstateBlock) {
699!
284
      qWarn("s-task:%s fill-history scan WAL, nextProcessVer:%" PRId64 " out of the maximum ver:%" PRId64
699!
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;
699✔
289
      qDebug("s-task:%s scan-history from WAL stage(step 2) ended, range:%" PRId64 "-%" PRId64 ", elapsed time:%.2fs",
699✔
290
             id, pTask->step2Range.minVer, maxVer, el);
291
      int32_t code = streamTaskPutTranstateIntoInputQ(pTask);
699✔
292
      if (code) {
699!
293
        qError("s-task:%s failed to put trans-state into inputQ", id);
×
294
      }
295

296
      return true;
699✔
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;
341,983✔
305
}
306

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

314
  if (pInfo->trigger == STREAM_TRIGGER_FORCE_WINDOW_CLOSE) {
298,761✔
315
    return false;
36,441✔
316
  }
317

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

322
  // not in ready state, do not handle the data from wal
323
  SStreamTaskState pState = streamTaskGetStatus(pTask);
262,320✔
324
  if (pState.state != TASK_STATUS__READY) {
262,226✔
325
    tqTrace("s-task:%s not ready for submit block in wal, status:%s", pTask->id.idStr, pState.name);
40,233✔
326
    return false;
40,231✔
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) {
221,993✔
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,
8,414✔
333
            pTask->dataRange.range.maxVer);
334
    return false;
8,414✔
335
  }
336

337
  // check whether input queue is full or not
338
  if (streamQueueIsFull(pTask->inputq.queue)) {
213,579✔
339
    tqTrace("s-task:%s input queue is full, launch task without scanning wal", pTask->id.idStr);
61!
340
    int32_t code = streamTrySchedExec(pTask, false);
61✔
341
    if (code) {
×
342
      tqError("s-task:%s failed to start task while inputQ is full", pTask->id.idStr);
×
343
    }
344
    return false;
×
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) {
213,629!
349
    tqDebug("s-task:%s inputQ is blocked, do nothing", pTask->id.idStr);
×
350
    return false;
×
351
  }
352

353
  return true;
213,629✔
354
}
355

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

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

368
    SStreamQueueItem* pItem = NULL;
343,240✔
369
    code = extractMsgFromWal(pTask->exec.pWalReader, (void**)&pItem, maxVer, id);
343,240✔
370
    if (code != TSDB_CODE_SUCCESS || pItem == NULL) {  // failed, continue
342,773✔
371
      int64_t currentVer = walReaderGetCurrentVer(pTask->exec.pWalReader);
212,711✔
372
      bool    itemInFillhistory = handleFillhistoryScanComplete(pTask, currentVer);
212,751✔
373
      if (itemInFillhistory) {
212,607✔
374
        numOfNewItems += 1;
470✔
375
      }
376
      break;
212,607✔
377
    }
378

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

387
        bool itemInFillhistory = handleFillhistoryScanComplete(pTask, ver);
130,073✔
388
        if (itemInFillhistory) {
130,064✔
389
          break;
229✔
390
        }
391
      } else {
392
        if (code == TSDB_CODE_OUT_OF_MEMORY) {
2!
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,
2!
396
                  pTask->chkInfo.nextProcessVer);
397
          code = walReaderSeekVer(pTask->exec.pWalReader, pTask->chkInfo.nextProcessVer);
2✔
398
          if (code) {
2!
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
2✔
403
        }
404

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

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

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

420
  // clone the task list, to avoid the task update during scan wal files
421
  streamMetaWLock(pStreamMeta);
199,267✔
422
  pTaskList = taosArrayDup(pStreamMeta->pTaskList, NULL);
199,334✔
423
  streamMetaWUnLock(pStreamMeta);
199,368✔
424
  if (pTaskList == NULL) {
199,202!
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);
199,202✔
431
  if (pNumOfTasks != NULL) {
199,103!
432
    *pNumOfTasks = numOfTasks;
199,161✔
433
  }
434

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

437
  for (int32_t i = 0; i < numOfTasks; ++i) {
774,807✔
438
    STaskId* pTaskId = taosArrayGet(pTaskList, i);
575,213✔
439
    if (pTaskId == NULL) {
574,046!
440
      continue;
362,068✔
441
    }
442

443
    SStreamTask* pTask = NULL;
574,046✔
444
    int32_t      code = streamMetaAcquireTask(pStreamMeta, pTaskId->streamId, pTaskId->taskId, &pTask);
574,046✔
445
    if (pTask == NULL || code != 0) {
575,429!
446
      continue;
6,509✔
447
    }
448

449
    if (!taskReadyForDataFromWal(pTask)) {
568,920✔
450
      streamMetaReleaseTask(pStreamMeta, pTask);
355,167✔
451
      continue;
355,576✔
452
    }
453

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

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

464
    streamMutexLock(&pTask->lock);
213,631✔
465

466
    SStreamTaskState state = streamTaskGetStatus(pTask);
213,634✔
467
    if (state.state != TASK_STATUS__READY) {
213,496!
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;
×
472
    }
473

474
    bool hasNewData = false;
213,496✔
475
    code = doPutDataIntoInputQ(pTask, maxVer, &numOfItems, &hasNewData);
213,496✔
476
    streamMutexUnlock(&pTask->lock);
212,729✔
477

478
    TAOS_UNUSED(code);
479

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

489
    streamMetaReleaseTask(pStreamMeta, pTask);
213,630✔
490
  }
491

492
  taosArrayDestroy(pTaskList);
199,594✔
493
  return TSDB_CODE_SUCCESS;
199,364✔
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