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