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.

48 lines
1.5 KiB

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