Skip to content

Commit 95aa525

Browse files
authored
CBG-5426 drop duplicate lasterror field with separate locks (#8338)
1 parent f79f1b0 commit 95aa525

1 file changed

Lines changed: 7 additions & 12 deletions

File tree

db/background_mgr.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ type BackgroundManager struct {
7878
status BackgroundManagerStatus
7979
statusLock sync.RWMutex
8080
name string
81-
lastError error
8281
terminator *base.SafeTerminator
8382
backgroundManagerStatusUpdateWaitGroup sync.WaitGroup
8483
clusterAwareOptions *ClusterAwareBackgroundManagerOptions
@@ -456,10 +455,6 @@ func (b *BackgroundManager) getStatusWithPrevious(previous []byte) ([]byte, []by
456455
backgroundStatus.State = BackgroundProcessStateCompleted
457456
}
458457

459-
if b.lastError != nil {
460-
backgroundStatus.LastErrorMessage = b.lastError.Error()
461-
}
462-
463458
return b.Process.GetProcessStatus(backgroundStatus, previous)
464459
}
465460

@@ -529,16 +524,18 @@ func (b *BackgroundManager) resetStatus() {
529524
b.lock.Lock()
530525
defer b.lock.Unlock()
531526

532-
b.lastError = nil
533-
b.clearLastErrorMessage()
527+
b.setLastErrorMessage("")
534528
b.Process.ResetStatus()
535529
}
536530

537531
// setLastErrorMessage sets the last error message
538-
func (b *BackgroundManager) clearLastErrorMessage() {
532+
func (b *BackgroundManager) setLastErrorMessage(msg string) {
539533
b.statusLock.Lock()
540534
defer b.statusLock.Unlock()
541-
b.status.LastErrorMessage = ""
535+
b.status.LastErrorMessage = msg
536+
if msg != "" {
537+
b.status.State = BackgroundProcessStateError
538+
}
542539
}
543540

544541
// Stop triggers a Stop of the background process. This will transition the state to BackgroundProcessStateStopping and
@@ -634,9 +631,7 @@ func (b *BackgroundManager) setStartTime(startTime time.Time) {
634631
func (b *BackgroundManager) SetError(err error) {
635632
b.lock.Lock()
636633
defer b.lock.Unlock()
637-
638-
b.lastError = err
639-
b.setRunState(BackgroundProcessStateError)
634+
b.setLastErrorMessage(err.Error())
640635
b.Terminate()
641636
}
642637

0 commit comments

Comments
 (0)