Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Combined node and status in a composite map in AbstractFailureDetector

  • Loading branch information...
commit d2fae73cb9ee1e69d611d2ec6ae6b870f529e76e 1 parent 78ee7c1
Chinmay Soman authored
View
59 src/java/voldemort/cluster/failuredetector/AbstractFailureDetector.java
@@ -43,10 +43,9 @@
// simply a wrapper around a ConcurrentHashMap anyway :(
protected final ConcurrentHashMap<FailureDetectorListener, Object> listeners;
- protected final Map<Node, NodeStatus> nodeStatusMap;
-
- // Also maintain the list of nodes by IDs (in order to handle host swaps)
- protected final Map<Integer, Node> nodeMap;
+ // Maintain the list of nodes and their status by IDs (in order to handle
+ // host swaps)
+ protected final Map<Integer, CompositeNodeStatus> idNodeStatusMap;
protected final Logger logger = Logger.getLogger(getClass().getName());
@@ -56,13 +55,13 @@ protected AbstractFailureDetector(FailureDetectorConfig failureDetectorConfig) {
this.failureDetectorConfig = failureDetectorConfig;
listeners = new ConcurrentHashMap<FailureDetectorListener, Object>();
- nodeStatusMap = new ConcurrentHashMap<Node, NodeStatus>();
- nodeMap = new ConcurrentHashMap<Integer, Node>();
+ idNodeStatusMap = new ConcurrentHashMap<Integer, CompositeNodeStatus>();
for(Node node: failureDetectorConfig.getNodes()) {
- nodeStatusMap.put(node, createNodeStatus(failureDetectorConfig.getTime()
- .getMilliseconds()));
- nodeMap.put(node.getId(), node);
+ idNodeStatusMap.put(node.getId(),
+ new CompositeNodeStatus(node,
+ createNodeStatus(failureDetectorConfig.getTime()
+ .getMilliseconds())));
}
}
@@ -216,29 +215,28 @@ protected void setUnavailable(Node node, UnreachableStoreException e) {
}
protected NodeStatus getNodeStatus(Node node) {
- NodeStatus nodeStatus = nodeStatusMap.get(node);
- Node currentTrackedNode = nodeMap.get(node.getId());
+ NodeStatus nodeStatus = null;
+ CompositeNodeStatus currentNodeStatus = idNodeStatusMap.get(node.getId());
- if(nodeStatus == null || !currentTrackedNode.isEqualState(node)) {
+ if(currentNodeStatus == null || !currentNodeStatus.getNode().isEqualState(node)) {
if(logger.isEnabledFor(Level.WARN))
logger.warn("creating new node status for node " + node.getId()
+ " for failure detector");
// If the host is being replaced, remove old tracking information
- if(nodeStatus != null) {
- nodeStatusMap.remove(currentTrackedNode);
- nodeMap.remove(currentTrackedNode);
- failureDetectorConfig.removeNode(currentTrackedNode);
+ if(currentNodeStatus != null) {
+ idNodeStatusMap.remove(currentNodeStatus);
+ failureDetectorConfig.removeNode(currentNodeStatus.getNode());
}
nodeStatus = createNodeStatus(failureDetectorConfig.getTime().getMilliseconds());
- nodeStatusMap.put(node, nodeStatus);
- nodeMap.put(node.getId(), node);
+ idNodeStatusMap.put(node.getId(), new CompositeNodeStatus(node, nodeStatus));
if(!failureDetectorConfig.getNodes().contains(node)) {
failureDetectorConfig.addNode(node);
}
- }
+ } else
+ nodeStatus = currentNodeStatus.getStatus();
return nodeStatus;
}
@@ -276,4 +274,27 @@ private boolean setAvailable(NodeStatus nodeStatus, boolean isAvailable) {
}
}
+ private class CompositeNodeStatus {
+
+ private Node node;
+ private NodeStatus status;
+
+ CompositeNodeStatus(Node node, NodeStatus status) {
+ this.node = node;
+ this.status = status;
+ }
+
+ public void setValues(Node node, NodeStatus status) {
+ this.node = node;
+ this.status = status;
+ }
+
+ public Node getNode() {
+ return this.node;
+ }
+
+ public NodeStatus getStatus() {
+ return this.status;
+ }
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.