"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "dso-l2/src/main/java/com/tc/l2/state/ElectionManagerImpl.java" between
terracotta-core-5.7.0.tar.gz and terracotta-core-5.7.1.tar.gz

About: Terracotta - Clustering technology for Java ("Network Attached Memory", "Distributed Cache"). Source code of the server (5.x) core components.

ElectionManagerImpl.java  (terracotta-core-5.7.0):ElectionManagerImpl.java  (terracotta-core-5.7.1)
skipping to change at line 35 skipping to change at line 35
import com.tc.async.api.EventHandler; import com.tc.async.api.EventHandler;
import com.tc.async.api.EventHandlerException; import com.tc.async.api.EventHandlerException;
import com.tc.l2.ha.WeightGeneratorFactory; import com.tc.l2.ha.WeightGeneratorFactory;
import com.tc.l2.msg.L2StateMessage; import com.tc.l2.msg.L2StateMessage;
import com.tc.net.NodeID; import com.tc.net.NodeID;
import com.tc.net.ServerID; import com.tc.net.ServerID;
import com.tc.net.groups.GroupEventsListener; import com.tc.net.groups.GroupEventsListener;
import com.tc.net.groups.GroupException; import com.tc.net.groups.GroupException;
import com.tc.net.groups.GroupManager; import com.tc.net.groups.GroupManager;
import com.tc.net.groups.GroupResponse; import com.tc.net.groups.GroupResponse;
import com.tc.objectserver.impl.Topology;
import com.tc.util.Assert; import com.tc.util.Assert;
import com.tc.util.State; import com.tc.util.State;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
skipping to change at line 65 skipping to change at line 64
private final GroupManager<L2StateMessage> groupManager; private final GroupManager<L2StateMessage> groupManager;
private final Map<NodeID, Enrollment> votes = new HashMap<>(); private final Map<NodeID, Enrollment> votes = new HashMap<>();
private State state = INIT; private State state = INIT;
// XXX::NOTE:: These variables are not reset until next election // XXX::NOTE:: These variables are not reset until next election
private Enrollment myVote = null; private Enrollment myVote = null;
private State serverState; private State serverState;
private Enrollment winner; private Enrollment winner;
private NodeID active = ServerID.NULL_ID; private NodeID active = ServerID.NULL_ID;
private Set<NodeID> passiveStandbys; private Set<ServerID> passiveStandbys;
private final long electionTime; private final long electionTime;
private int expectedServers; private int expectedServers;
public ElectionManagerImpl(GroupManager groupManager, int electionTimeInSec) { public ElectionManagerImpl(GroupManager groupManager, int electionTimeInSec) {
this.groupManager = groupManager; this.groupManager = groupManager;
this.electionTime = electionTimeInSec * 1000; this.electionTime = electionTimeInSec * 1000;
this.groupManager.registerForGroupEvents(new GroupEventsListener() { this.groupManager.registerForGroupEvents(new GroupEventsListener() {
@Override @Override
public void nodeJoined(NodeID nodeID) { public void nodeJoined(NodeID nodeID) {
skipping to change at line 96 skipping to change at line 95
public EventHandler<ElectionContext> getEventHandler() { public EventHandler<ElectionContext> getEventHandler() {
return new AbstractEventHandler<ElectionContext> () { return new AbstractEventHandler<ElectionContext> () {
@Override @Override
public void handleEvent(ElectionContext context) throws EventHandlerExcept ion { public void handleEvent(ElectionContext context) throws EventHandlerExcept ion {
context.setWinner(runElection(context.getNode(), context.getServers(), context.isNew(), context.getFactory(), context.setWinner(runElection(context.getNode(), context.getServers(), context.isNew(), context.getFactory(),
context.getCurrentState())); context.getCurrentState()));
} }
}; };
} }
public Set<NodeID> passiveStandbys() { public Set<ServerID> passiveStandbys() {
return passiveStandbys; return passiveStandbys;
} }
@Override @Override
public synchronized boolean handleStartElectionRequest(L2StateMessage msg, Sta te currentState) { public synchronized boolean handleStartElectionRequest(L2StateMessage msg, Sta te currentState) {
Assert.assertEquals(L2StateMessage.START_ELECTION, msg.getType()); Assert.assertEquals(L2StateMessage.START_ELECTION, msg.getType());
if (state == ELECTION_IN_PROGRESS) { if (state == ELECTION_IN_PROGRESS) {
Enrollment vote = msg.getEnrollment(); Enrollment vote = msg.getEnrollment();
Enrollment old = votes.put(vote.getNodeID(), vote); Enrollment old = votes.put(vote.getNodeID(), vote);
if (votes.size() == expectedServers) { if (votes.size() == expectedServers) {
skipping to change at line 280 skipping to change at line 279
Enrollment lWinner = computeResult(); Enrollment lWinner = computeResult();
if (lWinner != e) { if (lWinner != e) {
logger.info("Election lost : Winner is : " + lWinner); logger.info("Election lost : Winner is : " + lWinner);
Assert.assertNotNull(lWinner); Assert.assertNotNull(lWinner);
return active; return active;
} }
// Step 4 : local host won the election, so notify world for acceptance // Step 4 : local host won the election, so notify world for acceptance
msg = L2StateMessage.createElectionResultMessage(e, currentState); msg = L2StateMessage.createElectionResultMessage(e, currentState);
debugInfo("Won election, announcing to world and waiting for response..."); debugInfo("Won election, announcing to world and waiting for response...");
GroupResponse<L2StateMessage> responses = groupManager.sendToAndWaitForRespo nse(servers, msg); GroupResponse<L2StateMessage> responses = groupManager.sendToAndWaitForRespo nse(servers, msg);
Set<NodeID> passives = new HashSet<>(); Set<ServerID> passives = new HashSet<>();
for (L2StateMessage response : responses.getResponses()) { for (L2StateMessage response : responses.getResponses()) {
Assert.assertEquals(msg.getMessageID(), response.inResponseTo()); Assert.assertEquals(msg.getMessageID(), response.inResponseTo());
if (response.getType() == L2StateMessage.RESULT_AGREED) { if (response.getType() == L2StateMessage.RESULT_AGREED) {
Assert.assertEquals(e, response.getEnrollment()); Assert.assertEquals(e, response.getEnrollment());
if (StateManager.convert(response.getState()) == ServerMode.PASSIVE) { if (StateManager.convert(response.getState()) == ServerMode.PASSIVE) {
passives.add(response.messageFrom()); passives.add(response.messageFrom());
} }
} else if (response.getType() == L2StateMessage.RESULT_CONFLICT) { } else if (response.getType() == L2StateMessage.RESULT_CONFLICT) {
logger.info("Result Conflict: Local Result : " + e + " From : " + respon se.messageFrom() + " Result : " logger.info("Result Conflict: Local Result : " + e + " From : " + respon se.messageFrom() + " Result : "
+ response.getEnrollment()); + response.getEnrollment());
 End of changes. 4 change blocks. 
4 lines changed or deleted 3 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)