Skip to content

Commit

Permalink
handle error when fail to get backfill state (#120)
Browse files Browse the repository at this point in the history
* handle error when fail to get backfill state

* fix wrong condition

* update function name
  • Loading branch information
linhnt3400 authored Jan 14, 2025
1 parent 91263eb commit 016925a
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions v2/internal/worker/backfiller.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ func (w *BackFiller) run() error {
defer w.mu.Unlock()

for {
if !w.enableBackfill() {
enable, err := w.isEnableBackfill()
if err != nil {
return err
}
if !enable {
return nil
}
first, last, exclusions, err := w.GetBlockRanges()
Expand All @@ -86,17 +90,17 @@ func (w *BackFiller) run() error {
}
}

// enableBackfill check the state of enabling system backfill task
func (w *BackFiller) enableBackfill() bool {
// isEnableBackfill check the state of enabling system backfill task
func (w *BackFiller) isEnableBackfill() (bool, error) {
v, err := w.stateStorage.GetState(state.EnableSystemBackfillKey)
if err != nil {
return false
return false, fmt.Errorf("cannot get system backfill status: %w", err)
}
enable, err := strconv.ParseBool(v)
if err != nil {
return false
return false, fmt.Errorf("cannot parse system backfill status: %w", err)
}
return enable
return enable, nil
}

// CancelSystemBackfill stop the running system backfill task
Expand All @@ -106,10 +110,14 @@ func (w *BackFiller) CancelSystemBackfill() error {

// RunSystemBackfill run the system backfill task, if there is another running system backfill task, this task need to wait
func (w *BackFiller) RunSystemBackfill() error {
if w.enableBackfill() {
enable, err := w.isEnableBackfill()
if err != nil {
return err
}
if enable {
return nil
}
err := w.stateStorage.SetState(state.EnableSystemBackfillKey, strconv.FormatBool(true))
err = w.stateStorage.SetState(state.EnableSystemBackfillKey, strconv.FormatBool(true))
if err != nil {
return err
}
Expand Down

0 comments on commit 016925a

Please sign in to comment.