Skip to content

Commit

Permalink
Merge pull request #3556 from huangnauh/main
Browse files Browse the repository at this point in the history
feat: add option to disable combining the pending part
  • Loading branch information
milosgajdos committed Jan 18, 2022
2 parents bb1fb61 + 117757a commit c53f110
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
23 changes: 22 additions & 1 deletion registry/storage/driver/s3-aws/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ type DriverParameters struct {
MultipartCopyChunkSize int64
MultipartCopyMaxConcurrency int64
MultipartCopyThresholdSize int64
MultipartCombineSmallPart bool
RootDirectory string
StorageClass string
UserAgent string
Expand Down Expand Up @@ -146,6 +147,7 @@ type driver struct {
MultipartCopyChunkSize int64
MultipartCopyMaxConcurrency int64
MultipartCopyThresholdSize int64
MultipartCombineSmallPart bool
RootDirectory string
StorageClass string
ObjectACL string
Expand Down Expand Up @@ -356,6 +358,23 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) {
return nil, fmt.Errorf("the useDualStack parameter should be a boolean")
}

mutlipartCombineSmallPart := true
combine := parameters["multipartcombinesmallpart"]
switch combine := combine.(type) {
case string:
b, err := strconv.ParseBool(combine)
if err != nil {
return nil, fmt.Errorf("the multipartcombinesmallpart parameter should be a boolean")
}
mutlipartCombineSmallPart = b
case bool:
mutlipartCombineSmallPart = combine
case nil:
// do nothing
default:
return nil, fmt.Errorf("the multipartcombinesmallpart parameter should be a boolean")
}

sessionToken := ""

params := DriverParameters{
Expand All @@ -373,6 +392,7 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) {
multipartCopyChunkSize,
multipartCopyMaxConcurrency,
multipartCopyThresholdSize,
mutlipartCombineSmallPart,
fmt.Sprint(rootDirectory),
storageClass,
fmt.Sprint(userAgent),
Expand Down Expand Up @@ -497,6 +517,7 @@ func New(params DriverParameters) (*Driver, error) {
MultipartCopyChunkSize: params.MultipartCopyChunkSize,
MultipartCopyMaxConcurrency: params.MultipartCopyMaxConcurrency,
MultipartCopyThresholdSize: params.MultipartCopyThresholdSize,
MultipartCombineSmallPart: params.MultipartCombineSmallPart,
RootDirectory: params.RootDirectory,
StorageClass: params.StorageClass,
ObjectACL: params.ObjectACL,
Expand Down Expand Up @@ -1386,7 +1407,7 @@ func (w *writer) flushPart() error {
// nothing to write
return nil
}
if len(w.pendingPart) < int(w.driver.ChunkSize) {
if w.driver.MultipartCombineSmallPart && len(w.pendingPart) < int(w.driver.ChunkSize) {
// closing with a small pending part
// combine ready and pending to avoid writing a small part
w.readyPart = append(w.readyPart, w.pendingPart...)
Expand Down
6 changes: 6 additions & 0 deletions registry/storage/driver/s3-aws/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func init() {
regionEndpoint := os.Getenv("REGION_ENDPOINT")
sessionToken := os.Getenv("AWS_SESSION_TOKEN")
useDualStack := os.Getenv("S3_USE_DUALSTACK")
combineSmallPart := os.Getenv("MULTIPART_COMBINE_SMALL_PART")
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -84,6 +85,10 @@ func init() {
useDualStackBool := false
if useDualStack != "" {
useDualStackBool, err = strconv.ParseBool(useDualStack)
}
multipartCombineSmallPart := true
if combineSmallPart != "" {
multipartCombineSmallPart, err = strconv.ParseBool(combineSmallPart)
if err != nil {
return nil, err
}
Expand All @@ -104,6 +109,7 @@ func init() {
defaultMultipartCopyChunkSize,
defaultMultipartCopyMaxConcurrency,
defaultMultipartCopyThresholdSize,
multipartCombineSmallPart,
rootDirectory,
storageClass,
driverName + "-test",
Expand Down

0 comments on commit c53f110

Please sign in to comment.