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.

75 lines
1.4 KiB

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