123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- package main
- import (
- "flag"
- "fmt"
- "io"
- "log"
- "os"
- "github.com/golang/protobuf/proto"
- "github.com/chrislusf/seaweedfs/weed/filer2"
- "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
- "github.com/chrislusf/seaweedfs/weed/util"
- )
- var (
- logdataFile = flag.String("logdata", "", "log data file saved under "+ filer2.SystemLogDir)
- )
- func main() {
- flag.Parse()
- dst, err := os.OpenFile(*logdataFile, os.O_RDONLY, 0644)
- if err != nil {
- log.Fatalf("failed to open %s: %v", *logdataFile, err)
- }
- defer dst.Close()
- err = walkLogEntryFile(dst)
- if err != nil {
- log.Fatalf("failed to visit %s: %v", *logdataFile, err)
- }
- }
- func walkLogEntryFile(dst *os.File) error {
- sizeBuf := make([]byte, 4)
- for {
- if n, err := dst.Read(sizeBuf); n != 4 {
- if err == io.EOF {
- return nil
- }
- return err
- }
- size := util.BytesToUint32(sizeBuf)
- data := make([]byte, int(size))
- if n, err := dst.Read(data); n != len(data) {
- return err
- }
- logEntry := &filer_pb.LogEntry{}
- err := proto.Unmarshal(data, logEntry)
- if err != nil {
- log.Printf("unexpected unmarshal filer_pb.LogEntry: %v", err)
- return nil
- }
- event := &filer_pb.SubscribeMetadataResponse{}
- err = proto.Unmarshal(logEntry.Data, event)
- if err != nil {
- log.Printf("unexpected unmarshal filer_pb.SubscribeMetadataResponse: %v", err)
- return nil
- }
- fmt.Printf("event: %+v\n", event)
- }
- }
|