Skip to content

Commit

Permalink
fix calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernauer committed Sep 27, 2023
1 parent 3b9ead0 commit 2c343d7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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).

Check notice on line 35 in docs/modules/zookeeper/pages/usage_guide/operations/pod-disruptions.adoc

View workflow job for this annotation

GitHub Actions / LanguageTool

[LanguageTool] docs/modules/zookeeper/pages/usage_guide/operations/pod-disruptions.adoc#L35

Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’. (EN_A_VS_AN) Suggestions: `an` URL: https://languagetool.org/insights/post/indefinite-articles/ Rule: https://community.languagetool.org/rule/show/EN_A_VS_AN?lang=en-US Category: MISC
Raw output
docs/modules/zookeeper/pages/usage_guide/operations/pod-disruptions.adoc:35:39: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’. (EN_A_VS_AN)
 Suggestions: `an`
 URL: https://languagetool.org/insights/post/indefinite-articles/ 
 Rule: https://community.languagetool.org/rule/show/EN_A_VS_AN?lang=en-US
 Category: MISC

[cols="1,1,1"]
|===
|Number of servers
Expand All @@ -37,42 +45,42 @@ This results e.g. in the following numbers:
|1

|2
|1
|2
|1

|3
|2
|1

|4
|2
|3
|1

|5
|3
|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
|===
18 changes: 10 additions & 8 deletions rust/operator-binary/src/operations/pdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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,
Expand Down

0 comments on commit 2c343d7

Please sign in to comment.