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

taosdata / TDengine / #3621

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

push

travis-ci

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

merge: from main to 3.0 branch

4357 of 287032 branches covered (1.52%)

Branch coverage included in aggregate %.

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

213359 existing lines in 469 files now uncovered.

7260 of 283369 relevant lines covered (2.56%)

23737.72 hits per line

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

0.0
/source/dnode/vnode/src/tq/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 MAX_REPEAT_SCAN_THRESHOLD 3
20
#define SCAN_WAL_IDLE_DURATION    500    // idle for 500ms to do next wal scan
21

22
typedef struct SBuildScanWalMsgParam {
23
  int64_t metaId;
24
  int32_t numOfTasks;
25
  int8_t  restored;
26
  SMsgCb  msgCb;
27
} SBuildScanWalMsgParam;
28

29
static int32_t doScanWalForAllTasks(SStreamMeta* pStreamMeta);
30
static int32_t setWalReaderStartOffset(SStreamTask* pTask, int32_t vgId);
31
static bool    handleFillhistoryScanComplete(SStreamTask* pTask, int64_t ver);
32
static bool    taskReadyForDataFromWal(SStreamTask* pTask);
33
static int32_t doPutDataIntoInputQ(SStreamTask* pTask, int64_t maxVer, int32_t* numOfItems, bool* pSucc);
34
static int32_t tqScanWalInFuture(STQ* pTq, int32_t numOfTasks, int32_t idleDuration);
35
static int32_t doScanWalAsync(STQ* pTq, bool ckPause);
36

37
// extract data blocks(submit/delete) from WAL, and add them into the input queue for all the sources tasks.
UNCOV
38
int32_t tqScanWal(STQ* pTq) {
×
UNCOV
39
  SStreamMeta* pMeta = pTq->pStreamMeta;
×
UNCOV
40
  int32_t      vgId = pMeta->vgId;
×
UNCOV
41
  int64_t      st = taosGetTimestampMs();
×
UNCOV
42
  int32_t      numOfTasks = 0;
×
43

UNCOV
44
  tqDebug("vgId:%d continue to check if data in wal are available, scanCounter:%d", vgId, pMeta->scanInfo.scanCounter);
×
45

46
  // check all tasks
UNCOV
47
  int32_t code = doScanWalForAllTasks(pMeta);
×
UNCOV
48
  if (code) {
×
49
    tqError("vgId:%d failed to start all tasks, try next time, code:%s", vgId, tstrerror(code));
×
50
    return code;
×
51
  }
52

UNCOV
53
  streamMetaWLock(pMeta);
×
UNCOV
54
  int32_t times = (--pMeta->scanInfo.scanCounter);
×
UNCOV
55
  if (times < 0) {
×
56
    tqError("vgId:%d invalid scan counter:%d, reset to 0", vgId, times);
×
57
    times = 0;
×
58
  }
59

UNCOV
60
  numOfTasks = taosArrayGetSize(pMeta->pTaskList);
×
UNCOV
61
  streamMetaWUnLock(pMeta);
×
62

UNCOV
63
  int64_t el = (taosGetTimestampMs() - st);
×
UNCOV
64
  tqDebug("vgId:%d scan wal for stream tasks completed, elapsed time:%" PRId64 " ms", vgId, el);
×
65

UNCOV
66
  if (times > 0) {
×
UNCOV
67
    tqDebug("vgId:%d scan wal for stream tasks for %d times in %dms", vgId, times, SCAN_WAL_IDLE_DURATION);
×
UNCOV
68
    code = tqScanWalInFuture(pTq, numOfTasks, SCAN_WAL_IDLE_DURATION);
×
UNCOV
69
    if (code) {
×
70
      tqError("vgId:%d sched scan wal in %dms failed, ignore this failure", vgId, SCAN_WAL_IDLE_DURATION);
×
71
    }
72
  }
73

UNCOV
74
  return code;
×
75
}
76

UNCOV
77
static void doStartScanWal(void* param, void* tmrId) {
×
UNCOV
78
  int32_t vgId = 0;
×
UNCOV
79
  int32_t code = 0;
×
80

UNCOV
81
  SBuildScanWalMsgParam* pParam = (SBuildScanWalMsgParam*)param;
×
82

UNCOV
83
  SStreamMeta* pMeta = taosAcquireRef(streamMetaRefPool, pParam->metaId);
×
UNCOV
84
  if (pMeta == NULL) {
×
UNCOV
85
    tqError("metaRid:%" PRId64 " not valid now, stream meta has been freed", pParam->metaId);
×
UNCOV
86
    taosMemoryFree(pParam);
×
UNCOV
87
    return;
×
88
  }
89

UNCOV
90
  if (pMeta->closeFlag) {
×
UNCOV
91
    code = taosReleaseRef(streamMetaRefPool, pParam->metaId);
×
UNCOV
92
    if (code == TSDB_CODE_SUCCESS) {
×
UNCOV
93
      tqDebug("vgId:%d jump out of scan wal timer since closed", vgId);
×
94
    } else {
95
      tqError("vgId:%d failed to release ref for streamMeta, rid:%" PRId64 " code:%s", vgId, pParam->metaId,
×
96
              tstrerror(code));
97
    }
98

UNCOV
99
    taosMemoryFree(pParam);
×
UNCOV
100
    return;
×
101
  }
102

UNCOV
103
  vgId = pMeta->vgId;
×
104

UNCOV
105
  tqDebug("vgId:%d create msg to start wal scan, numOfTasks:%d, vnd restored:%d", vgId, pParam->numOfTasks,
×
106
          pParam->restored);
107
#if 0
108
  // wait for the vnode is freed, and invalid read may occur.
109
  taosMsleep(10000);
110
#endif
111

UNCOV
112
  code = streamTaskSchedTask(&pParam->msgCb, vgId, 0, 0, STREAM_EXEC_T_EXTRACT_WAL_DATA);
×
UNCOV
113
  if (code) {
×
UNCOV
114
    tqError("vgId:%d failed sched task to scan wal, code:%s", vgId, tstrerror(code));
×
115
  }
116

UNCOV
117
  code = taosReleaseRef(streamMetaRefPool, pParam->metaId);
×
UNCOV
118
  if (code) {
×
119
    tqError("vgId:%d failed to release ref for streamMeta, rid:%" PRId64 " code:%s", vgId, pParam->metaId,
×
120
            tstrerror(code));
121
  }
122

UNCOV
123
  taosMemoryFree(pParam);
×
124
}
125

UNCOV
126
int32_t tqScanWalInFuture(STQ* pTq, int32_t numOfTasks, int32_t idleDuration) {
×
UNCOV
127
  SStreamMeta*           pMeta = pTq->pStreamMeta;
×
UNCOV
128
  int32_t                code = 0;
×
UNCOV
129
  int32_t                vgId = TD_VID(pTq->pVnode);
×
UNCOV
130
  tmr_h                  pTimer = NULL;
×
UNCOV
131
  SBuildScanWalMsgParam* pParam = NULL;
×
132

UNCOV
133
  pParam = taosMemoryMalloc(sizeof(SBuildScanWalMsgParam));
×
UNCOV
134
  if (pParam == NULL) {
×
135
    return terrno;
×
136
  }
137

UNCOV
138
  pParam->metaId = pMeta->rid;
×
UNCOV
139
  pParam->numOfTasks = numOfTasks;
×
UNCOV
140
  pParam->restored = pTq->pVnode->restored;
×
UNCOV
141
  pParam->msgCb = pTq->pVnode->msgCb;
×
142

UNCOV
143
  code = streamTimerGetInstance(&pTimer);
×
UNCOV
144
  if (code) {
×
145
    tqError("vgId:%d failed to get tmr ctrl during sched scan wal", vgId);
×
146
    taosMemoryFree(pParam);
×
147
  } else {
UNCOV
148
    streamTmrStart(doStartScanWal, idleDuration, pParam, pTimer, &pMeta->scanInfo.scanTimer, vgId, "scan-wal-fut");
×
149
  }
150

UNCOV
151
  return code;
×
152
}
153

UNCOV
154
int32_t tqScanWalAsync(STQ* pTq, bool ckPause) {
×
UNCOV
155
  SStreamMeta* pMeta = pTq->pStreamMeta;
×
UNCOV
156
  bool         alreadyRestored = pTq->pVnode->restored;
×
UNCOV
157
  int32_t      code = 0;
×
158

159
  // do not launch the stream tasks, if it is a follower or not restored vnode.
UNCOV
160
  if (!(vnodeIsRoleLeader(pTq->pVnode) && alreadyRestored)) {
×
UNCOV
161
    return TSDB_CODE_SUCCESS;
×
162
  }
163

UNCOV
164
  streamMetaWLock(pMeta);
×
UNCOV
165
  code = doScanWalAsync(pTq, ckPause);
×
UNCOV
166
  streamMetaWUnLock(pMeta);
×
UNCOV
167
  return code;
×
168
}
169

UNCOV
170
int32_t tqStopStreamTasksAsync(STQ* pTq) {
×
UNCOV
171
  SStreamMeta* pMeta = pTq->pStreamMeta;
×
UNCOV
172
  int32_t      vgId = pMeta->vgId;
×
UNCOV
173
  return streamTaskSchedTask(&pTq->pVnode->msgCb, vgId, 0, 0, STREAM_EXEC_T_STOP_ALL_TASKS);
×
174
}
175

UNCOV
176
int32_t setWalReaderStartOffset(SStreamTask* pTask, int32_t vgId) {
×
177
  // seek the stored version and extract data from WAL
UNCOV
178
  int64_t firstVer = walReaderGetValidFirstVer(pTask->exec.pWalReader);
×
UNCOV
179
  if (pTask->chkInfo.nextProcessVer < firstVer) {
×
UNCOV
180
    tqWarn("vgId:%d s-task:%s ver:%" PRId64 " earlier than the first ver of wal range %" PRId64 ", forward to %" PRId64,
×
181
           vgId, pTask->id.idStr, pTask->chkInfo.nextProcessVer, firstVer, firstVer);
182

UNCOV
183
    pTask->chkInfo.nextProcessVer = firstVer;
×
184

185
    // todo need retry if failed
UNCOV
186
    int32_t code = walReaderSeekVer(pTask->exec.pWalReader, pTask->chkInfo.nextProcessVer);
×
UNCOV
187
    if (code != TSDB_CODE_SUCCESS) {
×
188
      return code;
×
189
    }
190

191
    // append the data for the stream
UNCOV
192
    tqDebug("vgId:%d s-task:%s wal reader seek to ver:%" PRId64, vgId, pTask->id.idStr, pTask->chkInfo.nextProcessVer);
×
193
  } else {
UNCOV
194
    int64_t currentVer = walReaderGetCurrentVer(pTask->exec.pWalReader);
×
UNCOV
195
    if (currentVer == -1) {  // we only seek the read for the first time
×
UNCOV
196
      int32_t code = walReaderSeekVer(pTask->exec.pWalReader, pTask->chkInfo.nextProcessVer);
×
UNCOV
197
      if (code != TSDB_CODE_SUCCESS) {  // no data in wal, quit
×
198
        return code;
×
199
      }
200

201
      // append the data for the stream
UNCOV
202
      tqDebug("vgId:%d s-task:%s wal reader initial seek to ver:%" PRId64, vgId, pTask->id.idStr,
×
203
              pTask->chkInfo.nextProcessVer);
204
    }
205
  }
206

UNCOV
207
  int64_t skipToVer = walReaderGetSkipToVersion(pTask->exec.pWalReader);
×
UNCOV
208
  if (skipToVer != 0 && skipToVer > pTask->chkInfo.nextProcessVer) {
×
UNCOV
209
    int32_t code = walReaderSeekVer(pTask->exec.pWalReader, skipToVer);
×
UNCOV
210
    if (code != TSDB_CODE_SUCCESS) {  // no data in wal, quit
×
211
      return code;
×
212
    }
213

UNCOV
214
    tqDebug("vgId:%d s-task:%s wal reader jump to ver:%" PRId64, vgId, pTask->id.idStr, skipToVer);
×
215
  }
216

UNCOV
217
  return TSDB_CODE_SUCCESS;
×
218
}
219

220
// todo handle memory error
UNCOV
221
bool handleFillhistoryScanComplete(SStreamTask* pTask, int64_t ver) {
×
UNCOV
222
  const char* id = pTask->id.idStr;
×
UNCOV
223
  int64_t     maxVer = pTask->step2Range.maxVer;
×
224

UNCOV
225
  if ((pTask->info.fillHistory == 1) && ver > maxVer) {
×
UNCOV
226
    if (!pTask->status.appendTranstateBlock) {
×
UNCOV
227
      qWarn("s-task:%s fill-history scan WAL, nextProcessVer:%" PRId64 " out of the maximum ver:%" PRId64
×
228
            ", not scan wal anymore, add transfer-state block into inputQ",
229
            id, ver, maxVer);
230

UNCOV
231
      double el = (taosGetTimestampMs() - pTask->execInfo.step2Start) / 1000.0;
×
UNCOV
232
      qDebug("s-task:%s scan-history from WAL stage(step 2) ended, range:%" PRId64 "-%" PRId64 ", elapsed time:%.2fs",
×
233
             id, pTask->step2Range.minVer, maxVer, el);
UNCOV
234
      int32_t code = streamTaskPutTranstateIntoInputQ(pTask);
×
UNCOV
235
      if (code) {
×
236
        qError("s-task:%s failed to put trans-state into inputQ", id);
×
237
      }
238

UNCOV
239
      return true;
×
240
    } else {
241
      qWarn("s-task:%s fill-history scan WAL, nextProcessVer:%" PRId64 " out of the ver range:%" PRId64 "-%" PRId64
×
242
            ", not scan wal",
243
            id, ver, pTask->step2Range.minVer, maxVer);
244
    }
245
  }
246

UNCOV
247
  return false;
×
248
}
249

UNCOV
250
bool taskReadyForDataFromWal(SStreamTask* pTask) {
×
251
  // non-source or fill-history tasks don't need to response the WAL scan action.
UNCOV
252
  SSTaskBasicInfo* pInfo = &pTask->info;
×
UNCOV
253
  if ((pInfo->taskLevel != TASK_LEVEL__SOURCE) || (pTask->status.downstreamReady == 0)) {
×
UNCOV
254
    return false;
×
255
  }
256

UNCOV
257
  if (pInfo->taskLevel == TASK_LEVEL__SOURCE && pInfo->trigger == STREAM_TRIGGER_FORCE_WINDOW_CLOSE) {
×
UNCOV
258
    return false;
×
259
  }
260

261
  // not in ready state, do not handle the data from wal
UNCOV
262
  SStreamTaskState pState = streamTaskGetStatus(pTask);
×
UNCOV
263
  if (pState.state != TASK_STATUS__READY) {
×
UNCOV
264
    tqTrace("s-task:%s not ready for submit block in wal, status:%s", pTask->id.idStr, pState.name);
×
UNCOV
265
    return false;
×
266
  }
267

268
  // fill-history task has entered into the last phase, no need to anything
UNCOV
269
  if ((pInfo->fillHistory == 1) && pTask->status.appendTranstateBlock) {
×
270
    // the maximum version of data in the WAL has reached already, the step2 is done
UNCOV
271
    tqDebug("s-task:%s fill-history reach the maximum ver:%" PRId64 ", not scan wal anymore", pTask->id.idStr,
×
272
            pTask->dataRange.range.maxVer);
UNCOV
273
    return false;
×
274
  }
275

276
  // check if input queue is full or not
UNCOV
277
  if (streamQueueIsFull(pTask->inputq.queue)) {
×
278
    tqTrace("s-task:%s input queue is full, do nothing", pTask->id.idStr);
×
UNCOV
279
    return false;
×
280
  }
281

282
  // the input queue of downstream task is full, so the output is blocked, stopped for a while
UNCOV
283
  if (pTask->inputq.status == TASK_INPUT_STATUS__BLOCKED) {
×
284
    tqDebug("s-task:%s inputQ is blocked, do nothing", pTask->id.idStr);
×
285
    return false;
×
286
  }
287

UNCOV
288
  return true;
×
289
}
290

UNCOV
291
int32_t doPutDataIntoInputQ(SStreamTask* pTask, int64_t maxVer, int32_t* numOfItems, bool* pSucc) {
×
UNCOV
292
  const char* id = pTask->id.idStr;
×
UNCOV
293
  int32_t     numOfNewItems = 0;
×
UNCOV
294
  int32_t     code = 0;
×
UNCOV
295
  *pSucc = false;
×
296

UNCOV
297
  while (1) {
×
UNCOV
298
    if ((pTask->info.fillHistory == 1) && pTask->status.appendTranstateBlock) {
×
299
      *numOfItems += numOfNewItems;
×
300
      return numOfNewItems > 0;
×
301
    }
302

UNCOV
303
    SStreamQueueItem* pItem = NULL;
×
UNCOV
304
    code = extractMsgFromWal(pTask->exec.pWalReader, (void**)&pItem, maxVer, id);
×
UNCOV
305
    if (code != TSDB_CODE_SUCCESS || pItem == NULL) {  // failed, continue
×
UNCOV
306
      int64_t currentVer = walReaderGetCurrentVer(pTask->exec.pWalReader);
×
UNCOV
307
      bool    itemInFillhistory = handleFillhistoryScanComplete(pTask, currentVer);
×
UNCOV
308
      if (itemInFillhistory) {
×
UNCOV
309
        numOfNewItems += 1;
×
310
      }
UNCOV
311
      break;
×
312
    }
313

UNCOV
314
    if (pItem != NULL) {
×
UNCOV
315
      code = streamTaskPutDataIntoInputQ(pTask, pItem);
×
UNCOV
316
      if (code == TSDB_CODE_SUCCESS) {
×
UNCOV
317
        numOfNewItems += 1;
×
UNCOV
318
        int64_t ver = walReaderGetCurrentVer(pTask->exec.pWalReader);
×
UNCOV
319
        pTask->chkInfo.nextProcessVer = ver;
×
UNCOV
320
        tqDebug("s-task:%s set ver:%" PRId64 " for reader after extract data from WAL", id, ver);
×
321

UNCOV
322
        bool itemInFillhistory = handleFillhistoryScanComplete(pTask, ver);
×
UNCOV
323
        if (itemInFillhistory) {
×
UNCOV
324
          break;
×
325
        }
326
      } else {
UNCOV
327
        if (code == TSDB_CODE_OUT_OF_MEMORY) {
×
328
          tqError("s-task:%s failed to put data into inputQ, since out of memory", id);
×
329
        } else {
UNCOV
330
          tqTrace("s-task:%s append input queue failed, code:inputQ is full, ver:%" PRId64, id,
×
331
                  pTask->chkInfo.nextProcessVer);
UNCOV
332
          code = walReaderSeekVer(pTask->exec.pWalReader, pTask->chkInfo.nextProcessVer);
×
UNCOV
333
          if (code) {
×
334
            tqError("s-task:%s failed to seek ver to:%" PRId64 " in wal", id, pTask->chkInfo.nextProcessVer);
×
335
          }
336

UNCOV
337
          code = 0;  // reset the error code
×
338
        }
339

UNCOV
340
        break;
×
341
      }
342
    }
343
  }
344

UNCOV
345
  *numOfItems += numOfNewItems;
×
UNCOV
346
  *pSucc = (numOfNewItems > 0);
×
UNCOV
347
  return code;
×
348
}
349

UNCOV
350
int32_t doScanWalForAllTasks(SStreamMeta* pStreamMeta) {
×
UNCOV
351
  int32_t vgId = pStreamMeta->vgId;
×
UNCOV
352
  SArray* pTaskList = NULL;
×
UNCOV
353
  int32_t numOfTasks = taosArrayGetSize(pStreamMeta->pTaskList);
×
UNCOV
354
  if (numOfTasks == 0) {
×
UNCOV
355
    return TSDB_CODE_SUCCESS;
×
356
  }
357

358
  // clone the task list, to avoid the task update during scan wal files
UNCOV
359
  streamMetaWLock(pStreamMeta);
×
UNCOV
360
  pTaskList = taosArrayDup(pStreamMeta->pTaskList, NULL);
×
UNCOV
361
  streamMetaWUnLock(pStreamMeta);
×
UNCOV
362
  if (pTaskList == NULL) {
×
363
    tqError("vgId:%d failed to create task list dup, code:%s", vgId, tstrerror(terrno));
×
364
    return terrno;
×
365
  }
366

UNCOV
367
  tqDebug("vgId:%d start to check wal to extract new submit block for %d tasks", vgId, numOfTasks);
×
368

369
  // update the new task number
UNCOV
370
  numOfTasks = taosArrayGetSize(pTaskList);
×
371

UNCOV
372
  for (int32_t i = 0; i < numOfTasks; ++i) {
×
UNCOV
373
    STaskId* pTaskId = taosArrayGet(pTaskList, i);
×
UNCOV
374
    if (pTaskId == NULL) {
×
UNCOV
375
      continue;
×
376
    }
377

UNCOV
378
    SStreamTask* pTask = NULL;
×
UNCOV
379
    int32_t      code = streamMetaAcquireTask(pStreamMeta, pTaskId->streamId, pTaskId->taskId, &pTask);
×
UNCOV
380
    if (pTask == NULL || code != 0) {
×
UNCOV
381
      continue;
×
382
    }
383

UNCOV
384
    if (!taskReadyForDataFromWal(pTask)) {
×
UNCOV
385
      streamMetaReleaseTask(pStreamMeta, pTask);
×
UNCOV
386
      continue;
×
387
    }
388

389
    // seek the stored version and extract data from WAL
UNCOV
390
    code = setWalReaderStartOffset(pTask, vgId);
×
UNCOV
391
    if (code != TSDB_CODE_SUCCESS) {
×
392
      streamMetaReleaseTask(pStreamMeta, pTask);
×
393
      continue;
×
394
    }
395

UNCOV
396
    int32_t numOfItems = streamQueueGetNumOfItems(pTask->inputq.queue);
×
UNCOV
397
    int64_t maxVer = (pTask->info.fillHistory == 1) ? pTask->step2Range.maxVer : INT64_MAX;
×
398

UNCOV
399
    streamMutexLock(&pTask->lock);
×
400

UNCOV
401
    SStreamTaskState state = streamTaskGetStatus(pTask);
×
UNCOV
402
    if (state.state != TASK_STATUS__READY) {
×
UNCOV
403
      tqDebug("s-task:%s not ready for submit block from wal, status:%s", pTask->id.idStr, state.name);
×
UNCOV
404
      streamMutexUnlock(&pTask->lock);
×
UNCOV
405
      streamMetaReleaseTask(pStreamMeta, pTask);
×
UNCOV
406
      continue;
×
407
    }
408

UNCOV
409
    bool hasNewData = false;
×
UNCOV
410
    code = doPutDataIntoInputQ(pTask, maxVer, &numOfItems, &hasNewData);
×
UNCOV
411
    streamMutexUnlock(&pTask->lock);
×
412

UNCOV
413
    if ((numOfItems > 0) || hasNewData) {
×
UNCOV
414
      code = streamTrySchedExec(pTask);
×
UNCOV
415
      if (code != TSDB_CODE_SUCCESS) {
×
416
        streamMetaReleaseTask(pStreamMeta, pTask);
×
417
        taosArrayDestroy(pTaskList);
×
418
        return code;
×
419
      }
420
    }
421

UNCOV
422
    streamMetaReleaseTask(pStreamMeta, pTask);
×
423
  }
424

UNCOV
425
  taosArrayDestroy(pTaskList);
×
UNCOV
426
  return TSDB_CODE_SUCCESS;
×
427
}
428

UNCOV
429
int32_t doScanWalAsync(STQ* pTq, bool ckPause) {
×
UNCOV
430
  SStreamMeta* pMeta = pTq->pStreamMeta;
×
UNCOV
431
  bool         alreadyRestored = pTq->pVnode->restored;
×
UNCOV
432
  int32_t      vgId = pMeta->vgId;
×
UNCOV
433
  int32_t      numOfTasks = taosArrayGetSize(pMeta->pTaskList);
×
434

UNCOV
435
  if (numOfTasks == 0) {
×
UNCOV
436
    tqDebug("vgId:%d no stream tasks existed to run", vgId);
×
UNCOV
437
    return 0;
×
438
  }
439

UNCOV
440
  if (pMeta->startInfo.startAllTasks) {
×
UNCOV
441
    tqTrace("vgId:%d in restart procedure, not scan wal", vgId);
×
UNCOV
442
    return 0;
×
443
  }
444

UNCOV
445
  pMeta->scanInfo.scanCounter += 1;
×
UNCOV
446
  if (pMeta->scanInfo.scanCounter > MAX_REPEAT_SCAN_THRESHOLD) {
×
UNCOV
447
    pMeta->scanInfo.scanCounter = MAX_REPEAT_SCAN_THRESHOLD;
×
448
  }
449

UNCOV
450
  if (pMeta->scanInfo.scanCounter > 1) {
×
UNCOV
451
    tqDebug("vgId:%d wal read task has been launched, remain scan times:%d", vgId, pMeta->scanInfo.scanCounter);
×
UNCOV
452
    return 0;
×
453
  }
454

UNCOV
455
  int32_t numOfPauseTasks = pMeta->numOfPausedTasks;
×
UNCOV
456
  if (ckPause && numOfTasks == numOfPauseTasks) {
×
UNCOV
457
    tqDebug("vgId:%d ignore all submit, all streams had been paused, reset the walScanCounter", vgId);
×
458

459
    // reset the counter value, since we do not launch the scan wal operation.
UNCOV
460
    pMeta->scanInfo.scanCounter = 0;
×
UNCOV
461
    return 0;
×
462
  }
463

UNCOV
464
  tqDebug("vgId:%d create msg to start wal scan to launch stream tasks, numOfTasks:%d, vnd restored:%d", vgId,
×
465
          numOfTasks, alreadyRestored);
466

UNCOV
467
  return streamTaskSchedTask(&pTq->pVnode->msgCb, vgId, 0, 0, STREAM_EXEC_T_EXTRACT_WAL_DATA);
×
468
}
469

470
void streamMetaFreeTQDuringScanWalError(STQ* pTq) {
×
471
  SBuildScanWalMsgParam* p = taosMemoryCalloc(1, sizeof(SBuildScanWalMsgParam));
×
472
  p->metaId = pTq->pStreamMeta->rid;
×
473
  p->numOfTasks = 0;
×
474

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