Class Writes
KVStore
.
Each mutation is either a key/value put, the removal of a key range (possibly containing only a single key), or a counter adjustment.
Instances are not thread safe.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Deprecated.void
Apply all mutations contained in this instance to the givenKVStore
.void
clear()
Clear all mutations.clone()
Clone this instance.static Writes
deserialize
(InputStream input) Deserialize a mutable instance created byserialize()
.static Writes
deserialize
(InputStream input, boolean immutable) Deserialize an instance created byserialize()
.static Mutations
deserializeOnline
(InputStream input) Get the counter adjustments contained by this instance.NavigableMap<byte[],
Long> Get the set of counter adjustments contained by this instance.Get the written key/value pairs contained by this instance.NavigableMap<byte[],
byte[]> getPuts()
Get the written key/value pairs contained by this instance.Get the key ranges removals contained by this instance.Get the key ranges removals contained by this instance.boolean
isEmpty()
Determine whether this instance is empty, i.e., contains zero mutations.Return an immutable snapshot of this instance.void
serialize
(OutputStream out) Serialize this instance.long
Calculate the number of bytes required to serialize this instance viaserialize()
.toString()
-
Constructor Details
-
Writes
public Writes()
-
-
Method Details
-
getRemoves
Get the key ranges removals contained by this instance.- Returns:
- key ranges removed
-
getPuts
Get the written key/value pairs contained by this instance.The caller must not modify any of the returned
byte[]
arrays.- Returns:
- mapping from key to corresponding value
-
getAdjusts
Get the set of counter adjustments contained by this instance.The caller must not modify any of the returned
byte[]
arrays.- Returns:
- mapping from key to corresponding counter adjustment
-
isEmpty
public boolean isEmpty()Determine whether this instance is empty, i.e., contains zero mutations.- Returns:
- true if this instance contains zero mutations, otherwise false
-
clear
public void clear()Clear all mutations. -
getRemoveRanges
Description copied from interface:Mutations
Get the key ranges removals contained by this instance.- Specified by:
getRemoveRanges
in interfaceMutations
- Returns:
- key ranges removed
-
getPutPairs
Description copied from interface:Mutations
Get the written key/value pairs contained by this instance.The caller must not modify any of the returned
byte[]
arrays.- Specified by:
getPutPairs
in interfaceMutations
- Returns:
- mapping from key to corresponding value
-
getAdjustPairs
Description copied from interface:Mutations
Get the counter adjustments contained by this instance.The caller must not modify any of the returned
byte[]
arrays.- Specified by:
getAdjustPairs
in interfaceMutations
- Returns:
- mapping from key to corresponding counter adjustment
-
applyTo
Apply all mutations contained in this instance to the givenKVStore
.Mutations are applied in this order: removes, puts, counter adjustments.
- Parameters:
target
- target for recorded mutations- Throws:
IllegalArgumentException
- iftarget
is null
-
apply
Deprecated.useKVStore.apply(io.permazen.kv.mvcc.Mutations)
insteadApply all the givenMutations
to the givenKVStore
.Mutations are applied in this order: removes, puts, counter adjustments.
- Parameters:
mutations
- mutations to applytarget
- target for mutations- Throws:
IllegalArgumentException
- if either parameter is nullUnsupportedOperationException
- if this instance is immutable
-
serialize
Serialize this instance.- Parameters:
out
- output- Throws:
IOException
- if an error occurs
-
serializedLength
public long serializedLength()Calculate the number of bytes required to serialize this instance viaserialize()
.- Returns:
- number of serialized bytes
-
deserialize
Deserialize a mutable instance created byserialize()
.Equivalent to
deserialize
(input, false)
.- Parameters:
input
- input stream containing data fromserialize()
- Returns:
- mutable deserialized instance
- Throws:
IllegalArgumentException
- ifinput
is nullIllegalArgumentException
- if malformed input is detectedIOException
- if an I/O error occurs
-
deserialize
Deserialize an instance created byserialize()
.- Parameters:
input
- input stream containing data fromserialize()
immutable
- true for an immutable instance, otherwise false- Returns:
- deserialized instance
- Throws:
IllegalArgumentException
- ifinput
is nullIllegalArgumentException
- if malformed input is detectedIOException
- if an I/O error occurs
-
deserializeOnline
Create an "online"Mutations
view of a serializedWrites
instance.This method returns a
Mutations
instance that decodes the serializedWrites
from the given input in an "online" fashion, i.e., it does not load the whole thing into memory. The returnedMutations
iterators may only be accessed once, and they must be accessed in this order: removes, puts, adjusts. Any duplicate or out-of-order access will result in anIllegalStateException
.If an
IOException
is thrown byinput
, theIterator
being used will throw aRuntimeException
wrapping it; if invalid data is encountered, theIterator
being used will throw anIllegalArgumentException
.- Parameters:
input
- input stream containing data fromserialize()
- Returns:
- online
Mutations
view ofinput
- Throws:
IllegalArgumentException
- ifinput
is null
-
clone
Clone this instance.This is a "mostly deep" clone: all of the mutations are copied, but the actual
byte[]
keys and values, which are already assumed non-mutable, are not copied.The returned clone will always be mutable, even if this instance is not.
-
readOnlySnapshot
Return an immutable snapshot of this instance.- Returns:
- immutable snapshot
-
toString
-
KVStore.apply(io.permazen.kv.mvcc.Mutations)
instead