Skip to content

Commit

Permalink
fix: merge fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vladopajic committed May 4, 2023
1 parent a9149c2 commit 3333119
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pkg/storer/internal/upload/uploadstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,14 +319,15 @@ type uploadPutter struct {
// NewPutter returns a new chunk putter associated with the tagID.
func NewPutter(s internal.Storage, tagID uint64) (internal.PutterCloserWithReference, error) {
ti := &TagItem{TagID: tagID}
err := s.IndexStore().Get(ti)
has, err := s.IndexStore().Has(ti)
if err != nil {
return nil, err
}
if !has {
return nil, fmt.Errorf("upload store: tag %d not found: %w", tagID, storage.ErrNotFound)
}
return &uploadPutter{
tagID: ti.TagID,
split: ti.Split,
seen: ti.Seen,
s: s,
}, nil
}
Expand Down Expand Up @@ -420,8 +421,8 @@ func (u *uploadPutter) Close(addr swarm.Address) error {
return fmt.Errorf("failed reading tag while closing: %w", err)
}

ti.Split = u.split
ti.Seen = u.seen
ti.Split += u.split
ti.Seen += u.seen

if !addr.IsZero() {
ti.Address = addr.Clone()
Expand Down
38 changes: 38 additions & 0 deletions pkg/storer/internal/upload/uploadstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,44 @@ func TestChunkPutter(t *testing.T) {
t.Fatalf("unexpected error, expected: %v, got: %v", upload.ErrPutterAlreadyClosed, err)
}
})

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

for _, chunk := range chunktest.GenerateTestRandomChunks(5) {
err := putter.Put(context.Background(), chunk)
if err != nil {
t.Fatalf("Put(...): unexpected error: %v", err)
}
}

// close with different address
addr := swarm.RandAddress(t)
err = putter.Close(addr)
if err != nil {
t.Fatalf("Close(...): unexpected error %v", err)
}

ti, err := upload.TagInfo(ts.IndexStore(), tag.TagID)
if err != nil {
t.Fatalf("TagInfo(...): unexpected error %v", err)
}

wantTI := upload.TagItem{
TagID: tag.TagID,
Split: 25,
Seen: 10,
StartedAt: now().Unix(),
Address: addr,
}

if diff := cmp.Diff(wantTI, ti); diff != "" {
t.Fatalf("Get(...): unexpected TagItem (-want +have):\n%s", diff)
}
})
}

func TestChunkReporter(t *testing.T) {
Expand Down

0 comments on commit 3333119

Please sign in to comment.