Package org.h2.mvstore.tx
Class TxDecisionMaker<K,V>
- java.lang.Object
-
- org.h2.mvstore.MVMap.DecisionMaker<VersionedValue<V>>
-
- org.h2.mvstore.tx.TxDecisionMaker<K,V>
-
- Direct Known Subclasses:
TxDecisionMaker.LockDecisionMaker,TxDecisionMaker.PutIfAbsentDecisionMaker
class TxDecisionMaker<K,V> extends MVMap.DecisionMaker<VersionedValue<V>>
Class TxDecisionMaker is a base implementation of MVMap.DecisionMaker to be used for TransactionMap modification.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTxDecisionMaker.LockDecisionMaker<K,V>static classTxDecisionMaker.PutIfAbsentDecisionMaker<K,V>static classTxDecisionMaker.RepeatableReadLockDecisionMaker<K,V>
-
Field Summary
Fields Modifier and Type Field Description private TransactionblockingTransactionprivate MVMap.Decisiondecisionprotected KkeyKey for the map entry to decide uponprivate longlastOperationIdId of the last operation, we decided toMVMap.Decision.REPEAT.private VlastValueprivate intmapIdMap to decide uponprivate TransactiontransactionTransaction we are operating withinprivate longundoKeyId for the undo log entry created for this modificationprivate VvalueValue for the map entry-
Fields inherited from class org.h2.mvstore.MVMap.DecisionMaker
DEFAULT, PUT, REMOVE
-
-
Constructor Summary
Constructors Constructor Description TxDecisionMaker(int mapId, Transaction transaction)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) booleanallowNonRepeatableRead()MVMap.Decisiondecide(VersionedValue<V> existingValue, VersionedValue<V> providedValue)Makes a decision about how to proceed with the update.(package private) MVMap.DecisiondecideToAbort(V lastValue)(package private) TransactiongetBlockingTransaction()(package private) MVMap.DecisiongetDecision()(package private) VgetLastValue()(package private) VgetNewValue(VersionedValue<V> existingValue)Get the new value.(package private) voidinitialize(K key, V value)(package private) booleanisCommitted(int transactionId)Determine whether specified id corresponds to a logically committed transaction.(package private) booleanisRepeatedOperation(long id)Store operation id provided, but before that, compare it against last stored one.(package private) booleanisThisTransaction(int transactionId)Check whether specified transaction id belongs to "current" transaction (transaction we are acting within).(package private) MVMap.DecisionlogAndDecideToPut(VersionedValue<V> valueToLog, V lastValue)Create undo log entry and record for future referencesMVMap.Decision.PUTdecision along with last known committed valuevoidreset()Resets internal state (if any) of a this DecisionMaker to it's initial state.<T extends VersionedValue<V>>
TselectValue(T existingValue, T providedValue)Provides revised value for insert/update based on original input value and value currently existing in the map.(package private) MVMap.DecisionsetDecision(MVMap.Decision decision)Record for future references specified value as a decision that has been made.java.lang.StringtoString()-
Methods inherited from class org.h2.mvstore.MVMap.DecisionMaker
decide
-
-
-
-
Field Detail
-
mapId
private final int mapId
Map to decide upon
-
key
protected K key
Key for the map entry to decide upon
-
value
private V value
Value for the map entry
-
transaction
private final Transaction transaction
Transaction we are operating within
-
undoKey
private long undoKey
Id for the undo log entry created for this modification
-
lastOperationId
private long lastOperationId
Id of the last operation, we decided toMVMap.Decision.REPEAT.
-
blockingTransaction
private Transaction blockingTransaction
-
decision
private MVMap.Decision decision
-
lastValue
private V lastValue
-
-
Constructor Detail
-
TxDecisionMaker
TxDecisionMaker(int mapId, Transaction transaction)
-
-
Method Detail
-
decide
public MVMap.Decision decide(VersionedValue<V> existingValue, VersionedValue<V> providedValue)
Description copied from class:MVMap.DecisionMakerMakes a decision about how to proceed with the update.- Specified by:
decidein classMVMap.DecisionMaker<VersionedValue<V>>- Parameters:
existingValue- value currently exists in the mapprovidedValue- original input value- Returns:
- PUT if a new value need to replace existing one or a new value to be inserted if there is none REMOVE if existing value should be deleted ABORT if update operation should be aborted or repeated later REPEAT if update operation should be repeated immediately
-
reset
public final void reset()
Description copied from class:MVMap.DecisionMakerResets internal state (if any) of a this DecisionMaker to it's initial state. This method is invoked whenever concurrent update failure is encountered, so we can re-start update process.- Overrides:
resetin classMVMap.DecisionMaker<VersionedValue<V>>
-
selectValue
public <T extends VersionedValue<V>> T selectValue(T existingValue, T providedValue)
Description copied from class:MVMap.DecisionMakerProvides revised value for insert/update based on original input value and value currently existing in the map. This method is only invoked after call to decide(), if it returns PUT.- Overrides:
selectValuein classMVMap.DecisionMaker<VersionedValue<V>>- Type Parameters:
T- value type- Parameters:
existingValue- value currently exists in the mapprovidedValue- original input value- Returns:
- value to be used by insert/update
-
getNewValue
V getNewValue(VersionedValue<V> existingValue)
Get the new value. This implementation always return the current value (ignores the parameter).- Parameters:
existingValue- the parameter value- Returns:
- the current value.
-
logAndDecideToPut
MVMap.Decision logAndDecideToPut(VersionedValue<V> valueToLog, V lastValue)
Create undo log entry and record for future referencesMVMap.Decision.PUTdecision along with last known committed value- Parameters:
valueToLog- previous value to be loggedlastValue- last known committed value- Returns:
MVMap.Decision.PUT
-
decideToAbort
final MVMap.Decision decideToAbort(V lastValue)
-
allowNonRepeatableRead
final boolean allowNonRepeatableRead()
-
getDecision
final MVMap.Decision getDecision()
-
getBlockingTransaction
final Transaction getBlockingTransaction()
-
getLastValue
final V getLastValue()
-
isThisTransaction
final boolean isThisTransaction(int transactionId)
Check whether specified transaction id belongs to "current" transaction (transaction we are acting within).- Parameters:
transactionId- to check- Returns:
- true it it is "current" transaction's id, false otherwise
-
isCommitted
final boolean isCommitted(int transactionId)
Determine whether specified id corresponds to a logically committed transaction. In case of pending transaction, reference to actual Transaction object (if any) is preserved for future use.- Parameters:
transactionId- to use- Returns:
- true if transaction should be considered as committed, false otherwise
-
isRepeatedOperation
final boolean isRepeatedOperation(long id)
Store operation id provided, but before that, compare it against last stored one. This is to prevent an infinite loop in case of uncommitted "leftover" entry (one without a corresponding undo log entry, most likely as a result of unclean shutdown).- Parameters:
id- for the operation we decided toMVMap.Decision.REPEAT- Returns:
- true if the same as last operation id, false otherwise
-
setDecision
final MVMap.Decision setDecision(MVMap.Decision decision)
Record for future references specified value as a decision that has been made.- Parameters:
decision- made- Returns:
- argument provided
-
toString
public final java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-