voldemort.cluster.failuredetector
Class NoopFailureDetector

java.lang.Object
  extended by voldemort.cluster.failuredetector.NoopFailureDetector
All Implemented Interfaces:
FailureDetector

public class NoopFailureDetector
extends java.lang.Object
implements FailureDetector

NoopFailureDetector is used for testing classes which don't actually need a working FailureDetector ;)


Constructor Summary
NoopFailureDetector()
           
 
Method Summary
 void addFailureDetectorListener(FailureDetectorListener failureDetectorListener)
          Adds a FailureDetectorListener instance that can receive event callbacks about node availability state changes.
 void destroy()
          Cleans up any open resources in preparation for shutdown.
 int getAvailableNodeCount()
          Returns the number of nodes that are considered to be available at the time of calling.
 FailureDetectorConfig getConfig()
          Retrieves the FailureDetectorConfig instance with which this FailureDetector was constructed.
 long getLastChecked(Node node)
          Returns the number of milliseconds since the node was last checked for availability.
 int getNodeCount()
          Returns the number of nodes that are in the set of all nodes at the time of calling.
 boolean isAvailable(Node node)
          Determines if the node is available or offline.
 void recordException(Node node, long requestTime, UnreachableStoreException e)
          Allows external callers to provide input to the FailureDetector that an error occurred when trying to access the node.
 void recordSuccess(Node node, long requestTime)
          Allows external callers to provide input to the FailureDetector that an access to the node succeeded.
 void removeFailureDetectorListener(FailureDetectorListener failureDetectorListener)
          Removes a FailureDetectorListener instance from the event listener list.
 void waitForAvailability(Node node)
          waitForAvailability causes the calling thread to block until the given Node is available.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NoopFailureDetector

public NoopFailureDetector()
Method Detail

getLastChecked

public long getLastChecked(Node node)
Description copied from interface: FailureDetector
Returns the number of milliseconds since the node was last checked for availability. Because of its lack of precision, this should really only be used for status/reporting.

Specified by:
getLastChecked in interface FailureDetector
Parameters:
node - Node to check
Returns:
Number of milliseconds since the node was last checked for availability

isAvailable

public boolean isAvailable(Node node)
Description copied from interface: FailureDetector
Determines if the node is available or offline. The isAvailable method is a simple boolean operation to determine if the node in question is available. As expected, the result of this call is an approximation given race conditions. However, the FailureDetector should do its best to determine the then-current state of the cluster to produce a minimum of false negatives and false positives.

Note: this determination is approximate and differs based upon the algorithm used by the implementation.

Specified by:
isAvailable in interface FailureDetector
Parameters:
node - Node to check
Returns:
True if available, false otherwise

getConfig

public FailureDetectorConfig getConfig()
Description copied from interface: FailureDetector
Retrieves the FailureDetectorConfig instance with which this FailureDetector was constructed.

Specified by:
getConfig in interface FailureDetector
Returns:
FailureDetectorConfig

recordException

public void recordException(Node node,
                            long requestTime,
                            UnreachableStoreException e)
Description copied from interface: FailureDetector
Allows external callers to provide input to the FailureDetector that an error occurred when trying to access the node. The implementation is free to use or ignore this input. It can be considered a "hint" to the FailureDetector rather than an absolute truth. For example, it is possible to call recordException for a given node and have an immediate call to isAvailable return true, depending on the implementation.

Specified by:
recordException in interface FailureDetector
Parameters:
node - Node to check
requestTime - Length of time (in milliseconds) to perform request
e - Exception that occurred when trying to access the node

recordSuccess

public void recordSuccess(Node node,
                          long requestTime)
Description copied from interface: FailureDetector
Allows external callers to provide input to the FailureDetector that an access to the node succeeded. As with recordException, the implementation is free to use or ignore this input. It can be considered a "hint" to the FailureDetector rather than gospel truth.

Note for implementors: because of threading issues it's possible for multiple threads to attempt access to a node and some fail and some succeed. In a classic last-one-in-wins scenario, it's possible for the failures to be recorded first and then the successes. It would be prudent for implementations not to immediately assume that the node is then available.

Specified by:
recordSuccess in interface FailureDetector
Parameters:
node - Node to check
requestTime - Length of time (in milliseconds) to perform request

addFailureDetectorListener

public void addFailureDetectorListener(FailureDetectorListener failureDetectorListener)
Description copied from interface: FailureDetector
Adds a FailureDetectorListener instance that can receive event callbacks about node availability state changes.

Notes:

  1. Make sure to clean up the listener by invoking removeFailureDetectorListener
  2. Make sure that the FailureDetectorListener implementation properly implements the hashCode/equals methods

      Note for implementors: When adding a FailureDetectorListener that has already been added, this should not add a second instance but should effectively be a no-op.

      Specified by:
      addFailureDetectorListener in interface FailureDetector
      Parameters:
      failureDetectorListener - FailureDetectorListener that receives events
      See Also:
      FailureDetector.removeFailureDetectorListener(voldemort.cluster.failuredetector.FailureDetectorListener)

removeFailureDetectorListener

public void removeFailureDetectorListener(FailureDetectorListener failureDetectorListener)
Description copied from interface: FailureDetector
Removes a FailureDetectorListener instance from the event listener list.

Note for implementors: When removing a FailureDetectorListener that has already been removed or was never in the list, this should not raise any errors but should effectively be a no-op.

Specified by:
removeFailureDetectorListener in interface FailureDetector
Parameters:
failureDetectorListener - FailureDetectorListener that was receiving events
See Also:
FailureDetector.addFailureDetectorListener(voldemort.cluster.failuredetector.FailureDetectorListener)

getAvailableNodeCount

public int getAvailableNodeCount()
Description copied from interface: FailureDetector
Returns the number of nodes that are considered to be available at the time of calling. Letting n = the results of getNodeCount(), the return value is bounded in the range [0..n].

Specified by:
getAvailableNodeCount in interface FailureDetector
Returns:
Number of available nodes
See Also:
FailureDetector.getNodeCount()

getNodeCount

public int getNodeCount()
Description copied from interface: FailureDetector
Returns the number of nodes that are in the set of all nodes at the time of calling.

Specified by:
getNodeCount in interface FailureDetector
Returns:
Number of nodes
See Also:
FailureDetector.getAvailableNodeCount()

waitForAvailability

public void waitForAvailability(Node node)
Description copied from interface: FailureDetector
waitForAvailability causes the calling thread to block until the given Node is available. If the node is already available, this will simply return.

Specified by:
waitForAvailability in interface FailureDetector
Parameters:
node - Node on which to wait

destroy

public void destroy()
Description copied from interface: FailureDetector
Cleans up any open resources in preparation for shutdown.

Note for implementors: After this method is called it is assumed that attempts to call the other methods will either silently fail, throw errors, or return stale information.

Specified by:
destroy in interface FailureDetector


Jay Kreps, Roshan Sumbaly, Alex Feinberg, Bhupesh Bansal, Lei Gao, Chinmay Soman, Vinoth Chandar, Zhongjie Wu