@InterfaceAudience.Public @InterfaceStability.Unstable public class AsyncKuduSession extends Object implements SessionConfiguration
AsyncKuduSession is separate from KuduTable because a given batch or transaction may span multiple tables. This is particularly important in the future when we add ACID support, but even in the context of batching, we may be able to coalesce writes to different tables hosted on the same server into the same RPC.
AsyncKuduSession is separate from AsyncKuduClient because, in a multi-threaded application, different threads may need to concurrently execute transactions. Similar to a JDBC "session", transaction boundaries will be delineated on a per-session basis -- in between a "BeginTransaction" and "Commit" call on a given session, all operations will be part of the same transaction. Meanwhile another concurrent Session object can safely run non-transactional work or other transactions without interfering.
Therefore, this class is not thread-safe.
Additionally, there is a guarantee that writes from different sessions do not get batched together into the same RPCs -- this means that latency-sensitive clients can run through the same AsyncKuduClient object as throughput-oriented clients, perhaps by setting the latency-sensitive session's timeouts low and priorities high. Without the separation of batches, a latency-sensitive single-row insert might get batched along with 10MB worth of inserts from the batch writer, thus delaying the response significantly.
Though we currently do not have transactional support, users will be forced to use a AsyncKuduSession to instantiate reads as well as writes. This will make it more straight-forward to add RW transactions in the future without significant modifications to the API.
Timeouts are handled differently depending on the flush mode. With AUTO_FLUSH_SYNC, the timeout is set on each apply()'d operation. With AUTO_FLUSH_BACKGROUND and MANUAL_FLUSH, the timeout is assigned to a whole batch of operations upon flush()'ing. It means that in a situation with a timeout of 500ms and a flush interval of 1000ms, an operation can be oustanding for up to 1500ms before being timed out.
SessionConfiguration.FlushMode
Modifier and Type | Field and Description |
---|---|
static org.slf4j.Logger |
LOG |
Modifier and Type | Method and Description |
---|---|
com.stumbleupon.async.Deferred<OperationResponse> |
apply(Operation operation)
Apply the given operation.
|
com.stumbleupon.async.Deferred<List<OperationResponse>> |
close()
Flushes the buffered operations and marks this sessions as closed.
|
int |
countPendingErrors()
Return the number of errors which are pending.
|
com.stumbleupon.async.Deferred<List<OperationResponse>> |
flush()
Flushes the buffered operations.
|
SessionConfiguration.FlushMode |
getFlushMode()
Get the current flush mode.
|
RowErrorsAndOverflowStatus |
getPendingErrors()
Return any errors from previous calls.
|
long |
getTimeoutMillis()
Get the current timeout.
|
boolean |
hasPendingOperations()
Check if there are operations that haven't been completely applied.
|
boolean |
isClosed()
Returns true if this session has already been closed.
|
boolean |
isIgnoreAllDuplicateRows()
Tells if the session is currently ignoring row errors when the whole list returned by a tablet
server is of the AlreadyPresent type.
|
void |
setExternalConsistencyMode(ExternalConsistencyMode consistencyMode)
Set the new external consistency mode for this session.
|
void |
setFlushInterval(int interval)
Set the flush interval, which will be used for the next scheduling decision.
|
void |
setFlushMode(SessionConfiguration.FlushMode flushMode)
Set the new flush mode for this session.
|
void |
setIgnoreAllDuplicateRows(boolean ignoreAllDuplicateRows)
Configures the option to ignore all the row errors if they are all of the AlreadyPresent type.
|
void |
setMutationBufferLowWatermark(float mutationBufferLowWatermarkPercentage)
Set the low watermark for this session.
|
void |
setMutationBufferSpace(int size)
Set the number of operations that can be buffered.
|
void |
setTimeoutMillis(long timeout)
Sets the timeout for the next applied operations.
|
public SessionConfiguration.FlushMode getFlushMode()
SessionConfiguration
getFlushMode
in interface SessionConfiguration
public void setFlushMode(SessionConfiguration.FlushMode flushMode)
SessionConfiguration
setFlushMode
in interface SessionConfiguration
flushMode
- new flush mode, can be the same as the previous one.public void setExternalConsistencyMode(ExternalConsistencyMode consistencyMode)
SessionConfiguration
setExternalConsistencyMode
in interface SessionConfiguration
consistencyMode
- new external consistency mode, can the same as the previous one.public void setMutationBufferSpace(int size)
SessionConfiguration
setMutationBufferSpace
in interface SessionConfiguration
size
- number of ops.public void setMutationBufferLowWatermark(float mutationBufferLowWatermarkPercentage)
SessionConfiguration
setMutationBufferLowWatermark
in interface SessionConfiguration
mutationBufferLowWatermarkPercentage
- a new low watermark as a percentage,
has to be between 0 and 1 (inclusive). A value of 1 disables
the low watermark since it's the same as the high onepublic void setFlushInterval(int interval)
SessionConfiguration
setFlushInterval
in interface SessionConfiguration
interval
- interval in milliseconds.public void setTimeoutMillis(long timeout)
SessionConfiguration
setTimeoutMillis
in interface SessionConfiguration
timeout
- Timeout in milliseconds.public long getTimeoutMillis()
SessionConfiguration
getTimeoutMillis
in interface SessionConfiguration
public boolean isClosed()
SessionConfiguration
isClosed
in interface SessionConfiguration
public boolean isIgnoreAllDuplicateRows()
SessionConfiguration
isIgnoreAllDuplicateRows
in interface SessionConfiguration
public void setIgnoreAllDuplicateRows(boolean ignoreAllDuplicateRows)
SessionConfiguration
setIgnoreAllDuplicateRows
in interface SessionConfiguration
ignoreAllDuplicateRows
- true if this session should enforce this, else falsepublic int countPendingErrors()
SessionConfiguration
countPendingErrors
in interface SessionConfiguration
public RowErrorsAndOverflowStatus getPendingErrors()
SessionConfiguration
getPendingErrors
in interface SessionConfiguration
public com.stumbleupon.async.Deferred<List<OperationResponse>> close()
flush()
on how to deal with exceptions coming out of this method.public com.stumbleupon.async.Deferred<List<OperationResponse>> flush()
public boolean hasPendingOperations()
SessionConfiguration
hasPendingOperations
in interface SessionConfiguration
public com.stumbleupon.async.Deferred<OperationResponse> apply(Operation operation)
operation
- operation to applyCopyright © 2016. All rights reserved.