Class TransactionMap<K,V>
- Type Parameters:
K- the key typeV- the value type
- All Implemented Interfaces:
Map<K,V>
Methods of this class may be changed at any time without notice. If you use this class directly make sure that your application or library requires exactly the same version of MVStore or H2 jar as the version that you use during its development and build.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classThe iterator for read committed isolation level.private static final classThe iterator for repeatable read and serializable isolation levels.static classprivate static classThe iterator for read uncommitted isolation level.private static final classNested classes/interfaces inherited from class AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanIndicates whether underlying map was modified from within related transactionprivate final TxDecisionMaker<K, V> private final TxDecisionMaker<K, V> final MVMap<K, VersionedValue<V>> The map used for writing (the latest version).private Snapshot<K, VersionedValue<V>> Snapshot of this map as of beginning of transaction or first usage within transaction or beginning of the statement, depending on isolation levelprivate Snapshot<K, VersionedValue<V>> Snapshot of this map as of beginning of beginning of the statementprivate final TransactionThe transaction which is used for this map.private final TxDecisionMaker<K, V> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate longadjustSize(RootReference<Long, Record<?, ?>>[] undoLogRootReferences, RootReference<K, VersionedValue<V>> mapRootReference, BitSet committingTransactions, long size, long undoLogsTotalSize) voidAppends entry to underlying map.ceilingEntry(K key) Get the entry with smallest key that is larger than or equal to this key, or null if no such key exists.ceilingKey(K key) Get the smallest key that is larger than or equal to this key, or null if no such key exists.private <X> TransactionMap.TMIterator<K, V, X> chooseIterator(K from, K to, boolean reverse, boolean forEntries) voidclear()Clear the map.booleancontainsKey(Object key) Whether the map contains the key.(package private) Snapshot<K, VersionedValue<V>> Create a new snapshot for this map.entryIterator(K from, K to) Iterate over entries.entrySet()Get the first entry.firstKey()Get the first key.floorEntry(K key) Get the entry with largest key that is smaller than or equal to this key, or null if no such key exists.Get the largest key that is smaller than or equal to this key, or null if no such key exists.Get the effective value for the given key.getFromSnapshot(K key) Get the value for the given key, or null if value does not exist in accordance with transactional rules.private VgetFromSnapshot(RootReference<K, VersionedValue<V>> rootRef, BitSet committingTransactions, K key) getImmediate(K key) Get the value for the given key, or null if not found.getInstance(Transaction transaction) Get a clone of this map for the given transaction.(package private) Snapshot<K, VersionedValue<V>> (package private) Snapshot<K, VersionedValue<V>> higherEntry(K key) Get the entry with smallest key that is larger than the given key, or null if no such key exists.Get the smallest key that is larger than the given key, or null if no such key exists.higherLowerEntry(K key, boolean lower) private KhigherLowerKey(K key, boolean lower) booleanisClosed()Check whether this map is closed.booleanCheck if the row was deleted by this transaction.private booleanisIrrelevant(long operationId, VersionedValue<?> currentValue, BitSet committingTransactions) booleanisSameTransaction(K key) Whether the entry for this key was added or removed from this session.keyIterator(K from) Iterate over keys.keyIterator(K from, boolean reverse) Iterate over keys in the specified order.keyIterator(K from, K to) Iterate over keys.keyIteratorUncommitted(K from, K to) Iterate over keys, including keys from uncommitted entries.Get the last entry.lastKey()Get the last key.Lock row for the given key.lowerEntry(K key) Get the entry with largest key that is smaller than the given key, or null if no such key exists.Get the largest key that is smaller than the given key, or null if no such key exists.(package private) voidUpdate the value for the given key.putCommitted(K key, V value) Update the value for the given key, without adding an undo log entry.putIfAbsent(K key, V value) Put the value for the given key if entry for this key does not exist.Remove an entry.private Vset(Object key, TxDecisionMaker<K, V> decisionMaker) private V(package private) voidsetStatementSnapshot(Snapshot<K, VersionedValue<V>> snapshot) intsize()Get the number of entries, as a integer.longGet the size of the map as seen by this transaction.longGet the size of the raw map.private longbooleanTry to update the value for the given key.booleanTry to remove the value for the given key.booleanTry to set or remove the value.(package private) <R> RuseSnapshot(BiFunction<RootReference<K, VersionedValue<V>>, BitSet, R> snapshotConsumer) Gets a coherent picture of committing transactions and root reference, passes it to the specified function, and returns its result.Methods inherited from class AbstractMap
clone, containsValue, equals, hashCode, isEmpty, keySet, putAll, toString, valuesMethods inherited from interface Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, remove, replace, replace, replaceAll
-
Field Details
-
map
The map used for writing (the latest version).Key: key the key of the data. Value: { transactionId, oldVersion, value }
-
transaction
The transaction which is used for this map. -
snapshot
Snapshot of this map as of beginning of transaction or first usage within transaction or beginning of the statement, depending on isolation level -
statementSnapshot
Snapshot of this map as of beginning of beginning of the statement -
hasChanges
private boolean hasChangesIndicates whether underlying map was modified from within related transaction -
txDecisionMaker
-
ifAbsentDecisionMaker
-
lockDecisionMaker
-
-
Constructor Details
-
TransactionMap
TransactionMap(Transaction transaction, MVMap<K, VersionedValue<V>> map)
-
-
Method Details
-
getInstance
Get a clone of this map for the given transaction.- Parameters:
transaction- the transaction- Returns:
- the map
-
size
public int size()Get the number of entries, as a integer.Integer.MAX_VALUEis returned if there are more than this entries. -
sizeAsLongMax
public long sizeAsLongMax()Get the size of the raw map. This includes uncommitted entries, and transiently removed entries, so it is the maximum number of entries.- Returns:
- the maximum size
-
sizeAsLong
public long sizeAsLong()Get the size of the map as seen by this transaction.- Returns:
- the size
-
adjustSize
private long adjustSize(RootReference<Long, Record<?, ?>>[] undoLogRootReferences, RootReference<K, VersionedValue<V>> mapRootReference, BitSet committingTransactions, long size, long undoLogsTotalSize) -
isIrrelevant
private boolean isIrrelevant(long operationId, VersionedValue<?> currentValue, BitSet committingTransactions) -
sizeAsLongRepeatableReadWithChanges
private long sizeAsLongRepeatableReadWithChanges() -
remove
Remove an entry.If the row is locked, this method will retry until the row could be updated or until a lock timeout.
- Specified by:
removein interfaceMap<K,V> - Overrides:
removein classAbstractMap<K,V> - Parameters:
key- the key- Throws:
MVStoreException- if a lock timeout occursClassCastException- if type of the specified key is not compatible with this map
-
put
Update the value for the given key.If the row is locked, this method will retry until the row could be updated or until a lock timeout.
- Specified by:
putin interfaceMap<K,V> - Overrides:
putin classAbstractMap<K,V> - Parameters:
key- the keyvalue- the new value (not null)- Returns:
- the old value
- Throws:
MVStoreException- if a lock timeout occurs
-
putIfAbsent
-
append
-
lock
Lock row for the given key.If the row is locked, this method will retry until the row could be updated or until a lock timeout.
- Parameters:
key- the key- Returns:
- the locked value
- Throws:
MVStoreException- if a lock timeout occurs
-
putCommitted
-
set
-
set
-
tryRemove
Try to remove the value for the given key.This will fail if the row is locked by another transaction (that means, if another open transaction changed the row).
- Parameters:
key- the key- Returns:
- whether the entry could be removed
-
tryPut
-
trySet
Try to set or remove the value. When updating only unchanged entries, then the value is only changed if it was not changed after opening the map.- Parameters:
key- the keyvalue- the new value (null to remove the value)- Returns:
- true if the value was set, false if there was a concurrent update
-
get
-
getFromSnapshot
-
getFromSnapshot
private V getFromSnapshot(RootReference<K, VersionedValue<V>> rootRef, BitSet committingTransactions, K key) -
getImmediate
-
getSnapshot
Snapshot<K, VersionedValue<V>> getSnapshot() -
getStatementSnapshot
Snapshot<K, VersionedValue<V>> getStatementSnapshot() -
setStatementSnapshot
-
promoteSnapshot
void promoteSnapshot() -
createSnapshot
Snapshot<K, VersionedValue<V>> createSnapshot()Create a new snapshot for this map.- Returns:
- the snapshot
-
useSnapshot
Gets a coherent picture of committing transactions and root reference, passes it to the specified function, and returns its result.- Type Parameters:
R- type of the result- Parameters:
snapshotConsumer- function to invoke on a snapshot- Returns:
- function's result
-
containsKey
Whether the map contains the key.- Specified by:
containsKeyin interfaceMap<K,V> - Overrides:
containsKeyin classAbstractMap<K,V> - Parameters:
key- the key- Returns:
- true if the map contains an entry for this key
- Throws:
ClassCastException- if type of the specified key is not compatible with this map
-
isDeletedByCurrentTransaction
Check if the row was deleted by this transaction.- Parameters:
key- the key- Returns:
trueif it was
-
isSameTransaction
Whether the entry for this key was added or removed from this session.- Parameters:
key- the key- Returns:
- true if yes
-
isClosed
public boolean isClosed()Check whether this map is closed.- Returns:
- true if closed
-
clear
-
entrySet
-
firstEntry
-
firstKey
-
lastEntry
-
lastKey
-
higherEntry
-
higherKey
-
ceilingEntry
-
ceilingKey
-
floorEntry
-
floorKey
-
lowerEntry
-
lowerKey
-
higherLowerEntry
-
higherLowerKey
-
keyIterator
-
keyIterator
Iterate over keys in the specified order.- Parameters:
from- the first key to returnreverse- if true, iterate in reverse (descending) order- Returns:
- the iterator
-
keyIterator
-
keyIteratorUncommitted
-
entryIterator
-
chooseIterator
private <X> TransactionMap.TMIterator<K,V, chooseIteratorX> (K from, K to, boolean reverse, boolean forEntries) -
getTransaction
-
getKeyType
-