filer_on_meta_event.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. }
  13. func (f *Filer) maybeReloadFilerConfiguration(event *filer_pb.SubscribeMetadataResponse) {
  14. if DirectoryEtcSeaweedFS != event.Directory {
  15. if DirectoryEtcSeaweedFS != event.EventNotification.NewParentPath {
  16. return
  17. }
  18. }
  19. entry := event.EventNotification.NewEntry
  20. if entry == nil {
  21. return
  22. }
  23. glog.V(0).Infof("procesing %v", event)
  24. if entry.Name == FilerConfName {
  25. f.reloadFilerConfiguration(entry)
  26. }
  27. }
  28. func (f *Filer) readEntry(chunks []*filer_pb.FileChunk) ([]byte, error) {
  29. var buf bytes.Buffer
  30. err := StreamContent(f.MasterClient, &buf, chunks, 0, math.MaxInt64)
  31. if err != nil {
  32. return nil, err
  33. }
  34. return buf.Bytes(), nil
  35. }
  36. func (f *Filer) reloadFilerConfiguration(entry *filer_pb.Entry) {
  37. fc := NewFilerConf()
  38. err := fc.loadFromChunks(f, entry.Content, entry.Chunks)
  39. if err != nil {
  40. glog.Errorf("read filer conf chunks: %v", err)
  41. return
  42. }
  43. f.FilerConf = fc
  44. }
  45. func (f *Filer) LoadFilerConf() {
  46. fc := NewFilerConf()
  47. err := util.Retry("loadFilerConf", func() error {
  48. return fc.loadFromFiler(f)
  49. })
  50. if err != nil {
  51. glog.Errorf("read filer conf: %v", err)
  52. return
  53. }
  54. f.FilerConf = fc
  55. }