diff options
author | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-04-30 16:34:09 +0200 |
---|---|---|
committer | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-04-30 16:34:09 +0200 |
commit | 0dd079fe8d74efa57f7b346dd356b6f68cc2f1d0 (patch) | |
tree | 875b445052d6cb7fa51cd7e023781aa961a038a2 /same/src/main/java/com/orbekk/paxos | |
parent | e14b207dfb82b9f7aa491c1fe1fd9c91ddae49b2 (diff) |
Fix threading bug.
Diffstat (limited to 'same/src/main/java/com/orbekk/paxos')
-rw-r--r-- | same/src/main/java/com/orbekk/paxos/MasterProposer.java | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/same/src/main/java/com/orbekk/paxos/MasterProposer.java b/same/src/main/java/com/orbekk/paxos/MasterProposer.java index 3343988..58356a7 100644 --- a/same/src/main/java/com/orbekk/paxos/MasterProposer.java +++ b/same/src/main/java/com/orbekk/paxos/MasterProposer.java @@ -34,7 +34,7 @@ public class MasterProposer extends Thread { this.rpcf = rpcf; } - private static class ResponseHandler implements RpcCallback<PaxosResponse> { + private class ResponseHandler implements RpcCallback<PaxosResponse> { final int proposalNumber; final int numRequests; final AtomicInteger bestPromise = new AtomicInteger(); @@ -50,7 +50,6 @@ public class MasterProposer extends Thread { } @Override public void run(PaxosResponse response) { - numResponses.incrementAndGet(); if (response != null) { int result = response.getResult(); if (result == proposalNumber) { @@ -63,18 +62,17 @@ public class MasterProposer extends Thread { updated = bestPromise.compareAndSet(oldVal, update); } } + numResponses.incrementAndGet(); checkDone(); } private void checkDone() { - if (done.getCount() > 0) { - if (numPromises.get() > numRequests / 2) { - result.set(proposalNumber); - done.countDown(); - } else if (numResponses.get() >= numRequests) { - result.set(bestPromise.get()); - done.countDown(); - } + if (numPromises.get() > numRequests / 2) { + result.set(proposalNumber); + done.countDown(); + } else if (numResponses.get() >= numRequests) { + result.set(bestPromise.get()); + done.countDown(); } } |