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

chore: add redundancy fallback mode header #384

Merged
merged 2 commits into from
Feb 29, 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
21 changes: 13 additions & 8 deletions pkg/bee/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ import (
)

const (
apiVersion = "v1"
contentType = "application/json; charset=utf-8"
postageStampBatchHeader = "Swarm-Postage-Batch-Id"
deferredUploadHeader = "Swarm-Deferred-Upload"
swarmPinHeader = "Swarm-Pin"
swarmTagHeader = "Swarm-Tag"
swarmCacheDownloadHeader = "Swarm-Cache"
apiVersion = "v1"
contentType = "application/json; charset=utf-8"
postageStampBatchHeader = "Swarm-Postage-Batch-Id"
deferredUploadHeader = "Swarm-Deferred-Upload"
swarmPinHeader = "Swarm-Pin"
swarmTagHeader = "Swarm-Tag"
swarmCacheDownloadHeader = "Swarm-Cache"
swarmRedundancyFallbackMode = "Swarm-Redundancy-Fallback-Mode"
)

var userAgent = "beekeeper/" + beekeeper.Version
Expand Down Expand Up @@ -196,6 +197,9 @@ func (c *Client) requestData(ctx context.Context, method, path string, body io.R
if opts != nil && opts.Cache != nil {
req.Header.Set(swarmCacheDownloadHeader, strconv.FormatBool(*opts.Cache))
}
if opts != nil && opts.RedundancyFallbackMode != nil {
req.Header.Set(swarmRedundancyFallbackMode, strconv.FormatBool(*opts.RedundancyFallbackMode))
}

r, err := c.httpClient.Do(req)
if err != nil {
Expand Down Expand Up @@ -317,5 +321,6 @@ type UploadOptions struct {
}

type DownloadOptions struct {
Cache *bool
Cache *bool
RedundancyFallbackMode *bool
}
4 changes: 2 additions & 2 deletions pkg/bee/api/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
type BytesService service

// Download downloads data from the node
func (b *BytesService) Download(ctx context.Context, a swarm.Address) (resp io.ReadCloser, err error) {
return b.client.requestData(ctx, http.MethodGet, "/"+apiVersion+"/bytes/"+a.String(), nil, nil)
func (b *BytesService) Download(ctx context.Context, a swarm.Address, opts *DownloadOptions) (resp io.ReadCloser, err error) {
return b.client.requestData(ctx, http.MethodGet, "/"+apiVersion+"/bytes/"+a.String(), nil, opts)
}

// BytesUploadResponse represents Upload's response
Expand Down
4 changes: 2 additions & 2 deletions pkg/bee/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ func (c *Client) Balances(ctx context.Context) (resp Balances, err error) {
}

// DownloadBytes downloads chunk from the node
func (c *Client) DownloadBytes(ctx context.Context, a swarm.Address) (data []byte, err error) {
r, err := c.api.Bytes.Download(ctx, a)
func (c *Client) DownloadBytes(ctx context.Context, a swarm.Address, opts *api.DownloadOptions) (data []byte, err error) {
r, err := c.api.Bytes.Download(ctx, a, opts)
if err != nil {
return nil, fmt.Errorf("download chunk %s: %w", a, err)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/check/redundancy/redundancy.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, o interf
return fmt.Errorf("upload chunks: %w", err)
}
c.logger.Infof("upload completed. Downloading %s", root.String())
d, err := downloadClient.DownloadBytes(ctx, root)
fallbackMode := true
d, err := downloadClient.DownloadBytes(ctx, root, &api.DownloadOptions{RedundancyFallbackMode: &fallbackMode})
if err != nil {
return fmt.Errorf("download bytes: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/check/smoke/smoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func (t *test) download(ctx context.Context, cName string, addr swarm.Address) (
client := t.clients[cName]
t.logger.Infof("node %s: downloading address %s", cName, addr)
start := time.Now()
data, err := client.DownloadBytes(ctx, addr)
data, err := client.DownloadBytes(ctx, addr, nil)
if err != nil {
return nil, 0, fmt.Errorf("download from node %s: %w", cName, err)
}
Expand Down
Loading