Search in sources :

Example 1 with VersionedValue

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);
        }
    }
}
Also used : VersionedValue(org.h2.value.VersionedValue) BitSet(java.util.BitSet)

Example 2 with VersionedValue

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);
                    }
                }
            }
        }
    }
}
Also used : ValueLob(org.h2.value.ValueLob) MVTable(org.h2.mvstore.db.MVTable) VersionedValue(org.h2.value.VersionedValue) Value(org.h2.value.Value) Store(org.h2.mvstore.db.Store) TransactionStore(org.h2.mvstore.tx.TransactionStore) Row(org.h2.result.Row) Constraint(org.h2.constraint.Constraint)

Example 3 with VersionedValue

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;
}
Also used : VersionedValue(org.gridgain.internal.h2.value.VersionedValue)

Example 4 with VersionedValue

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;
}
Also used : VersionedValue(org.gridgain.internal.h2.value.VersionedValue)

Example 5 with VersionedValue

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;
}
Also used : VersionedValue(org.gridgain.internal.h2.value.VersionedValue)

Aggregations

VersionedValue (org.h2.value.VersionedValue)19 VersionedValue (org.gridgain.internal.h2.value.VersionedValue)13 BitSet (java.util.BitSet)7 Value (org.h2.value.Value)7 Spatial (org.h2.mvstore.rtree.Spatial)6 Constraint (org.h2.constraint.Constraint)4 MVTable (org.h2.mvstore.db.MVTable)4 Store (org.h2.mvstore.db.Store)4 TransactionStore (org.h2.mvstore.tx.TransactionStore)4 Row (org.h2.result.Row)4 ValueLob (org.h2.value.ValueLob)4 IsolationLevel (org.h2.engine.IsolationLevel)3 MVStoreException (org.h2.mvstore.MVStoreException)3 RootReference (org.h2.mvstore.RootReference)3 MVMap (org.gridgain.internal.h2.mvstore.MVMap)2 Row (org.gridgain.internal.h2.result.Row)2 Iterator (java.util.Iterator)1 Constraint (org.gridgain.internal.h2.constraint.Constraint)1 Cursor (org.gridgain.internal.h2.mvstore.Cursor)1 Page (org.gridgain.internal.h2.mvstore.Page)1