diff --git a/docs/modules/zookeeper/pages/usage_guide/operations/pod-disruptions.adoc b/docs/modules/zookeeper/pages/usage_guide/operations/pod-disruptions.adoc index 79371875..90e0361d 100644 --- a/docs/modules/zookeeper/pages/usage_guide/operations/pod-disruptions.adoc +++ b/docs/modules/zookeeper/pages/usage_guide/operations/pod-disruptions.adoc @@ -14,6 +14,12 @@ Taking this into consideration, our operator uses the following algorithm to det [source,rust] ---- +fn quorum_size(num_servers: u16) -> u16 { + // Same as max((num_servers / 2) + 1, 1), but without the need for floating point arithmetics, + // which are subject to rounding errors. + max((num_servers + 2) / 2, 1) +} + // Minimum required amount of servers to form quorum. let quorum_size = quorum_size(num_servers); @@ -26,6 +32,8 @@ let max_unavailable = max(max_unavailable, 1) This results e.g. in the following numbers: +TIP: It is strongly recommended to use a odd number of servers (e.g. 3, 5 or 7). + [cols="1,1,1"] |=== |Number of servers @@ -37,7 +45,7 @@ This results e.g. in the following numbers: |1 |2 -|1 +|2 |1 |3 @@ -45,7 +53,7 @@ This results e.g. in the following numbers: |1 |4 -|2 +|3 |1 |5 @@ -53,26 +61,26 @@ This results e.g. in the following numbers: |1 |6 -|3 -|2 +|4 +|1 |7 |4 |2 |8 -|4 -|3 +|5 +|2 |9 |5 |3 |10 -|5 -|4 +|6 +|3 |20 -|10 -|9 +|11 +|8 |=== diff --git a/rust/operator-binary/src/operations/pdb.rs b/rust/operator-binary/src/operations/pdb.rs index 7e5aa947..780d5152 100644 --- a/rust/operator-binary/src/operations/pdb.rs +++ b/rust/operator-binary/src/operations/pdb.rs @@ -69,7 +69,9 @@ fn max_unavailable_servers(num_servers: u16) -> u16 { } fn quorum_size(num_servers: u16) -> u16 { - max((num_servers as f32 / 2.0).ceil() as u16, 1) + // Same as max((num_servers / 2) + 1, 1), but without the need for floating point arithmetics, + // which are subject to rounding errors. + max((num_servers + 2) / 2, 1) } #[cfg(test)] @@ -80,17 +82,17 @@ mod test { #[rstest] #[case(0, 1, 1)] #[case(1, 1, 1)] - #[case(2, 1, 1)] + #[case(2, 2, 1)] #[case(3, 2, 1)] - #[case(4, 2, 1)] + #[case(4, 3, 1)] #[case(5, 3, 1)] - #[case(6, 3, 2)] + #[case(6, 4, 1)] #[case(7, 4, 2)] - #[case(8, 4, 3)] + #[case(8, 5, 2)] #[case(9, 5, 3)] - #[case(10, 5, 4)] - #[case(20, 10, 9)] - #[case(100, 50, 49)] + #[case(10, 6, 3)] + #[case(20, 11, 8)] + #[case(100, 51, 48)] fn test_max_unavailable_servers( #[case] num_servers: u16,