summaryrefslogtreecommitdiff
path: root/same/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'same/src/main')
-rw-r--r--same/src/main/java/com/orbekk/paxos/MasterProposer.java13
1 files changed, 8 insertions, 5 deletions
diff --git a/same/src/main/java/com/orbekk/paxos/MasterProposer.java b/same/src/main/java/com/orbekk/paxos/MasterProposer.java
index 129f336..7dc5090 100644
--- a/same/src/main/java/com/orbekk/paxos/MasterProposer.java
+++ b/same/src/main/java/com/orbekk/paxos/MasterProposer.java
@@ -82,11 +82,14 @@ public class MasterProposer extends Thread {
}
private void checkDone() {
- if (numPromises.get() > numRequests / 2) {
- result.set(proposalNumber);
- done.countDown();
- } else if (numResponses.get() >= numRequests) {
- result.set(bestPromise.get());
+ if (numPromises.get() > numRequests / 2 ||
+ numResponses.get() >= numRequests) {
+ // Test again to avoid race condition.
+ if (numPromises.get() > numRequests / 2) {
+ result.set(proposalNumber);
+ } else {
+ result.set(bestPromise.get());
+ }
done.countDown();
}
}