From 8b3e5b998aa87a77ac6571e8648f400a6610effb Mon Sep 17 00:00:00 2001 From: Matt Jaffee Date: Tue, 11 Dec 2018 15:33:58 -0600 Subject: [PATCH] fix data race which appears to be unrelated to previous changes --- cluster.go | 7 +++++++ executor.go | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cluster.go b/cluster.go index af54132e8..ad6cdbe6a 100644 --- a/cluster.go +++ b/cluster.go @@ -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)) diff --git a/executor.go b/executor.go index d8a24f8dd..dca0bd546 100644 --- a/executor.go +++ b/executor.go @@ -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