History

hash-set: Add file input for debug tool (#14965)

Add input option for a file list to display total distribution.

Klaus Post committed 4 years ago

Commit fc08fca1 parent 77dc99e1 file · +43 −11Browse files

Showing the changes to docs/debugging (1 of 1 file). Show all

Unified · Split

docs/debugging/hash-set/main.go+43−11
@@ -18,11 +18,16 @@ · 17 unmodified lines
1818 package main
1919
2020 import (
21+ "bufio"
22+ "bytes"
2123 "encoding/binary"
2224 "flag"
2325 "fmt"
2426 "hash/crc32"
27+ "io/ioutil"
2528 "log"
29+ "os"
30+ "strings"
2631
2732 "github.com/dchest/siphash"
2833 "github.com/google/uuid"
@@ -64,22 +69,22 @@ func hashOrder(key string, cardinality int) []int { · 35 unmodified lines
6469 }
6570
6671 var (
67− object, deploymentID string
68− setCount, shards int
72+ file, object, deploymentID, prefix string
73+ setCount, shards int
74+ verbose bool
6975 )
7076
7177 func main() {
78+ flag.StringVar(&file, "file", "", "Read all objects from file, newline separated")
79+ flag.StringVar(&prefix, "prefix", "", "Add prefix to all objects")
7280 flag.StringVar(&object, "object", "", "Select an object")
7381 flag.StringVar(&deploymentID, "deployment-id", "", "MinIO deployment ID, obtained from 'format.json'")
7482 flag.IntVar(&setCount, "set-count", 0, "Total set count")
7583 flag.IntVar(&shards, "shards", 0, "Total shards count")
84+ flag.BoolVar(&verbose, "v", false, "Display all objects")
7685
7786 flag.Parse()
7887
79− if object == "" {
80− log.Fatalln("object name is mandatory")
81− }
82−
8388 if deploymentID == "" {
8489 log.Fatalln("deployment ID is mandatory")
8590 }
@@ -88,12 +93,39 @@ func main() { · 2 unmodified lines
8893 log.Fatalln("set count cannot be zero")
8994 }
9095
91− if shards == 0 {
92− log.Fatalln("total shards cannot be zero")
96+ id := uuid.MustParse(deploymentID)
97+
98+ if file != "" {
99+ distrib := make([][]string, setCount)
100+ b, err := ioutil.ReadFile(file)
101+ if err != nil {
102+ log.Fatalln(err)
103+ }
104+ b = bytes.ReplaceAll(b, []byte("\r"), []byte{})
105+ sc := bufio.NewScanner(bytes.NewBuffer(b))
106+ for sc.Scan() {
107+ object = strings.TrimSpace(sc.Text())
108+ set := sipHashMod(prefix+object, setCount, id)
109+ distrib[set] = append(distrib[set], prefix+object)
110+ }
111+ for set, files := range distrib {
112+ fmt.Println("Set:", set+1, "Objects:", len(files))
113+ if !verbose {
114+ continue
115+ }
116+ for _, s := range files {
117+ fmt.Printf("\t%s\n", s)
118+ }
119+ }
120+ os.Exit(0)
93121 }
94122
95− id := uuid.MustParse(deploymentID)
123+ if object == "" {
124+ log.Fatalln("object name is mandatory")
125+ }
96126
97− fmt.Println("Erasure distribution for the object", hashOrder(object, shards))
98− fmt.Println("Erasure setNumber for the object", sipHashMod(object, setCount, id)+1)
127+ if shards != 0 {
128+ fmt.Println("Erasure distribution for the object", hashOrder(prefix+object, shards))
129+ }
130+ fmt.Println("Erasure setNumber for the object", sipHashMod(prefix+object, setCount, id)+1)
99131 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t