public class PartitionUpdate extends AbstractBTreePartition
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
).
Modifier and Type | Class and Description |
---|---|
static class |
PartitionUpdate.CounterMark
A counter mark is basically a pointer to a counter update inside this partition update.
|
static class |
PartitionUpdate.PartitionUpdateSerializer |
AbstractBTreePartition.Holder, AbstractBTreePartition.SliceableIterator, AbstractBTreePartition.SlicesIterator
Modifier and Type | Field and Description |
---|---|
protected static org.slf4j.Logger |
logger |
static PartitionUpdate.PartitionUpdateSerializer |
serializer |
EMPTY, metadata, partitionKey
Constructor and Description |
---|
PartitionUpdate(CFMetaData metadata,
java.nio.ByteBuffer key,
PartitionColumns columns,
int initialRowCapacity) |
PartitionUpdate(CFMetaData metadata,
DecoratedKey key,
PartitionColumns columns,
int initialRowCapacity) |
Modifier and Type | Method and Description |
---|---|
void |
add(RangeTombstone range) |
void |
add(Row row)
Adds a row to this update.
|
void |
addPartitionDeletion(DeletionTime deletionTime) |
void |
allowNewUpdates()
If a partition update has been read (and is thus unmodifiable), a call to this method
makes the update modifiable again.
|
protected boolean |
canHaveShadowedData() |
java.util.List<PartitionUpdate.CounterMark> |
collectCounterMarks()
For an update on a counter table, returns a list containing a
CounterMark for
every counter contained in the update. |
PartitionColumns |
columns() |
int |
dataSize()
The size of the data contained in this update.
|
static PartitionUpdate |
emptyUpdate(CFMetaData metadata,
DecoratedKey key)
Creates a empty immutable partition update.
|
static PartitionUpdate |
fromBytes(java.nio.ByteBuffer bytes,
int version,
DecoratedKey key)
Deserialize a partition update from a provided byte buffer.
|
static PartitionUpdate |
fromIterator(RowIterator iterator) |
static PartitionUpdate |
fromIterator(UnfilteredRowIterator iterator)
Turns the given iterator into an update.
|
static PartitionUpdate |
fullPartitionDelete(CFMetaData metadata,
java.nio.ByteBuffer key,
long timestamp,
int nowInSec)
Creates a partition update that entirely deletes a given partition.
|
static PartitionUpdate |
fullPartitionDelete(CFMetaData metadata,
DecoratedKey key,
long timestamp,
int nowInSec)
Creates an immutable partition update that entirely deletes a given partition.
|
protected AbstractBTreePartition.Holder |
holder() |
java.util.Iterator<Row> |
iterator()
Returns an iterator that iterates over the rows of this update in clustering order.
|
long |
maxTimestamp()
The maximum timestamp used in this update.
|
static PartitionUpdate |
merge(java.util.List<PartitionUpdate> updates)
Merges the provided updates, yielding a new update that incorporates all those updates.
|
int |
operationCount()
The number of "operations" contained in the update.
|
static PartitionUpdate |
singleRowUpdate(CFMetaData metadata,
java.nio.ByteBuffer key,
Row row)
Creates an immutable partition update that contains a single row update.
|
static PartitionUpdate |
singleRowUpdate(CFMetaData metadata,
DecoratedKey key,
Row row)
Creates an immutable partition update that contains a single row update.
|
SliceableUnfilteredRowIterator |
sliceableUnfilteredIterator(ColumnFilter columns,
boolean reversed) |
EncodingStats |
stats() |
static java.nio.ByteBuffer |
toBytes(PartitionUpdate update,
int version)
Serialize a partition update as a byte buffer.
|
java.lang.String |
toString() |
void |
updateAllTimestamp(long newTimestamp)
Modify this update to set every timestamp for live data to
newTimestamp and
every deletion timestamp to newTimestamp - 1 . |
void |
validate()
Validates the data contained in this update.
|
build, build, deletionInfo, getRow, hasRows, isEmpty, lastRow, metadata, partitionKey, partitionLevelDeletion, rowCount, searchIterator, sliceableUnfilteredIterator, staticRow, unfilteredIterator, unfilteredIterator, unfilteredIterator
protected static final org.slf4j.Logger logger
public static final PartitionUpdate.PartitionUpdateSerializer serializer
public PartitionUpdate(CFMetaData metadata, DecoratedKey key, PartitionColumns columns, int initialRowCapacity)
public PartitionUpdate(CFMetaData metadata, java.nio.ByteBuffer key, PartitionColumns columns, int initialRowCapacity)
public static PartitionUpdate emptyUpdate(CFMetaData metadata, DecoratedKey key)
metadata
- the metadata for the created update.key
- the partition key for the created update.public static PartitionUpdate fullPartitionDelete(CFMetaData metadata, DecoratedKey key, long timestamp, int nowInSec)
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.public static PartitionUpdate singleRowUpdate(CFMetaData metadata, DecoratedKey key, Row row)
metadata
- the metadata for the created update.key
- the partition key for the partition to update.row
- the row for the update.row
.public static PartitionUpdate singleRowUpdate(CFMetaData metadata, java.nio.ByteBuffer key, Row row)
metadata
- the metadata for the created update.key
- the partition key for the partition to update.row
- the row for the update.row
.public static PartitionUpdate fromIterator(UnfilteredRowIterator iterator)
public static PartitionUpdate fromIterator(RowIterator iterator)
protected boolean canHaveShadowedData()
canHaveShadowedData
in class AbstractBTreePartition
public static PartitionUpdate fromBytes(java.nio.ByteBuffer bytes, int version, DecoratedKey key)
bytes
- the byte buffer that contains the serialized update.version
- the version with which the update is serialized.key
- the partition key for the update. This is only used if version < 3.0
and can be null
otherwise.null
if bytes == null
.public static java.nio.ByteBuffer toBytes(PartitionUpdate update, int version)
update
- the partition update to serialize.version
- the version to serialize the update into.public static PartitionUpdate fullPartitionDelete(CFMetaData metadata, java.nio.ByteBuffer key, long timestamp, int nowInSec)
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.public static PartitionUpdate merge(java.util.List<PartitionUpdate> updates)
updates
- the collection of updates to merge. This shouldn't be empty.updates
.public void updateAllTimestamp(long newTimestamp)
newTimestamp
and
every deletion timestamp to newTimestamp - 1
.
There is no reason to use that expect on the Paxos code path, where we need ensure that
anything inserted use the ballot timestamp (to respect the order of update decided by
the Paxos algorithm). We use newTimestamp - 1
for deletions because tombstones
always win on timestamp equality and we don't want to delete our own insertions
(typically, when we overwrite a collection, we first set a complex deletion to delete the
previous collection before adding new elements. If we were to set that complex deletion
to the same timestamp that the new elements, it would delete those elements). And since
tombstones always wins on timestamp equality, using -1 guarantees our deletion will still
delete anything from a previous update.public int operationCount()
This is used by Memtable
to 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.
public int dataSize()
public PartitionColumns columns()
columns
in interface Partition
columns
in class AbstractBTreePartition
protected AbstractBTreePartition.Holder holder()
holder
in class AbstractBTreePartition
public EncodingStats stats()
stats
in interface Partition
stats
in class AbstractBTreePartition
public void allowNewUpdates()
Please note that calling this method won't result in optimal behavior in the sense that even if very little is added to the update after this call, the whole update will be sorted again on read. This should thus be used sparingly (and if it turns that we end up using this often, we should consider optimizing the behavior).
public java.util.Iterator<Row> iterator()
Note that this might trigger a sorting of the update, and as such the update will not be modifiable anymore after this call.
iterator
in interface java.lang.Iterable<Row>
iterator
in class AbstractBTreePartition
public SliceableUnfilteredRowIterator sliceableUnfilteredIterator(ColumnFilter columns, boolean reversed)
sliceableUnfilteredIterator
in class AbstractBTreePartition
public void validate()
MarshalException
- if some of the data contained in this update is corrupted.public long maxTimestamp()
public java.util.List<PartitionUpdate.CounterMark> collectCounterMarks()
CounterMark
for
every counter contained in the update.public void addPartitionDeletion(DeletionTime deletionTime)
public void add(RangeTombstone range)
public void add(Row row)
row
- the row to add.public java.lang.String toString()
toString
in class AbstractBTreePartition
Copyright © 2016 The Apache Software Foundation