Mercurial > hg > Database > Christie
changeset 164:c6250ad544e0
fix paxos
author | akahori |
---|---|
date | Tue, 22 Jan 2019 14:46:12 +0900 |
parents | c94a4b1b8f36 |
children | e0fb4f8699f8 |
files | src/main/java/christie/test/topology/paxos/StartLocalPaxos.java src/main/java/christie/test/topology/paxos/acceptor/AcceptCodeGear.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/SendAcceptRequestCodeGear.java src/main/java/christie/test/topology/paxos/proposer/SendPrepareRequestCodeGear.java src/main/java/christie/test/topology/paxos/proposer/StartProposer.java |
diffstat | 7 files changed, 103 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/test/topology/paxos/StartLocalPaxos.java Tue Jan 22 14:46:12 2019 +0900 @@ -0,0 +1,84 @@ +package christie.test.topology.paxos; + +import christie.codegear.CodeGearManager; +import christie.codegear.StartCodeGear; +import christie.test.topology.paxos.acceptor.AcceptorCodeGear; +import christie.test.topology.paxos.learner.LearnerCodeGear; +import christie.test.topology.paxos.proposer.ProposerCodeGear; +import christie.topology.TopologyDataGear; + +import java.util.ArrayList; +import java.util.List; + +public class StartLocalPaxos extends StartCodeGear{ + + public StartLocalPaxos(CodeGearManager cgm) { + super(cgm); + + } + + public static void main(String args[]){ + int proposerPort = 10000; + int proposersNum = 2; + int acceptorPort = proposerPort + proposersNum; + int acceptorsNum = 3; + int learnerPort = acceptorPort + acceptorsNum; + int learnersNum = 1; + + List<CodeGearManager> proposers = new ArrayList<>(proposersNum); + List<CodeGearManager> acceptors = new ArrayList<>(acceptorsNum); + List<CodeGearManager> learners = new ArrayList<>(learnersNum); + TopologyDataGear proposerTopoDG = new TopologyDataGear(); + TopologyDataGear acceptorTopoDG = new TopologyDataGear(); + + + for(int i = 0; i < learnersNum; i++){ + String nodeName = "learner" + i; + acceptorTopoDG.addConnection(nodeName); + + CodeGearManager learner = createCGM(learnerPort + i); + learner.setup(new LearnerCodeGear()); + learners.add(learner); + } + + for(int i = 0; i < acceptorsNum; i++){ + String nodeName = "acceptor" + i; + proposerTopoDG.addConnection(nodeName); + + CodeGearManager acceptor = createCGM(acceptorPort + i); + TopologyDataGear topoDG = acceptorTopoDG.clone(); + topoDG.setNodeName(nodeName); + acceptor.getLocalDGM().put("topoDG", topoDG); + acceptor.setup(new AcceptorCodeGear()); + acceptors.add(acceptor); + } + + for(int i = 0; i < proposersNum; i++){ + String nodeName = "proposer" + i; + + CodeGearManager proposer = createCGM(proposerPort + i); + TopologyDataGear topoDG = proposerTopoDG.clone(); + topoDG.setNodeName(nodeName); + topoDG.setTotalNodeNum(proposersNum); + proposer.getLocalDGM().put("topoDG", topoDG); + + proposers.add(proposer); + } + + for(int i = 0; i < proposersNum; i++){ + for(int j = 0; j < acceptorsNum; j++){ + proposers.get(i).createRemoteDGM(proposerTopoDG.getConnectionList().get(j), "localhost", acceptors.get(j).localPort); + acceptors.get(j).createRemoteDGM("proposer" + i, "localhost", proposers.get(i).localPort); + + } + proposers.get(i).setup(new ProposerCodeGear()); + } + + for(int i = 0; i < acceptorsNum; i++){ + for(int j = 0; j < learnersNum; j++){ + acceptors.get(i).createRemoteDGM(acceptorTopoDG.getConnectionList().get(j), "localhost", learners.get(j).localPort); + learners.get(j).createRemoteDGM(proposerTopoDG.getConnectionList().get(j), "localhost", acceptors.get(i).localPort); + } + } + } +} \ No newline at end of file
--- a/src/main/java/christie/test/topology/paxos/acceptor/AcceptCodeGear.java Tue Jan 22 14:45:43 2019 +0900 +++ b/src/main/java/christie/test/topology/paxos/acceptor/AcceptCodeGear.java Tue Jan 22 14:46:12 2019 +0900 @@ -5,16 +5,14 @@ import christie.codegear.CodeGear; import christie.codegear.CodeGearManager; import christie.test.topology.paxos.Proposal; +import christie.topology.TopologyDataGear; import java.util.List; public class AcceptCodeGear extends CodeGear { @Peek - String nodeName; - - @Peek - List<String> _CLIST; + TopologyDataGear topoDG; @Take Proposal acceptProposal; @@ -24,10 +22,11 @@ @Override protected void run(CodeGearManager cgm) { + List<String> _CLIST = topoDG.getConnectionList(); if(acceptProposal.getNumber() >= promisedProposal.getNumber()){ acceptProposal.setAccepted(true); - acceptProposal.setAcceptorName(nodeName); + acceptProposal.setAcceptorName(topoDG.getNodeName()); for(String learnerName : _CLIST) put(learnerName, "acceptedProposal", acceptProposal);
--- a/src/main/java/christie/test/topology/paxos/proposer/ProposerCodeGear.java Tue Jan 22 14:45:43 2019 +0900 +++ b/src/main/java/christie/test/topology/paxos/proposer/ProposerCodeGear.java Tue Jan 22 14:46:12 2019 +0900 @@ -5,26 +5,24 @@ import christie.codegear.CodeGear; import christie.codegear.CodeGearManager; import christie.test.topology.paxos.Proposal; +import christie.topology.TopologyDataGear; import java.util.List; public class ProposerCodeGear extends CodeGear { @Peek - String nodeName; - - @Peek - int nodeNum; - - @Peek - List<String> _CLIST; + TopologyDataGear topoDG; @Override protected void run(CodeGearManager cgm) { + String nodeName = topoDG.getNodeName(); + int proposerNum = topoDG.getTotalNodeNum(); + List<String> _CLIST = topoDG.getConnectionList(); cgm.setup(new SendPrepareRequestCodeGear()); put("promiseCount", 0); - int id = nodeName.charAt(nodeName.length() - 1); - put("sendProposal", new Proposal(nodeName, nodeNum, id, id, _CLIST.size())); + int id = Character.getNumericValue(nodeName.charAt(nodeName.length() - 1)); + put("sendProposal", new Proposal(nodeName, proposerNum, id, id, _CLIST.size())); } }
--- a/src/main/java/christie/test/topology/paxos/proposer/ReceivePromiseCodeGear.java Tue Jan 22 14:45:43 2019 +0900 +++ b/src/main/java/christie/test/topology/paxos/proposer/ReceivePromiseCodeGear.java Tue Jan 22 14:46:12 2019 +0900 @@ -42,8 +42,6 @@ } } - System.out.println("recieve"); - put("promiseCount", promiseCount);
--- a/src/main/java/christie/test/topology/paxos/proposer/SendAcceptRequestCodeGear.java Tue Jan 22 14:45:43 2019 +0900 +++ b/src/main/java/christie/test/topology/paxos/proposer/SendAcceptRequestCodeGear.java Tue Jan 22 14:46:12 2019 +0900 @@ -5,6 +5,7 @@ import christie.codegear.CodeGear; import christie.codegear.CodeGearManager; import christie.test.topology.paxos.Proposal; +import christie.topology.TopologyDataGear; import java.util.List; @@ -15,10 +16,11 @@ Proposal acceptProposal; @Peek - List<String> _CLIST; + TopologyDataGear topoDG; @Override protected void run(CodeGearManager cgm) { + List<String> _CLIST = topoDG.getConnectionList(); for(String acceptorName: _CLIST) put(acceptorName, "acceptProposal", acceptProposal);
--- a/src/main/java/christie/test/topology/paxos/proposer/SendPrepareRequestCodeGear.java Tue Jan 22 14:45:43 2019 +0900 +++ b/src/main/java/christie/test/topology/paxos/proposer/SendPrepareRequestCodeGear.java Tue Jan 22 14:46:12 2019 +0900 @@ -5,6 +5,7 @@ import christie.codegear.CodeGear; import christie.codegear.CodeGearManager; import christie.test.topology.paxos.Proposal; +import christie.topology.TopologyDataGear; import java.util.List; @@ -14,12 +15,11 @@ Proposal sendProposal; @Peek - List<String> _CLIST; - + TopologyDataGear topoDG; @Override protected void run(CodeGearManager cgm) { - + List<String> _CLIST = topoDG.getConnectionList(); for(String acceptorName: _CLIST) put(acceptorName, "prepareProposal", sendProposal);
--- a/src/main/java/christie/test/topology/paxos/proposer/StartProposer.java Tue Jan 22 14:45:43 2019 +0900 +++ b/src/main/java/christie/test/topology/paxos/proposer/StartProposer.java Tue Jan 22 14:46:12 2019 +0900 @@ -7,17 +7,11 @@ import christie.topology.node.StartTopologyNode; import christie.topology.node.TopologyNodeConfig; -public class StartProposer extends StartCodeGear { - - - public StartProposer(CodeGearManager cgm) { - super(cgm); - } +public class StartProposer { public static void main(String[] args){ TopologyNodeConfig topologyNodeConfig = new TopologyNodeConfig(args); - StartTopologyNode proposer = new StartTopologyNode(topologyNodeConfig, new ProposerCodeGear()); - + new StartTopologyNode(topologyNodeConfig, new ProposerCodeGear()); } }