@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 the ringbuffer and into a sync runner 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. Unimplemented methods throw UnsupportedOperationException
.
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 |
doneSequence
The sequence that was set in here when we were marked done.
|
private static long |
NOT_DONE |
private long |
ringBufferSequence
The sequence at which we were added to the ring buffer.
|
private org.apache.htrace.Span |
span
Optionally carry a disconnected scope to the SyncRunner.
|
private Thread |
t |
private Throwable |
throwable
If error, the associated throwable.
|
Constructor and Description |
---|
SyncFuture() |
Modifier and Type | Method and Description |
---|---|
boolean |
cancel(boolean mayInterruptIfRunning) |
(package private) boolean |
done(long sequence,
Throwable t) |
long |
get(long timeout) |
Long |
get(long timeout,
TimeUnit unit) |
(package private) long |
getRingBufferSequence() |
(package private) org.apache.htrace.Span |
getSpan()
Retrieve the
span instance from this Future. |
(package private) Throwable |
getThrowable() |
boolean |
isCancelled() |
(package private) boolean |
isDone() |
(package private) boolean |
isThrowable() |
(package private) SyncFuture |
reset(long sequence)
Call this method to clear old usage and get it ready for new deploy.
|
(package private) SyncFuture |
reset(long sequence,
org.apache.htrace.Span span)
Call this method to clear old usage and get it ready for new deploy.
|
(package private) void |
setSpan(org.apache.htrace.Span span)
Used to re-attach a
span to the Future. |
String |
toString() |
private static final long NOT_DONE
private long ringBufferSequence
private long doneSequence
reset(long, Span)
below and it will work.private Throwable throwable
private Thread t
private org.apache.htrace.Span span
SyncFuture reset(long sequence)
sequence
- sequenceId from this Future's position in the RingBufferSyncFuture reset(long sequence, org.apache.htrace.Span span)
sequence
- sequenceId from this Future's position in the RingBufferspan
- curren span, detached from caller. Don't forget to attach it when
resuming after a call to #get()
.long getRingBufferSequence()
org.apache.htrace.Span getSpan()
span
instance from this Future. EventHandler calls
this method to continue the span. Thread waiting on this Future musn't call
this method until AFTER calling #get()
and the future has been
released back to the originating thread.void setSpan(org.apache.htrace.Span span)
span
to the Future. Called by the EventHandler
after a it has completed processing and detached the span from its scope.boolean done(long sequence, Throwable t)
sequence
- Sync sequence at which this future 'completed'.t
- Can be null. Set if we are 'completing' on error (and this 't' is the error).public boolean cancel(boolean mayInterruptIfRunning)
public long get(long timeout) throws InterruptedException, ExecutionException, TimeoutIOException
public Long get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException
public boolean isCancelled()
boolean isDone()
boolean isThrowable()
Throwable getThrowable()
Copyright © 2007–2019 The Apache Software Foundation. All rights reserved.