Search in sources :

Example 66 with GridCacheContext

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

the class GridCacheQueryRequest method prepareMarshal.

/**
 * {@inheritDoc}
 */
@Override
public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException {
    super.prepareMarshal(ctx);
    GridCacheContext cctx = ctx.cacheContext(cacheId);
    if (keyValFilter != null && keyValFilterBytes == null) {
        if (addDepInfo)
            prepareObject(keyValFilter, cctx);
        keyValFilterBytes = CU.marshal(cctx, keyValFilter);
    }
    if (rdc != null && rdcBytes == null) {
        if (addDepInfo)
            prepareObject(rdc, cctx);
        rdcBytes = CU.marshal(cctx, rdc);
    }
    if (trans != null && transBytes == null) {
        if (addDepInfo)
            prepareObject(trans, cctx);
        transBytes = CU.marshal(cctx, trans);
    }
    if (!F.isEmpty(args) && argsBytes == null) {
        if (addDepInfo) {
            for (Object arg : args) prepareObject(arg, cctx);
        }
        argsBytes = CU.marshal(cctx, args);
    }
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext)

Example 67 with GridCacheContext

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

the class GridNearSingleGetRequest method prepareMarshal.

/**
 * {@inheritDoc}
 */
@Override
public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException {
    super.prepareMarshal(ctx);
    assert key != null;
    GridCacheContext cctx = ctx.cacheContext(cacheId);
    prepareMarshalCacheObject(key, cctx);
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext)

Example 68 with GridCacheContext

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

the class GridNearTxFinishFuture method onDone.

/**
 * {@inheritDoc}
 */
@Override
public boolean onDone(IgniteInternalTx tx0, Throwable err) {
    if (isDone())
        return false;
    synchronized (this) {
        if (isDone())
            return false;
        boolean nodeStop = false;
        if (err != null) {
            tx.setRollbackOnly();
            nodeStop = err instanceof NodeStoppingException;
        }
        if (commit) {
            if (tx.commitError() != null)
                err = tx.commitError();
            else if (err != null)
                tx.commitError(err);
        }
        if (initialized() || err != null) {
            if (tx.needCheckBackup()) {
                assert tx.onePhaseCommit();
                if (err != null)
                    err = new TransactionRollbackException("Failed to commit transaction.", err);
                try {
                    tx.localFinish(err == null, true);
                } catch (IgniteCheckedException e) {
                    if (err != null)
                        err.addSuppressed(e);
                    else
                        err = e;
                }
            }
            if (tx.onePhaseCommit()) {
                boolean commit = this.commit && err == null;
                if (!nodeStop)
                    finishOnePhase(commit);
                try {
                    tx.tmFinish(commit, nodeStop, true);
                } catch (IgniteCheckedException e) {
                    U.error(log, "Failed to finish tx: " + tx, e);
                    if (err == null)
                        err = e;
                }
            }
            if (super.onDone(tx0, err)) {
                if (error() instanceof IgniteTxHeuristicCheckedException && !nodeStop) {
                    AffinityTopologyVersion topVer = tx.topologyVersion();
                    for (IgniteTxEntry e : tx.writeMap().values()) {
                        GridCacheContext cacheCtx = e.context();
                        try {
                            if (e.op() != NOOP && !cacheCtx.affinity().keyLocalNode(e.key(), topVer)) {
                                GridCacheEntryEx entry = cacheCtx.cache().peekEx(e.key());
                                if (entry != null)
                                    entry.invalidate(tx.xidVersion());
                            }
                        } catch (Throwable t) {
                            U.error(log, "Failed to invalidate entry.", t);
                            if (t instanceof Error)
                                throw (Error) t;
                        }
                    }
                }
                // Don't forget to clean up.
                cctx.mvcc().removeFuture(futId);
                return true;
            }
        }
    }
    return false;
}
Also used : IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException) IgniteTxHeuristicCheckedException(org.apache.ignite.internal.transactions.IgniteTxHeuristicCheckedException)

Example 69 with GridCacheContext

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

the class GridCacheDatabaseSharedManager method applyUpdatesOnRecovery.

/**
 * Apply update from some iterator and with specific filters.
 *
 * @param it WalIterator.
 * @param recPredicate Wal record filter.
 * @param entryPredicate Entry filter.
 * @param partStates Partition to restore state.
 */
public void applyUpdatesOnRecovery(@Nullable WALIterator it, IgnitePredicate<IgniteBiTuple<WALPointer, WALRecord>> recPredicate, IgnitePredicate<DataEntry> entryPredicate, Map<T2<Integer, Integer>, T2<Integer, Long>> partStates) throws IgniteCheckedException {
    if (it != null) {
        while (it.hasNextX()) {
            IgniteBiTuple<WALPointer, WALRecord> next = it.nextX();
            WALRecord rec = next.get2();
            if (!recPredicate.apply(next))
                break;
            switch(rec.type()) {
                case DATA_RECORD:
                    checkpointReadLock();
                    try {
                        DataRecord dataRec = (DataRecord) rec;
                        for (DataEntry dataEntry : dataRec.writeEntries()) {
                            if (entryPredicate.apply(dataEntry)) {
                                checkpointReadLock();
                                try {
                                    int cacheId = dataEntry.cacheId();
                                    GridCacheContext cacheCtx = cctx.cacheContext(cacheId);
                                    if (cacheCtx != null)
                                        applyUpdate(cacheCtx, dataEntry);
                                    else if (log != null)
                                        log.warning("Cache (cacheId=" + cacheId + ") is not started, can't apply updates.");
                                } finally {
                                    checkpointReadUnlock();
                                }
                            }
                        }
                    } finally {
                        checkpointReadUnlock();
                    }
                    break;
                default:
            }
        }
    }
    checkpointReadLock();
    try {
        restorePartitionState(partStates, Collections.emptySet());
    } finally {
        checkpointReadUnlock();
    }
}
Also used : WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) DataEntry(org.apache.ignite.internal.pagemem.wal.record.DataEntry) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) DataRecord(org.apache.ignite.internal.pagemem.wal.record.DataRecord) MetastoreDataRecord(org.apache.ignite.internal.pagemem.wal.record.MetastoreDataRecord) WALPointer(org.apache.ignite.internal.pagemem.wal.WALPointer) FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer)

Example 70 with GridCacheContext

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

the class GridDhtForceKeysRequest method finishUnmarshal.

/**
 * {@inheritDoc}
 */
@Override
public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException {
    super.finishUnmarshal(ctx, ldr);
    GridCacheContext cctx = ctx.cacheContext(cacheId);
    finishUnmarshalCacheObjects(keys, cctx, ldr);
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext)

Aggregations

GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)147 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)37 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)22 HashMap (java.util.HashMap)21 ClusterNode (org.apache.ignite.cluster.ClusterNode)20 Map (java.util.Map)19 UUID (java.util.UUID)18 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)18 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)16 ArrayList (java.util.ArrayList)15 IgniteException (org.apache.ignite.IgniteException)14 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)14 List (java.util.List)13 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)13 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)13 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)11 ConcurrentMap (java.util.concurrent.ConcurrentMap)10 IgniteTxEntry (org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry)10 GridCacheEntryInfo (org.apache.ignite.internal.processors.cache.GridCacheEntryInfo)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8