Mercurial > hg > Database > Christie
changeset 189:9b0a7f8dde81
refactor proposer
author | akahori |
---|---|
date | Tue, 12 Feb 2019 11:12:48 +0900 |
parents | 3d2a964d2355 |
children | 2d0d41b648fa |
files | src/main/java/christie/test/topology/paxos/Proposal.java src/main/java/christie/test/topology/paxos/proposer/ProposerCodeGear.java src/main/java/christie/test/topology/paxos/proposer/ReceivePromiseCodeGear.java src/main/java/christie/test/topology/paxos/proposer/RecieveAcceptedCodeGear.java src/main/java/christie/test/topology/paxos/proposer/SendAcceptRequestCodeGear.java src/main/java/christie/test/topology/paxos/proposer/SendPrepareRequestCodeGear.java |
diffstat | 6 files changed, 63 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/christie/test/topology/paxos/Proposal.java Sat Feb 09 14:06:17 2019 +0900 +++ b/src/main/java/christie/test/topology/paxos/Proposal.java Tue Feb 12 11:12:48 2019 +0900 @@ -24,9 +24,6 @@ this.value = value; this.id = id; this.acceptorNum = acceptorNum; - - incrementNumber(); - } public void setValue(int value){
--- a/src/main/java/christie/test/topology/paxos/proposer/ProposerCodeGear.java Sat Feb 09 14:06:17 2019 +0900 +++ b/src/main/java/christie/test/topology/paxos/proposer/ProposerCodeGear.java Tue Feb 12 11:12:48 2019 +0900 @@ -21,10 +21,9 @@ String nodeName = topoDG.getNodeName(); int proposerNum = topoDG.getTotalNodeNum(); List<String> _CLIST = topoDG.getConnectionList(); - cgm.setup(new SendPrepareRequestCodeGear()); - put("promiseCount", 0); - int id = Character.getNumericValue(nodeName.charAt(nodeName.length() - 1)); - put("sendProposal", new Proposal(nodeName, proposerNum, id, id, _CLIST.size())); + + int id = Character.getNumericValue(nodeName.charAt(nodeName.length() - 1)) + 1; + cgm.setup(new SendPrepareRequestCodeGear(new Proposal(nodeName, proposerNum, id, id, _CLIST.size()))); } }
--- a/src/main/java/christie/test/topology/paxos/proposer/ReceivePromiseCodeGear.java Sat Feb 09 14:06:17 2019 +0900 +++ b/src/main/java/christie/test/topology/paxos/proposer/ReceivePromiseCodeGear.java Tue Feb 12 11:12:48 2019 +0900 @@ -4,26 +4,42 @@ import christie.codegear.CodeGear; import christie.codegear.CodeGearManager; import christie.test.topology.paxos.Proposal; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class ReceivePromiseCodeGear extends CodeGear{ - @Take + //@Take Proposal sendedProposal; @Take Proposal receivePromise; - @Take + //@Take int promiseCount; + Logger logger = LogManager.getLogger(RecieveAcceptedCodeGear.class); + + + public ReceivePromiseCodeGear(Proposal sendedProposal){ + this(0, sendedProposal); + } + + public ReceivePromiseCodeGear(int promiseCount, Proposal sendedProposal){ + this.promiseCount = promiseCount; + this.sendedProposal = sendedProposal; + } + @Override protected void run(CodeGearManager cgm) { promiseCount++; + if(receivePromise.getNumber() > sendedProposal.getNumber()){ - promiseCount = 0; - sendedProposal.incrementNumber(); - put("sendProposal", sendedProposal); - cgm.setup(new SendPrepareRequestCodeGear()); + //logger.debug("increment : ", sendedProposal); + //put("sendProposal", sendedProposal); + + cgm.setup(new SendPrepareRequestCodeGear(sendedProposal)); + return; }else{ if(receivePromise.isAccepted()){ if(!sendedProposal.isAccepted()){ @@ -32,14 +48,14 @@ } } - put("sendedProposal", sendedProposal); - put("promiseCount", promiseCount); + //put("sendedProposal", sendedProposal); + //put("promiseCount", promiseCount); if(promiseCount > sendedProposal.getAcceptorNum()/2){ - put("acceptProposal", sendedProposal); - cgm.setup(new SendAcceptRequestCodeGear()); + //put("acceptProposal", sendedProposal); + cgm.setup(new SendAcceptRequestCodeGear(sendedProposal)); }else { - cgm.setup(new ReceivePromiseCodeGear()); + cgm.setup(new ReceivePromiseCodeGear(promiseCount, sendedProposal)); } } }
--- a/src/main/java/christie/test/topology/paxos/proposer/RecieveAcceptedCodeGear.java Sat Feb 09 14:06:17 2019 +0900 +++ b/src/main/java/christie/test/topology/paxos/proposer/RecieveAcceptedCodeGear.java Tue Feb 12 11:12:48 2019 +0900 @@ -12,21 +12,24 @@ @Take Proposal acceptedProposal; - @Take + //@Take Proposal sendedProposal; Logger logger = LogManager.getLogger(RecieveAcceptedCodeGear.class); + public RecieveAcceptedCodeGear(Proposal sendedProposal){ + this.sendedProposal = sendedProposal; + } + @Override protected void run(CodeGearManager cgm) { if(!acceptedProposal.isAccepted()){ - sendedProposal.incrementNumber(); - put("sendProposal", sendedProposal); - logger.debug("transition send preparerequest"); - cgm.setup(new SendPrepareRequestCodeGear()); + //put("sendProposal", sendedProposal); + //logger.debug("transition send preparerequest"); + cgm.setup(new SendPrepareRequestCodeGear(sendedProposal)); }else{ - logger.debug("accepted " + sendedProposal); - return; + //logger.debug("accepted " + sendedProposal); + cgm.setup(new RecieveAcceptedCodeGear(sendedProposal)); } } }
--- a/src/main/java/christie/test/topology/paxos/proposer/SendAcceptRequestCodeGear.java Sat Feb 09 14:06:17 2019 +0900 +++ b/src/main/java/christie/test/topology/paxos/proposer/SendAcceptRequestCodeGear.java Tue Feb 12 11:12:48 2019 +0900 @@ -15,7 +15,7 @@ public class SendAcceptRequestCodeGear extends CodeGear { - @Take + //@Take Proposal acceptProposal; @Peek @@ -23,22 +23,27 @@ Logger logger = LogManager.getLogger(SendPrepareRequestCodeGear.class); + public SendAcceptRequestCodeGear(Proposal acceptProposal){ + this.acceptProposal = acceptProposal; + } + @Override protected void run(CodeGearManager cgm) { List<String> _CLIST = topoDG.getConnectionList(); - /* - try { - Thread.currentThread().sleep(1000); + + /*try { + Thread.sleep(10000); } catch (InterruptedException e) { e.printStackTrace(); }*/ - for(String acceptorName: _CLIST) + + for(String acceptorName: _CLIST) { put(acceptorName, "acceptProposal", acceptProposal); - + } logger.debug("send accept request : " + acceptProposal); - put("sendedProposal", acceptProposal); - cgm.setup(new RecieveAcceptedCodeGear()); + //put("sendedProposal", acceptProposal); + cgm.setup(new RecieveAcceptedCodeGear(acceptProposal)); } }
--- a/src/main/java/christie/test/topology/paxos/proposer/SendPrepareRequestCodeGear.java Sat Feb 09 14:06:17 2019 +0900 +++ b/src/main/java/christie/test/topology/paxos/proposer/SendPrepareRequestCodeGear.java Tue Feb 12 11:12:48 2019 +0900 @@ -13,7 +13,7 @@ public class SendPrepareRequestCodeGear extends CodeGear{ - @Take + //@Take Proposal sendProposal; @Peek @@ -21,15 +21,20 @@ Logger logger = LogManager.getLogger(SendPrepareRequestCodeGear.class); + public SendPrepareRequestCodeGear(Proposal sendProposal){ + this.sendProposal = sendProposal; + } + @Override protected void run(CodeGearManager cgm) { List<String> _CLIST = topoDG.getConnectionList(); - for(String acceptorName: _CLIST) + sendProposal.incrementNumber(); + + for(String acceptorName: _CLIST) { put(acceptorName, "prepareProposal", sendProposal); - + } logger.debug("send prepare request : " + sendProposal); - put("sendedProposal", sendProposal); - cgm.setup(new ReceivePromiseCodeGear()); + cgm.setup(new ReceivePromiseCodeGear(sendProposal)); } }