see_idx.go 1.1 KB

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