Browse Source

avoid creating the same bucket with a different randomized name

related to https://github.com/chrislusf/seaweedfs/issues/2492
pull/2500/head
chrislu 3 years ago
parent
commit
c146c76d10
  1. 24
      weed/command/filer_remote_gateway_buckets.go

24
weed/command/filer_remote_gateway_buckets.go

@ -86,6 +86,10 @@ func (option *RemoteGatewayOptions) makeBucketedEventProcessor(filerSource *sour
return nil return nil
} }
} }
bucketPath := util.FullPath(option.bucketsDir).Child(entry.Name)
remoteLocation, found := option.mappings.Mappings[string(bucketPath)]
if !found {
if *option.createBucketRandomSuffix { if *option.createBucketRandomSuffix {
// https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html // https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html
if len(bucketName)+5 > 63 { if len(bucketName)+5 > 63 {
@ -93,21 +97,21 @@ func (option *RemoteGatewayOptions) makeBucketedEventProcessor(filerSource *sour
} }
bucketName = fmt.Sprintf("%s-%04d", bucketName, rand.Uint32()%10000) bucketName = fmt.Sprintf("%s-%04d", bucketName, rand.Uint32()%10000)
} }
glog.V(0).Infof("create bucket %s", bucketName)
if err := client.CreateBucket(bucketName); err != nil {
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{
remoteLocation = &remote_pb.RemoteStorageLocation{
Name: *option.createBucketAt, Name: *option.createBucketAt,
Bucket: bucketName, Bucket: bucketName,
Path: "/", Path: "/",
} }
// need to add new mapping here before getting upates from metadata tailing
// need to add new mapping here before getting updates from metadata tailing
option.mappings.Mappings[string(bucketPath)] = remoteLocation option.mappings.Mappings[string(bucketPath)] = remoteLocation
} else {
bucketName = remoteLocation.Bucket
}
glog.V(0).Infof("create bucket %s", bucketName)
if err := client.CreateBucket(bucketName); err != nil {
return fmt.Errorf("create bucket %s in %s: %v", bucketName, remoteConf.Name, err)
}
return filer.InsertMountMapping(option, string(bucketPath), remoteLocation) return filer.InsertMountMapping(option, string(bucketPath), remoteLocation)

Loading…
Cancel
Save