Skip to content

Commit

Permalink
fix: refine lock related error message
Browse files Browse the repository at this point in the history
ref: longhorn/longhorn 8713

Signed-off-by: Jack Lin <[email protected]>
  • Loading branch information
ChanYiLin committed Sep 3, 2024
1 parent fe89e48 commit a01169c
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ const BACKUP_LOCK LockType = 1
const RESTORE_LOCK LockType = 1
const DELETION_LOCK LockType = 2

type Operation string

const CREATERESTORE Operation = "create/restore"
const DELETE Operation = "delete"
const UNDEFINED Operation = "undefined"

type FileLock struct {
Name string
Type LockType
Expand Down Expand Up @@ -80,6 +86,14 @@ func (lock *FileLock) canAcquire() bool {
func (lock *FileLock) Lock() error {
lock.mutex.Lock()
defer lock.mutex.Unlock()

operation := UNDEFINED
if lock.Type == BACKUP_LOCK || lock.Type == RESTORE_LOCK {
operation = CREATERESTORE
} else if lock.Type == DELETION_LOCK {
operation = DELETE
}

if lock.Acquired {
atomic.AddInt32(&lock.count, 1)
_ = saveLock(lock)
Expand Down Expand Up @@ -107,16 +121,16 @@ func (lock *FileLock) Lock() error {
if !lock.canAcquire() {
file := getLockFilePath(lock.volume, lock.Name)
_ = removeLock(lock)
return fmt.Errorf("failed lock %v type %v acquisition", file, lock.Type)
return fmt.Errorf("failed to aquire lock %v when performing backup %v, please try again later.", file, operation)

Check failure on line 124 in lock.go

View workflow job for this annotation

GitHub Actions / codespell

aquire ==> acquire
}

file := getLockFilePath(lock.volume, lock.Name)
log.Infof("Acquired lock %v type %v on backupstore", file, lock.Type)
log.Infof("Acquired lock %v for backup %v on backupstore", file, operation)
lock.Acquired = true
atomic.AddInt32(&lock.count, 1)
if err := saveLock(lock); err != nil {
_ = removeLock(lock)
return errors.Wrapf(err, "failed to store updated lock %v type %v after acquisition", file, lock.Type)
return errors.Wrapf(err, "failed to store updated lock %v when performing backup %v, please try again later", file, operation)
}

// enable lock refresh
Expand All @@ -133,7 +147,7 @@ func (lock *FileLock) Lock() error {
if lock.Acquired {
if err := saveLock(lock); err != nil {
// nothing we can do here, that's why the lock acquisition time is 2x lock refresh interval
log.WithError(err).Warnf("Failed to refresh acquired lock %v type %v", file, lock.Type)
log.WithError(err).Warnf("Failed to refresh acquired lock %v when performing backup %v, please try again later", file, operation)
}
}
lock.mutex.Unlock()
Expand Down

0 comments on commit a01169c

Please sign in to comment.