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 class
TxDecisionMaker.LockDecisionMaker<K,V>
static class
TxDecisionMaker.PutIfAbsentDecisionMaker<K,V>
static class
TxDecisionMaker.RepeatableReadLockDecisionMaker<K,V>
-
Field Summary
Fields Modifier and Type Field Description private Transaction
blockingTransaction
private MVMap.Decision
decision
protected K
key
Key for the map entry to decide uponprivate long
lastOperationId
Id of the last operation, we decided toMVMap.Decision.REPEAT
.private V
lastValue
private int
mapId
Map to decide uponprivate Transaction
transaction
Transaction we are operating withinprivate long
undoKey
Id for the undo log entry created for this modificationprivate V
value
Value 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) boolean
allowNonRepeatableRead()
MVMap.Decision
decide(VersionedValue<V> existingValue, VersionedValue<V> providedValue)
Makes a decision about how to proceed with the update.(package private) MVMap.Decision
decideToAbort(V lastValue)
(package private) Transaction
getBlockingTransaction()
(package private) MVMap.Decision
getDecision()
(package private) V
getLastValue()
(package private) V
getNewValue(VersionedValue<V> existingValue)
Get the new value.(package private) void
initialize(K key, V value)
(package private) boolean
isCommitted(int transactionId)
Determine whether specified id corresponds to a logically committed transaction.(package private) boolean
isRepeatedOperation(long id)
Store operation id provided, but before that, compare it against last stored one.(package private) boolean
isThisTransaction(int transactionId)
Check whether specified transaction id belongs to "current" transaction (transaction we are acting within).(package private) MVMap.Decision
logAndDecideToPut(VersionedValue<V> valueToLog, V lastValue)
Create undo log entry and record for future referencesMVMap.Decision.PUT
decision along with last known committed valuevoid
reset()
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.Decision
setDecision(MVMap.Decision decision)
Record for future references specified value as a decision that has been made.java.lang.String
toString()
-
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.DecisionMaker
Makes a decision about how to proceed with the update.- Specified by:
decide
in 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.DecisionMaker
Resets 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:
reset
in classMVMap.DecisionMaker<VersionedValue<V>>
-
selectValue
public <T extends VersionedValue<V>> T selectValue(T existingValue, T providedValue)
Description copied from class:MVMap.DecisionMaker
Provides 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:
selectValue
in 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.PUT
decision 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:
toString
in classjava.lang.Object
-
-