fix data race which appears to be unrelated to previous changes

This commit is contained in:
Matt Jaffee 2018-12-11 15:33:58 -06:00
parent 7304258967
commit 8b3e5b998a
No known key found for this signature in database
GPG key ID: 08A3DFFF987B11BF
2 changed files with 8 additions and 1 deletions

View file

@ -836,6 +836,13 @@ func (c *cluster) partition(index string, shard uint64) int {
return int(h.Sum64() % uint64(c.partitionN))
}
// ShardNodes returns a list of nodes that own a fragment. Safe for concurrent use.
func (c *cluster) ShardNodes(index string, shard uint64) []*Node {
c.mu.RLock()
defer c.mu.RUnlock()
return c.shardNodes(index, shard)
}
// shardNodes returns a list of nodes that own a fragment. unprotected
func (c *cluster) shardNodes(index string, shard uint64) []*Node {
return c.partitionNodes(c.partition(index, shard))

View file

@ -2138,7 +2138,7 @@ func (e *executor) shardsByNode(nodes []*Node, index string, shards []uint64) (m
loop:
for _, shard := range shards {
for _, node := range e.Cluster.shardNodes(index, shard) {
for _, node := range e.Cluster.ShardNodes(index, shard) {
if Nodes(nodes).Contains(node) {
m[node] = append(m[node], shard)
continue loop