seaweedfs/unmaintained/see_idx/see_idx.go

49 lines
1.3 KiB
Go
Raw Normal View History

2015-03-28 07:29:13 +08:00
package main
import (
"flag"
2018-11-04 13:32:04 +08:00
"fmt"
2015-03-28 07:29:13 +08:00
"os"
"path"
"strconv"
"github.com/seaweedfs/seaweedfs/weed/util"
"github.com/seaweedfs/seaweedfs/weed/glog"
"github.com/seaweedfs/seaweedfs/weed/storage/idx"
"github.com/seaweedfs/seaweedfs/weed/storage/types"
util_http "github.com/seaweedfs/seaweedfs/weed/util/http"
2015-03-28 07:29:13 +08:00
)
var (
fixVolumePath = flag.String("dir", "/tmp", "data directory to store files")
fixVolumeCollection = flag.String("collection", "", "the volume collection name")
fixVolumeId = flag.Int("volumeId", -1, "a volume id. The volume should already exist in the dir. The volume index file should not exist.")
)
/*
This is to see content in .idx files.
see_idx -v=4 -volumeId=9 -dir=/Users/chrislu/Downloads
*/
func main() {
flag.Parse()
util_http.InitGlobalHttpClient()
2015-03-28 07:29:13 +08:00
fileName := strconv.Itoa(*fixVolumeId)
if *fixVolumeCollection != "" {
fileName = *fixVolumeCollection + "_" + fileName
}
indexFile, err := os.OpenFile(path.Join(*fixVolumePath, fileName+".idx"), os.O_RDONLY, 0644)
if err != nil {
glog.Fatalf("Create Volume Index [ERROR] %s\n", err)
}
defer indexFile.Close()
idx.WalkIndexFile(indexFile, 0, func(key types.NeedleId, offset types.Offset, size types.Size) error {
2020-05-29 10:00:07 +08:00
fmt.Printf("key:%v offset:%v size:%v(%v)\n", key, offset, size, util.BytesToHumanReadable(uint64(size)))
2018-07-10 13:48:30 +08:00
return nil
})
2015-03-28 07:29:13 +08:00
}