Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(reserve): evict just enough chunks to reach the capacity #4549

Merged
merged 4 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading