@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 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 |
cancel(boolean mayInterruptIfRunning) |
(package private) boolean |
done(long txid,
Throwable t) |
(package private) long |
get(long timeoutNs) |
(package private) Throwable |
getThrowable() |
(package private) long |
getTxid() |
(package private) boolean |
isDone() |
(package private) boolean |
isForceSync() |
(package private) boolean |
isThrowable() |
(package private) SyncFuture |
reset(long txid)
Call this method to clear old usage and get it ready for new deploy.
|
(package private) SyncFuture |
setForceSync(boolean forceSync) |
String |
toString() |
private static final long NOT_DONE
private long txid
private long doneTxid
private Throwable throwable
private boolean forceSync
SyncFuture()
SyncFuture reset(long txid)
txid
- the new transaction idlong getTxid()
boolean isForceSync()
SyncFuture setForceSync(boolean forceSync)
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).boolean cancel(boolean mayInterruptIfRunning)
long get(long timeoutNs) throws InterruptedException, ExecutionException, TimeoutIOException
boolean isDone()
boolean isThrowable()
Throwable getThrowable()
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.