public class DefaultStatementBatcher extends Object implements StatementBatcher
| Modifier and Type | Class and Description |
|---|---|
protected class |
DefaultStatementBatcher.AdaptiveSizingBatchPredicate |
| Modifier and Type | Field and Description |
|---|---|
protected BatchMode |
batchMode |
protected BatchType |
batchType |
protected CodecRegistry |
codecRegistry |
protected int |
maxBatchStatements |
protected long |
maxSizeInBytes |
protected ProtocolVersion |
protocolVersion |
protected CqlSession |
session |
| Modifier | Constructor and Description |
|---|---|
protected |
DefaultStatementBatcher()
Creates a new
DefaultStatementBatcher that produces unlogged batches, operates in partition key mode and uses the default maximum number of statements
(100) and the default maximum data size in bytes (unlimited). |
|
DefaultStatementBatcher(CqlSession session)
Creates a new
DefaultStatementBatcher that produces unlogged batches, operates in partition key mode and uses the default maximum number of statements
(100) and the default maximum data size in bytes (unlimited). |
|
DefaultStatementBatcher(CqlSession session,
BatchMode batchMode)
Creates a new
DefaultStatementBatcher that produces unlogged batches, operates in the specified batch mode and uses the given session as its source for the
protocol version and the CodecRegistry instance to use. |
|
DefaultStatementBatcher(CqlSession session,
BatchMode batchMode,
BatchType batchType,
int maxBatchStatements)
Creates a new
DefaultStatementBatcher that produces batches of the given batchType, operates in the specified batchMode and uses the given session as its source for the protocol version and the
CodecRegistry instance to use. |
|
DefaultStatementBatcher(CqlSession session,
BatchMode batchMode,
BatchType batchType,
int maxBatchStatements,
long maxSizeInBytes)
Creates a new
DefaultStatementBatcher that produces batches of the given batchType, operates in the specified batchMode and uses the given session as its source for the protocol version and the
CodecRegistry instance to use. |
|
DefaultStatementBatcher(int maxBatchStatements)
Creates a new
DefaultStatementBatcher that produces unlogged batches, operates in partition key mode and uses the default maximum data size in bytes (unlimited). |
|
DefaultStatementBatcher(int maxBatchStatements,
long maxSizeInBytes)
Creates a new
DefaultStatementBatcher that produces unlogged batches, operates in partition key mode and uses the given maximum number of statements and the maximum data size
in bytes. |
|
DefaultStatementBatcher(long maxSizeInBytes)
Creates a new
DefaultStatementBatcher that produces unlogged batches, operates in partition key mode and uses the default maximum number of statements
(100). |
| Modifier and Type | Method and Description |
|---|---|
List<Statement<?>> |
batchAll(Collection<BatchableStatement<?>> statements)
Batches together all the given statements into one or more
BatchStatements,
regardless of their grouping key. |
List<Statement<?>> |
batchByGroupingKey(Iterable<BatchableStatement<?>> statements)
Batches together the given statements into groups of statements having the same grouping key.
|
protected Object |
groupingKey(Statement<?> statement) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitbatchAll, batchByGroupingKeyprotected final CqlSession session
protected final BatchMode batchMode
protected final BatchType batchType
protected final ProtocolVersion protocolVersion
protected final CodecRegistry codecRegistry
protected final int maxBatchStatements
protected final long maxSizeInBytes
protected DefaultStatementBatcher()
DefaultStatementBatcher that produces unlogged batches, operates in partition key mode and uses the default maximum number of statements
(100) and the default maximum data size in bytes (unlimited).public DefaultStatementBatcher(int maxBatchStatements)
DefaultStatementBatcher that produces unlogged batches, operates in partition key mode and uses the default maximum data size in bytes (unlimited).
It uses the given maximum number of statements.maxBatchStatements - The maximum number of statements in a batch. If set to zero or any
negative value, the number of statements is considered unlimited.public DefaultStatementBatcher(long maxSizeInBytes)
DefaultStatementBatcher that produces unlogged batches, operates in partition key mode and uses the default maximum number of statements
(100). It uses the given maximum data size in bytes.maxSizeInBytes - The maximum number of bytes of data in one batch. If set to zero or any
negative value, the data size is considered unlimited.public DefaultStatementBatcher(int maxBatchStatements,
long maxSizeInBytes)
DefaultStatementBatcher that produces unlogged batches, operates in partition key mode and uses the given maximum number of statements and the maximum data size
in bytes.maxBatchStatements - The maximum number of statements in a batch. If set to zero or any
negative value, the number of statements is considered unlimited.maxSizeInBytes - The maximum number of bytes of data in one batch. If set to zero or any
negative value, the data size is considered unlimited.public DefaultStatementBatcher(@Nullable
CqlSession session)
DefaultStatementBatcher that produces unlogged batches, operates in partition key mode and uses the default maximum number of statements
(100) and the default maximum data size in bytes (unlimited).session - The session to use; cannot be null if batchMode is REPLICA_SET.public DefaultStatementBatcher(@Nullable
CqlSession session,
@NonNull
BatchMode batchMode)
DefaultStatementBatcher that produces unlogged batches, operates in the specified batch mode and uses the given session as its source for the
protocol version and the CodecRegistry instance to use. It
also uses the default maximum number of statements (100) and the default maximum data size in bytes (unlimited).session - The session to use; cannot be null if batchMode is REPLICA_SET.batchMode - The batch mode to use; cannot be null.public DefaultStatementBatcher(@Nullable
CqlSession session,
@NonNull
BatchMode batchMode,
@NonNull
BatchType batchType,
int maxBatchStatements)
DefaultStatementBatcher that produces batches of the given batchType, operates in the specified batchMode and uses the given session as its source for the protocol version and the
CodecRegistry instance to use. It also uses uses the given maximum number of statements
and the default maximum data
size in bytes (unlimited).session - The session to use; cannot be null if batchMode is REPLICA_SET.batchMode - The batch mode to use; cannot be null.batchType - The batch type to use; cannot be null.maxBatchStatements - The maximum number of statements in a batch. If set to zero or any
negative value, the number of statements is considered unlimited.public DefaultStatementBatcher(@Nullable
CqlSession session,
@NonNull
BatchMode batchMode,
@NonNull
BatchType batchType,
int maxBatchStatements,
long maxSizeInBytes)
DefaultStatementBatcher that produces batches of the given batchType, operates in the specified batchMode and uses the given session as its source for the protocol version and the
CodecRegistry instance to use. It uses the given maximum number of statements and the
maximum data size in bytes.session - The session to use; cannot be null if batchMode is REPLICA_SET.batchMode - The batch mode to use; cannot be null.batchType - The batch type to use; cannot be null.maxBatchStatements - The maximum number of statements in a batch. If set to zero or any
negative value, the number of statements is considered unlimited.maxSizeInBytes - The maximum number of bytes of data in one batch. If set to zero or any
negative value, the data size is considered unlimited.@NonNull public List<Statement<?>> batchByGroupingKey(@NonNull Iterable<BatchableStatement<?>> statements)
StatementBatcherThe grouping key to use is determined by the batch mode in use by this statement batcher.
Note that when a resulting group contains only one statement, this method will not create a batch statement containing that single statement; instead, it will return that same statement.
When the number of statements for the same grouping key is greater than the maximum number of statements, or when their total data size is greater than the maximum data size, statements will be split into smaller batches.
When PARTITION_KEY is used, the grouping key is the
statement's routing key or routing token, whichever is available.
When REPLICA_SET is used, the grouping key is the replica set
owning the statement's routing key or routing token, whichever is available.
batchByGroupingKey in interface StatementBatcherstatements - the statements to batch together.@NonNull public List<Statement<?>> batchAll(@NonNull Collection<BatchableStatement<?>> statements)
StatementBatcherBatchStatements,
regardless of their grouping key. Each group size is capped by the maximum number of
statements and the maximum data size.
Note that when a resulting group contains only one statement, this method will not create a batch statement containing that single statement; instead, it will return that same statement.
When the number of statements is greater than the maximum number of statements, or when their total data size is greater than the maximum data size, statements will be split into smaller batches.
Use this method with caution; if the given statements do not share the same routing key, the resulting batch could lead to write throughput degradation.
batchAll in interface StatementBatcherstatements - the statements to batch together.BatchStatements containing all the given statements batched together,
or the original statement, if only one was provided.Copyright © 2017–2021 DataStax. All rights reserved.