Skip to content

Commit

Permalink
Disable chunk encoding for put requests to Google Cloud Storage (La…
Browse files Browse the repository at this point in the history
…yr-Labs#167)

* Set DisableContentSha256=true for Put() requests to Google

* Move putObjectOptions to s3 Store struct
  • Loading branch information
jcortejoso authored Oct 8, 2024
1 parent 754ef4a commit fba1762
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions store/precomputed_key/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/hex"
"errors"
"io"
"net/url"
"path"
"time"

Expand All @@ -14,6 +15,7 @@ import (
"github.com/minio/minio-go/v7"

"github.com/minio/minio-go/v7/pkg/credentials"
"github.com/minio/minio-go/v7/pkg/s3utils"
)

const (
Expand Down Expand Up @@ -50,12 +52,22 @@ type Config struct {
}

type Store struct {
cfg Config
client *minio.Client
stats *store.Stats
cfg Config
client *minio.Client
putObjectOptions minio.PutObjectOptions
stats *store.Stats
}

func NewS3(cfg Config) (*Store, error) {
endpointURL, err := url.Parse(cfg.Endpoint)
if err != nil {
return nil, err
}
putObjectOptions := minio.PutObjectOptions{}
if s3utils.IsGoogleEndpoint(*endpointURL) {
putObjectOptions.DisableContentSha256 = true // Avoid chunk signatures on GCS: https://github.com/minio/minio-go/issues/1922
}

client, err := minio.New(cfg.Endpoint, &minio.Options{
Creds: creds(cfg),
Secure: cfg.EnableTLS,
Expand All @@ -65,8 +77,9 @@ func NewS3(cfg Config) (*Store, error) {
}

return &Store{
cfg: cfg,
client: client,
cfg: cfg,
client: client,
putObjectOptions: putObjectOptions,
stats: &store.Stats{
Entries: 0,
Reads: 0,
Expand Down Expand Up @@ -97,7 +110,7 @@ func (s *Store) Get(ctx context.Context, key []byte) ([]byte, error) {
}

func (s *Store) Put(ctx context.Context, key []byte, value []byte) error {
_, err := s.client.PutObject(ctx, s.cfg.Bucket, path.Join(s.cfg.Path, hex.EncodeToString(key)), bytes.NewReader(value), int64(len(value)), minio.PutObjectOptions{})
_, err := s.client.PutObject(ctx, s.cfg.Bucket, path.Join(s.cfg.Path, hex.EncodeToString(key)), bytes.NewReader(value), int64(len(value)), s.putObjectOptions)
if err != nil {
return err
}
Expand Down

0 comments on commit fba1762

Please sign in to comment.