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.

100 lines
2.6 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.maybeReloadRemoteStorageConfigurationAndMapping(event)
  13. f.onBucketEvents(event)
  14. }
  15. func (f *Filer) onBucketEvents(event *filer_pb.SubscribeMetadataResponse) {
  16. message := event.EventNotification
  17. for _, sig := range message.Signatures {
  18. if sig == f.Signature {
  19. return
  20. }
  21. }
  22. if f.DirBucketsPath == event.Directory {
  23. if message.OldEntry == nil && message.NewEntry != nil {
  24. if message.NewEntry.IsDirectory {
  25. f.Store.OnBucketCreation(message.NewEntry.Name)
  26. }
  27. }
  28. if message.OldEntry != nil && message.NewEntry == nil {
  29. if message.OldEntry.IsDirectory {
  30. f.Store.OnBucketDeletion(message.OldEntry.Name)
  31. }
  32. }
  33. }
  34. }
  35. func (f *Filer) maybeReloadFilerConfiguration(event *filer_pb.SubscribeMetadataResponse) {
  36. if DirectoryEtcSeaweedFS != event.Directory {
  37. if DirectoryEtcSeaweedFS != event.EventNotification.NewParentPath {
  38. return
  39. }
  40. }
  41. entry := event.EventNotification.NewEntry
  42. if entry == nil {
  43. return
  44. }
  45. glog.V(0).Infof("procesing %v", event)
  46. if entry.Name == FilerConfName {
  47. f.reloadFilerConfiguration(entry)
  48. }
  49. }
  50. func (f *Filer) readEntry(chunks []*filer_pb.FileChunk) ([]byte, error) {
  51. var buf bytes.Buffer
  52. err := StreamContent(f.MasterClient, &buf, chunks, 0, math.MaxInt64)
  53. if err != nil {
  54. return nil, err
  55. }
  56. return buf.Bytes(), nil
  57. }
  58. func (f *Filer) reloadFilerConfiguration(entry *filer_pb.Entry) {
  59. fc := NewFilerConf()
  60. err := fc.loadFromChunks(f, entry.Content, entry.Chunks)
  61. if err != nil {
  62. glog.Errorf("read filer conf chunks: %v", err)
  63. return
  64. }
  65. f.FilerConf = fc
  66. }
  67. func (f *Filer) LoadFilerConf() {
  68. fc := NewFilerConf()
  69. err := util.Retry("loadFilerConf", func() error {
  70. return fc.loadFromFiler(f)
  71. })
  72. if err != nil {
  73. glog.Errorf("read filer conf: %v", err)
  74. return
  75. }
  76. f.FilerConf = fc
  77. }
  78. ////////////////////////////////////
  79. // load and maintain remote storages
  80. ////////////////////////////////////
  81. func (f *Filer) LoadRemoteStorageConfAndMapping() {
  82. if err := f.RemoteStorage.LoadRemoteStorageConfigurationsAndMapping(f); err != nil {
  83. glog.Errorf("read remote conf and mapping: %v", err)
  84. return
  85. }
  86. }
  87. func (f *Filer) maybeReloadRemoteStorageConfigurationAndMapping(event *filer_pb.SubscribeMetadataResponse) {
  88. // FIXME add reloading
  89. }