From 263f3a0b4425287ef234d0dbf039e0027c4ad6c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjetil=20=C3=98rbekk?= Date: Tue, 24 Jan 2012 11:11:45 +0100 Subject: Paxos: Remove roundId parameter. --- .../java/com/orbekk/paxos/PaxosServiceImpl.java | 51 +++++++--------------- 1 file changed, 15 insertions(+), 36 deletions(-) (limited to 'same/src/main/java/com/orbekk/paxos/PaxosServiceImpl.java') 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; - } } -- cgit v1.2.3