@InterfaceAudience.Private class SyncFuture extends Object
Handlers coming in call append, append, append, and then do a flush/sync of the edits they have appended the WAL before returning. Since sync takes a while to complete, we give the Handlers back this sync future to wait on until the actual HDFS sync completes. Meantime this sync future goes across a queue and is handled by a background thread; when it completes, it finishes up the future, the handler get or failed check completes and the Handler can then progress.
This is just a partial implementation of Future; we just implement get and failure.
There is not a one-to-one correlation between dfs sync invocations and instances of this class. A single dfs sync call may complete and mark many SyncFutures as done; i.e. we batch up sync calls rather than do a dfs sync call every time a Handler asks for it.
SyncFutures are immutable but recycled. Call #reset(long, Span) before use even if it the first time, start the sync, then park the 'hitched' thread on a call to #get().
Modifier and Type | Field and Description |
---|---|
private Condition |
doneCondition
Condition to wait on for client threads.
|
private ReentrantLock |
doneLock
Lock protecting the thread-safe fields.
|
private long |
doneTxid
The transaction id that was set in here when we were marked done.
|
private boolean |
forceSync |
private static long |
NOT_DONE |
private Thread |
t |
private Throwable |
throwable
If error, the associated throwable.
|
private long |
txid
The transaction id of this operation, monotonically increases.
|
Constructor and Description |
---|
SyncFuture() |
Modifier and Type | Method and Description |
---|---|
(package private) boolean |
done(long txid,
Throwable t) |
(package private) long |
get(long timeoutNs) |
(package private) Thread |
getThread()
Returns the thread that owned this sync future, use with caution as we return the reference to
the actual thread object.
|
(package private) Throwable |
getThrowable() |
(package private) long |
getTxid() |
(package private) boolean |
isDone() |
(package private) boolean |
isForceSync() |
(package private) SyncFuture |
reset(long txid,
boolean forceSync)
Call this method to clear old usage and get it ready for new deploy.
|
String |
toString() |
private static final long NOT_DONE
private final ReentrantLock doneLock
private final Condition doneCondition
private long doneTxid
private Throwable throwable
private long txid
private boolean forceSync
SyncFuture()
SyncFuture reset(long txid, boolean forceSync)
txid
- the new transaction id nlong getTxid()
boolean isForceSync()
Thread getThread()
boolean done(long txid, Throwable t)
txid
- the transaction id at which this future 'completed'.t
- Can be null. Set if we are 'completing' on error (and this 't' is the error).long get(long timeoutNs) throws InterruptedException, ExecutionException, TimeoutIOException
boolean isDone()
Throwable getThrowable()
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.