Skip to content

Commit

Permalink
fix(redundancy): on by default when downloading (#4602)
Browse files Browse the repository at this point in the history
  • Loading branch information
istae authored Feb 29, 2024
1 parent b49d9e8 commit a4fa9b8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
6 changes: 3 additions & 3 deletions pkg/file/joiner/joiner.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func (j *joiner) readAtOffset(
}

// fast forward the cursor
sec := j.subtrieSection(data, cursor, pSize, parity, subTrieSize)
sec := j.subtrieSection(cursor, pSize, parity, subTrieSize)
if cur+sec <= off {
cur += sec
continue
Expand Down Expand Up @@ -277,7 +277,7 @@ func (j *joiner) getShards(payloadSize, parities int) int {
}

// brute-forces the subtrie size for each of the sections in this intermediate chunk
func (j *joiner) subtrieSection(data []byte, startIdx, payloadSize, parities int, subtrieSize int64) int64 {
func (j *joiner) subtrieSection(startIdx, payloadSize, parities int, subtrieSize int64) int64 {
// assume we have a trie of size `y` then we can assume that all of
// the forks except for the last one on the right are of equal size
// this is due to how the splitter wraps levels.
Expand Down Expand Up @@ -375,7 +375,7 @@ func (j *joiner) processChunkAddresses(ctx context.Context, fn swarm.AddressIter
if j.refLength == encryption.ReferenceSize {
cursor += swarm.HashSize * min(i, shardCnt)
}
sec := j.subtrieSection(data, cursor, eSize, parity, subTrieSize)
sec := j.subtrieSection(cursor, eSize, parity, subTrieSize)
if sec <= swarm.ChunkSize {
continue
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/file/redundancy/getter/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func (g *decoder) recover(ctx context.Context) error {
}

// decode using Reed-Solomon decoder
if err := g.decode(ctx); err != nil {
if err := g.decode(); err != nil {
return err
}

Expand All @@ -292,7 +292,7 @@ func (g *decoder) recover(ctx context.Context) error {

// decode uses Reed-Solomon erasure coding decoder to recover data shards
// it must be called after shqrdcnt shards are retrieved
func (g *decoder) decode(ctx context.Context) error {
func (g *decoder) decode() error {
g.mu.Lock()
defer g.mu.Unlock()

Expand Down
10 changes: 3 additions & 7 deletions pkg/file/redundancy/getter/strategies.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package getter

import (
"context"
"errors"
"fmt"
"time"

Expand All @@ -15,8 +14,8 @@ import (
)

const (
DefaultStrategy = NONE // default prefetching strategy
DefaultStrict = true // default fallback modes
DefaultStrategy = DATA // default prefetching strategy
DefaultStrict = false // default fallback modes
DefaultFetchTimeout = retrieval.RetrieveChunkTimeout // timeout for each chunk retrieval
DefaultStrategyTimeout = 300 * time.Millisecond // timeout for each strategy
)
Expand Down Expand Up @@ -60,10 +59,7 @@ var DefaultConfig = Config{
func NewConfigFromContext(ctx context.Context, def Config) (conf Config, err error) {
var ok bool
conf = def
e := func(s string, errs ...error) error {
if len(errs) > 0 {
return fmt.Errorf("error setting %s from context: %w", s, errors.Join(errs...))
}
e := func(s string) error {
return fmt.Errorf("error setting %s from context", s)
}
if val := ctx.Value(strategyKey{}); val != nil {
Expand Down

0 comments on commit a4fa9b8

Please sign in to comment.