Skip to content

Commit

Permalink
fix: remove stampindex check
Browse files Browse the repository at this point in the history
  • Loading branch information
acha-bill committed Jan 31, 2024
1 parent e55f32d commit 9c1a8d3
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 116 deletions.
27 changes: 0 additions & 27 deletions pkg/storer/internal/upload/uploadstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/ethersphere/bee/pkg/storage/storageutil"
"github.com/ethersphere/bee/pkg/storer/internal"
"github.com/ethersphere/bee/pkg/storer/internal/chunkstamp"
"github.com/ethersphere/bee/pkg/storer/internal/stampindex"
"github.com/ethersphere/bee/pkg/swarm"
)

Expand Down Expand Up @@ -351,10 +350,6 @@ func (i dirtyTagItem) String() string {
return storageutil.JoinFields(i.Namespace(), i.ID())
}

// stampIndexUploadNamespace represents the
// namespace name of the stamp index for upload.
const stampIndexUploadNamespace = "upload"

var (
// errPutterAlreadyClosed is returned when trying to Put a new chunk
// after the putter has been closed.
Expand Down Expand Up @@ -420,28 +415,6 @@ func (u *uploadPutter) Put(ctx context.Context, s internal.Storage, writer stora
return nil
}

switch item, loaded, err := stampindex.LoadOrStore(
s.IndexStore(),
writer,
stampIndexUploadNamespace,
chunk,
); {
case err != nil:
return fmt.Errorf("load or store stamp index for chunk %v has fail: %w", chunk, err)
case loaded && item.ChunkIsImmutable:
return errOverwriteOfImmutableBatch
case loaded && !item.ChunkIsImmutable:
prev := binary.BigEndian.Uint64(item.StampTimestamp)
curr := binary.BigEndian.Uint64(chunk.Stamp().Timestamp())
if prev > curr {
return errOverwriteOfNewerBatch
}
err = stampindex.Store(writer, stampIndexUploadNamespace, chunk)
if err != nil {
return fmt.Errorf("failed updating stamp index: %w", err)
}
}

u.split++

if err := s.ChunkStore().Put(ctx, chunk); err != nil {
Expand Down
89 changes: 0 additions & 89 deletions pkg/storer/internal/upload/uploadstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package upload_test
import (
"bytes"
"context"
"encoding/binary"
"errors"
"fmt"
"math"
Expand All @@ -16,7 +15,6 @@ import (
"testing"
"time"

"github.com/ethersphere/bee/pkg/postage"
storage "github.com/ethersphere/bee/pkg/storage"
"github.com/ethersphere/bee/pkg/storage/storagetest"
chunktest "github.com/ethersphere/bee/pkg/storage/testing"
Expand Down Expand Up @@ -794,93 +792,6 @@ func TestChunkReporter(t *testing.T) {
})
}

func TestStampIndexHandling(t *testing.T) {
t.Parallel()

ts := newTestStorage(t)

tag, err := upload.NextTag(ts.IndexStore())
if err != nil {
t.Fatalf("failed creating tag: %v", err)
}

putter, err := upload.NewPutter(ts, tag.TagID)
if err != nil {
t.Fatalf("failed creating putter: %v", err)
}

t.Run("put chunk with immutable batch", func(t *testing.T) {
chunk := chunktest.GenerateTestRandomChunk()
chunk = chunk.WithBatch(
chunk.Radius(),
chunk.Depth(),
chunk.BucketDepth(),
true,
)
if err := putter.Put(context.Background(), ts, ts.IndexStore(), chunk); err != nil {
t.Fatalf("Put(...): unexpected error: %v", err)
}

chunk2 := chunktest.GenerateTestRandomChunk().WithStamp(chunk.Stamp())

want := upload.ErrOverwriteOfImmutableBatch
have := putter.Put(context.Background(), ts, ts.IndexStore(), chunk2)
if !errors.Is(have, want) {
t.Fatalf("Put(...): unexpected error:\n\twant: %v\n\thave: %v", want, have)
}
})

t.Run("put existing index with older batch timestamp", func(t *testing.T) {
chunk := chunktest.GenerateTestRandomChunk()
if err := putter.Put(context.Background(), ts, ts.IndexStore(), chunk); err != nil {
t.Fatalf("Put(...): unexpected error: %v", err)
}

decTS := binary.BigEndian.Uint64(chunk.Stamp().Timestamp())
encTS := make([]byte, 8)
binary.BigEndian.PutUint64(encTS, decTS-1)

stamp := postage.NewStamp(
chunk.Stamp().BatchID(),
chunk.Stamp().Index(),
encTS,
chunk.Stamp().Sig(),
)

chunk2 := chunktest.GenerateTestRandomChunk().WithStamp(stamp)

want := upload.ErrOverwriteOfNewerBatch
have := putter.Put(context.Background(), ts, ts.IndexStore(), chunk2)
if !errors.Is(have, want) {
t.Fatalf("Put(...): unexpected error:\n\twant: %v\n\thave: %v", want, have)
}
})

t.Run("put existing chunk with newer batch timestamp", func(t *testing.T) {
chunk := chunktest.GenerateTestRandomChunk()
if err := putter.Put(context.Background(), ts, ts.IndexStore(), chunk); err != nil {
t.Fatalf("Put(...): unexpected error: %v", err)
}

decTS := binary.BigEndian.Uint64(chunk.Stamp().Timestamp())
encTS := make([]byte, 8)
binary.BigEndian.PutUint64(encTS, decTS+1)

stamp := postage.NewStamp(
chunk.Stamp().BatchID(),
chunk.Stamp().Index(),
encTS,
chunk.Stamp().Sig(),
)

chunk2 := chunktest.GenerateTestRandomChunk().WithStamp(stamp)

if err := putter.Put(context.Background(), ts, ts.IndexStore(), chunk2); err != nil {
t.Fatalf("Put(...): unexpected error: %v", err)
}
})
}

func TestNextTagID(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 9c1a8d3

Please sign in to comment.