@Test public void testRaftNode() throws Exception{ Thread.sleep(10000); cluster.printNodesState(); for(int i =0; i< 100; i++) { for(RaftNode n :nodes) n.testHearBeat(); } cluster.printNodesState(); Thread.sleep(10000); cluster.printNodesState(); }
public RaftNode(Configuration conf) { this.conf = conf; memberManager = new ClusterMemberManager(conf); raftService = RaftRpcService.create(this, conf); raftLog= new DefaultRaftLog(this, conf); currentTerm.set(raftLog.getLogTerm(raftLog.getCommitIndex())); fsm = new StateMachine(stateChangeListener); rpcServer = new RpcServer(conf, raftService, getServerInfo()); nodeConnectionManager = new NodeConnectionManager(conf, this); rpcServer.startRpcServer(); timer = RaftNodeTimer.create(getName()+ "-timeout-worker", getElectionTimeout(), timeoutListener); LOG.info(String.format("%s initialized", getName())); }
RaftNode { public RaftNode(Configuration conf) { this.conf = conf; memberManager = new ClusterMemberManager(conf); raftService = RaftRpcService.create(this, conf); raftLog= new DefaultRaftLog(this, conf); currentTerm.set(raftLog.getLogTerm(raftLog.getCommitIndex())); fsm = new StateMachine(stateChangeListener); rpcServer = new RpcServer(conf, raftService, getServerInfo()); nodeConnectionManager = new NodeConnectionManager(conf, this); rpcServer.startRpcServer(); timer = RaftNodeTimer.create(getName()+ "-timeout-worker", getElectionTimeout(), timeoutListener); LOG.info(String.format("%s initialized", getName())); } }
RaftNode { public RaftNode(Configuration conf) { this.conf = conf; memberManager = new ClusterMemberManager(conf); raftService = RaftRpcService.create(this, conf); raftLog= new DefaultRaftLog(this, conf); currentTerm.set(raftLog.getLogTerm(raftLog.getCommitIndex())); fsm = new StateMachine(stateChangeListener); rpcServer = new RpcServer(conf, raftService, getServerInfo()); nodeConnectionManager = new NodeConnectionManager(conf, this); rpcServer.startRpcServer(); timer = RaftNodeTimer.create(getName()+ "-timeout-worker", getElectionTimeout(), timeoutListener); LOG.info(String.format("%s initialized", getName())); } RaftNode(Configuration conf); }
RaftNode { public RaftNode(Configuration conf) { this.conf = conf; memberManager = new ClusterMemberManager(conf); raftService = RaftRpcService.create(this, conf); raftLog= new DefaultRaftLog(this, conf); currentTerm.set(raftLog.getLogTerm(raftLog.getCommitIndex())); fsm = new StateMachine(stateChangeListener); rpcServer = new RpcServer(conf, raftService, getServerInfo()); nodeConnectionManager = new NodeConnectionManager(conf, this); rpcServer.startRpcServer(); timer = RaftNodeTimer.create(getName()+ "-timeout-worker", getElectionTimeout(), timeoutListener); LOG.info(String.format("%s initialized", getName())); } RaftNode(Configuration conf); long getCurrentTerm(); ServerInfo getServerInfo(); Set<ServerInfo> getRemoteServers(); ServerInfo getCurrentLeader(); RaftLog getRaftLog(); RaftRpcService getRaftService(); NodeConnectionManager getNodeConnectionManager(); String getName(); int getTotalServerNumbers(); void resetTimer(); boolean isLeader(); State getState(); void kill(); void increaseTerm(); void checkRpcTerm(ServerInfo leader, long term); synchronized void discoverHigherTerm(ServerInfo remoteServer, long newTerm); synchronized void discoverLeader(ServerInfo leader, long term); void voteReceived(ServerInfo server, long term); synchronized boolean voteRequest(ServerInfo candidate, long term, long lastLogIndex, long lastLogTerm); void testHearBeat(); static void main(String[] args); }
RaftNode { public RaftNode(Configuration conf) { this.conf = conf; memberManager = new ClusterMemberManager(conf); raftService = RaftRpcService.create(this, conf); raftLog= new DefaultRaftLog(this, conf); currentTerm.set(raftLog.getLogTerm(raftLog.getCommitIndex())); fsm = new StateMachine(stateChangeListener); rpcServer = new RpcServer(conf, raftService, getServerInfo()); nodeConnectionManager = new NodeConnectionManager(conf, this); rpcServer.startRpcServer(); timer = RaftNodeTimer.create(getName()+ "-timeout-worker", getElectionTimeout(), timeoutListener); LOG.info(String.format("%s initialized", getName())); } RaftNode(Configuration conf); long getCurrentTerm(); ServerInfo getServerInfo(); Set<ServerInfo> getRemoteServers(); ServerInfo getCurrentLeader(); RaftLog getRaftLog(); RaftRpcService getRaftService(); NodeConnectionManager getNodeConnectionManager(); String getName(); int getTotalServerNumbers(); void resetTimer(); boolean isLeader(); State getState(); void kill(); void increaseTerm(); void checkRpcTerm(ServerInfo leader, long term); synchronized void discoverHigherTerm(ServerInfo remoteServer, long newTerm); synchronized void discoverLeader(ServerInfo leader, long term); void voteReceived(ServerInfo server, long term); synchronized boolean voteRequest(ServerInfo candidate, long term, long lastLogIndex, long lastLogTerm); void testHearBeat(); static void main(String[] args);  }