2020-12-07 08:10:29 +00:00
|
|
|
package s3api
|
|
|
|
|
|
|
|
import (
|
2022-07-29 07:17:28 +00:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/filer"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
2020-12-07 08:10:29 +00:00
|
|
|
)
|
|
|
|
|
2022-09-29 19:29:01 +00:00
|
|
|
func (s3a *S3ApiServer) subscribeMetaEvents(clientName string, lastTsNs int64, prefix string, directoriesToWatch []string) {
|
2020-12-07 08:10:29 +00:00
|
|
|
|
|
|
|
processEventFn := func(resp *filer_pb.SubscribeMetadataResponse) error {
|
|
|
|
|
|
|
|
message := resp.EventNotification
|
|
|
|
if message.NewEntry == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
dir := resp.Directory
|
|
|
|
|
|
|
|
if message.NewParentPath != "" {
|
|
|
|
dir = message.NewParentPath
|
|
|
|
}
|
2022-06-15 13:07:55 +00:00
|
|
|
fileName := message.NewEntry.Name
|
|
|
|
content := message.NewEntry.Content
|
|
|
|
|
|
|
|
_ = s3a.onIamConfigUpdate(dir, fileName, content)
|
2022-06-17 09:11:18 +00:00
|
|
|
_ = s3a.onCircuitBreakerConfigUpdate(dir, fileName, content)
|
2022-09-29 19:29:01 +00:00
|
|
|
_ = s3a.onBucketMetadataChange(dir, message.OldEntry, message.NewEntry)
|
2020-12-07 08:10:29 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-07-23 17:50:28 +00:00
|
|
|
var clientEpoch int32
|
2021-10-17 08:04:19 +00:00
|
|
|
util.RetryForever("followIamChanges", func() error {
|
2022-07-23 17:50:28 +00:00
|
|
|
clientEpoch++
|
2022-09-29 19:29:01 +00:00
|
|
|
return pb.WithFilerClientFollowMetadata(s3a, clientName, s3a.randomClientId, clientEpoch, prefix, directoriesToWatch, &lastTsNs, 0, 0, processEventFn, pb.FatalOnError)
|
2021-10-17 08:04:19 +00:00
|
|
|
}, func(err error) bool {
|
|
|
|
glog.V(0).Infof("iam follow metadata changes: %v", err)
|
|
|
|
return true
|
2021-08-04 23:25:46 +00:00
|
|
|
})
|
2022-06-15 13:07:55 +00:00
|
|
|
}
|
2020-12-07 08:10:29 +00:00
|
|
|
|
2022-09-15 06:06:44 +00:00
|
|
|
// reload iam config
|
2022-06-15 13:07:55 +00:00
|
|
|
func (s3a *S3ApiServer) onIamConfigUpdate(dir, filename string, content []byte) error {
|
2022-09-14 17:11:31 +00:00
|
|
|
if dir == filer.IamConfigDirectory && filename == filer.IamIdentityFile {
|
2022-06-15 13:07:55 +00:00
|
|
|
if err := s3a.iam.LoadS3ApiConfigurationFromBytes(content); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
glog.V(0).Infof("updated %s/%s", dir, filename)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-09-15 06:06:44 +00:00
|
|
|
// reload circuit breaker config
|
2022-06-17 09:11:18 +00:00
|
|
|
func (s3a *S3ApiServer) onCircuitBreakerConfigUpdate(dir, filename string, content []byte) error {
|
2022-06-17 11:07:39 +00:00
|
|
|
if dir == s3_constants.CircuitBreakerConfigDir && filename == s3_constants.CircuitBreakerConfigFile {
|
2022-06-15 13:07:55 +00:00
|
|
|
if err := s3a.cb.LoadS3ApiConfigurationFromBytes(content); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
glog.V(0).Infof("updated %s/%s", dir, filename)
|
|
|
|
}
|
|
|
|
return nil
|
2020-12-07 08:10:29 +00:00
|
|
|
}
|
2022-09-29 19:29:01 +00:00
|
|
|
|
|
|
|
//reload bucket metadata
|
|
|
|
func (s3a *S3ApiServer) onBucketMetadataChange(dir string, oldEntry *filer_pb.Entry, newEntry *filer_pb.Entry) error {
|
|
|
|
if dir == s3a.option.BucketsPath {
|
|
|
|
if newEntry != nil {
|
|
|
|
s3a.bucketRegistry.LoadBucketMetadata(newEntry)
|
|
|
|
glog.V(0).Infof("updated bucketMetadata %s/%s", dir, newEntry)
|
|
|
|
} else {
|
|
|
|
s3a.bucketRegistry.RemoveBucketMetadata(oldEntry)
|
|
|
|
glog.V(0).Infof("remove bucketMetadata %s/%s", dir, newEntry)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|