Skip to content

Commit

Permalink
Merge #85493
Browse files Browse the repository at this point in the history
85493: cloud/amazon: add toggle for s3 storage to list prefix with additiona… r=rhu713 a=rhu713

…l marker

Add toggle for s3 storage to list prefixes with a paging marker that's the
prefix with an additional `/`. This allows certain s3 clones which return
`s3://<prefix>/` as the first result of listing `s3://<prefix>` to exclude that
result.

This behavior is toggled via setting the environment variable
`COCKROACH_S3_LIST_WITH_PREFIX_SLASH_MARKER` to true.

Release note: None

Co-authored-by: Rui Hu <[email protected]>
  • Loading branch information
craig[bot] and Rui Hu committed Aug 15, 2022
2 parents 4561f22 + 23b3a70 commit 91d47e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/cloud/amazon/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ go_library(
"//pkg/settings",
"//pkg/settings/cluster",
"//pkg/util/contextutil",
"//pkg/util/envutil",
"//pkg/util/ioctx",
"//pkg/util/log",
"//pkg/util/syncutil",
Expand Down
14 changes: 13 additions & 1 deletion pkg/cloud/amazon/s3_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/settings"
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
"github.com/cockroachdb/cockroach/pkg/util/contextutil"
"github.com/cockroachdb/cockroach/pkg/util/envutil"
"github.com/cockroachdb/cockroach/pkg/util/ioctx"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/syncutil"
Expand Down Expand Up @@ -678,8 +679,19 @@ func (s *s3Storage) List(ctx context.Context, prefix, delim string, fn cloud.Lis
return true
}

var s3Input *s3.ListObjectsInput
// Add an environment variable toggle for s3 storage to list prefixes with a
// paging marker that's the prefix with an additional /. This allows certain
// s3 clones which return s3://<prefix>/ as the first result of listing
// s3://<prefix> to exclude that result.
if envutil.EnvOrDefaultBool("COCKROACH_S3_LIST_WITH_PREFIX_SLASH_MARKER", false) {
s3Input = &s3.ListObjectsInput{Bucket: s.bucket, Prefix: aws.String(dest), Delimiter: nilIfEmpty(delim), Marker: aws.String(dest + "/")}
} else {
s3Input = &s3.ListObjectsInput{Bucket: s.bucket, Prefix: aws.String(dest), Delimiter: nilIfEmpty(delim)}
}

if err := client.ListObjectsPagesWithContext(
ctx, &s3.ListObjectsInput{Bucket: s.bucket, Prefix: aws.String(dest), Delimiter: nilIfEmpty(delim)}, pageFn,
ctx, s3Input, pageFn,
); err != nil {
return errors.Wrap(err, `failed to list s3 bucket`)
}
Expand Down

0 comments on commit 91d47e8

Please sign in to comment.