summaryrefslogtreecommitdiff
path: root/same/src/main/java
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-24 11:11:45 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-24 11:11:45 +0100
commit263f3a0b4425287ef234d0dbf039e0027c4ad6c1 (patch)
tree20f06878f41654007d9ae243eda25cd6e3a6e5a7 /same/src/main/java
parent3e50334e2233b7180b9895d106074aad914ca412 (diff)
Paxos: Remove roundId parameter.
Diffstat (limited to 'same/src/main/java')
-rw-r--r--same/src/main/java/com/orbekk/paxos/MasterProposer.java14
-rw-r--r--same/src/main/java/com/orbekk/paxos/PaxosService.java4
-rw-r--r--same/src/main/java/com/orbekk/paxos/PaxosServiceImpl.java51
3 files changed, 24 insertions, 45 deletions
diff --git a/same/src/main/java/com/orbekk/paxos/MasterProposer.java b/same/src/main/java/com/orbekk/paxos/MasterProposer.java
index 3a451d0..912de7e 100644
--- a/same/src/main/java/com/orbekk/paxos/MasterProposer.java
+++ b/same/src/main/java/com/orbekk/paxos/MasterProposer.java
@@ -17,11 +17,11 @@ public class MasterProposer {
this.connections = connections;
}
- private boolean internalPropose(int roundId, int proposalNumber) {
+ private boolean internalPropose(int proposalNumber) {
int promises = 0;
for (String url : paxosUrls) {
PaxosService paxos = connections.getPaxos(url);
- boolean success = paxos.propose(myUrl, roundId, proposalNumber);
+ boolean success = paxos.propose(myUrl, proposalNumber);
if (success) {
promises += 1;
}
@@ -29,11 +29,11 @@ public class MasterProposer {
return promises > paxosUrls.size() / 2;
}
- private boolean internalAcceptRequest(int roundId, int proposalNumber) {
+ private boolean internalAcceptRequest(int proposalNumber) {
int accepts = 0;
for (String url : paxosUrls) {
PaxosService paxos = connections.getPaxos(url);
- boolean success = paxos.acceptRequest(myUrl, roundId, proposalNumber);
+ boolean success = paxos.acceptRequest(myUrl, proposalNumber);
if (success) {
accepts += 1;
}
@@ -41,11 +41,11 @@ public class MasterProposer {
return accepts > paxosUrls.size() / 2;
}
- public boolean propose(int roundId, int proposalNumber) {
+ public boolean propose(int proposalNumber) {
boolean success = false;
- success = internalPropose(roundId, proposalNumber);
+ success = internalPropose(proposalNumber);
if (success) {
- success = internalAcceptRequest(roundId, proposalNumber);
+ success = internalAcceptRequest(proposalNumber);
}
if (success) {
return true;
diff --git a/same/src/main/java/com/orbekk/paxos/PaxosService.java b/same/src/main/java/com/orbekk/paxos/PaxosService.java
index b650ed5..b515fa9 100644
--- a/same/src/main/java/com/orbekk/paxos/PaxosService.java
+++ b/same/src/main/java/com/orbekk/paxos/PaxosService.java
@@ -1,6 +1,6 @@
package com.orbekk.paxos;
public interface PaxosService {
- boolean propose(String clientUrl, int roundId, int proposalNumber);
- boolean acceptRequest(String clientUrl, int roundId, int proposalNumber);
+ boolean propose(String clientUrl, int proposalNumber);
+ boolean acceptRequest(String clientUrl, int proposalNumber);
}
diff --git a/same/src/main/java/com/orbekk/paxos/PaxosServiceImpl.java b/same/src/main/java/com/orbekk/paxos/PaxosServiceImpl.java
index 70e1618..1e8387e 100644
--- a/same/src/main/java/com/orbekk/paxos/PaxosServiceImpl.java
+++ b/same/src/main/java/com/orbekk/paxos/PaxosServiceImpl.java
@@ -8,8 +8,8 @@ import org.slf4j.LoggerFactory;
*/
public class PaxosServiceImpl implements PaxosService {
private Logger logger = LoggerFactory.getLogger(getClass());
- private int roundId = 0;
private int highestPromise = 0;
+ private int highestAcceptedValue = 0;
private String tag = "";
public PaxosServiceImpl(String tag) {
@@ -17,57 +17,36 @@ public class PaxosServiceImpl implements PaxosService {
}
@Override
- public synchronized boolean propose(String clientUrl, int roundId,
+ public synchronized boolean propose(String clientUrl,
int proposalNumber) {
- if (roundId > this.roundId) {
- newRound(roundId);
- }
- if (roundId < this.roundId) {
- logger.info(tag + "propose({}, {}, {}) = rejected " +
- "(current round: {})",
- new Object[]{clientUrl, roundId, proposalNumber,
- this.roundId});
- return false;
- }
-
if (proposalNumber > highestPromise) {
highestPromise = proposalNumber;
- logger.info(tag + "propose({}, {}, {}) = accepted",
- new Object[]{clientUrl, roundId, proposalNumber});
+ logger.info(tag + "propose({}, {}) = accepted",
+ new Object[]{clientUrl, proposalNumber});
return true;
} else {
- logger.info(tag + "propose({}, {}, {}) = rejected " +
+ logger.info(tag + "propose({}, {}) = rejected " +
"(promised: {})",
- new Object[]{clientUrl, roundId, proposalNumber,
+ new Object[]{clientUrl, proposalNumber,
highestPromise});
return false;
}
}
@Override
- public synchronized boolean acceptRequest(String clientUrl, int roundId,
+ public synchronized boolean acceptRequest(String clientUrl,
int proposalNumber) {
- if (roundId == this.roundId && proposalNumber == highestPromise) {
- logger.info(tag + "acceptRequest({}, {}, {}) = accepted",
- new Object[]{clientUrl, roundId, proposalNumber});
- finishRound();
+ if (proposalNumber == highestPromise) {
+ logger.info(tag + "acceptRequest({}, {}) = accepted",
+ new Object[]{clientUrl, proposalNumber});
+ highestAcceptedValue = proposalNumber;
return true;
} else {
- logger.info(tag + "acceptRequest({}, {}, {}) = rejected " +
- "(roundId={}, promise={})",
- new Object[]{clientUrl, roundId, proposalNumber,
- this.roundId, highestPromise});
+ logger.info(tag + "acceptRequest({}, {}) = rejected " +
+ "(promise={})",
+ new Object[]{clientUrl, proposalNumber,
+ highestPromise});
return false;
}
}
-
- private synchronized void finishRound() {
- newRound(roundId + 1);
- }
-
- private synchronized void newRound(int roundId) {
- logger.info(tag + "new round: {}", roundId);
- this.roundId = roundId;
- highestPromise = 0;
- }
}