vedhavyas / hashring Goto Github PK
View Code? Open in Web Editor NEWConsistent-hashing: Hash ring implementation in Go
License: The Unlicense
Consistent-hashing: Hash ring implementation in Go
License: The Unlicense
Locate is acquiring a read lock, but it is calling getHash(hr.hash, []byte(key)):
// Locate returns the node for a given key
func (hr *HashRing) Locate(key string) (node string, err error) {
hr.mu.RLock()
defer hr.mu.RUnlock()
if len(hr.idx) < 1 {
return node, fmt.Errorf("no available nodes")
}
hkey, err := getHash(hr.hash, []byte(key))
if err != nil {
return node, fmt.Errorf("failed to fetch node: %v", err)
}
pos := sort.Search(len(hr.idx), func(i int) bool { return hr.idx[i] >= hkey })
if pos == len(hr.idx) {
return hr.nodes[hr.idx[0]], nil
}
return hr.nodes[hr.idx[pos]], nil
}
in getHash() we see it performing a hash reset:
// getHash returns uint32 hash
func getHash(hash hash.Hash32, key []byte) (uint32, error) {
hash.Reset()
_, err := hash.Write(key)
if err != nil {
return 0, err
}
return hash.Sum32(), nil
}
this appears to trigger the race detector:
Write at 0x00c0005000c8 by goroutine 85:
hash/fnv.(*sum32a).Reset()
/usr/local/go/src/hash/fnv/fnv.go:88 +0x3a
github.com/vedhavyas/hashring.getHash()
/home/jimr/proj/github/src/github.com/highwire/rstore/vendor/github.com/vedhavyas/hashring/hashring.go:54 +0x42
github.com/vedhavyas/hashring.(*HashRing).Locate()
/home/jimr/proj/github/src/github.com/highwire/rstore/vendor/github.com/vedhavyas/hashring/hashring.go:121 +0x17d
github.com/highwire/rstore/peers.(*Peers).Resolve()
/home/jimr/proj/github/src/github.com/highwire/rstore/peers/peers.go:181 +0x20b
github.com/highwire/rstore/peers.BenchmarkPeersResolve.func1.1()
/home/jimr/proj/github/src/github.com/highwire/rstore/peers/peers_test.go:104 +0xcb
testing.(*B).RunParallel.func1()
/usr/local/go/src/testing/benchmark.go:763 +0x182
Previous write at 0x00c0005000c8 by goroutine 82:
hash/fnv.(*sum32a).Reset()
/usr/local/go/src/hash/fnv/fnv.go:88 +0x3a
github.com/vedhavyas/hashring.getHash()
/home/jimr/proj/github/src/github.com/highwire/rstore/vendor/github.com/vedhavyas/hashring/hashring.go:54 +0x42
github.com/vedhavyas/hashring.(*HashRing).Locate()
/home/jimr/proj/github/src/github.com/highwire/rstore/vendor/github.com/vedhavyas/hashring/hashring.go:121 +0x17d
github.com/highwire/rstore/peers.(*Peers).Resolve()
/home/jimr/proj/github/src/github.com/highwire/rstore/peers/peers.go:181 +0x20b
github.com/highwire/rstore/peers.BenchmarkPeersResolve.func1.1()
/home/jimr/proj/github/src/github.com/highwire/rstore/peers/peers_test.go:104 +0xcb
testing.(*B).RunParallel.func1()
/usr/local/go/src/testing/benchmark.go:763 +0x182
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.