see_idx.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "github.com/chrislusf/seaweedfs/weed/util"
  6. "os"
  7. "path"
  8. "strconv"
  9. "github.com/chrislusf/seaweedfs/weed/util/log"
  10. "github.com/chrislusf/seaweedfs/weed/storage/idx"
  11. "github.com/chrislusf/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. log.Fatalf("Create Volume Index [ERROR] %s\n", err)
  31. }
  32. defer indexFile.Close()
  33. idx.WalkIndexFile(indexFile, 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. }