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 cffd1cc commit ff3eb1d
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 157 deletions.
6 changes: 3 additions & 3 deletions pkg/storer/compact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ func TestCompact(t *testing.T) {
}
}

c, unsub := st.Events().Subscribe("batchExpiryDone")
t.Cleanup(unsub)

err = st.EvictBatch(ctx, evictBatch.ID)
if err != nil {
t.Fatal(err)
}

c, unsub := st.Events().Subscribe("batchExpiryDone")
t.Cleanup(unsub)
<-c

time.Sleep(time.Second)
Expand Down
9 changes: 3 additions & 6 deletions pkg/storer/epoch_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ func (p *putOpStorage) Write(_ context.Context, _ []byte) (sharky.Location, erro
}

type reservePutter interface {
Put(context.Context, internal.Storage, swarm.Chunk) (bool, error)
AddSize(int)
Put(context.Context, internal.Storage, swarm.Chunk) error
Size() int
}

Expand Down Expand Up @@ -297,11 +296,9 @@ func (e *epochMigrator) migrateReserve(ctx context.Context) error {
recovery: e.recovery,
}

switch newIdx, err := e.reserve.Put(egCtx, pStorage, op.chunk); {
case err != nil:
err := e.reserve.Put(egCtx, pStorage, op.chunk)
if err != nil {
return err
case newIdx:
e.reserve.AddSize(1)
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/storer/epoch_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ type testReservePutter struct {
calls int
}

func (t *testReservePutter) Put(ctx context.Context, st internal.Storage, ch swarm.Chunk) (bool, error) {
func (t *testReservePutter) Put(ctx context.Context, st internal.Storage, ch swarm.Chunk) error {
t.mtx.Lock()
t.calls++
t.mtx.Unlock()
return true, st.ChunkStore().Put(ctx, ch)
return st.ChunkStore().Put(ctx, ch)
}

func (t *testReservePutter) AddSize(size int) {
Expand All @@ -203,6 +203,7 @@ func (t *testReservePutter) Size() int {
// TestEpochMigration_FLAKY is flaky on windows.
func TestEpochMigration_FLAKY(t *testing.T) {
t.Parallel()
t.Skip("will be removed")

var (
dataPath = t.TempDir()
Expand Down
2 changes: 0 additions & 2 deletions pkg/storer/internal/chunkstamp/chunkstamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,11 @@ func (i item) String() string {
}

// Load returns first found swarm.Stamp related to the given address.
// The storage.ErrNoStampsForChunk is returned if no record is found.
func Load(s storage.Reader, namespace string, addr swarm.Address) (swarm.Stamp, error) {
return LoadWithBatchID(s, namespace, addr, nil)
}

// LoadWithBatchID returns swarm.Stamp related to the given address and batchID.
// The storage.ErrNoStampsForChunk is returned if no record is found.
func LoadWithBatchID(s storage.Reader, namespace string, addr swarm.Address, batchID []byte) (swarm.Stamp, error) {
var stamp swarm.Stamp

Expand Down
Loading

0 comments on commit ff3eb1d

Please sign in to comment.