diff options
| author | chrislu <chrislu@roblox.com> | 2021-12-05 13:06:41 -0800 |
|---|---|---|
| committer | chrislu <chrislu@roblox.com> | 2021-12-05 13:06:41 -0800 |
| commit | c146c76d1061c85a4ea4651e0538bb39219fedbb (patch) | |
| tree | b83bbe58671f7a5b5d9df3ae16028adf8c5e86b6 | |
| parent | 42d97a34422b74f0e88b5fa439779a517acecded (diff) | |
| download | seaweedfs-c146c76d1061c85a4ea4651e0538bb39219fedbb.tar.xz seaweedfs-c146c76d1061c85a4ea4651e0538bb39219fedbb.zip | |
avoid creating the same bucket with a different randomized name
related to https://github.com/chrislusf/seaweedfs/issues/2492
| -rw-r--r-- | weed/command/filer_remote_gateway_buckets.go | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/weed/command/filer_remote_gateway_buckets.go b/weed/command/filer_remote_gateway_buckets.go index 61bb1e434..af851e2b9 100644 --- a/weed/command/filer_remote_gateway_buckets.go +++ b/weed/command/filer_remote_gateway_buckets.go @@ -86,12 +86,26 @@ func (option *RemoteGatewayOptions) makeBucketedEventProcessor(filerSource *sour return nil } } - if *option.createBucketRandomSuffix { - // https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html - if len(bucketName)+5 > 63 { - bucketName = bucketName[:58] + + bucketPath := util.FullPath(option.bucketsDir).Child(entry.Name) + remoteLocation, found := option.mappings.Mappings[string(bucketPath)] + if !found { + if *option.createBucketRandomSuffix { + // https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html + if len(bucketName)+5 > 63 { + bucketName = bucketName[:58] + } + bucketName = fmt.Sprintf("%s-%04d", bucketName, rand.Uint32()%10000) + } + remoteLocation = &remote_pb.RemoteStorageLocation{ + Name: *option.createBucketAt, + Bucket: bucketName, + Path: "/", } - bucketName = fmt.Sprintf("%s-%04d", bucketName, rand.Uint32()%10000) + // need to add new mapping here before getting updates from metadata tailing + option.mappings.Mappings[string(bucketPath)] = remoteLocation + } else { + bucketName = remoteLocation.Bucket } glog.V(0).Infof("create bucket %s", bucketName) @@ -99,16 +113,6 @@ func (option *RemoteGatewayOptions) makeBucketedEventProcessor(filerSource *sour return fmt.Errorf("create bucket %s in %s: %v", bucketName, remoteConf.Name, err) } - bucketPath := util.FullPath(option.bucketsDir).Child(entry.Name) - remoteLocation := &remote_pb.RemoteStorageLocation{ - Name: *option.createBucketAt, - Bucket: bucketName, - Path: "/", - } - - // need to add new mapping here before getting upates from metadata tailing - option.mappings.Mappings[string(bucketPath)] = remoteLocation - return filer.InsertMountMapping(option, string(bucketPath), remoteLocation) } |
