see_dat.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. }