see_dat.go 1.6 KB

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