func main() {
nodes := []string{"shard-1", "shard-2", "shard-3"}
config := &xring.Config{
VirtualNodes: len(nodes),
LoadFactor: 40,
}
hashRing := xring.NewRing(nodes, config)
keyCount := 100
fmt.Println("with 3 nodes")
distribution := simulateKeyDistribution(hashRing, keyCount)
printDistribution(distribution)
fmt.Println("------------------------------------------------")
fmt.Println("with 4 nodes")
hashRing.Add("shard-4")
distribution = simulateKeyDistribution(hashRing, keyCount)
printDistribution(distribution)
fmt.Println("------------------------------------------------")
fmt.Println("with 5 nodes")
hashRing.Add("shard-5")
distribution = simulateKeyDistribution(hashRing, keyCount)
printDistribution(distribution)
fmt.Println("------------------------------------------------")
fmt.Println("with 4 nodes")
hashRing.Remove("shard-4")
distribution = simulateKeyDistribution(hashRing, keyCount)
printDistribution(distribution)
}
------------------------------------------------
with 4 nodes
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x104afbbd8]
goroutine 1 [running]:
github.com/arriqaaq/rbt.(*Tree).delete(0x140000a13e0?, 0x140000aa4e0?)
/Users/akram/go/pkg/mod/github.com/arriqaaq/[email protected]/rbt.go:265 +0x1e8
github.com/arriqaaq/rbt.(*Tree).Delete(0x104afe391?, 0x140000a13e0?)
/Users/akram/go/pkg/mod/github.com/arriqaaq/[email protected]/rbt.go:242 +0x2c
github.com/argoproj/xring.(*Ring).Remove(0x140000b8000, {0x104afe5d0, 0x7})
/Users/akram/go/src/github.com/arriqaaq/xring/xring.go:144 +0x244
main.main()
/Users/akram/go/src/github.com/arriqaaq/xring/examples/relocation.go:82 +0x2a0
exit status 2