|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.jgit.storage.dht.spi.util.AbstractWriteBuffer
public abstract class AbstractWriteBuffer
Abstract buffer service built on top of an ExecutorService.
Writes are combined together into batches, to reduce RPC overhead when there are many small writes occurring. Batches are sent asynchronously when they reach 512 KiB worth of key/column/value data. The calling application is throttled when the outstanding writes are equal to the buffer size, waiting until the cluster has replied with success or failure.
This buffer implementation is not thread-safe, it assumes only one thread will use the buffer instance. (It does however correctly synchronize with the background tasks it spawns.)
Constructor Summary | |
---|---|
protected |
AbstractWriteBuffer(java.util.concurrent.ExecutorService executor,
int bufferSize)
Initialize a buffer with a backing executor service. |
Method Summary | ||
---|---|---|
void |
abort()
Abort pending writes, and wait for acknowledgment. |
|
protected boolean |
add(int size)
Notify the buffer data is being added onto it. |
|
void |
flush()
Flush any pending writes, and wait for them to complete. |
|
protected void |
queued(int size)
Notify the buffer bytes were enqueued. |
|
protected
|
start(java.util.concurrent.Callable<T> task,
int size)
Start a mutation task. |
|
protected abstract void |
startQueuedOperations(int bufferedByteCount)
Start all queued operations. |
|
protected
|
wrap(AsyncCallback<T> callback,
int size)
Wrap a callback to update the buffer. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected AbstractWriteBuffer(java.util.concurrent.ExecutorService executor, int bufferSize)
executor
- service to run mutation tasks on.bufferSize
- maximum number of bytes to have pending at once.Method Detail |
---|
protected boolean add(int size) throws DhtException
This method waits until the buffer has sufficient space for the requested data, thereby throttling the calling application code. It returns true if its recommendation is for the buffer subclass to copy the data onto its internal buffer and defer starting until later. It returns false if the recommendation is to start the operation immediately, due to the large size of the request.
Buffer implementors should keep in mind that the return value is offered as advice only, they may choose to implement different behavior.
size
- an estimated number of bytes that the buffer will be
responsible for until the operation completes. This should
include the row keys and column headers, in addition to the
data values.
DhtException
- the current thread was interrupted before space became
available in the buffer.protected void queued(int size) throws DhtException
size
- the estimated number of bytes that were enqueued.
DhtException
- a previously started operation completed and failed.protected abstract void startQueuedOperations(int bufferedByteCount) throws DhtException
This method is invoked by queued(int)
or by flush()
when there is a non-zero number of bytes already enqueued as a result of
prior add(int)
and {#link queued(int)
calls.
Implementors should use start(Callable, int)
to begin their
mutation tasks in the background.
bufferedByteCount
- number of bytes that were already enqueued. This count should
be passed to start(Callable, int)
.
DhtException
- a previously started operation completed and failed.public void flush() throws DhtException
WriteBuffer
flush
in interface WriteBuffer
DhtException
- one or more writes failed. As writes may occur in any order,
the exact state of the database is unspecified.public void abort() throws DhtException
WriteBuffer
Once a buffer has been aborted, it cannot be reused. Application code must discard the buffer instance and use a different buffer to issue subsequent operations.
If writes have not been started yet, they should be discarded and not submitted to the storage system.
If writes have already been started asynchronously in the background, this method may try to cancel them, but must wait for the operation to either complete or abort before returning. This allows callers to clean up by scanning the storage system and making corrections to clean up any partial writes.
abort
in interface WriteBuffer
DhtException
- one or more already started writes failed.protected <T> void start(java.util.concurrent.Callable<T> task, int size) throws DhtException
T
- any type the task might return.task
- the mutation task. The result of the task is discarded, so
callers should perform result validation within the task.size
- number of bytes that are buffered within the task.
DhtException
- a prior task has completed, and failed.protected <T> AsyncCallback<T> wrap(AsyncCallback<T> callback, int size) throws DhtException
Flushing the buffer will wait for the returned callback to complete.
T
- any type the task might return.callback
- callback invoked when the task has finished.size
- number of bytes that are buffered within the task.
DhtException
- a prior task has completed, and failed.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |