Mercurial > hg > Database > Christie
changeset 181:33b4966d4d24
update paxos
line wrap: on
line diff
--- a/src/main/java/christie/test/topology/paxos/acceptor/AcceptCodeGear.java Sat Feb 02 11:40:31 2019 +0900 +++ b/src/main/java/christie/test/topology/paxos/acceptor/AcceptCodeGear.java Sat Feb 02 11:42:48 2019 +0900 @@ -6,6 +6,8 @@ import christie.codegear.CodeGearManager; import christie.test.topology.paxos.Proposal; import christie.topology.TopologyDataGear; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.List; import java.util.regex.Matcher; @@ -21,34 +23,35 @@ Pattern pattern = Pattern.compile("^(proposer|acceptor|learner)([0-9]+)$"); - @Take Proposal promisedProposal; + Logger logger = LogManager.getLogger(AcceptCodeGear.class); + @Override protected void run(CodeGearManager cgm) { List<String> _CLIST = topoDG.getConnectionList(); - if(acceptProposal.getNumber() >= promisedProposal.getNumber()) { acceptProposal.setAccepted(true); acceptProposal.setAcceptorName(topoDG.getNodeName()); + logger.debug("accept " + acceptProposal); + + promisedProposal = acceptProposal; + for (String connectionNodeName : _CLIST){ Matcher matcher = pattern.matcher(connectionNodeName); matcher.find(); if(matcher.group(1).equals("learner")) { - put(connectionNodeName, "acceptedProposal", acceptProposal); + logger.debug("send learner " + promisedProposal); + put(connectionNodeName, "acceptedProposal", promisedProposal); } } - put(acceptProposal.getProposerName(), "acceptedProposal", acceptProposal); - put("promisedProposal", acceptProposal); + } - }else{ - put(acceptProposal.getProposerName(), "acceptedProposal", promisedProposal); - put("promisedProposal", promisedProposal); - - } + put(acceptProposal.getProposerName(), "acceptedProposal", promisedProposal); + put("promisedProposal", promisedProposal); cgm.setup(new AcceptCodeGear());
--- a/src/main/java/christie/test/topology/paxos/acceptor/PromiseCodeGear.java Sat Feb 02 11:40:31 2019 +0900 +++ b/src/main/java/christie/test/topology/paxos/acceptor/PromiseCodeGear.java Sat Feb 02 11:42:48 2019 +0900 @@ -4,6 +4,8 @@ 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 PromiseCodeGear extends CodeGear { @@ -13,12 +15,13 @@ @Take Proposal prepareProposal; + Logger logger = LogManager.getLogger(PromiseCodeGear.class); + public PromiseCodeGear(){ } @Override protected void run(CodeGearManager cgm) { - if(promisedProposal.getNumber() < prepareProposal.getNumber()) { if(promisedProposal.isAccepted()){ promisedProposal.setNumber(prepareProposal.getNumber()); @@ -27,6 +30,7 @@ } } put("promisedProposal", promisedProposal); + logger.debug("promise code gear : promise " + promisedProposal); put(prepareProposal.getProposerName(),"receivePromise", promisedProposal); cgm.setup(new PromiseCodeGear()); }
--- a/src/main/java/christie/test/topology/paxos/learner/AggregateProposalCodeGear.java Sat Feb 02 11:40:31 2019 +0900 +++ b/src/main/java/christie/test/topology/paxos/learner/AggregateProposalCodeGear.java Sat Feb 02 11:42:48 2019 +0900 @@ -27,8 +27,8 @@ count++; if(count > proposal.getAcceptorNum()/2) { System.out.println("finish " + proposal); - //break; - getDGM(topologyNodeConfig.getManagerKey()).put("finish", ""); + break; + //getDGM(topologyNodeConfig.getManagerKey()).put("finish", ""); } proposalValueMap.replace(value, count); }else{
--- a/src/main/java/christie/test/topology/paxos/learner/RecieveAcceptProposalCodeGear.java Sat Feb 02 11:40:31 2019 +0900 +++ b/src/main/java/christie/test/topology/paxos/learner/RecieveAcceptProposalCodeGear.java Sat Feb 02 11:42:48 2019 +0900 @@ -19,6 +19,7 @@ @Override protected void run(CodeGearManager cgm) { + System.out.println("accepted : " + acceptedProposal); acceptedMap.put(acceptedProposal.getAcceptorName(), acceptedProposal); put("acceptedMap", acceptedMap);
--- a/src/main/java/christie/test/topology/paxos/proposer/ProposerCodeGear.java Sat Feb 02 11:40:31 2019 +0900 +++ b/src/main/java/christie/test/topology/paxos/proposer/ProposerCodeGear.java Sat Feb 02 11:42:48 2019 +0900 @@ -6,6 +6,8 @@ import christie.codegear.CodeGearManager; import christie.test.topology.paxos.Proposal; import christie.topology.TopologyDataGear; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.List;
--- a/src/main/java/christie/test/topology/paxos/proposer/ReceivePromiseCodeGear.java Sat Feb 02 11:40:31 2019 +0900 +++ b/src/main/java/christie/test/topology/paxos/proposer/ReceivePromiseCodeGear.java Sat Feb 02 11:42:48 2019 +0900 @@ -19,32 +19,22 @@ @Override protected void run(CodeGearManager cgm) { promiseCount++; - - if(receivePromise.isAccepted()){ - if(sendedProposal.isAccepted()){ - if(receivePromise.getNumber() > sendedProposal.getNumber()){ - put("sendedProposal", receivePromise); - }else{ - put("sendedProposal", sendedProposal); + if(receivePromise.getNumber() > sendedProposal.getNumber()){ + promiseCount = 0; + sendedProposal.incrementNumber(); + put("sendProposal", sendedProposal); + cgm.setup(new SendPrepareRequestCodeGear()); + }else{ + if(receivePromise.isAccepted()){ + if(!sendedProposal.isAccepted()){ + sendedProposal.setValue(receivePromise.getValue()); } - }else{ - sendedProposal.setValue(receivePromise.getValue()); - put("sendedProposal", sendedProposal); - } - }else{ - if(receivePromise.getNumber() > sendedProposal.getNumber()){ - promiseCount = 0; - sendedProposal.incrementNumber(); - put("sendProposal", sendedProposal); - cgm.setup(new SendPrepareRequestCodeGear()); - }else{ - put("sendedProposal", sendedProposal); } } + put("sendedProposal", sendedProposal); put("promiseCount", promiseCount); - if(promiseCount > sendedProposal.getAcceptorNum()/2){ put("acceptProposal", sendedProposal); cgm.setup(new SendAcceptRequestCodeGear());
--- a/src/main/java/christie/test/topology/paxos/proposer/RecieveAcceptedCodeGear.java Sat Feb 02 11:40:31 2019 +0900 +++ b/src/main/java/christie/test/topology/paxos/proposer/RecieveAcceptedCodeGear.java Sat Feb 02 11:42:48 2019 +0900 @@ -4,6 +4,8 @@ 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 RecieveAcceptedCodeGear extends CodeGear { @@ -13,14 +15,18 @@ @Take Proposal sendedProposal; + Logger logger = LogManager.getLogger(RecieveAcceptedCodeGear.class); + @Override protected void run(CodeGearManager cgm) { if(!acceptedProposal.isAccepted()){ sendedProposal.incrementNumber(); put("sendProposal", sendedProposal); + logger.debug("transition send preparerequest"); cgm.setup(new SendPrepareRequestCodeGear()); }else{ - cgm.setup(new RecieveAcceptedCodeGear()); + logger.debug("accepted " + sendedProposal); + return; } } }
--- a/src/main/java/christie/test/topology/paxos/proposer/SendAcceptRequestCodeGear.java Sat Feb 02 11:40:31 2019 +0900 +++ b/src/main/java/christie/test/topology/paxos/proposer/SendAcceptRequestCodeGear.java Sat Feb 02 11:42:48 2019 +0900 @@ -6,8 +6,11 @@ import christie.codegear.CodeGearManager; import christie.test.topology.paxos.Proposal; import christie.topology.TopologyDataGear; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.List; +import java.util.concurrent.TimeUnit; public class SendAcceptRequestCodeGear extends CodeGear { @@ -18,12 +21,16 @@ @Peek TopologyDataGear topoDG; + Logger logger = LogManager.getLogger(SendPrepareRequestCodeGear.class); + @Override protected void run(CodeGearManager cgm) { List<String> _CLIST = topoDG.getConnectionList(); for(String acceptorName: _CLIST) put(acceptorName, "acceptProposal", acceptProposal); + logger.debug("send accept request : " + acceptProposal); + put("sendedProposal", acceptProposal); cgm.setup(new RecieveAcceptedCodeGear()); }
--- a/src/main/java/christie/test/topology/paxos/proposer/SendPrepareRequestCodeGear.java Sat Feb 02 11:40:31 2019 +0900 +++ b/src/main/java/christie/test/topology/paxos/proposer/SendPrepareRequestCodeGear.java Sat Feb 02 11:42:48 2019 +0900 @@ -6,6 +6,8 @@ import christie.codegear.CodeGearManager; import christie.test.topology.paxos.Proposal; import christie.topology.TopologyDataGear; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.List; @@ -17,12 +19,16 @@ @Peek TopologyDataGear topoDG; + Logger logger = LogManager.getLogger(SendPrepareRequestCodeGear.class); + @Override protected void run(CodeGearManager cgm) { List<String> _CLIST = topoDG.getConnectionList(); for(String acceptorName: _CLIST) put(acceptorName, "prepareProposal", sendProposal); + logger.debug("send prepare request : " + sendProposal); + put("sendedProposal", sendProposal); cgm.setup(new ReceivePromiseCodeGear()); }