use of org.gridgain.internal.h2.value.VersionedValue in project h2database by h2database.
the class TransactionMap method useSnapshot.
/**
* Gets a coherent picture of committing transactions and root reference,
* passes it to the specified function, and returns its result.
*
* @param <R> type of the result
*
* @param snapshotConsumer
* function to invoke on a snapshot
* @return function's result
*/
<R> R useSnapshot(BiFunction<RootReference<K, VersionedValue<V>>, BitSet, R> snapshotConsumer) {
// The purpose of the following loop is to get a coherent picture
// of a state of two independent volatile / atomic variables,
// which they had at some recent moment in time.
// In order to get such a "snapshot", we wait for a moment of silence,
// when neither of the variables concurrently changes it's value.
AtomicReference<BitSet> holder = transaction.store.committingTransactions;
BitSet committingTransactions = holder.get();
while (true) {
BitSet prevCommittingTransactions = committingTransactions;
RootReference<K, VersionedValue<V>> root = map.getRoot();
committingTransactions = holder.get();
if (committingTransactions == prevCommittingTransactions) {
return snapshotConsumer.apply(root, committingTransactions);
}
}
}
use of org.gridgain.internal.h2.value.VersionedValue in project apollo by salesforce.
the class SessionLocal method onRollback.
@Override
public void onRollback(MVMap<Object, VersionedValue<Object>> map, Object key, VersionedValue<Object> existingValue, VersionedValue<Object> restoredValue) {
// Here we are relying on the fact that map which backs table's primary index
// has the same name as the table itself
Store store = database.getStore();
MVTable table = store.getTable(map.getName());
if (table != null) {
Row oldRow = existingValue == null ? null : (Row) existingValue.getCurrentValue();
Row newRow = restoredValue == null ? null : (Row) restoredValue.getCurrentValue();
table.fireAfterRow(this, oldRow, newRow, true);
if (table.getContainsLargeObject()) {
if (oldRow != null) {
for (int i = 0, len = oldRow.getColumnCount(); i < len; i++) {
Value v = oldRow.getValue(i);
if (v instanceof ValueLob) {
removeAtCommit((ValueLob) v);
}
}
}
if (newRow != null) {
for (int i = 0, len = newRow.getColumnCount(); i < len; i++) {
Value v = newRow.getValue(i);
if (v instanceof ValueLob) {
removeAtCommitStop((ValueLob) v);
}
}
}
}
}
}
use of org.gridgain.internal.h2.value.VersionedValue in project gridgain by gridgain.
the class RollbackDecisionMaker method decide.
@Override
public MVMap.Decision decide(Object[] existingValue, Object[] providedValue) {
assert decision == null;
if (existingValue == null) {
// normally existingValue will always be there except of db initialization
// where some undo log entry was captured on disk but actual map entry was not
decision = MVMap.Decision.ABORT;
} else {
VersionedValue valueToRestore = (VersionedValue) existingValue[2];
long operationId;
if (valueToRestore == null || (operationId = valueToRestore.getOperationId()) == 0 || TransactionStore.getTransactionId(operationId) == transactionId && TransactionStore.getLogId(operationId) < toLogId) {
int mapId = (Integer) existingValue[0];
MVMap<Object, VersionedValue> map = store.openMap(mapId);
if (map != null && !map.isClosed()) {
Object key = existingValue[1];
VersionedValue previousValue = map.operate(key, valueToRestore, MVMap.DecisionMaker.DEFAULT);
listener.onRollback(map, key, previousValue, valueToRestore);
}
}
decision = MVMap.Decision.REMOVE;
}
return decision;
}
use of org.gridgain.internal.h2.value.VersionedValue in project gridgain by gridgain.
the class TransactionMap method isSameTransaction.
/**
* Whether the entry for this key was added or removed from this
* session.
*
* @param key the key
* @return true if yes
*/
public boolean isSameTransaction(K key) {
VersionedValue data = map.get(key);
if (data == null) {
// doesn't exist or deleted by a committed transaction
return false;
}
int tx = TransactionStore.getTransactionId(data.getOperationId());
return tx == transaction.transactionId;
}
use of org.gridgain.internal.h2.value.VersionedValue in project gridgain by gridgain.
the class TransactionMap method putCommitted.
/**
* Update the value for the given key, without adding an undo log entry.
*
* @param key the key
* @param value the value
* @return the old value
*/
public V putCommitted(K key, V value) {
DataUtils.checkArgument(value != null, "The value may not be null");
VersionedValue newValue = VersionedValueCommitted.getInstance(value);
VersionedValue oldValue = map.put(key, newValue);
@SuppressWarnings("unchecked") V result = (V) (oldValue == null ? null : oldValue.getCurrentValue());
return result;
}
Aggregations