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.

81 lines
2.0 KiB

6 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. package filer2
  2. import (
  3. "fmt"
  4. "strings"
  5. "time"
  6. "github.com/golang/protobuf/proto"
  7. "github.com/chrislusf/seaweedfs/weed/glog"
  8. "github.com/chrislusf/seaweedfs/weed/notification"
  9. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  10. "github.com/chrislusf/seaweedfs/weed/util"
  11. )
  12. func (f *Filer) NotifyUpdateEvent(oldEntry, newEntry *Entry, deleteChunks bool) {
  13. var fullpath string
  14. if oldEntry != nil {
  15. fullpath = string(oldEntry.FullPath)
  16. } else if newEntry != nil {
  17. fullpath = string(newEntry.FullPath)
  18. } else {
  19. return
  20. }
  21. // println("fullpath:", fullpath)
  22. if strings.HasPrefix(fullpath, SystemLogDir) {
  23. return
  24. }
  25. newParentPath := ""
  26. if newEntry != nil {
  27. newParentPath, _ = newEntry.FullPath.DirAndName()
  28. }
  29. eventNotification := &filer_pb.EventNotification{
  30. OldEntry: oldEntry.ToProtoEntry(),
  31. NewEntry: newEntry.ToProtoEntry(),
  32. DeleteChunks: deleteChunks,
  33. NewParentPath: newParentPath,
  34. }
  35. if notification.Queue != nil {
  36. glog.V(3).Infof("notifying entry update %v", fullpath)
  37. notification.Queue.SendMessage(fullpath, eventNotification)
  38. }
  39. f.logMetaEvent(fullpath, eventNotification)
  40. }
  41. func (f *Filer) logMetaEvent(fullpath string, eventNotification *filer_pb.EventNotification) {
  42. dir, _ := util.FullPath(fullpath).DirAndName()
  43. event := &filer_pb.SubscribeMetadataResponse{
  44. Directory: dir,
  45. EventNotification: eventNotification,
  46. TsNs: time.Now().UnixNano(),
  47. }
  48. data, err := proto.Marshal(event)
  49. if err != nil {
  50. glog.Errorf("failed to marshal filer_pb.SubscribeMetadataResponse %+v: %v", event, err)
  51. return
  52. }
  53. f.MetaLogBuffer.AddToBuffer([]byte(dir), data)
  54. }
  55. func (f *Filer) logFlushFunc(startTime, stopTime time.Time, buf []byte) {
  56. targetFile := fmt.Sprintf("%s/%04d-%02d-%02d/%02d-%02d.segment", SystemLogDir,
  57. startTime.Year(), startTime.Month(), startTime.Day(), startTime.Hour(), startTime.Minute(),
  58. // startTime.Second(), startTime.Nanosecond(),
  59. )
  60. if err := f.appendToFile(targetFile, buf); err != nil {
  61. glog.V(0).Infof("log write failed %s: %v", targetFile, err)
  62. }
  63. }