From 08b8a9b4e9194e22ca31c209778c57bd5e129c5d Mon Sep 17 00:00:00 2001 From: Sam-Kramer Date: Mon, 30 Jan 2023 11:23:37 +0000 Subject: [PATCH] create test case which shows quorum calculation is wrong (#6427) Quorum is now correctly calculated when validating cluster topology. --- .../keyvalue/cassandra/CassandraTopologyValidator.java | 2 +- .../keyvalue/cassandra/CassandraTopologyValidatorTest.java | 6 +++++- changelog/@unreleased/pr-6427.v2.yml | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 changelog/@unreleased/pr-6427.v2.yml diff --git a/atlasdb-cassandra/src/main/java/com/palantir/atlasdb/keyvalue/cassandra/CassandraTopologyValidator.java b/atlasdb-cassandra/src/main/java/com/palantir/atlasdb/keyvalue/cassandra/CassandraTopologyValidator.java index 0cfd6f2ecf2..031ce04c30a 100644 --- a/atlasdb-cassandra/src/main/java/com/palantir/atlasdb/keyvalue/cassandra/CassandraTopologyValidator.java +++ b/atlasdb-cassandra/src/main/java/com/palantir/atlasdb/keyvalue/cassandra/CassandraTopologyValidator.java @@ -264,7 +264,7 @@ private ClusterTopologyResult maybeGetConsistentClusterTopology( // Only consider hosts that have the endpoint for quorum calculations. // Otherwise, we will never add hosts when we're in a mixed state - int quorum = (hostIdsByServerWithoutSoftFailures.size() + 1) / 2; + int quorum = (hostIdsByServerWithoutSoftFailures.size() / 2) + 1; // If too many hosts are unreachable, then we cannot come to a consensus if (hostIdsWithoutFailures.size() < quorum) { diff --git a/atlasdb-cassandra/src/test/java/com/palantir/atlasdb/keyvalue/cassandra/CassandraTopologyValidatorTest.java b/atlasdb-cassandra/src/test/java/com/palantir/atlasdb/keyvalue/cassandra/CassandraTopologyValidatorTest.java index 2592e111f4c..83bf94eb438 100644 --- a/atlasdb-cassandra/src/test/java/com/palantir/atlasdb/keyvalue/cassandra/CassandraTopologyValidatorTest.java +++ b/atlasdb-cassandra/src/test/java/com/palantir/atlasdb/keyvalue/cassandra/CassandraTopologyValidatorTest.java @@ -280,7 +280,11 @@ public void validateNewlyAddedHostsNewHostsNotAddedIfTheyDisagreeWithOldHostsOnP @Test public void validateNewlyAddedHostsNoNewHostsAddedIfNewHostsDoNotHaveQuorumAndNoCurrentServers() { - Map allHosts = setupHosts(NEW_HOSTS); + Set hosts = ImmutableSet.builder() + .addAll(NEW_HOSTS) + .add(OLD_HOST_ONE) + .build(); + Map allHosts = setupHosts(hosts); Set hostsOffline = ImmutableSet.of(NEW_HOST_ONE, NEW_HOST_TWO); setHostIds(filterContainers(allHosts, hostsOffline::contains), HostIdResult.hardFailure()); setHostIds(filterContainers(allHosts, server -> !hostsOffline.contains(server)), HostIdResult.success(UUIDS)); diff --git a/changelog/@unreleased/pr-6427.v2.yml b/changelog/@unreleased/pr-6427.v2.yml new file mode 100644 index 00000000000..0fe5d43f82b --- /dev/null +++ b/changelog/@unreleased/pr-6427.v2.yml @@ -0,0 +1,5 @@ +type: fix +fix: + description: 'Fixes bug where quorum calculation was incorrect for topology validation. ' + links: + - https://github.com/palantir/atlasdb/pull/6427