Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b9517de

Browse files
add token range example in the distributed-db playground
1 parent f6233a1 commit b9517de

File tree

1 file changed

+9
-1
lines changed
  • mutexes/distributed-db/playground/tokens

1 file changed

+9
-1
lines changed

‎mutexes/distributed-db/playground/tokens/main.go‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package main
22

33
import (
4+
"crypto/md5"
5+
"encoding/json"
46
"fmt"
57
"hash/fnv"
68
"math"
@@ -46,11 +48,17 @@ func main() {
4648
}
4749
tokens.AddNode(newNode)
4850

49-
for i := 0; i < 1000; i++ {
51+
for i := 0; i < 50; i++ {
5052
key := fmt.Sprintf("k%d", i+1)
5153
sum := hash(key)
5254
fmt.Println(key, sum, tokens.GetNode(sum).Name)
5355
}
56+
57+
// the message is quite big,
58+
// but it is exchanged only 1 time when a node joins
59+
bs, _ := json.Marshal(tokens.Mappings)
60+
// sending only the checksum can save a lot of space
61+
fmt.Printf("%x", md5.Sum(bs))
5462
}
5563

5664
func NewTokens(nodes []Node, numberOfTokenRanges int) Tokens {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /