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.

37 lines
969 B

  1. package filer
  2. import (
  3. "context"
  4. "github.com/seaweedfs/seaweedfs/weed/glog"
  5. "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
  6. "github.com/seaweedfs/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. }