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

Add the chunk_size optional parameter to gcs storage #4060

Merged
merged 1 commit into from
Mar 5, 2018
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
25 changes: 22 additions & 3 deletions physical/gcs/gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ import (
"google.golang.org/api/option"
)

// Verify GCSBackend satisfies the correct interfaces
var _ physical.Backend = (*GCSBackend)(nil)

// GCSBackend is a physical backend that stores data
// within an Google Cloud Storage bucket.
type GCSBackend struct {
Expand All @@ -33,6 +30,15 @@ type GCSBackend struct {
logger log.Logger
}

var (
// Verify GCSBackend satisfies the correct interfaces
_ physical.Backend = (*GCSBackend)(nil)

// Number of bytes the writer will attempt to write in a single request.
// Defaults to 8Mb, as defined in the gcs library
chunkSize = 8 * 1024 * 1024
)

// NewGCSBackend constructs a Google Cloud Storage backend using a pre-existing
// bucket. Credentials can be provided to the backend, sourced
// from environment variables or a service account file
Expand Down Expand Up @@ -70,6 +76,18 @@ func NewGCSBackend(conf map[string]string, logger log.Logger) (physical.Backend,
}
}

chunkSizeStr, ok := conf["chunk_size"]
if ok {
chunkSize, err = strconv.Atoi(chunkSizeStr)
if err != nil {
return nil, errwrap.Wrapf("failed parsing chunk_size parameter: {{err}}", err)
}
chunkSize *= 1024
if logger.IsDebug() {
logger.Debug("physical/gcs: chunk_size set", "chunk_size", chunkSize)
}
}

g := GCSBackend{
bucketName: bucketName,
client: client,
Expand Down Expand Up @@ -111,6 +129,7 @@ func (g *GCSBackend) Put(ctx context.Context, entry *physical.Entry) error {

bucket := g.client.Bucket(g.bucketName)
writer := bucket.Object(entry.Key).NewWriter(context.Background())
writer.ChunkSize = chunkSize

g.permitPool.Acquire()
defer g.permitPool.Release()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ storage "gcs" {
- `max_parallel` `(string: "128")` – Specifies the maximum number of concurrent
requests.

- `chunk_size` `(string: "8192")` – Specifies the maximum kilobytes of each object
the gcs writer will attempt to send to the server in a single request.
If set to 0, it will attempt to send the whole object at once, but it will
not retry any failures either (not recommended). If you are not storing large
objects in Vault, it is recommended to set this to a low value (minimum is 256)
since it will drastically reduce the amount of memory Vault uses.

## `gcs` Examples

### Default Example
Expand Down