From 18e7a81047ec764252afb5bc5a952866de387969 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Wed, 21 Nov 2018 10:49:30 +0200 Subject: [PATCH] Fix corner cases and a bug --- cluster.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cluster.go b/cluster.go index 55bc5ba..03c186c 100644 --- a/cluster.go +++ b/cluster.go @@ -533,10 +533,12 @@ func (c *clusterState) slotSlaveNode(slot int) (*clusterNode, error) { n := rand.Intn(len(nodes)-1) + 1 slave = nodes[n] if !slave.Loading() { - break + return slave, nil } } - return slave, nil + + // All slaves are loading - use master. + return nodes[0], nil } } @@ -979,9 +981,10 @@ func (c *ClusterClient) defaultProcess(cmd Cmder) error { break } - // If slave is loading - read from master. + // If slave is loading - pick another node. if c.opt.ReadOnly && internal.IsLoadingError(err) { node.MarkAsLoading() + node = nil continue }