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: redundancy root push #4711

Merged
merged 4 commits into from
Jul 9, 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
2 changes: 2 additions & 0 deletions pkg/api/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ func (s *Service) bytesUploadHandler(w http.ResponseWriter, r *http.Request) {
deferred = defaultUploadMethod(headers.Deferred)
)

ctx = redundancy.SetLevelInContext(ctx, headers.RLevel)

if deferred || headers.Pin {
tag, err = s.getOrCreateSessionID(headers.SwarmTag)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/bzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ func (s *Service) bzzUploadHandler(w http.ResponseWriter, r *http.Request) {
deferred = defaultUploadMethod(headers.Deferred)
)

ctx = redundancy.SetLevelInContext(ctx, headers.RLevel)

if deferred || headers.Pin {
tag, err = s.getOrCreateSessionID(headers.SwarmTag)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/file/pipeline/hashtrie/hashtrie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ func TestRedundancy(t *testing.T) {
if expectedParities != parity {
t.Fatalf("want parity %d got %d", expectedParities, parity)
}
if tc.level.GetReplicaCount()+1 != int(replicaChunkCounter.replicaCount.Load()) { // +1 is the original chunk
if tc.level.GetReplicaCount() != int(replicaChunkCounter.replicaCount.Load()) {
t.Fatalf("unexpected number of replicas: want %d. Got: %d", tc.level.GetReplicaCount(), int(replicaChunkCounter.replicaCount.Load()))
}
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/replicas/putter.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ func NewPutter(p storage.Putter) storage.Putter {
// Put makes the getter satisfy the storage.Getter interface
func (p *putter) Put(ctx context.Context, ch swarm.Chunk) (err error) {
rlevel := redundancy.GetLevelFromContext(ctx)
errs := []error{p.putter.Put(ctx, ch)}
errs := []error{}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so THIS is where the redundant put of the root chunk came from? I was wondering! Do you mind my asking (for my own education) where the root chunk actually gets put for rlevel==0?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is done by the hashtrie module which is in a chunk pipeline process that has a ChainWrite function which does the job.

if rlevel == 0 {
return errs[0]
return nil
}

rr := newReplicator(ch.Address(), rlevel)
Expand Down
4 changes: 4 additions & 0 deletions pkg/replicas/putter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ func TestPutter(t *testing.T) {
defer store.Close()
p := replicas.NewPutter(store)

// original chunk
if err := store.Put(ctx, ch); err != nil {
t.Fatalf("expected no error. got %v", err)
}
if err := p.Put(ctx, ch); err != nil {
t.Fatalf("expected no error. got %v", err)
}
Expand Down
Loading