meta_replay.go 969 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package filer
  2. import (
  3. "context"
  4. "github.com/chrislusf/seaweedfs/weed/glog"
  5. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  6. "github.com/chrislusf/seaweedfs/weed/util"
  7. )
  8. func Replay(filerStore FilerStore, resp *filer_pb.SubscribeMetadataResponse) error {
  9. message := resp.EventNotification
  10. var oldPath util.FullPath
  11. var newEntry *Entry
  12. if message.OldEntry != nil {
  13. oldPath = util.NewFullPath(resp.Directory, message.OldEntry.Name)
  14. glog.V(4).Infof("deleting %v", oldPath)
  15. if err := filerStore.DeleteEntry(context.Background(), oldPath); err != nil {
  16. return err
  17. }
  18. }
  19. if message.NewEntry != nil {
  20. dir := resp.Directory
  21. if message.NewParentPath != "" {
  22. dir = message.NewParentPath
  23. }
  24. key := util.NewFullPath(dir, message.NewEntry.Name)
  25. glog.V(4).Infof("creating %v", key)
  26. newEntry = FromPbEntry(dir, message.NewEntry)
  27. if err := filerStore.InsertEntry(context.Background(), newEntry); err != nil {
  28. return err
  29. }
  30. }
  31. return nil
  32. }