From d0ec27816d1f2e7bcb78edf3b2294be0c470fd27 Mon Sep 17 00:00:00 2001 From: Acha Bill <57879913+acha-bill@users.noreply.github.com> Date: Thu, 29 Feb 2024 16:06:48 +0100 Subject: [PATCH] chore: add redundancy fallback mode header (#384) * fix: explicity set fallback mode * fix: remove debug log --- pkg/bee/api/api.go | 21 +++++++++++++-------- pkg/bee/api/bytes.go | 4 ++-- pkg/bee/client.go | 4 ++-- pkg/check/redundancy/redundancy.go | 3 ++- pkg/check/smoke/smoke.go | 2 +- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/pkg/bee/api/api.go b/pkg/bee/api/api.go index f79c377e4..6e488dc12 100644 --- a/pkg/bee/api/api.go +++ b/pkg/bee/api/api.go @@ -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 @@ -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 { @@ -317,5 +321,6 @@ type UploadOptions struct { } type DownloadOptions struct { - Cache *bool + Cache *bool + RedundancyFallbackMode *bool } diff --git a/pkg/bee/api/bytes.go b/pkg/bee/api/bytes.go index f4ea0c8ee..7593fbeef 100644 --- a/pkg/bee/api/bytes.go +++ b/pkg/bee/api/bytes.go @@ -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 diff --git a/pkg/bee/client.go b/pkg/bee/client.go index 89f847bab..b696c6ed5 100644 --- a/pkg/bee/client.go +++ b/pkg/bee/client.go @@ -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) } diff --git a/pkg/check/redundancy/redundancy.go b/pkg/check/redundancy/redundancy.go index 489a709ae..550c5c90f 100644 --- a/pkg/check/redundancy/redundancy.go +++ b/pkg/check/redundancy/redundancy.go @@ -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) } diff --git a/pkg/check/smoke/smoke.go b/pkg/check/smoke/smoke.go index f0b03c4c7..8d90b8efc 100644 --- a/pkg/check/smoke/smoke.go +++ b/pkg/check/smoke/smoke.go @@ -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) }