public class SessionState extends Object
| Modifier and Type | Field and Description |
|---|---|
static int |
CURRENT_VERSION
The current version format used on export, respected on import to aid backwards compatibility.
|
static long |
NO_END_SEQNO
The highest possible sequence number,
(2^64)-1. |
| Constructor and Description |
|---|
SessionState()
Initializes with an empty partition state for 1024 partitions.
|
| Modifier and Type | Method and Description |
|---|---|
byte[] |
export(StateFormat format)
Export the
PartitionState into the desired format. |
void |
foreachPartition(BiConsumer<Integer,PartitionState> consumer) |
void |
foreachPartition(Consumer<PartitionState> action)
Provides an iterator over all partitions, calling the callback for each one.
|
PartitionState |
get(int partition)
Accessor into the partition state, only use this if really needed.
|
boolean |
isAtEnd()
Check if the current sequence numbers for all partitions are >= the ones set as end.
|
void |
rollbackToPosition(int partition,
long seqno)
Helper method to rollback the given partition to the given sequence number.
|
void |
set(int partition,
PartitionState partitionState)
Accessor to set/override the current partition state, only use this if really needed.
|
void |
setFromJson(byte[] persisted)
Recovers the session state from persisted JSON.
|
void |
setToBeginningWithNoEnd(int numPartitions)
Initializes all partition states to start at the beginning (0) with no end.
|
String |
toString() |
public static final long NO_END_SEQNO
(2^64)-1. Sequence numbers must be interpreted as unsigned values.
When comparing two sequence numbers to see which is greater, use Long.compareUnsigned.public static final int CURRENT_VERSION
public SessionState()
public void setToBeginningWithNoEnd(int numPartitions)
numPartitions - the actual number of partitions used.public void setFromJson(byte[] persisted)
persisted - the persisted JSON format.public PartitionState get(int partition)
If you want to avoid going out of bounds, use the simpler iterator way on foreachPartition(Consumer).
partition - the index of the partition.public void set(int partition,
PartitionState partitionState)
partition - the index of the partition.partitionState - the partition state to override.public boolean isAtEnd()
public void rollbackToPosition(int partition,
long seqno)
This will set the seqno AND REMOVE ALL ENTRIES from the failover log that are higher than the given sequence number!
partition - the partition to rollbackseqno - the sequence number where to roll it back to.public void foreachPartition(Consumer<PartitionState> action)
action - the action to be called with the state for every partition.public void foreachPartition(BiConsumer<Integer,PartitionState> consumer)
public byte[] export(StateFormat format)
PartitionState into the desired format.format - the format in which the state should be exposed, always uses the current version.Copyright © 2021 Couchbase, Inc.. All rights reserved.