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

feat: redundancy retrieve api #4529

Merged
merged 52 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
cf63d66
fix: copyright header year
zelig Dec 20, 2023
9bb8112
fix: openapi param name
zelig Dec 20, 2023
d628dc4
refactor(getter): add delayed and forgetting store mocks
zelig Dec 20, 2023
a202707
fix(getter): timeout header parsing for time duration
zelig Dec 20, 2023
df9a82b
feat(api): extensive api tests for redundancy
zelig Dec 21, 2023
b54e832
fix(api): redundancy param strict = !fallbackmode (value of header)
zelig Dec 21, 2023
0738117
test: tmp, trying to figure out context
zelig Dec 21, 2023
14c8627
fix(api): context passing
zelig Dec 21, 2023
fad1062
fix(api): amend value passing through context
zelig Dec 21, 2023
37e4b5f
fix(pipeline): capitalisation
zelig Jan 1, 2024
44b5261
refactor(pseudorand): fix and add match
zelig Jan 1, 2024
bd4acad
refactor(storer/mock): redesign forgettingstore
zelig Jan 1, 2024
817816d
feat(joiner): introduce fetchtimeout on decoder get calls
zelig Jan 1, 2024
c01ceb0
fix(redundancy/getter): fill incomplete shard, recover from cancelled…
zelig Jan 1, 2024
808ba4c
test: add extensive multilevel joiner tests for redundancy
zelig Jan 1, 2024
2de2007
fix: check seek error and add Size func
zelig Jan 4, 2024
fdb02ec
fix: remove spurious selector in import
zelig Jan 4, 2024
2dcaef4
fix: improve GetParamsFromContext and remove debug lines
zelig Jan 4, 2024
65e3f23
fix: add comments and improve test
zelig Jan 4, 2024
5a59b65
fix: disable langos and lookahead buffer on top of joiner
zelig Jan 4, 2024
2ac6937
fix: bzz upload/download tests with redundancy and improve range quer…
zelig Jan 4, 2024
b7b1a76
fix(getter): fix default assignment to fetcher timeout
zelig Jan 4, 2024
7846bcd
fix: langos back, debug print lines removed
zelig Jan 4, 2024
89a756c
test: temporary debug lines in redundancy tests
zelig Jan 4, 2024
57f430e
refactor(replicas,redundancy): move level in context accessors
zelig Jan 4, 2024
867e1cd
fix(api): typo
zelig Jan 4, 2024
484310a
fix: set NONE as default replicas getter
zelig Jan 5, 2024
f208167
test: remove t.Parallel from inclusion proof test
zelig Jan 5, 2024
eb8fb71
fix: heed linter complaints
zelig Jan 5, 2024
56ba972
chore: remove langos from deps
zelig Jan 6, 2024
a2194d3
test: speed up
zelig Jan 6, 2024
050a3e8
fix: remove unused consts
zelig Jan 6, 2024
2f52ef3
test: speed up
zelig Jan 6, 2024
e563c82
fix(getter): lastIdx unnecessary
zelig Jan 6, 2024
a0b2dc9
test: increase timeout
zelig Jan 6, 2024
5f8862a
fix: typo
zelig Jan 10, 2024
0624ea4
fix: incorrectly placed context timeouts
zelig Jan 10, 2024
2e97467
fix: comment
zelig Jan 19, 2024
02ddf61
fix: slow redundancy test (#4537)
notanatol Jan 19, 2024
218fe7e
fix(redunadncy): amend parity numbers (#4547)
dysordys Jan 20, 2024
6139ab0
test(getter): decrease flakiness
zelig Jan 20, 2024
74bd848
chore(pseudorand): move from ioutil to testutil
zelig Jan 20, 2024
68c3483
refactor(redundancy): introduce getter Config and improve default params
zelig Jan 23, 2024
2821ff5
fix: simplify error
zelig Jan 23, 2024
606f2a8
test: add race detection detection
zelig Jan 23, 2024
6d4f2cb
fix: contexts
zelig Jan 23, 2024
3dc5df9
test: fix timeout
zelig Jan 24, 2024
5dc1802
test: increase timeout
zelig Jan 25, 2024
a1eb893
fix: file header added to new files
zelig Jan 25, 2024
3a47dc6
fix(joiner): reintroduces langos restrict no change in behaviour, loo…
zelig Jan 25, 2024
ec66cc4
fix(api): return after Serve
zelig Feb 3, 2024
969a134
test(file): fix timeouts
zelig Feb 3, 2024
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
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ require (
github.com/ethersphere/go-price-oracle-abi v0.1.0
github.com/ethersphere/go-storage-incentives-abi v0.6.0
github.com/ethersphere/go-sw3-abi v0.4.0
github.com/ethersphere/langos v1.0.0
github.com/go-playground/validator/v10 v10.11.1
github.com/gogo/protobuf v1.3.2
github.com/google/go-cmp v0.5.9
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,6 @@ github.com/ethersphere/go-storage-incentives-abi v0.6.0 h1:lfGViU/wJg/CyXlntNvTQ
github.com/ethersphere/go-storage-incentives-abi v0.6.0/go.mod h1:SXvJVtM4sEsaSKD0jc1ClpDLw8ErPoROZDme4Wrc/Nc=
github.com/ethersphere/go-sw3-abi v0.4.0 h1:T3ANY+ktWrPAwe2U0tZi+DILpkHzto5ym/XwV/Bbz8g=
github.com/ethersphere/go-sw3-abi v0.4.0/go.mod h1:BmpsvJ8idQZdYEtWnvxA8POYQ8Rl/NhyCdF0zLMOOJU=
github.com/ethersphere/langos v1.0.0 h1:NBtNKzXTTRSue95uOlzPN4py7Aofs0xWPzyj4AI1Vcc=
github.com/ethersphere/langos v1.0.0/go.mod h1:dlcN2j4O8sQ+BlCaxeBu43bgr4RQ+inJ+pHwLeZg5Tw=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 h1:FtmdgXiUlNeRsoNMFlKLDt+S+6hbjVMEW6RGQ7aUf7c=
github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0=
Expand Down
2 changes: 1 addition & 1 deletion openapi/SwarmCommon.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ components:
required: false
description: >
Specify the retrieve strategy on redundant data.
The mumbers stand for NONE, DATA, PROX and RACE, respectively.
The numbers stand for NONE, DATA, PROX and RACE, respectively.
Strategy NONE means no prefetching takes place.
Strategy DATA means only data chunks are prefetched.
Strategy PROX means only chunks that are close to the node are prefetched.
Expand Down
21 changes: 1 addition & 20 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const (
SwarmRedundancyLevelHeader = "Swarm-Redundancy-Level"
SwarmRedundancyStrategyHeader = "Swarm-Redundancy-Strategy"
SwarmRedundancyFallbackModeHeader = "Swarm-Redundancy-Fallback-Mode"
SwarmChunkRetrievalTimeoutHeader = "Swarm-Chunk-Retrieval-Timeout-Level"
SwarmChunkRetrievalTimeoutHeader = "Swarm-Chunk-Retrieval-Timeout"

ImmutableHeader = "Immutable"
GasPriceHeader = "Gas-Price"
Expand All @@ -99,18 +99,6 @@ const (
OriginHeader = "Origin"
)

// The size of buffer used for prefetching content with Langos.
// Warning: This value influences the number of chunk requests and chunker join goroutines
// per file request.
// Recommended value is 8 or 16 times the io.Copy default buffer value which is 32kB, depending
// on the file size. Use lookaheadBufferSize() to get the correct buffer size for the request.
const (
smallFileBufferSize = 8 * 32 * 1024
largeFileBufferSize = 16 * 32 * 1024

largeBufferFilesizeThreshold = 10 * 1000000 // ten megs
)

const (
multiPartFormData = "multipart/form-data"
contentTypeTar = "application/x-tar"
Expand Down Expand Up @@ -615,13 +603,6 @@ func (s *Service) gasConfigMiddleware(handlerName string) func(h http.Handler) h
}
}

func lookaheadBufferSize(size int64) int {
if size <= largeBufferFilesizeThreshold {
return smallFileBufferSize
}
return largeFileBufferSize
}

// corsHandler sets CORS headers to HTTP response if allowed origins are configured.
func (s *Service) corsHandler(h http.Handler) http.Handler {
allowedHeaders := []string{
Expand Down
21 changes: 13 additions & 8 deletions pkg/api/bzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/ethersphere/bee/pkg/swarm"
"github.com/ethersphere/bee/pkg/topology"
"github.com/ethersphere/bee/pkg/tracing"
"github.com/ethersphere/langos"
"github.com/gorilla/mux"
)

Expand Down Expand Up @@ -272,8 +271,12 @@ func (s *Service) serveReference(logger log.Logger, address swarm.Address, pathV
loggerV1 := logger.V(1).Build()

headers := struct {
Cache *bool `map:"Swarm-Cache"`
Cache *bool `map:"Swarm-Cache"`
Strategy getter.Strategy `map:"Swarm-Redundancy-Strategy"`
FallbackMode bool `map:"Swarm-Redundancy-Fallback-Mode"`
ChunkRetrievalTimeout string `map:"Swarm-Chunk-Retrieval-Timeout"`
}{}

if response := s.mapStructure(r.Header, &headers); response != nil {
response("invalid header params", logger, w)
return
Expand All @@ -282,10 +285,12 @@ func (s *Service) serveReference(logger log.Logger, address swarm.Address, pathV
if headers.Cache != nil {
cache = *headers.Cache
}

ls := loadsave.NewReadonly(s.storer.Download(cache))
feedDereferenced := false

ctx := r.Context()
ctx = getter.SetParamsInContext(ctx, headers.Strategy, headers.FallbackMode, headers.ChunkRetrievalTimeout)

FETCH:
// read manifest entry
Expand Down Expand Up @@ -366,7 +371,6 @@ FETCH:
jsonhttp.NotFound(w, "address not found or incorrect")
return
}

me, err := m.Lookup(ctx, pathVar)
if err != nil {
loggerV1.Debug("bzz download: invalid path", "address", address, "path", pathVar, "error", err)
Expand Down Expand Up @@ -459,8 +463,9 @@ func (s *Service) downloadHandler(logger log.Logger, w http.ResponseWriter, r *h
Cache *bool `map:"Swarm-Cache"`
Strategy getter.Strategy `map:"Swarm-Redundancy-Strategy"`
FallbackMode bool `map:"Swarm-Redundancy-Fallback-Mode"`
ChunkRetrievalTimeout time.Duration `map:"Swarm-Chunk-Retrieval-Timeout"`
ChunkRetrievalTimeout string `map:"Swarm-Chunk-Retrieval-Timeout"`
}{}

if response := s.mapStructure(r.Header, &headers); response != nil {
response("invalid header params", logger, w)
return
Expand All @@ -471,9 +476,7 @@ func (s *Service) downloadHandler(logger log.Logger, w http.ResponseWriter, r *h
}

ctx := r.Context()
ctx = getter.SetStrategy(ctx, headers.Strategy)
ctx = getter.SetStrict(ctx, headers.FallbackMode)
ctx = getter.SetFetchTimeout(ctx, headers.ChunkRetrievalTimeout)
ctx = getter.SetParamsInContext(ctx, headers.Strategy, headers.FallbackMode, headers.ChunkRetrievalTimeout)
reader, l, err := joiner.New(ctx, s.storer.Download(cache), s.storer.Cache(), reference)
if err != nil {
if errors.Is(err, storage.ErrNotFound) || errors.Is(err, topology.ErrNotFound) {
Expand All @@ -497,7 +500,9 @@ func (s *Service) downloadHandler(logger log.Logger, w http.ResponseWriter, r *h
}
w.Header().Set(ContentLengthHeader, strconv.FormatInt(l, 10))
w.Header().Set("Access-Control-Expose-Headers", ContentDispositionHeader)
http.ServeContent(w, r, "", time.Now(), langos.NewBufferedLangos(reader, lookaheadBufferSize(l)))
http.ServeContent(w, r, "", time.Now(), reader)
// NOTE: temporary workaround for testing, watch this...
// http.ServeContent(w, r, "", time.Now(), langos.NewBufferedLangos(reader, lookaheadBufferSize(l)))
zelig marked this conversation as resolved.
Show resolved Hide resolved
}

// manifestMetadataLoad returns the value for a key stored in the metadata of
Expand Down
Loading
Loading