Skip to content

Commit

Permalink
Merge pull request #3177 from redpanda-data/snowflake-upload
Browse files Browse the repository at this point in the history
snowflake: force singleshot object uploads
  • Loading branch information
rockwotj authored Feb 10, 2025
2 parents 0953711 + ffafb76 commit 55f270f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ Changelog

All notable changes to this project will be documented in this file.

## 4.47.1 - 2025-02-11

### Fixed

- Fix an issue with left over staging files being left around in the `snowflake_streaming` output. (@rockwotj)

## 4.47.0 - 2025-02-07

### Added
Expand Down
22 changes: 12 additions & 10 deletions internal/impl/snowflake/streaming/uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blockblob"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/credentials"
"github.com/aws/aws-sdk-go-v2/feature/s3/manager"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/cenkalti/backoff/v4"
"golang.org/x/oauth2"
Expand Down Expand Up @@ -70,9 +69,8 @@ func newUploader(fileLocationInfo fileLocationInfo) (uploader, error) {
if err != nil {
return nil, err
}
uploader := manager.NewUploader(client)
return &s3Uploader{
client: uploader,
client: client,
bucket: bucket,
pathPrefix: pathPrefix,
}, nil
Expand Down Expand Up @@ -146,19 +144,20 @@ func (u *azureUploader) upload(ctx context.Context, path string, encrypted, md5H
}

type s3Uploader struct {
client *manager.Uploader
client *s3.Client
bucket, pathPrefix string
}

func (u *s3Uploader) upload(ctx context.Context, path string, encrypted, md5Hash []byte, metadata map[string]string) error {
input := &s3.PutObjectInput{
Bucket: &u.bucket,
Key: aws.String(filepath.Join(u.pathPrefix, path)),
Body: bytes.NewReader(encrypted),
Metadata: metadata,
ContentMD5: aws.String(base64.StdEncoding.EncodeToString(md5Hash)),
Bucket: &u.bucket,
Key: aws.String(filepath.Join(u.pathPrefix, path)),
ContentLength: aws.Int64(int64(len(encrypted))),
Body: bytes.NewReader(encrypted),
Metadata: metadata,
ContentMD5: aws.String(base64.StdEncoding.EncodeToString(md5Hash)),
}
_, err := u.client.Upload(ctx, input)
_, err := u.client.PutObject(ctx, input)
return err
}

Expand All @@ -174,6 +173,9 @@ func (u *gcsUploader) upload(ctx context.Context, path string, encrypted, md5Has
ow := object.NewWriter(ctx)
ow.Metadata = metadata
ow.MD5 = md5Hash
// Prevent resumable uploads and staging files in the bucket by removing the chunk size.
// https://cloud.google.com/storage/docs/uploading-objects-from-memory#storage-upload-object-from-memory-go
ow.ChunkSize = 0
for len(encrypted) > 0 {
n, err := ow.Write(encrypted)
if err != nil {
Expand Down

0 comments on commit 55f270f

Please sign in to comment.