@@ -26,19 +26,9 @@ func NewDefaultReplicationStrategy() ReplicationStrategy {
26
26
// - Checks there are enough instances for an operation to succeed.
27
27
// The instances argument may be overwritten.
28
28
func (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
37
29
now := time .Now ()
38
30
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.
42
32
var unhealthy []string
43
33
for i := 0 ; i < len (instances ); {
44
34
if instances [i ].IsHealthy (op , heartbeatTimeout , now ) {
@@ -49,6 +39,14 @@ func (s *defaultReplicationStrategy) Filter(instances []InstanceDesc, op Operati
49
39
}
50
40
}
51
41
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
52
50
// This is just a shortcut - if there are not minSuccess available instances,
53
51
// after filtering out dead ones, don't even bother trying.
54
52
if len (instances ) < minSuccess {
0 commit comments