Search in sources :

Example 1 with MvccVersion

use of org.apache.ignite.internal.processors.cache.mvcc.MvccVersion in project ignite by apache.

the class RecordDataV2Serializer method readMvccDataEntry.

/**
 * @param in Input to read from.
 * @return Read entry.
 */
private MvccDataEntry readMvccDataEntry(ByteBufferBackedDataInput in) throws IOException, IgniteCheckedException {
    int cacheId = in.readInt();
    int keySize = in.readInt();
    byte keyType = in.readByte();
    byte[] keyBytes = new byte[keySize];
    in.readFully(keyBytes);
    int valSize = in.readInt();
    byte valType = 0;
    byte[] valBytes = null;
    if (valSize >= 0) {
        valType = in.readByte();
        valBytes = new byte[valSize];
        in.readFully(valBytes);
    }
    byte ord = in.readByte();
    GridCacheOperation op = GridCacheOperation.fromOrdinal(ord & 0xFF);
    GridCacheVersion nearXidVer = readVersion(in, true);
    GridCacheVersion writeVer = readVersion(in, false);
    int partId = in.readInt();
    long partCntr = in.readLong();
    long expireTime = in.readLong();
    MvccVersion mvccVer = txRecordSerializer.readMvccVersion(in);
    GridCacheContext cacheCtx = cctx.cacheContext(cacheId);
    if (cacheCtx != null) {
        CacheObjectContext coCtx = cacheCtx.cacheObjectContext();
        KeyCacheObject key = co.toKeyCacheObject(coCtx, keyType, keyBytes);
        if (key.partition() == -1)
            key.partition(partId);
        CacheObject val = valBytes != null ? co.toCacheObject(coCtx, valType, valBytes) : null;
        return new MvccDataEntry(cacheId, key, val, op, nearXidVer, writeVer, expireTime, partId, partCntr, mvccVer);
    } else
        return new LazyMvccDataEntry(cctx, cacheId, keyType, keyBytes, valType, valBytes, op, nearXidVer, writeVer, expireTime, partId, partCntr, mvccVer);
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) MvccDataEntry(org.apache.ignite.internal.pagemem.wal.record.MvccDataEntry) LazyMvccDataEntry(org.apache.ignite.internal.pagemem.wal.record.LazyMvccDataEntry) CacheObjectContext(org.apache.ignite.internal.processors.cache.CacheObjectContext) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) MvccVersion(org.apache.ignite.internal.processors.cache.mvcc.MvccVersion) LazyMvccDataEntry(org.apache.ignite.internal.pagemem.wal.record.LazyMvccDataEntry) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) GridCacheOperation(org.apache.ignite.internal.processors.cache.GridCacheOperation) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 2 with MvccVersion

use of org.apache.ignite.internal.processors.cache.mvcc.MvccVersion in project ignite by apache.

the class TxRecordSerializer method readMvccTx.

/**
 * Reads {@link MvccTxRecord} from given input.
 *
 * @param in Input
 * @return MvccTxRecord.
 * @throws IOException In case of fail.
 */
public MvccTxRecord readMvccTx(ByteBufferBackedDataInput in) throws IOException {
    byte txState = in.readByte();
    TransactionState state = TransactionState.fromOrdinal(txState);
    GridCacheVersion nearXidVer = RecordV1Serializer.readVersion(in, true);
    GridCacheVersion writeVer = RecordV1Serializer.readVersion(in, true);
    MvccVersion mvccVer = readMvccVersion(in);
    int participatingNodesSize = in.readInt();
    Map<Short, Collection<Short>> participatingNodes = U.newHashMap(participatingNodesSize);
    for (int i = 0; i < participatingNodesSize; i++) {
        short primaryNode = in.readShort();
        int backupNodesSize = in.readInt();
        Collection<Short> backupNodes = new ArrayList<>(backupNodesSize);
        for (int j = 0; j < backupNodesSize; j++) {
            short backupNode = in.readShort();
            backupNodes.add(backupNode);
        }
        participatingNodes.put(primaryNode, backupNodes);
    }
    long ts = in.readLong();
    return new MvccTxRecord(state, nearXidVer, writeVer, participatingNodes, mvccVer, ts);
}
Also used : TransactionState(org.apache.ignite.transactions.TransactionState) ArrayList(java.util.ArrayList) MvccTxRecord(org.apache.ignite.internal.pagemem.wal.record.MvccTxRecord) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) MvccVersion(org.apache.ignite.internal.processors.cache.mvcc.MvccVersion) Collection(java.util.Collection)

Example 3 with MvccVersion

use of org.apache.ignite.internal.processors.cache.mvcc.MvccVersion in project ignite by apache.

the class MvccFirstRowTreeClosure method apply.

/**
 * {@inheritDoc}
 */
@Override
public boolean apply(BPlusTree<CacheSearchRow, CacheDataRow> tree, BPlusIO<CacheSearchRow> io, long pageAddr, int idx) throws IgniteCheckedException {
    RowLinkIO rowIo = (RowLinkIO) io;
    MvccVersion newVersion = getNewVersion(cctx, rowIo.getLink(pageAddr, idx));
    if (newVersion == null)
        res = tree.getRow(io, pageAddr, idx, CacheDataRowAdapter.RowData.NO_KEY);
    // Stop search.
    return false;
}
Also used : MvccVersion(org.apache.ignite.internal.processors.cache.mvcc.MvccVersion) RowLinkIO(org.apache.ignite.internal.processors.cache.tree.RowLinkIO)

Example 4 with MvccVersion

use of org.apache.ignite.internal.processors.cache.mvcc.MvccVersion in project ignite by apache.

the class GridCacheMapEntry method mvccLock.

/**
 * {@inheritDoc}
 */
@Override
public GridCacheUpdateTxResult mvccLock(GridDhtTxLocalAdapter tx, MvccSnapshot mvccVer) throws GridCacheEntryRemovedException, IgniteCheckedException {
    assert tx != null;
    assert mvccVer != null;
    final boolean valid = valid(tx.topologyVersion());
    final GridCacheVersion newVer;
    WALPointer logPtr = null;
    lockEntry();
    try {
        checkObsolete();
        newVer = tx.writeVersion();
        assert newVer != null : "Failed to get write version for tx: " + tx;
        assert tx.local();
        MvccUpdateResult res = cctx.offheap().mvccLock(this, mvccVer);
        assert res != null;
        if (res.resultType() == ResultType.VERSION_MISMATCH)
            throw serializationError();
        else if (res.resultType() == ResultType.LOCKED) {
            unlockEntry();
            MvccVersion lockVer = res.resultVersion();
            GridFutureAdapter<GridCacheUpdateTxResult> resFut = new GridFutureAdapter<>();
            IgniteInternalFuture<?> lockFut = cctx.kernalContext().coordinators().waitForLock(cctx, mvccVer, lockVer);
            lockFut.listen(new MvccAcquireLockListener(tx, this, mvccVer, resFut));
            return new GridCacheUpdateTxResult(false, resFut);
        }
    } finally {
        if (lockedByCurrentThread()) {
            unlockEntry();
            cctx.evicts().touch(this);
        }
    }
    onUpdateFinished(0L);
    return new GridCacheUpdateTxResult(valid, logPtr);
}
Also used : GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) MvccVersion(org.apache.ignite.internal.processors.cache.mvcc.MvccVersion) MvccUpdateResult(org.apache.ignite.internal.processors.cache.tree.mvcc.data.MvccUpdateResult) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)

Example 5 with MvccVersion

use of org.apache.ignite.internal.processors.cache.mvcc.MvccVersion in project ignite by apache.

the class GridCacheMapEntry method mvccRemove.

/**
 * {@inheritDoc}
 */
@Override
public final GridCacheUpdateTxResult mvccRemove(IgniteInternalTx tx, UUID affNodeId, AffinityTopologyVersion topVer, MvccSnapshot mvccVer, boolean needHistory, boolean needOldVal, @Nullable CacheEntryPredicate filter, boolean retVal) throws IgniteCheckedException, GridCacheEntryRemovedException {
    assert tx != null;
    assert mvccVer != null;
    final boolean valid = valid(tx.topologyVersion());
    final GridCacheVersion newVer;
    WALPointer logPtr = null;
    lockEntry();
    MvccUpdateResult res;
    try {
        checkObsolete();
        newVer = tx.writeVersion();
        assert newVer != null : "Failed to get write version for tx: " + tx;
        res = cctx.offheap().mvccRemove(this, mvccVer, tx.local(), needHistory, needOldVal, filter, retVal);
        assert res != null;
        if (res.resultType() == ResultType.VERSION_MISMATCH)
            throw serializationError();
        else if (res.resultType() == ResultType.PREV_NULL)
            return new GridCacheUpdateTxResult(false);
        else if (res.resultType() == ResultType.FILTERED) {
            GridCacheUpdateTxResult updRes = new GridCacheUpdateTxResult(false);
            updRes.filtered(true);
            return updRes;
        } else if (res.resultType() == ResultType.LOCKED) {
            unlockEntry();
            MvccVersion lockVer = res.resultVersion();
            GridFutureAdapter<GridCacheUpdateTxResult> resFut = new GridFutureAdapter<>();
            IgniteInternalFuture<?> lockFut = cctx.kernalContext().coordinators().waitForLock(cctx, mvccVer, lockVer);
            lockFut.listen(new MvccRemoveLockListener(tx, this, affNodeId, topVer, mvccVer, needHistory, resFut, needOldVal, retVal, filter));
            return new GridCacheUpdateTxResult(false, resFut);
        }
        if (cctx.deferredDelete() && deletedUnlocked() && !detached())
            deletedUnlocked(false);
        if (res.resultType() == ResultType.PREV_NOT_NULL) {
            TxCounters counters = tx.txCounters(true);
            if (compareIgnoreOpCounter(res.resultVersion(), mvccVer) == 0) {
                if (// Do not count own update removal.
                res.isKeyAbsentBefore())
                    counters.decrementUpdateCounter(cctx.cacheId(), partition());
            } else
                counters.incrementUpdateCounter(cctx.cacheId(), partition());
            counters.accumulateSizeDelta(cctx.cacheId(), partition(), -1);
        }
        if (cctx.group().persistenceEnabled() && cctx.group().walEnabled())
            logPtr = logMvccUpdate(tx, null, 0, 0L, mvccVer);
        update(null, 0, 0, newVer, true);
        recordNodeId(affNodeId, topVer);
    } finally {
        if (lockedByCurrentThread()) {
            unlockEntry();
            cctx.evicts().touch(this);
        }
    }
    onUpdateFinished(0L);
    GridCacheUpdateTxResult updRes = valid ? new GridCacheUpdateTxResult(true, 0L, logPtr) : new GridCacheUpdateTxResult(false, logPtr);
    if (retVal && (res.resultType() == ResultType.PREV_NOT_NULL || res.resultType() == ResultType.VERSION_FOUND))
        updRes.prevValue(res.oldValue());
    if (needOldVal && compareIgnoreOpCounter(res.resultVersion(), mvccVer) != 0 && (res.resultType() == ResultType.PREV_NOT_NULL || res.resultType() == ResultType.REMOVED_NOT_NULL))
        updRes.oldValue(res.oldValue());
    updRes.mvccHistory(res.history());
    return updRes;
}
Also used : TxCounters(org.apache.ignite.internal.processors.cache.transactions.TxCounters) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) MvccVersion(org.apache.ignite.internal.processors.cache.mvcc.MvccVersion) MvccUpdateResult(org.apache.ignite.internal.processors.cache.tree.mvcc.data.MvccUpdateResult) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)

Aggregations

MvccVersion (org.apache.ignite.internal.processors.cache.mvcc.MvccVersion)6 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)5 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)3 WALPointer (org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)3 MvccUpdateResult (org.apache.ignite.internal.processors.cache.tree.mvcc.data.MvccUpdateResult)3 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)3 MvccDataEntry (org.apache.ignite.internal.pagemem.wal.record.MvccDataEntry)2 TxCounters (org.apache.ignite.internal.processors.cache.transactions.TxCounters)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 LazyMvccDataEntry (org.apache.ignite.internal.pagemem.wal.record.LazyMvccDataEntry)1 MvccDataRecord (org.apache.ignite.internal.pagemem.wal.record.MvccDataRecord)1 MvccTxRecord (org.apache.ignite.internal.pagemem.wal.record.MvccTxRecord)1 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)1 CacheObjectContext (org.apache.ignite.internal.processors.cache.CacheObjectContext)1 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)1 GridCacheOperation (org.apache.ignite.internal.processors.cache.GridCacheOperation)1 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)1 RowLinkIO (org.apache.ignite.internal.processors.cache.tree.RowLinkIO)1 IgniteTxDuplicateKeyCheckedException (org.apache.ignite.internal.transactions.IgniteTxDuplicateKeyCheckedException)1