Class PartitionUpdate
A PartitionUpdate object requires that all writes/additions are performed before we try to read the updates (attempts to write to the PartitionUpdate after a read method has been called will result in an exception being thrown). In other words, a Partition is mutable while it's written but becomes immutable as soon as it is read.
A typical usage is to create a new update (new PartitionUpdate(metadata, key, columns, capacity))
and then add rows and range tombstones through the add() methods (the partition
level deletion time can also be set with addPartitionDeletion()). However, there
is also a few static helper constructor methods for special cases (emptyUpdate(),
fullPartitionDelete and singleRowUpdate).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for PartitionUpdates This class is not thread safe, but the PartitionUpdate it produces is (since it is immutable).static classA counter mark is basically a pointer to a counter update inside this partition update.static classstatic interfaceInterface for building partition updates geared towards human. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final org.slf4j.Loggerstatic final PartitionUpdate.PartitionUpdateSerializerFields inherited from class org.apache.cassandra.db.partitions.AbstractBTreePartition
partitionKey -
Method Summary
Modifier and TypeMethodDescriptionintintprotected booleanFor an update on a counter table, returns a list containing aCounterMarkfor every counter contained in the update.columns()intdataSize()The size of the data contained in this update.static PartitionUpdateemptyUpdate(TableMetadata metadata, DecoratedKey key) Creates a empty immutable partition update.static PartitionUpdatefromBytes(ByteBuffer bytes, int version) Deserialize a partition update from a provided byte buffer.static PartitionUpdatefromIterator(RowIterator iterator, ColumnFilter filter) Turns the given iterator into an update.static PartitionUpdatefromIterator(UnfilteredRowIterator iterator, ColumnFilter filter) Turns the given iterator into an update.static PartitionUpdatefullPartitionDelete(TableMetadata metadata, ByteBuffer key, long timestamp, long nowInSec) Creates a partition update that entirely deletes a given partition.static PartitionUpdatefullPartitionDelete(TableMetadata metadata, DecoratedKey key, long timestamp, long nowInSec) Creates an immutable partition update that entirely deletes a given partition.protected BTreePartitionDataholder()longThe maximum timestamp used in this update.static PartitionUpdatemerge(List<PartitionUpdate> updates) Merges the provided updates, yielding a new update that incorporates all those updates.metadata()intThe number of "operations" contained in the update.simpleBuilder(TableMetadata metadata, Object... partitionKeyValues) Creates a new simple partition update builder.static PartitionUpdatesingleRowUpdate(TableMetadata metadata, ByteBuffer key, Row row) Creates an immutable partition update that contains a single row update.static PartitionUpdatesingleRowUpdate(TableMetadata metadata, DecoratedKey key, Row row) Creates an immutable partition update that contains a single row update.static PartitionUpdatesingleRowUpdate(TableMetadata metadata, DecoratedKey key, Row row, Row staticRow) Creates an immutable partition update that contains a single row update.stats()static ByteBuffertoBytes(PartitionUpdate update, int version) Serialize a partition update as a byte buffer.static PartitionUpdateunsafeConstruct(TableMetadata metadata, DecoratedKey key, BTreePartitionData holder, MutableDeletionInfo deletionInfo, boolean canHaveShadowedData) longThe size of the data contained in this update.voidvalidate()Validates the data contained in this update.voidMethods inherited from class org.apache.cassandra.db.partitions.AbstractBTreePartition
build, build, build, equals, getRow, hasRows, isEmpty, iterator, lastRow, partitionKey, partitionLevelDeletion, rowCount, staticRow, toString, toString, unfilteredIterator, unfilteredIterator, unfilteredIterator, unfilteredIteratorMethods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
logger
protected static final org.slf4j.Logger logger -
serializer
-
-
Method Details
-
emptyUpdate
Creates a empty immutable partition update.- Parameters:
metadata- the metadata for the created update.key- the partition key for the created update.- Returns:
- the newly created empty (and immutable) update.
-
fullPartitionDelete
public static PartitionUpdate fullPartitionDelete(TableMetadata metadata, DecoratedKey key, long timestamp, long nowInSec) Creates an immutable partition update that entirely deletes a given partition.- Parameters:
metadata- the metadata for the created update.key- the partition key for the partition that the created update should delete.timestamp- the timestamp for the deletion.nowInSec- the current time in seconds to use as local deletion time for the partition deletion.- Returns:
- the newly created partition deletion update.
-
singleRowUpdate
public static PartitionUpdate singleRowUpdate(TableMetadata metadata, DecoratedKey key, Row row, Row staticRow) Creates an immutable partition update that contains a single row update.- Parameters:
metadata- the metadata for the created update.key- the partition key for the partition to update.row- the row for the update (may be null).row- the static row for the update (may be null).- Returns:
- the newly created partition update containing only
row.
-
singleRowUpdate
Creates an immutable partition update that contains a single row update.- Parameters:
metadata- the metadata for the created update.key- the partition key for the partition to update.row- the row for the update (may be static).- Returns:
- the newly created partition update containing only
row.
-
singleRowUpdate
Creates an immutable partition update that contains a single row update.- Parameters:
metadata- the metadata for the created update.key- the partition key for the partition to update.row- the row for the update.- Returns:
- the newly created partition update containing only
row.
-
fromIterator
Turns the given iterator into an update.- Parameters:
iterator- the iterator to turn into updates.filter- the column filter used when queryingiterator. This is used to make sure we don't include data for which the value has been skipped while reading (as we would then be writing something incorrect). Warning: this method does not close the provided iterator, it is up to the caller to close it.
-
fromIterator
Turns the given iterator into an update.- Parameters:
iterator- the iterator to turn into updates.filter- the column filter used when queryingiterator. This is used to make sure we don't include data for which the value has been skipped while reading (as we would then be writing something incorrect). Warning: this method does not close the provided iterator, it is up to the caller to close it.
-
withOnlyPresentColumns
-
canHaveShadowedData
protected boolean canHaveShadowedData()- Specified by:
canHaveShadowedDatain classAbstractBTreePartition
-
fromBytes
Deserialize a partition update from a provided byte buffer.- Parameters:
bytes- the byte buffer that contains the serialized update.version- the version with which the update is serialized.- Returns:
- the deserialized update or
nullifbytes == null.
-
toBytes
Serialize a partition update as a byte buffer.- Parameters:
update- the partition update to serialize.version- the version to serialize the update into.- Returns:
- a newly allocated byte buffer containing the serialized update.
-
fullPartitionDelete
public static PartitionUpdate fullPartitionDelete(TableMetadata metadata, ByteBuffer key, long timestamp, long nowInSec) Creates a partition update that entirely deletes a given partition.- Parameters:
metadata- the metadata for the created update.key- the partition key for the partition that the created update should delete.timestamp- the timestamp for the deletion.nowInSec- the current time in seconds to use as local deletion time for the partition deletion.- Returns:
- the newly created partition deletion update.
-
merge
Merges the provided updates, yielding a new update that incorporates all those updates.- Parameters:
updates- the collection of updates to merge. This shouldn't be empty.- Returns:
- a partition update that include (merge) all the updates from
updates.
-
deletionInfo
- Overrides:
deletionInfoin classAbstractBTreePartition
-
operationCount
public int operationCount()The number of "operations" contained in the update.This is used by
Memtableto approximate how much work this update does. In practice, this count how many rows are updated and how many ranges are deleted by the partition update.- Returns:
- the number of "operations" performed by the update.
-
dataSize
public int dataSize()The size of the data contained in this update.- Returns:
- the size of the data contained in this update.
-
metadata
- Specified by:
metadatain interfacePartition- Specified by:
metadatain classAbstractBTreePartition
-
columns
- Specified by:
columnsin interfacePartition- Overrides:
columnsin classAbstractBTreePartition
-
holder
- Specified by:
holderin classAbstractBTreePartition
-
stats
- Specified by:
statsin interfacePartition- Overrides:
statsin classAbstractBTreePartition
-
validate
public void validate()Validates the data contained in this update.- Throws:
MarshalException- if some of the data contained in this update is corrupted.
-
maxTimestamp
public long maxTimestamp()The maximum timestamp used in this update.- Returns:
- the maximum timestamp used in this update.
-
collectCounterMarks
For an update on a counter table, returns a list containing aCounterMarkfor every counter contained in the update.- Returns:
- a list with counter marks for every counter in this update.
-
affectedRowCount
public int affectedRowCount()- Returns:
- the estimated number of rows affected by this mutation
-
affectedColumnCount
public int affectedColumnCount()- Returns:
- the estimated total number of columns that either have live data or are covered by a delete
-
simpleBuilder
public static PartitionUpdate.SimpleBuilder simpleBuilder(TableMetadata metadata, Object... partitionKeyValues) Creates a new simple partition update builder.- Parameters:
metadata- the metadata for the table this is a partition of.partitionKeyValues- the values for partition key columns identifying this partition. The values for each partition key column can be passed either directly asByteBufferor using a "native" value (int for Int32Type, string for UTF8Type, ...). It is also allowed to pass a singleDecoratedKeyvalue directly.- Returns:
- a newly created builder.
-
validateIndexedColumns
-
unsafeConstruct
public static PartitionUpdate unsafeConstruct(TableMetadata metadata, DecoratedKey key, BTreePartitionData holder, MutableDeletionInfo deletionInfo, boolean canHaveShadowedData)
-