Search in sources :

Example 6 with MvccDataEntry

use of org.apache.ignite.internal.pagemem.wal.record.MvccDataEntry in project ignite by apache.

the class GridCacheMapEntry method mvccUpdateRowsWithPreloadInfo.

/**
 * {@inheritDoc}
 */
@Override
public GridCacheUpdateTxResult mvccUpdateRowsWithPreloadInfo(IgniteInternalTx tx, UUID affNodeId, AffinityTopologyVersion topVer, List<GridCacheEntryInfo> entries, GridCacheOperation op, MvccSnapshot mvccVer, IgniteUuid futId, int batchNum) throws IgniteCheckedException, GridCacheEntryRemovedException {
    assert mvccVer != null && MvccUtils.mvccVersionIsValid(mvccVer.coordinatorVersion(), mvccVer.counter(), mvccVer.operationCounter());
    assert !F.isEmpty(entries);
    WALPointer logPtr = null;
    ensureFreeSpace();
    CacheObject val = null;
    CacheObject oldVal = null;
    lockEntry();
    try {
        checkObsolete();
        boolean walEnabled = cctx.group().persistenceEnabled() && cctx.group().walEnabled();
        List<DataEntry> walEntries = walEnabled ? new ArrayList<>(entries.size() + 1) : Collections.EMPTY_LIST;
        // or via rebalance.
        for (int i = 0; i < entries.size(); i++) {
            GridCacheMvccEntryInfo info = (GridCacheMvccEntryInfo) entries.get(i);
            assert info.mvccTxState() == TxState.COMMITTED || MvccUtils.compare(info, mvccVer.coordinatorVersion(), mvccVer.counter()) == 0;
            assert info.newMvccTxState() == TxState.COMMITTED || MvccUtils.compareNewVersion(info, mvccVer.coordinatorVersion(), mvccVer.counter()) == 0 || info.newMvccCoordinatorVersion() == MvccUtils.MVCC_CRD_COUNTER_NA;
            boolean added = cctx.offheap().mvccUpdateRowWithPreloadInfo(this, info.value(), info.version(), info.expireTime(), info.mvccVersion(), info.newMvccVersion(), info.mvccTxState(), info.newMvccTxState());
            if (walEnabled)
                walEntries.add(toMvccDataEntry(info, tx));
            if (oldVal == null && MvccUtils.compare(info.mvccVersion(), mvccVer.coordinatorVersion(), mvccVer.counter()) != 0 && MvccUtils.compareNewVersion(info, mvccVer.coordinatorVersion(), mvccVer.counter()) == 0)
                // Old means a value before current transaction.
                oldVal = info.value();
            if (!added)
                break;
        }
        GridCacheMvccEntryInfo last = (GridCacheMvccEntryInfo) entries.get(0);
        if (walEnabled)
            Collections.reverse(walEntries);
        if (op == DELETE) {
            assert MvccUtils.compareNewVersion(last, mvccVer) == 0;
            if (walEnabled)
                walEntries.add(new MvccDataEntry(cctx.cacheId(), key, null, DELETE, tx.nearXidVersion(), last.version(), last.expireTime(), key.partition(), 0, last.mvccVersion()));
        } else {
            assert last.newMvccCoordinatorVersion() == MvccUtils.MVCC_CRD_COUNTER_NA;
            assert MvccUtils.compare(last, mvccVer) == 0;
            val = last.value();
        }
        if (walEnabled)
            logPtr = cctx.shared().wal().log(new MvccDataRecord(walEntries));
    } finally {
        if (lockedByCurrentThread()) {
            unlockEntry();
            cctx.evicts().touch(this);
        }
    }
    GridCacheUpdateTxResult res = new GridCacheUpdateTxResult(true, logPtr);
    res.newValue(val);
    res.oldValue(oldVal);
    return res;
}
Also used : DataEntry(org.apache.ignite.internal.pagemem.wal.record.DataEntry) MvccDataEntry(org.apache.ignite.internal.pagemem.wal.record.MvccDataEntry) MvccDataEntry(org.apache.ignite.internal.pagemem.wal.record.MvccDataEntry) MvccDataRecord(org.apache.ignite.internal.pagemem.wal.record.MvccDataRecord) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)

Example 7 with MvccDataEntry

use of org.apache.ignite.internal.pagemem.wal.record.MvccDataEntry in project ignite by apache.

the class GridCacheDatabaseSharedManager method applyUpdate.

/**
 * @param cacheCtx Cache context to apply an update.
 * @param dataEntry Data entry to apply.
 * @throws IgniteCheckedException If failed to restore.
 */
private void applyUpdate(GridCacheContext<?, ?> cacheCtx, DataEntry dataEntry) throws IgniteCheckedException {
    assert cacheCtx.offheap() instanceof GridCacheOffheapManager;
    int partId = dataEntry.partitionId();
    if (partId == -1)
        partId = cacheCtx.affinity().partition(dataEntry.key());
    GridDhtLocalPartition locPart = cacheCtx.isLocal() ? null : cacheCtx.topology().forceCreatePartition(partId);
    switch(dataEntry.op()) {
        case CREATE:
        case UPDATE:
            if (dataEntry instanceof MvccDataEntry) {
                cacheCtx.offheap().mvccApplyUpdate(cacheCtx, dataEntry.key(), dataEntry.value(), dataEntry.writeVersion(), dataEntry.expireTime(), locPart, ((MvccDataEntry) dataEntry).mvccVer());
            } else {
                cacheCtx.offheap().update(cacheCtx, dataEntry.key(), dataEntry.value(), dataEntry.writeVersion(), dataEntry.expireTime(), locPart, null);
            }
            if (dataEntry.partitionCounter() != 0)
                cacheCtx.offheap().dataStore(locPart).updateInitialCounter(dataEntry.partitionCounter() - 1, 1);
            break;
        case DELETE:
            if (dataEntry instanceof MvccDataEntry) {
                cacheCtx.offheap().mvccApplyUpdate(cacheCtx, dataEntry.key(), null, dataEntry.writeVersion(), 0L, locPart, ((MvccDataEntry) dataEntry).mvccVer());
            } else
                cacheCtx.offheap().remove(cacheCtx, dataEntry.key(), partId, locPart);
            if (dataEntry.partitionCounter() != 0)
                cacheCtx.offheap().dataStore(locPart).updateInitialCounter(dataEntry.partitionCounter() - 1, 1);
            break;
        case READ:
            // do nothing
            break;
        default:
            throw new IgniteCheckedException("Invalid operation for WAL entry update: " + dataEntry.op());
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) MvccDataEntry(org.apache.ignite.internal.pagemem.wal.record.MvccDataEntry) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)

Aggregations

MvccDataEntry (org.apache.ignite.internal.pagemem.wal.record.MvccDataEntry)7 MvccDataRecord (org.apache.ignite.internal.pagemem.wal.record.MvccDataRecord)4 DataEntry (org.apache.ignite.internal.pagemem.wal.record.DataEntry)3 CacheObjectContext (org.apache.ignite.internal.processors.cache.CacheObjectContext)3 WALPointer (org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)3 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)3 DataRecord (org.apache.ignite.internal.pagemem.wal.record.DataRecord)2 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)2 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)2 GridCacheOperation (org.apache.ignite.internal.processors.cache.GridCacheOperation)2 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)2 MvccVersion (org.apache.ignite.internal.processors.cache.mvcc.MvccVersion)2 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)1 IgniteWriteAheadLogManager (org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager)1 CheckpointRecord (org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord)1 LazyMvccDataEntry (org.apache.ignite.internal.pagemem.wal.record.LazyMvccDataEntry)1