Skip to content

Commit

Permalink
fix(compact): mark already used slots (#4395)
Browse files Browse the repository at this point in the history
  • Loading branch information
istae authored Oct 11, 2023
1 parent 8b150cf commit 519c1ac
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
5 changes: 4 additions & 1 deletion pkg/storer/compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,12 @@ func Compact(ctx context.Context, basePath string, opts *Options, validate bool)
return err
}

for start < end {
for start <= end {

if slots[start] != nil {
if err := sharkyRecover.Add(slots[start].Location); err != nil {
return fmt.Errorf("sharky add: %w", err)
}
start++ // walk to the right until a free slot is found
continue
}
Expand Down
26 changes: 17 additions & 9 deletions pkg/storer/compact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,14 @@ func TestCompact(t *testing.T) {
st.StartReserveWorker(ctx, pullerMock.NewMockRateReporter(0), networkRadiusFunc(0))

var chunks []swarm.Chunk
var chunksPerPO uint64 = 50
batches := []*postage.Batch{postagetesting.MustNewBatch(), postagetesting.MustNewBatch()}
evictBatch := batches[0]
batches := []*postage.Batch{postagetesting.MustNewBatch(), postagetesting.MustNewBatch(), postagetesting.MustNewBatch()}
evictBatch := batches[1]

putter := st.ReservePutter()

for b := 0; b < len(batches); b++ {
for i := uint64(0); i < chunksPerPO; i++ {
ch := chunk.GenerateValidRandomChunkAt(baseAddr, b)
for i := uint64(0); i < 100; i++ {
ch := chunk.GenerateTestRandomChunk()
ch = ch.WithStamp(postagetesting.MustNewBatchStamp(batches[b].ID))
chunks = append(chunks, ch)
err := putter.Put(ctx, ch)
Expand Down Expand Up @@ -81,14 +80,21 @@ func TestCompact(t *testing.T) {
t.Fatal(err)
}

for _, ch := range chunks {
has, err := st.ReserveHas(ch.Address(), ch.Stamp().BatchID())
putter = st.ReservePutter()
for i := uint64(0); i < 100; i++ {
ch := chunk.GenerateTestRandomChunk()
ch = ch.WithStamp(postagetesting.MustNewBatchStamp(batches[0].ID))
chunks = append(chunks, ch)
err := putter.Put(ctx, ch)
if err != nil {
t.Fatal(err)
}
}

if has {
checkSaved(t, st, ch, true, true)
for _, ch := range chunks {
has, err := st.ReserveHas(ch.Address(), ch.Stamp().BatchID())
if err != nil {
t.Fatal(err)
}

if bytes.Equal(ch.Stamp().BatchID(), evictBatch.ID) {
Expand All @@ -98,6 +104,8 @@ func TestCompact(t *testing.T) {
checkSaved(t, st, ch, false, false)
} else if !has {
t.Fatal("store should have chunk")
} else {
checkSaved(t, st, ch, true, true)
}
}

Expand Down

0 comments on commit 519c1ac

Please sign in to comment.