Skip to content

Commit

Permalink
fix(reserve): evict just enough chunks to reach the capacity (#4549)
Browse files Browse the repository at this point in the history
  • Loading branch information
istae committed Jan 30, 2024
1 parent ff3eb1d commit ecfc1c1
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions pkg/storer/internal/reserve/reserve.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,11 @@ func (r *Reserve) Put(ctx context.Context, store internal.Storage, chunk swarm.C
return err
}

newStampIndex := true

item, loaded, err := stampindex.LoadOrStore(indexStore, storeBatch, reserveNamespace, chunk)
item, loadedStamp, err := stampindex.LoadOrStore(indexStore, storeBatch, reserveNamespace, chunk)
if err != nil {
return fmt.Errorf("load or store stamp index for chunk %v has fail: %w", chunk, err)
}
if loaded {
if loadedStamp {
prev := binary.BigEndian.Uint64(item.StampTimestamp)
curr := binary.BigEndian.Uint64(chunk.Stamp().Timestamp())
if prev >= curr {
Expand All @@ -129,7 +127,6 @@ func (r *Reserve) Put(ctx context.Context, store internal.Storage, chunk swarm.C
// 2. Delete the old chunk's stamp data.
// 3. Delete ALL old chunk related items from the reserve.
// 4. Update the stamp index.
newStampIndex = false

err := r.removeChunk(ctx, store, storeBatch, item.ChunkAddress, chunk.Stamp().BatchID())
if err != nil {
Expand Down Expand Up @@ -190,7 +187,7 @@ func (r *Reserve) Put(ctx context.Context, store internal.Storage, chunk swarm.C
return err
}

if newStampIndex {
if !loadedStamp {
r.size.Add(1)
}

Expand Down

0 comments on commit ecfc1c1

Please sign in to comment.