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.

47 lines
1.4 KiB

6 years ago
6 years ago
6 years ago
6 years ago
  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. }