diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/RoundRobinDistributionSchedule.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/RoundRobinDistributionSchedule.java index 220779bbed8..149af201d13 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/RoundRobinDistributionSchedule.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/RoundRobinDistributionSchedule.java @@ -358,23 +358,16 @@ public synchronized void addBookie(int bookieIndexHeardFrom, int rc) { public synchronized boolean checkCovered() { // now check if there are any write quorums, with |ackQuorum| nodes available for (int i = 0; i < ensembleSize; i++) { - int nodesNotCovered = 0; int nodesOkay = 0; - int nodesUninitialized = 0; for (int j = 0; j < writeQuorumSize; j++) { int nodeIndex = (i + j) % ensembleSize; - if (covered[nodeIndex] == BKException.Code.OK) { + if ((covered[nodeIndex] == BKException.Code.OK) + || (covered[nodeIndex] == BKException.Code.NoSuchEntryException) + || (covered[nodeIndex] == BKException.Code.NoSuchLedgerExistsException)) { nodesOkay++; - } else if (covered[nodeIndex] != BKException.Code.NoSuchEntryException - && covered[nodeIndex] != BKException.Code.NoSuchLedgerExistsException) { - nodesNotCovered++; - } else if (covered[nodeIndex] == BKException.Code.UNINITIALIZED) { - nodesUninitialized++; } } - // if we haven't seen any OK responses and there are still nodes not heard from, - // let's wait until - if (nodesNotCovered >= ackQuorumSize || (nodesOkay == 0 && nodesUninitialized > 0)) { + if (nodesOkay < ackQuorumSize) { return false; } } diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/RoundRobinDistributionScheduleTest.java b/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/RoundRobinDistributionScheduleTest.java index b78f1adf090..b5489c2ed66 100644 --- a/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/RoundRobinDistributionScheduleTest.java +++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/RoundRobinDistributionScheduleTest.java @@ -31,6 +31,8 @@ import java.util.HashSet; import java.util.Set; +import org.apache.bookkeeper.client.DistributionSchedule.QuorumCoverageSet; +import org.junit.Assert; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -161,4 +163,28 @@ public void testMoveAndShift() { w.moveAndShift(4, 4); assertEquals(w, writeSetFromValues(1, 2, 3, 4, 5)); } + + @Test + public void testRRQuorumCoverageSet() throws Exception { + int ensembleSize = 9; + int writeQuorumSize = 7; + int ackQuorumSize = 5; + RoundRobinDistributionSchedule schedule = new RoundRobinDistributionSchedule(writeQuorumSize, ackQuorumSize, + ensembleSize); + QuorumCoverageSet rrQuorumCoverageSet = schedule.getCoverageSet(); + rrQuorumCoverageSet.addBookie(0, BKException.Code.DigestMatchException); + rrQuorumCoverageSet.addBookie(1, BKException.Code.OK); + rrQuorumCoverageSet.addBookie(2, BKException.Code.DigestMatchException); + rrQuorumCoverageSet.addBookie(3, BKException.Code.OK); + rrQuorumCoverageSet.addBookie(4, BKException.Code.DigestMatchException); + rrQuorumCoverageSet.addBookie(5, BKException.Code.OK); + rrQuorumCoverageSet.addBookie(6, BKException.Code.DigestMatchException); + rrQuorumCoverageSet.addBookie(7, BKException.Code.OK); + rrQuorumCoverageSet.addBookie(8, BKException.Code.DigestMatchException); + /* + * since not in any write quorum, there is |ackQuorum| number of OKs, + * so checkcovered should be false + */ + Assert.assertFalse("RRQuorumCoverageSet covered should be false", rrQuorumCoverageSet.checkCovered()); + } }