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

Update go-ds-s3 plugin to utilize prefixes for massive rate limit improvements #195

Closed
wants to merge 7 commits into from
Closed
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
9 changes: 9 additions & 0 deletions plugin/s3ds.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ func (s3p S3Plugin) DatastoreConfigParser() fsrepo.ConfigFromMap {
return nil, fmt.Errorf("s3ds: credentialsEndpoint not a string")
}
}

var keySuffix string
if v, ok := m["keySuffix"]; ok {
keySuffix, ok = v.(string)
if !ok {
return nil, fmt.Errorf("s3ds: keySuffix not a string")
}
}

return &S3Config{
cfg: s3ds.Config{
Expand All @@ -109,6 +117,7 @@ func (s3p S3Plugin) DatastoreConfigParser() fsrepo.ConfigFromMap {
Workers: workers,
RegionEndpoint: endpoint,
CredentialsEndpoint: credentialsEndpoint,
KeySuffix: keySuffix,
},
}, nil
}
Expand Down
13 changes: 9 additions & 4 deletions s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ type Config struct {
RootDirectory string
Workers int
CredentialsEndpoint string
KeySuffix string
}

func (s *S3Bucket) TransformKey(key string) (newKey string) {
return key + s.Config.KeySuffix
}

func NewS3Datastore(conf Config) (*S3Bucket, error) {
Expand Down Expand Up @@ -105,7 +110,7 @@ func NewS3Datastore(conf Config) (*S3Bucket, error) {
func (s *S3Bucket) Put(k ds.Key, value []byte) error {
_, err := s.S3.PutObject(&s3.PutObjectInput{
Bucket: aws.String(s.Bucket),
Key: aws.String(s.s3Path(k.String())),
Key: aws.String(s.s3Path(s.TransformKey(k.String()))),
Body: bytes.NewReader(value),
})
return err
Expand All @@ -118,7 +123,7 @@ func (s *S3Bucket) Sync(prefix ds.Key) error {
func (s *S3Bucket) Get(k ds.Key) ([]byte, error) {
resp, err := s.S3.GetObject(&s3.GetObjectInput{
Bucket: aws.String(s.Bucket),
Key: aws.String(s.s3Path(k.String())),
Key: aws.String(s.s3Path(s.TransformKey(k.String()))),
})
if err != nil {
if isNotFound(err) {
Expand All @@ -145,7 +150,7 @@ func (s *S3Bucket) Has(k ds.Key) (exists bool, err error) {
func (s *S3Bucket) GetSize(k ds.Key) (size int, err error) {
resp, err := s.S3.HeadObject(&s3.HeadObjectInput{
Bucket: aws.String(s.Bucket),
Key: aws.String(s.s3Path(k.String())),
Key: aws.String(s.s3Path(s.TransformKey(k.String()))),
})
if err != nil {
if s3Err, ok := err.(awserr.Error); ok && s3Err.Code() == "NotFound" {
Expand All @@ -159,7 +164,7 @@ func (s *S3Bucket) GetSize(k ds.Key) (size int, err error) {
func (s *S3Bucket) Delete(k ds.Key) error {
_, err := s.S3.DeleteObject(&s3.DeleteObjectInput{
Bucket: aws.String(s.Bucket),
Key: aws.String(s.s3Path(k.String())),
Key: aws.String(s.s3Path(s.TransformKey(k.String()))),
})
if isNotFound(err) {
// delete is idempotent
Expand Down