Skip to content

Commit

Permalink
fix: include deferred header (#332)
Browse files Browse the repository at this point in the history
  • Loading branch information
istae authored Mar 9, 2023
1 parent 7838c5a commit a0c8735
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 17 deletions.
11 changes: 7 additions & 4 deletions pkg/bee/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ const (
apiVersion = "v1"
contentType = "application/json; charset=utf-8"
postageStampBatchHeader = "Swarm-Postage-Batch-Id"
deferredUploadHeader = "Swarm-Deferred-Upload"
swarmPinHeader = "Swarm-Pin"
swarmTagHeader = "Swarm-Tag"
)

var userAgent = "beekeeper/" + beekeeper.Version
Expand Down Expand Up @@ -301,8 +304,8 @@ func (f roundTripperFunc) RoundTrip(r *http.Request) (*http.Response, error) {
}

type UploadOptions struct {
Pin bool
Tag uint32
BatchID string
Deferred bool
Pin bool
Tag uint32
BatchID string
Direct bool
}
5 changes: 3 additions & 2 deletions pkg/bee/api/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ func (b *BytesService) Upload(ctx context.Context, data io.Reader, o UploadOptio
var resp BytesUploadResponse
h := http.Header{}
if o.Pin {
h.Add("Swarm-Pin", "true")
h.Add(swarmPinHeader, "true")
}
if o.Tag != 0 {
h.Add("Swarm-Tag", strconv.FormatUint(uint64(o.Tag), 10))
h.Add(swarmTagHeader, strconv.FormatUint(uint64(o.Tag), 10))
}
h.Add(deferredUploadHeader, strconv.FormatBool(!o.Direct))
h.Add(postageStampBatchHeader, o.BatchID)
err := b.client.requestWithHeader(ctx, http.MethodPost, "/"+apiVersion+"/bytes", h, data, &resp)
return resp, err
Expand Down
6 changes: 3 additions & 3 deletions pkg/bee/api/chunks.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ func (c *ChunksService) Upload(ctx context.Context, data []byte, o UploadOptions
var resp ChunksUploadResponse
h := http.Header{}
if o.Pin {
h.Add("Swarm-Pin", "true")
h.Add(swarmPinHeader, "true")
}
if o.Deferred {
h.Add("Swarm-Deferred-Upload", "true")
if o.Direct {
h.Add(deferredUploadHeader, "false")
}
h.Add(postageStampBatchHeader, o.BatchID)
err := c.client.requestWithHeader(ctx, http.MethodPost, "/"+apiVersion+"/chunks", h, bytes.NewReader(data), &resp)
Expand Down
4 changes: 2 additions & 2 deletions pkg/bee/api/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ func (f *FilesService) Upload(ctx context.Context, name string, data io.Reader,
header.Set("Content-Type", "application/octet-stream")
header.Set("Content-Length", strconv.FormatInt(size, 10))
if o.Pin {
header.Set("Swarm-Pin", "true")
header.Set(swarmPinHeader, "true")
}
if o.Tag != 0 {
header.Set("Swarm-Tag", strconv.FormatUint(uint64(o.Tag), 10))
header.Set(swarmTagHeader, strconv.FormatUint(uint64(o.Tag), 10))
}
header.Set(postageStampBatchHeader, o.BatchID)

Expand Down
8 changes: 4 additions & 4 deletions pkg/check/gc/reserve.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,14 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts int
}
// radius is 4

_, err = client.UploadChunk(ctx, pinnedChunk.Data(), api.UploadOptions{Pin: true, BatchID: batchID, Deferred: true})
_, err = client.UploadChunk(ctx, pinnedChunk.Data(), api.UploadOptions{Pin: true, BatchID: batchID})
if err != nil {
return fmt.Errorf("unable to upload chunk: %w", err)
}
c.logger.Infof("uploaded pinned chunk %q", pinnedChunk.Address())

for _, c := range lowValueChunks {
_, err := client.UploadChunk(ctx, c.Data(), api.UploadOptions{BatchID: batchID, Deferred: true})
_, err := client.UploadChunk(ctx, c.Data(), api.UploadOptions{BatchID: batchID})
if err != nil {
return fmt.Errorf("low value chunk: %w", err)
}
Expand All @@ -214,7 +214,7 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts int
// radius is 5

for _, c := range lowValueHigherRadiusChunks {
if _, err := client.UploadChunk(ctx, c.Data(), api.UploadOptions{BatchID: batchID, Deferred: true}); err != nil {
if _, err := client.UploadChunk(ctx, c.Data(), api.UploadOptions{BatchID: batchID}); err != nil {
return fmt.Errorf("low value chunk: %w", err)
}
}
Expand Down Expand Up @@ -259,7 +259,7 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts int

highValueChunks := bee.GenerateNRandomChunksAt(rnd, overlay, 5, state.Radius)
for _, c := range highValueChunks {
if _, err := client.UploadChunk(ctx, c.Data(), api.UploadOptions{BatchID: highValueBatch, Deferred: true}); err != nil {
if _, err := client.UploadChunk(ctx, c.Data(), api.UploadOptions{BatchID: highValueBatch}); err != nil {
return fmt.Errorf("high value chunks: %w", err)
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/check/smoke/smoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func (t *test) uploadWithBatch(cName string, data []byte, batchID string) (swarm
client := t.clients[cName]
t.logger.Infof("node %s: uploading data, batch id %s", cName, batchID)
start := time.Now()
addr, err := client.UploadBytes(t.ctx, data, api.UploadOptions{Pin: false, BatchID: batchID, Deferred: false})
addr, err := client.UploadBytes(t.ctx, data, api.UploadOptions{Pin: false, BatchID: batchID, Direct: true})
if err != nil {
return swarm.ZeroAddress, 0, fmt.Errorf("upload to the node %s: %w", cName, err)
}
Expand All @@ -242,7 +242,7 @@ func (t *test) upload(cName string, data []byte) (swarm.Address, time.Duration,
}
t.logger.Infof("node %s: uploading data, batch id %s", cName, batchID)
start := time.Now()
addr, err := client.UploadBytes(t.ctx, data, api.UploadOptions{Pin: false, BatchID: batchID, Deferred: false})
addr, err := client.UploadBytes(t.ctx, data, api.UploadOptions{Pin: false, BatchID: batchID, Direct: true})
if err != nil {
return swarm.ZeroAddress, 0, fmt.Errorf("upload to the node %s: %w", cName, err)
}
Expand Down

0 comments on commit a0c8735

Please sign in to comment.