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.

53 lines
1.7 KiB

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