see_dat.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package main
  2. import (
  3. "flag"
  4. "time"
  5. "github.com/chrislusf/seaweedfs/weed/glog"
  6. "github.com/chrislusf/seaweedfs/weed/storage"
  7. "github.com/chrislusf/seaweedfs/weed/storage/needle"
  8. )
  9. var (
  10. volumePath = flag.String("dir", "/tmp", "data directory to store files")
  11. volumeCollection = flag.String("collection", "", "the volume collection name")
  12. volumeId = flag.Int("volumeId", -1, "a volume id. The volume should already exist in the dir. The volume index file should not exist.")
  13. )
  14. type VolumeFileScanner4SeeDat struct {
  15. version needle.Version
  16. }
  17. func (scanner *VolumeFileScanner4SeeDat) VisitSuperBlock(superBlock storage.SuperBlock) error {
  18. scanner.version = superBlock.Version()
  19. return nil
  20. }
  21. func (scanner *VolumeFileScanner4SeeDat) ReadNeedleBody() bool {
  22. return true
  23. }
  24. func (scanner *VolumeFileScanner4SeeDat) VisitNeedle(n *needle.Needle, offset int64, needleHeader, needleBody []byte) error {
  25. t := time.Unix(int64(n.AppendAtNs)/int64(time.Second), int64(n.AppendAtNs)%int64(time.Second))
  26. glog.V(0).Infof("%d,%s%x offset %d size %d cookie %x appendedAt %v", *volumeId, n.Id, n.Cookie, offset, n.Size, n.Cookie, t)
  27. return nil
  28. }
  29. func main() {
  30. flag.Parse()
  31. vid := needle.VolumeId(*volumeId)
  32. scanner := &VolumeFileScanner4SeeDat{}
  33. err := storage.ScanVolumeFile(*volumePath, *volumeCollection, vid, storage.NeedleMapInMemory, scanner)
  34. if err != nil {
  35. glog.Fatalf("Reading Volume File [ERROR] %s\n", err)
  36. }
  37. }