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.

74 lines
1.3 KiB

  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "io"
  6. "log"
  7. "os"
  8. "github.com/golang/protobuf/proto"
  9. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  10. "github.com/chrislusf/seaweedfs/weed/util"
  11. )
  12. var (
  13. logdataFile = flag.String("logdata", "", "log data file saved under /.meta/log/...")
  14. )
  15. func main() {
  16. flag.Parse()
  17. dst, err := os.OpenFile(*logdataFile, os.O_RDONLY, 0644)
  18. if err != nil {
  19. log.Fatalf("failed to open %s: %v", *logdataFile, err)
  20. }
  21. defer dst.Close()
  22. err = walkLogEntryFile(dst)
  23. if err != nil {
  24. log.Fatalf("failed to visit %s: %v", *logdataFile, err)
  25. }
  26. }
  27. func walkLogEntryFile(dst *os.File) error {
  28. sizeBuf := make([]byte, 4)
  29. for {
  30. if n, err := dst.Read(sizeBuf); n != 4 {
  31. if err == io.EOF {
  32. return nil
  33. }
  34. return err
  35. }
  36. size := util.BytesToUint32(sizeBuf)
  37. data := make([]byte, int(size))
  38. if n, err := dst.Read(data); n != len(data) {
  39. return err
  40. }
  41. logEntry := &filer_pb.LogEntry{}
  42. err := proto.Unmarshal(data, logEntry)
  43. if err != nil {
  44. log.Printf("unexpected unmarshal filer_pb.LogEntry: %v", err)
  45. return nil
  46. }
  47. event := &filer_pb.FullEventNotification{}
  48. err = proto.Unmarshal(logEntry.Data, event)
  49. if err != nil {
  50. log.Printf("unexpected unmarshal filer_pb.FullEventNotification: %v", err)
  51. return nil
  52. }
  53. fmt.Printf("event: %+v\n", event)
  54. }
  55. }