Class ThrottledAsyncChecker<K,V>
java.lang.Object
org.apache.hadoop.hdfs.server.datanode.checker.ThrottledAsyncChecker<K,V>
- All Implemented Interfaces:
AsyncChecker<K,V>
@Private
@Unstable
public class ThrottledAsyncChecker<K,V>
extends Object
implements AsyncChecker<K,V>
An implementation of
AsyncChecker that skips checking recently
checked objects. It will enforce at least minMsBetweenChecks
milliseconds between two successive checks of any one object.
It is assumed that the total number of Checkable objects in the system
is small, (not more than a few dozen) since the checker uses O(Checkables)
storage and also potentially O(Checkables) threads.
minMsBetweenChecks should be configured reasonably
by the caller to avoid spinning up too many threads frequently.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionThrottledAsyncChecker(org.apache.hadoop.util.Timer timer, long minMsBetweenChecks, long diskCheckTimeout, ExecutorService executorService) -
Method Summary
Modifier and TypeMethodDescriptionSeeAsyncChecker.schedule(org.apache.hadoop.hdfs.server.datanode.checker.Checkable<K, V>, K)If the object has been checked recently then the check will be skipped.voidshutdownAndWait(long timeout, TimeUnit timeUnit) Cancel all executing checks and wait for them to complete.
-
Field Details
-
LOG
public static final org.slf4j.Logger LOG
-
-
Constructor Details
-
ThrottledAsyncChecker
public ThrottledAsyncChecker(org.apache.hadoop.util.Timer timer, long minMsBetweenChecks, long diskCheckTimeout, ExecutorService executorService)
-
-
Method Details
-
schedule
public Optional<org.apache.hadoop.thirdparty.com.google.common.util.concurrent.ListenableFuture<V>> schedule(Checkable<K, V> target, K context) SeeAsyncChecker.schedule(org.apache.hadoop.hdfs.server.datanode.checker.Checkable<K, V>, K)If the object has been checked recently then the check will be skipped. Multiple concurrent checks for the same object will receive the same Future.- Specified by:
schedulein interfaceAsyncChecker<K,V> - Parameters:
target- object to be checked.context- the interpretation of the context depends on the target.- Returns:
- returns a
of ListenableFuturethat can be used to retrieve the result of the asynchronous check.
-
shutdownAndWait
Cancel all executing checks and wait for them to complete. First attempts a graceful cancellation, then cancels forcefully. Waits for the supplied timeout after both attempts. SeeExecutorService.awaitTermination(long, java.util.concurrent.TimeUnit)for a description of the parameters.. The results of in-progress checks are not useful during shutdown, so we optimize for faster shutdown by interrupt all actively executing checks.- Specified by:
shutdownAndWaitin interfaceAsyncChecker<K,V> - Throws:
InterruptedException
-