ARTEMIS-742 = replication quorum broken

https://issues.apache.org/jira/browse/ARTEMIS-742
This commit is contained in:
Andy Taylor 2016-09-06 11:49:23 +01:00
parent 501d127b35
commit 680f84b5a2
2 changed files with 25 additions and 24 deletions

View File

@ -31,35 +31,35 @@ public class QuorumVoteServerConnect extends QuorumVote<BooleanVote, Boolean> {
private static final SimpleString LIVE_FAILOVER_VOTE = new SimpleString("LIVE_FAILOVER)VOTE"); private static final SimpleString LIVE_FAILOVER_VOTE = new SimpleString("LIVE_FAILOVER)VOTE");
private final CountDownLatch latch; private final CountDownLatch latch;
private double votesNeeded; private int votesNeeded;
private int total = 0; private int total = 0;
private boolean decision = false; private boolean decision = false;
/** /**
* vote the remaining nodes not including ourself., so * live nodes | remaining nodes | majority | votes needed
* 1 remaining nodes would be 0/2 = 0 vote needed * 1 | 0 | 0 | 0
* 2 remaining nodes would be 1/2 = 0 vote needed * 2 | 1 | 1 | 1
* 3 remaining nodes would be 2/2 = 1 vote needed * n | r = n-1 | n/2 + 1 | n/2 + 1 rounded
* 4 remaining nodes would be 3/2 = 2 vote needed * 3 | 2 | 2.5 | 2
* 5 remaining nodes would be 4/2 = 3 vote needed * 4 | 3 | 3 | 3
* 6 remaining nodes would be 5/2 = 3 vote needed * 5 | 4 | 3.5 | 3
* 6 | 5 | 4 | 4
*/ */
public QuorumVoteServerConnect(int size, StorageManager storageManager) { public QuorumVoteServerConnect(int size, StorageManager storageManager) {
super(LIVE_FAILOVER_VOTE); super(LIVE_FAILOVER_VOTE);
//we don't count ourself double majority;
int actualSize = size - 1; if (size <= 2) {
if (actualSize <= 2) { majority = ((double)size) / 2;
votesNeeded = actualSize / 2;
} }
else { else {
//even //even
votesNeeded = actualSize / 2 + 1; majority = ((double)size) / 2 + 1;
} }
//votes needed could be say 2.5 so we add 1 in this case //votes needed could be say 2.5 so we add 1 in this case
int latchSize = votesNeeded > (int) votesNeeded ? (int) votesNeeded + 1 : (int) votesNeeded; votesNeeded = (int) majority;
latch = new CountDownLatch(latchSize); latch = new CountDownLatch(votesNeeded);
if (votesNeeded == 0) { if (votesNeeded == 0) {
decision = true; decision = true;
} }
@ -86,13 +86,14 @@ public class QuorumVoteServerConnect extends QuorumVote<BooleanVote, Boolean> {
} }
/** /**
* vote the remaining nodes not including ourself., so * live nodes | remaining nodes | majority | votes needed
* 1 remaining nodes would be 0/2 = 0 vote needed * 1 | 0 | 0 | 0
* 2 remaining nodes would be 1/2 = 0 vote needed * 2 | 1 | 1 | 1
* 3 remaining nodes would be 2/2 = 1 vote needed * n | r = n-1 | n/2 + 1 | n/2 + 1 rounded
* 4 remaining nodes would be 3/2 = 2 vote needed * 3 | 2 | 2.5 | 2
* 5 remaining nodes would be 4/2 = 3 vote needed * 4 | 3 | 3 | 3
* 6 remaining nodes would be 5/2 = 3 vote needed * 5 | 4 | 3.5 | 3
* 6 | 5 | 4 | 4
* *
* @param vote the vote to make. * @param vote the vote to make.
*/ */
@ -102,9 +103,9 @@ public class QuorumVoteServerConnect extends QuorumVote<BooleanVote, Boolean> {
return; return;
if (vote.getVote()) { if (vote.getVote()) {
total++; total++;
latch.countDown();
if (total >= votesNeeded) { if (total >= votesNeeded) {
decision = true; decision = true;
latch.countDown();
} }
} }
} }

View File

@ -252,7 +252,7 @@ public class SharedNothingBackupQuorum implements Quorum, SessionFailureListener
*/ */
private boolean isLiveDown() { private boolean isLiveDown() {
// we use 1 less than the max cluste size as we arent bothered about the replicated live node // we use 1 less than the max cluste size as we arent bothered about the replicated live node
int size = quorumManager.getMaxClusterSize() - 1; int size = quorumManager.getMaxClusterSize();
QuorumVoteServerConnect quorumVote = new QuorumVoteServerConnect(size, storageManager); QuorumVoteServerConnect quorumVote = new QuorumVoteServerConnect(size, storageManager);