@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.
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.
|
com.stumbleupon.async.Deferred<List<OperationResponse>> |
flush()
Flushes the buffered operations.
|
SessionConfiguration.FlushMode |
getFlushMode()
Get the current flush mode.
|
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()
SessionConfigurationgetFlushMode in interface SessionConfigurationpublic void setFlushMode(SessionConfiguration.FlushMode flushMode)
SessionConfigurationsetFlushMode in interface SessionConfigurationflushMode - new flush mode, can be the same as the previous one.public void setExternalConsistencyMode(ExternalConsistencyMode consistencyMode)
SessionConfigurationsetExternalConsistencyMode in interface SessionConfigurationconsistencyMode - new external consistency mode, can the same as the previous one.public void setMutationBufferSpace(int size)
SessionConfigurationsetMutationBufferSpace in interface SessionConfigurationsize - number of ops.public void setMutationBufferLowWatermark(float mutationBufferLowWatermarkPercentage)
SessionConfigurationsetMutationBufferLowWatermark in interface SessionConfigurationmutationBufferLowWatermarkPercentage - 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)
SessionConfigurationsetFlushInterval in interface SessionConfigurationinterval - interval in milliseconds.public void setTimeoutMillis(long timeout)
SessionConfigurationsetTimeoutMillis in interface SessionConfigurationtimeout - Timeout in milliseconds.public long getTimeoutMillis()
SessionConfigurationgetTimeoutMillis in interface SessionConfigurationpublic boolean isClosed()
SessionConfigurationisClosed in interface SessionConfigurationpublic boolean isIgnoreAllDuplicateRows()
SessionConfigurationisIgnoreAllDuplicateRows in interface SessionConfigurationpublic void setIgnoreAllDuplicateRows(boolean ignoreAllDuplicateRows)
SessionConfigurationsetIgnoreAllDuplicateRows in interface SessionConfigurationignoreAllDuplicateRows - true if this session should enforce this, else falsepublic 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()
SessionConfigurationhasPendingOperations in interface SessionConfigurationpublic com.stumbleupon.async.Deferred<OperationResponse> apply(Operation operation)
operation - operation to applyCopyright © 2015. All rights reserved.