Package org.h2.mvstore.tx
Class TxDecisionMaker<K,V>
- Direct Known Subclasses:
TxDecisionMaker.LockDecisionMaker
,TxDecisionMaker.PutIfAbsentDecisionMaker
Class TxDecisionMaker is a base implementation of MVMap.DecisionMaker
to be used for TransactionMap modification.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static final class
static final class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Transaction
private MVMap.Decision
protected K
Key for the map entry to decide uponprivate long
Id of the last operation, we decided toMVMap.Decision.REPEAT
.private V
private final int
Map to decide uponprivate final Transaction
Transaction we are operating withinprivate long
Id for the undo log entry created for this modificationprivate V
Value for the map entryFields inherited from class org.h2.mvstore.MVMap.DecisionMaker
DEFAULT, PUT, REMOVE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) final boolean
decide
(VersionedValue<V> existingValue, VersionedValue<V> providedValue) Makes a decision about how to proceed with the update.(package private) final MVMap.Decision
decideToAbort
(V lastValue) (package private) final Transaction
(package private) final MVMap.Decision
(package private) final V
(package private) V
getNewValue
(VersionedValue<V> existingValue) Get the new value.(package private) void
initialize
(K key, V value) (package private) final boolean
isCommitted
(int transactionId) Determine whether specified id corresponds to a logically committed transaction.(package private) final boolean
isRepeatedOperation
(long id) Store operation id provided, but before that, compare it against last stored one.(package private) final 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 valuefinal void
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) final MVMap.Decision
setDecision
(MVMap.Decision decision) Record for future references specified value as a decision that has been made.final String
toString()
Methods inherited from class org.h2.mvstore.MVMap.DecisionMaker
decide
-
Field Details
-
mapId
private final int mapIdMap to decide upon -
key
Key for the map entry to decide upon -
value
Value for the map entry -
transaction
Transaction we are operating within -
undoKey
private long undoKeyId for the undo log entry created for this modification -
lastOperationId
private long lastOperationIdId of the last operation, we decided toMVMap.Decision.REPEAT
. -
blockingTransaction
-
decision
-
lastValue
-
-
Constructor Details
-
TxDecisionMaker
TxDecisionMaker(int mapId, Transaction transaction)
-
-
Method Details
-
initialize
-
decide
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
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
Get the new value. This implementation always return the current value (ignores the parameter).- Parameters:
existingValue
- the parameter value- Returns:
- the current value.
-
logAndDecideToPut
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
-
allowNonRepeatableRead
final boolean allowNonRepeatableRead() -
getDecision
-
getBlockingTransaction
-
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
Record for future references specified value as a decision that has been made.- Parameters:
decision
- made- Returns:
- argument provided
-
toString
-