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.

82 lines
2.0 KiB

4 years ago
4 years ago
  1. package filer
  2. import (
  3. "bytes"
  4. "math"
  5. "github.com/chrislusf/seaweedfs/weed/glog"
  6. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  7. "github.com/chrislusf/seaweedfs/weed/util"
  8. )
  9. // onMetadataChangeEvent is triggered after filer processed change events from local or remote filers
  10. func (f *Filer) onMetadataChangeEvent(event *filer_pb.SubscribeMetadataResponse) {
  11. f.maybeReloadFilerConfiguration(event)
  12. f.onBucketEvents(event)
  13. }
  14. func (f *Filer) onBucketEvents(event *filer_pb.SubscribeMetadataResponse) {
  15. message := event.EventNotification
  16. for _, sig := range message.Signatures {
  17. if sig == f.Signature {
  18. return
  19. }
  20. }
  21. if f.DirBucketsPath == event.Directory {
  22. if message.OldEntry == nil && message.NewEntry != nil {
  23. f.Store.OnBucketCreation(message.NewEntry.Name)
  24. }
  25. if message.OldEntry != nil && message.NewEntry == nil {
  26. f.Store.OnBucketDeletion(message.OldEntry.Name)
  27. }
  28. }
  29. }
  30. func (f *Filer) maybeReloadFilerConfiguration(event *filer_pb.SubscribeMetadataResponse) {
  31. if DirectoryEtcSeaweedFS != event.Directory {
  32. if DirectoryEtcSeaweedFS != event.EventNotification.NewParentPath {
  33. return
  34. }
  35. }
  36. entry := event.EventNotification.NewEntry
  37. if entry == nil {
  38. return
  39. }
  40. glog.V(0).Infof("procesing %v", event)
  41. if entry.Name == FilerConfName {
  42. f.reloadFilerConfiguration(entry)
  43. }
  44. }
  45. func (f *Filer) readEntry(chunks []*filer_pb.FileChunk) ([]byte, error) {
  46. var buf bytes.Buffer
  47. err := StreamContent(f.MasterClient, &buf, chunks, 0, math.MaxInt64)
  48. if err != nil {
  49. return nil, err
  50. }
  51. return buf.Bytes(), nil
  52. }
  53. func (f *Filer) reloadFilerConfiguration(entry *filer_pb.Entry) {
  54. fc := NewFilerConf()
  55. err := fc.loadFromChunks(f, entry.Content, entry.Chunks)
  56. if err != nil {
  57. glog.Errorf("read filer conf chunks: %v", err)
  58. return
  59. }
  60. f.FilerConf = fc
  61. }
  62. func (f *Filer) LoadFilerConf() {
  63. fc := NewFilerConf()
  64. err := util.Retry("loadFilerConf", func() error {
  65. return fc.loadFromFiler(f)
  66. })
  67. if err != nil {
  68. glog.Errorf("read filer conf: %v", err)
  69. return
  70. }
  71. f.FilerConf = fc
  72. }