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.

48 lines
1.3 KiB

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