mirror of
https://github.com/minio/minio.git
synced 2025-02-28 13:59:15 -05:00
hash-set: Add file input for debug tool (#14965)
Add input option for a file list to display total distribution.
This commit is contained in:
parent
77dc99e71d
commit
fc08fcab52
@ -18,11 +18,16 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"hash/crc32"
|
"hash/crc32"
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/dchest/siphash"
|
"github.com/dchest/siphash"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
@ -64,22 +69,22 @@ func hashOrder(key string, cardinality int) []int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
object, deploymentID string
|
file, object, deploymentID, prefix string
|
||||||
setCount, shards int
|
setCount, shards int
|
||||||
|
verbose bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
flag.StringVar(&file, "file", "", "Read all objects from file, newline separated")
|
||||||
|
flag.StringVar(&prefix, "prefix", "", "Add prefix to all objects")
|
||||||
flag.StringVar(&object, "object", "", "Select an object")
|
flag.StringVar(&object, "object", "", "Select an object")
|
||||||
flag.StringVar(&deploymentID, "deployment-id", "", "MinIO deployment ID, obtained from 'format.json'")
|
flag.StringVar(&deploymentID, "deployment-id", "", "MinIO deployment ID, obtained from 'format.json'")
|
||||||
flag.IntVar(&setCount, "set-count", 0, "Total set count")
|
flag.IntVar(&setCount, "set-count", 0, "Total set count")
|
||||||
flag.IntVar(&shards, "shards", 0, "Total shards count")
|
flag.IntVar(&shards, "shards", 0, "Total shards count")
|
||||||
|
flag.BoolVar(&verbose, "v", false, "Display all objects")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if object == "" {
|
|
||||||
log.Fatalln("object name is mandatory")
|
|
||||||
}
|
|
||||||
|
|
||||||
if deploymentID == "" {
|
if deploymentID == "" {
|
||||||
log.Fatalln("deployment ID is mandatory")
|
log.Fatalln("deployment ID is mandatory")
|
||||||
}
|
}
|
||||||
@ -88,12 +93,39 @@ func main() {
|
|||||||
log.Fatalln("set count cannot be zero")
|
log.Fatalln("set count cannot be zero")
|
||||||
}
|
}
|
||||||
|
|
||||||
if shards == 0 {
|
|
||||||
log.Fatalln("total shards cannot be zero")
|
|
||||||
}
|
|
||||||
|
|
||||||
id := uuid.MustParse(deploymentID)
|
id := uuid.MustParse(deploymentID)
|
||||||
|
|
||||||
fmt.Println("Erasure distribution for the object", hashOrder(object, shards))
|
if file != "" {
|
||||||
fmt.Println("Erasure setNumber for the object", sipHashMod(object, setCount, id)+1)
|
distrib := make([][]string, setCount)
|
||||||
|
b, err := ioutil.ReadFile(file)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
b = bytes.ReplaceAll(b, []byte("\r"), []byte{})
|
||||||
|
sc := bufio.NewScanner(bytes.NewBuffer(b))
|
||||||
|
for sc.Scan() {
|
||||||
|
object = strings.TrimSpace(sc.Text())
|
||||||
|
set := sipHashMod(prefix+object, setCount, id)
|
||||||
|
distrib[set] = append(distrib[set], prefix+object)
|
||||||
|
}
|
||||||
|
for set, files := range distrib {
|
||||||
|
fmt.Println("Set:", set+1, "Objects:", len(files))
|
||||||
|
if !verbose {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, s := range files {
|
||||||
|
fmt.Printf("\t%s\n", s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
if object == "" {
|
||||||
|
log.Fatalln("object name is mandatory")
|
||||||
|
}
|
||||||
|
|
||||||
|
if shards != 0 {
|
||||||
|
fmt.Println("Erasure distribution for the object", hashOrder(prefix+object, shards))
|
||||||
|
}
|
||||||
|
fmt.Println("Erasure setNumber for the object", sipHashMod(prefix+object, setCount, id)+1)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user