Class SyncFuture
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().
-
Field Summary
Modifier and TypeFieldDescriptionprivate final Condition
Condition to wait on for client threads.private final ReentrantLock
Lock protecting the thread-safe fields.private long
The transaction id that was set in here when we were marked done.private boolean
private static final long
private Thread
private Throwable
If error, the associated throwable.private long
The transaction id of this operation, monotonically increases. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription(package private) boolean
(package private) long
get
(long timeoutNs) (package private) Thread
Returns the thread that owned this sync future, use with caution as we return the reference to the actual thread object.(package private) Throwable
(package private) long
getTxid()
(package private) boolean
isDone()
(package private) boolean
(package private) SyncFuture
reset
(long txid, boolean forceSync) Call this method to clear old usage and get it ready for new deploy.toString()
-
Field Details
-
NOT_DONE
- See Also:
-
t
-
doneLock
Lock protecting the thread-safe fields. -
doneCondition
Condition to wait on for client threads. -
doneTxid
The transaction id that was set in here when we were marked done. Should be equal or > txnId. Put this data member into the NOT_DONE state while this class is in use. -
throwable
If error, the associated throwable. Set when the future is 'done'. -
txid
The transaction id of this operation, monotonically increases. -
forceSync
-
-
Constructor Details
-
SyncFuture
-
-
Method Details
-
reset
Call this method to clear old usage and get it ready for new deploy.- Parameters:
txid
- the new transaction id
-
toString
-
getTxid
long getTxid() -
isForceSync
boolean isForceSync() -
getThread
Returns the thread that owned this sync future, use with caution as we return the reference to the actual thread object.- Returns:
- the associated thread instance.
-
done
- Parameters:
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).- Returns:
- True if we successfully marked this outstanding future as completed/done. Returns false if this future is already 'done' when this method called.
-
get
-
isDone
boolean isDone() -
getThrowable
-