see_idx.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "os"
  6. "path"
  7. "strconv"
  8. "github.com/seaweedfs/seaweedfs/weed/util"
  9. "github.com/seaweedfs/seaweedfs/weed/glog"
  10. "github.com/seaweedfs/seaweedfs/weed/storage/idx"
  11. "github.com/seaweedfs/seaweedfs/weed/storage/types"
  12. )
  13. var (
  14. fixVolumePath = flag.String("dir", "/tmp", "data directory to store files")
  15. fixVolumeCollection = flag.String("collection", "", "the volume collection name")
  16. fixVolumeId = flag.Int("volumeId", -1, "a volume id. The volume should already exist in the dir. The volume index file should not exist.")
  17. )
  18. /*
  19. This is to see content in .idx files.
  20. see_idx -v=4 -volumeId=9 -dir=/Users/chrislu/Downloads
  21. */
  22. func main() {
  23. flag.Parse()
  24. fileName := strconv.Itoa(*fixVolumeId)
  25. if *fixVolumeCollection != "" {
  26. fileName = *fixVolumeCollection + "_" + fileName
  27. }
  28. indexFile, err := os.OpenFile(path.Join(*fixVolumePath, fileName+".idx"), os.O_RDONLY, 0644)
  29. if err != nil {
  30. glog.Fatalf("Create Volume Index [ERROR] %s\n", err)
  31. }
  32. defer indexFile.Close()
  33. idx.WalkIndexFile(indexFile, 0, func(key types.NeedleId, offset types.Offset, size types.Size) error {
  34. fmt.Printf("key:%v offset:%v size:%v(%v)\n", key, offset, size, util.BytesToHumanReadable(uint64(size)))
  35. return nil
  36. })
  37. }