see_dat.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package main
  2. import (
  3. "flag"
  4. "time"
  5. "github.com/seaweedfs/seaweedfs/weed/util"
  6. "github.com/seaweedfs/seaweedfs/weed/glog"
  7. "github.com/seaweedfs/seaweedfs/weed/storage"
  8. "github.com/seaweedfs/seaweedfs/weed/storage/needle"
  9. "github.com/seaweedfs/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%08x offset %d size %d(%s) cookie %08x 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. }