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

taosdata / TDengine / #4473

08 Jul 2025 09:38AM UTC coverage: 62.922% (+0.7%) from 62.22%
#4473

push

travis-ci

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

merge: from main to 3.0 branch

158525 of 321496 branches covered (49.31%)

Branch coverage included in aggregate %.

56 of 60 new or added lines in 13 files covered. (93.33%)

1333 existing lines in 67 files now uncovered.

245526 of 320647 relevant lines covered (76.57%)

17689640.25 hits per line

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

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

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

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

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

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

70
  atomic_store_32(&pMeta->scanInfo.scanSentinel, 0);
196,668✔
71
  return code;
196,745✔
72
}
73

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

80
  return false;
1,368,740✔
81
}
82

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

233
int32_t setWalReaderStartOffset(SStreamTask* pTask, int32_t vgId) {
212,874✔
234
  // seek the stored version and extract data from WAL
235
  int64_t firstVer = walReaderGetValidFirstVer(pTask->exec.pWalReader);
212,874✔
236
  if (pTask->chkInfo.nextProcessVer < firstVer) {
212,961✔
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);
212,956✔
252
    if (currentVer == -1) {  // we only seek the read for the first time
212,793✔
253
      int32_t code = walReaderSeekVer(pTask->exec.pWalReader, pTask->chkInfo.nextProcessVer);
4,064✔
254
      if (code != TSDB_CODE_SUCCESS) {  // no data in wal, quit
4,065!
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,065✔
260
              pTask->chkInfo.nextProcessVer);
261
    }
262
  }
263

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

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

274
  return TSDB_CODE_SUCCESS;
212,764✔
275
}
276

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

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

296
      return true;
658✔
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;
336,254✔
305
}
306

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

314
  if (pInfo->trigger == STREAM_TRIGGER_FORCE_WINDOW_CLOSE) {
293,075✔
315
    return false;
36,492✔
316
  }
317

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

322
  // not in ready state, do not handle the data from wal
323
  SStreamTaskState pState = streamTaskGetStatus(pTask);
256,583✔
324
  if (pState.state != TASK_STATUS__READY) {
256,519✔
325
    tqTrace("s-task:%s not ready for submit block in wal, status:%s", pTask->id.idStr, pState.name);
36,029✔
326
    return false;
36,034✔
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) {
220,490✔
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,411✔
333
            pTask->dataRange.range.maxVer);
334
    return false;
7,411✔
335
  }
336

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

353
  return true;
213,113✔
354
}
355

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

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

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

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

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

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

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

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

420
  // clone the task list, to avoid the task update during scan wal files
421
  streamMetaWLock(pStreamMeta);
196,660✔
422
  pTaskList = taosArrayDup(pStreamMeta->pTaskList, NULL);
196,726✔
423
  streamMetaWUnLock(pStreamMeta);
196,762✔
424
  if (pTaskList == NULL) {
196,620!
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);
196,620✔
431
  if (pNumOfTasks != NULL) {
196,628!
432
    *pNumOfTasks = numOfTasks;
196,656✔
433
  }
434

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

437
  for (int32_t i = 0; i < numOfTasks; ++i) {
759,507✔
438
    STaskId* pTaskId = taosArrayGet(pTaskList, i);
562,578✔
439
    if (pTaskId == NULL) {
562,315!
440
      continue;
349,724✔
441
    }
442

443
    SStreamTask* pTask = NULL;
562,315✔
444
    int32_t      code = streamMetaAcquireTask(pStreamMeta, pTaskId->streamId, pTaskId->taskId, &pTask);
562,315✔
445
    if (pTask == NULL || code != 0) {
562,870!
446
      continue;
6,381✔
447
    }
448

449
    if (!taskReadyForDataFromWal(pTask)) {
556,489✔
450
      streamMetaReleaseTask(pStreamMeta, pTask);
343,147✔
451
      continue;
343,380✔
452
    }
453

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

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

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

466
    SStreamTaskState state = streamTaskGetStatus(pTask);
213,100✔
467
    if (state.state != TASK_STATUS__READY) {
212,953!
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);
×
UNCOV
471
      continue;
×
472
    }
473

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

478
    TAOS_UNUSED(code);
479

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

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

492
  taosArrayDestroy(pTaskList);
196,929✔
493
  return TSDB_CODE_SUCCESS;
196,709✔
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

© 2025 Coveralls, Inc