You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.9 KiB

  1. package s3api
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/filer"
  4. "github.com/chrislusf/seaweedfs/weed/glog"
  5. "github.com/chrislusf/seaweedfs/weed/pb"
  6. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  7. "github.com/chrislusf/seaweedfs/weed/s3api/s3_constants"
  8. "github.com/chrislusf/seaweedfs/weed/util"
  9. )
  10. func (s3a *S3ApiServer) subscribeMetaEvents(clientName string, prefix string, lastTsNs int64) {
  11. processEventFn := func(resp *filer_pb.SubscribeMetadataResponse) error {
  12. message := resp.EventNotification
  13. if message.NewEntry == nil {
  14. return nil
  15. }
  16. dir := resp.Directory
  17. if message.NewParentPath != "" {
  18. dir = message.NewParentPath
  19. }
  20. fileName := message.NewEntry.Name
  21. content := message.NewEntry.Content
  22. _ = s3a.onIamConfigUpdate(dir, fileName, content)
  23. _ = s3a.onCircuitBreakerConfigUpdate(dir, fileName, content)
  24. return nil
  25. }
  26. util.RetryForever("followIamChanges", func() error {
  27. return pb.WithFilerClientFollowMetadata(s3a, clientName, s3a.randomClientId, prefix, &lastTsNs, 0, 0, processEventFn, pb.FatalOnError)
  28. }, func(err error) bool {
  29. glog.V(0).Infof("iam follow metadata changes: %v", err)
  30. return true
  31. })
  32. }
  33. //reload iam config
  34. func (s3a *S3ApiServer) onIamConfigUpdate(dir, filename string, content []byte) error {
  35. if dir == filer.IamConfigDirecotry && filename == filer.IamIdentityFile {
  36. if err := s3a.iam.LoadS3ApiConfigurationFromBytes(content); err != nil {
  37. return err
  38. }
  39. glog.V(0).Infof("updated %s/%s", dir, filename)
  40. }
  41. return nil
  42. }
  43. //reload circuit breaker config
  44. func (s3a *S3ApiServer) onCircuitBreakerConfigUpdate(dir, filename string, content []byte) error {
  45. if dir == s3_constants.CircuitBreakerConfigDir && filename == s3_constants.CircuitBreakerConfigFile {
  46. if err := s3a.cb.LoadS3ApiConfigurationFromBytes(content); err != nil {
  47. return err
  48. }
  49. glog.V(0).Infof("updated %s/%s", dir, filename)
  50. }
  51. return nil
  52. }