Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Combined node and status in a composite map in AbstractFailureDetector

  • Loading branch information...
commit d2fae73cb9ee1e69d611d2ec6ae6b870f529e76e 1 parent 78ee7c1
Chinmay Soman authored
59 src/java/voldemort/cluster/failuredetector/AbstractFailureDetector.java
@@ -43,10 +43,9 @@
43 43 // simply a wrapper around a ConcurrentHashMap anyway :(
44 44 protected final ConcurrentHashMap<FailureDetectorListener, Object> listeners;
45 45
46   - protected final Map<Node, NodeStatus> nodeStatusMap;
47   -
48   - // Also maintain the list of nodes by IDs (in order to handle host swaps)
49   - protected final Map<Integer, Node> nodeMap;
  46 + // Maintain the list of nodes and their status by IDs (in order to handle
  47 + // host swaps)
  48 + protected final Map<Integer, CompositeNodeStatus> idNodeStatusMap;
50 49
51 50 protected final Logger logger = Logger.getLogger(getClass().getName());
52 51
@@ -56,13 +55,13 @@ protected AbstractFailureDetector(FailureDetectorConfig failureDetectorConfig) {
56 55
57 56 this.failureDetectorConfig = failureDetectorConfig;
58 57 listeners = new ConcurrentHashMap<FailureDetectorListener, Object>();
59   - nodeStatusMap = new ConcurrentHashMap<Node, NodeStatus>();
60   - nodeMap = new ConcurrentHashMap<Integer, Node>();
  58 + idNodeStatusMap = new ConcurrentHashMap<Integer, CompositeNodeStatus>();
61 59
62 60 for(Node node: failureDetectorConfig.getNodes()) {
63   - nodeStatusMap.put(node, createNodeStatus(failureDetectorConfig.getTime()
64   - .getMilliseconds()));
65   - nodeMap.put(node.getId(), node);
  61 + idNodeStatusMap.put(node.getId(),
  62 + new CompositeNodeStatus(node,
  63 + createNodeStatus(failureDetectorConfig.getTime()
  64 + .getMilliseconds())));
66 65 }
67 66 }
68 67
@@ -216,29 +215,28 @@ protected void setUnavailable(Node node, UnreachableStoreException e) {
216 215 }
217 216
218 217 protected NodeStatus getNodeStatus(Node node) {
219   - NodeStatus nodeStatus = nodeStatusMap.get(node);
220   - Node currentTrackedNode = nodeMap.get(node.getId());
  218 + NodeStatus nodeStatus = null;
  219 + CompositeNodeStatus currentNodeStatus = idNodeStatusMap.get(node.getId());
221 220
222   - if(nodeStatus == null || !currentTrackedNode.isEqualState(node)) {
  221 + if(currentNodeStatus == null || !currentNodeStatus.getNode().isEqualState(node)) {
223 222 if(logger.isEnabledFor(Level.WARN))
224 223 logger.warn("creating new node status for node " + node.getId()
225 224 + " for failure detector");
226 225
227 226 // If the host is being replaced, remove old tracking information
228   - if(nodeStatus != null) {
229   - nodeStatusMap.remove(currentTrackedNode);
230   - nodeMap.remove(currentTrackedNode);
231   - failureDetectorConfig.removeNode(currentTrackedNode);
  227 + if(currentNodeStatus != null) {
  228 + idNodeStatusMap.remove(currentNodeStatus);
  229 + failureDetectorConfig.removeNode(currentNodeStatus.getNode());
232 230 }
233 231
234 232 nodeStatus = createNodeStatus(failureDetectorConfig.getTime().getMilliseconds());
235   - nodeStatusMap.put(node, nodeStatus);
236   - nodeMap.put(node.getId(), node);
  233 + idNodeStatusMap.put(node.getId(), new CompositeNodeStatus(node, nodeStatus));
237 234
238 235 if(!failureDetectorConfig.getNodes().contains(node)) {
239 236 failureDetectorConfig.addNode(node);
240 237 }
241   - }
  238 + } else
  239 + nodeStatus = currentNodeStatus.getStatus();
242 240
243 241 return nodeStatus;
244 242 }
@@ -276,4 +274,27 @@ private boolean setAvailable(NodeStatus nodeStatus, boolean isAvailable) {
276 274 }
277 275 }
278 276
  277 + private class CompositeNodeStatus {
  278 +
  279 + private Node node;
  280 + private NodeStatus status;
  281 +
  282 + CompositeNodeStatus(Node node, NodeStatus status) {
  283 + this.node = node;
  284 + this.status = status;
  285 + }
  286 +
  287 + public void setValues(Node node, NodeStatus status) {
  288 + this.node = node;
  289 + this.status = status;
  290 + }
  291 +
  292 + public Node getNode() {
  293 + return this.node;
  294 + }
  295 +
  296 + public NodeStatus getStatus() {
  297 + return this.status;
  298 + }
  299 + }
279 300 }

0 comments on commit d2fae73

Please sign in to comment.
Something went wrong with that request. Please try again.