@@ -26,19 +26,9 @@ func NewDefaultReplicationStrategy() ReplicationStrategy {
2626// - Checks there are enough instances for an operation to succeed.
2727// The instances argument may be overwritten.
2828func (s * defaultReplicationStrategy ) Filter (instances []InstanceDesc , op Operation , replicationFactor int , heartbeatTimeout time.Duration , zoneAwarenessEnabled bool ) ([]InstanceDesc , int , error ) {
29- // We need a response from a quorum of instances, which is n/2 + 1. In the
30- // case of a node joining/leaving, the actual replica set might be bigger
31- // than the replication factor, so use the bigger or the two.
32- if len (instances ) > replicationFactor {
33- replicationFactor = len (instances )
34- }
35-
36- minSuccess := (replicationFactor / 2 ) + 1
3729 now := time .Now ()
3830
39- // Skip those that have not heartbeated in a while. NB these are still
40- // included in the calculation of minSuccess, so if too many failed instances
41- // will cause the whole write to fail.
31+ // Skip those that have not heartbeated in a while.
4232 var unhealthy []string
4333 for i := 0 ; i < len (instances ); {
4434 if instances [i ].IsHealthy (op , heartbeatTimeout , now ) {
@@ -49,6 +39,14 @@ func (s *defaultReplicationStrategy) Filter(instances []InstanceDesc, op Operati
4939 }
5040 }
5141
42+ // We need a response from a quorum of instances, which is n/2 + 1. In the
43+ // case of a node joining/leaving with extend-writes enabled, the actual replica
44+ // set will be bigger than the replication factor, so use the bigger or the two.
45+ if len (instances ) > replicationFactor {
46+ replicationFactor = len (instances )
47+ }
48+
49+ minSuccess := (replicationFactor / 2 ) + 1
5250 // This is just a shortcut - if there are not minSuccess available instances,
5351 // after filtering out dead ones, don't even bother trying.
5452 if len (instances ) < minSuccess {
0 commit comments