Giter VIP home page Giter VIP logo

hashring's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

hashring's Issues

Does Locate() need a Lock instead of an RLock?

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.