Skip to content

Commit

Permalink
Avoid contention with early check
Browse files Browse the repository at this point in the history
  • Loading branch information
karimodm committed Dec 12, 2023
1 parent 7bac679 commit a69e15f
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/storage/permanent/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,11 @@ func (s *Settings) SetLatestNonEmptySlot(slot iotago.SlotIndex) (err error) {
}

func (s *Settings) AdvanceLatestNonEmptySlot(slot iotago.SlotIndex) (err error) {
// Avoid write-locking within the Compute with an early check.
if s.LatestNonEmptySlot() >= slot {
return nil
}

if _, err = s.storeLatestNonEmptySlot.Compute(func(latestNonEmptySlot iotago.SlotIndex, _ bool) (newValue iotago.SlotIndex, err error) {
if latestNonEmptySlot >= slot {
return latestNonEmptySlot, kvstore.ErrTypedValueNotChanged
Expand Down

0 comments on commit a69e15f

Please sign in to comment.