Search in sources :

Example 11 with GridCacheEntryInfo

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

the class GridNearCacheEntry method initializeFromDht.

/**
     * @param topVer Topology version.
     * @throws GridCacheEntryRemovedException If this entry is obsolete.
     */
public void initializeFromDht(AffinityTopologyVersion topVer) throws GridCacheEntryRemovedException {
    GridDhtCacheEntry entry = cctx.near().dht().peekExx(key);
    if (entry != null) {
        GridCacheEntryInfo e = entry.info();
        if (e != null) {
            GridCacheVersion enqueueVer = null;
            try {
                ClusterNode primaryNode = cctx.affinity().primaryByKey(key, topVer);
                synchronized (this) {
                    checkObsolete();
                    if (isNew() || !valid(topVer)) {
                        // Version does not change for load ops.
                        update(e.value(), e.expireTime(), e.ttl(), e.isNew() ? ver : e.version(), true);
                        if (cctx.deferredDelete() && !isNew() && !isInternal()) {
                            boolean deleted = val == null;
                            if (deleted != deletedUnlocked()) {
                                deletedUnlocked(deleted);
                                if (deleted)
                                    enqueueVer = e.version();
                            }
                        }
                        if (primaryNode == null)
                            this.topVer = AffinityTopologyVersion.NONE;
                        else
                            recordNodeId(primaryNode.id(), topVer);
                        dhtVer = e.isNew() || e.isDeleted() ? null : e.version();
                    }
                }
            } finally {
                if (enqueueVer != null)
                    cctx.onDeferredDelete(this, enqueueVer);
            }
        }
    }
}
Also used : GridCacheEntryInfo(org.apache.ignite.internal.processors.cache.GridCacheEntryInfo) ClusterNode(org.apache.ignite.cluster.ClusterNode) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) GridDhtCacheEntry(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry)

Example 12 with GridCacheEntryInfo

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

the class GridDhtForceKeysResponse method finishUnmarshal.

/** {@inheritDoc} */
@Override
public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException {
    super.finishUnmarshal(ctx, ldr);
    GridCacheContext cctx = ctx.cacheContext(cacheId);
    if (missedKeys != null)
        finishUnmarshalCacheObjects(missedKeys, cctx, ldr);
    if (infos != null) {
        for (GridCacheEntryInfo info : infos) info.unmarshal(cctx, ldr);
    }
    if (errBytes != null && err == null)
        err = U.unmarshal(ctx, errBytes, U.resolveClassLoader(ldr, ctx.gridConfig()));
}
Also used : GridCacheEntryInfo(org.apache.ignite.internal.processors.cache.GridCacheEntryInfo) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext)

Example 13 with GridCacheEntryInfo

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

the class GridDhtTxPrepareResponse method prepareMarshal.

/** {@inheritDoc} */
@Override
public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException {
    super.prepareMarshal(ctx);
    if (nearEvicted != null) {
        for (IgniteTxKey key : nearEvicted) {
            GridCacheContext cctx = ctx.cacheContext(key.cacheId());
            key.prepareMarshal(cctx);
        }
    }
    if (preloadEntries != null) {
        for (GridCacheEntryInfo info : preloadEntries) {
            GridCacheContext cctx = ctx.cacheContext(info.cacheId());
            info.marshal(cctx);
        }
    }
}
Also used : GridCacheEntryInfo(org.apache.ignite.internal.processors.cache.GridCacheEntryInfo) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) IgniteTxKey(org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey)

Example 14 with GridCacheEntryInfo

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

the class GridDhtTransactionalCacheAdapter method startRemoteTx.

/**
     * @param nodeId Primary node ID.
     * @param req Request.
     * @param res Response.
     * @return Remote transaction.
     * @throws IgniteCheckedException If failed.
     * @throws GridDistributedLockCancelledException If lock has been cancelled.
     */
@SuppressWarnings({ "RedundantTypeArguments" })
@Nullable
private GridDhtTxRemote startRemoteTx(UUID nodeId, GridDhtLockRequest req, GridDhtLockResponse res) throws IgniteCheckedException, GridDistributedLockCancelledException {
    List<KeyCacheObject> keys = req.keys();
    GridDhtTxRemote tx = null;
    int size = F.size(keys);
    for (int i = 0; i < size; i++) {
        KeyCacheObject key = keys.get(i);
        if (key == null)
            continue;
        IgniteTxKey txKey = ctx.txKey(key);
        if (log.isDebugEnabled())
            log.debug("Unmarshalled key: " + key);
        GridDistributedCacheEntry entry = null;
        while (true) {
            try {
                int part = ctx.affinity().partition(key);
                GridDhtLocalPartition locPart = ctx.topology().localPartition(part, req.topologyVersion(), false);
                if (locPart == null || !locPart.reserve()) {
                    if (log.isDebugEnabled())
                        log.debug("Local partition for given key is already evicted (will add to invalid " + "partition list) [key=" + key + ", part=" + part + ", locPart=" + locPart + ']');
                    res.addInvalidPartition(part);
                    // Invalidate key in near cache, if any.
                    if (isNearEnabled(cacheCfg))
                        obsoleteNearEntry(key);
                    break;
                }
                try {
                    // Handle implicit locks for pessimistic transactions.
                    if (req.inTx()) {
                        if (tx == null)
                            tx = ctx.tm().tx(req.version());
                        if (tx == null) {
                            tx = new GridDhtTxRemote(ctx.shared(), req.nodeId(), req.futureId(), nodeId, req.nearXidVersion(), req.topologyVersion(), req.version(), /*commitVer*/
                            null, ctx.systemTx(), ctx.ioPolicy(), PESSIMISTIC, req.isolation(), req.isInvalidate(), req.timeout(), req.txSize(), req.subjectId(), req.taskNameHash());
                            tx = ctx.tm().onCreated(null, tx);
                            if (tx == null || !ctx.tm().onStarted(tx))
                                throw new IgniteTxRollbackCheckedException("Failed to acquire lock (transaction " + "has been completed) [ver=" + req.version() + ", tx=" + tx + ']');
                        }
                        tx.addWrite(ctx, NOOP, txKey, null, null, req.accessTtl(), req.skipStore(), req.keepBinary());
                    }
                    entry = entryExx(key, req.topologyVersion());
                    // Add remote candidate before reordering.
                    entry.addRemote(req.nodeId(), nodeId, req.threadId(), req.version(), tx != null, tx != null && tx.implicitSingle(), null);
                    // Invalidate key in near cache, if any.
                    if (isNearEnabled(cacheCfg) && req.invalidateNearEntry(i))
                        invalidateNearEntry(key, req.version());
                    // Get entry info after candidate is added.
                    if (req.needPreloadKey(i)) {
                        entry.unswap();
                        GridCacheEntryInfo info = entry.info();
                        if (info != null && !info.isNew() && !info.isDeleted())
                            res.addPreloadEntry(info);
                    }
                    // Double-check in case if sender node left the grid.
                    if (ctx.discovery().node(req.nodeId()) == null) {
                        if (log.isDebugEnabled())
                            log.debug("Node requesting lock left grid (lock request will be ignored): " + req);
                        entry.removeLock(req.version());
                        if (tx != null) {
                            tx.clearEntry(txKey);
                            // COMMITTING state, but this lock is never acquired.
                            if (tx.state() == COMMITTING)
                                tx.forceCommit();
                            else
                                tx.rollbackRemoteTx();
                        }
                        return null;
                    }
                    // Entry is legit.
                    break;
                } finally {
                    locPart.release();
                }
            } catch (GridDhtInvalidPartitionException e) {
                if (log.isDebugEnabled())
                    log.debug("Received invalid partition exception [e=" + e + ", req=" + req + ']');
                res.addInvalidPartition(e.partition());
                // Invalidate key in near cache, if any.
                if (isNearEnabled(cacheCfg))
                    obsoleteNearEntry(key);
                if (tx != null) {
                    tx.clearEntry(txKey);
                    if (log.isDebugEnabled())
                        log.debug("Cleared invalid entry from remote transaction (will skip) [entry=" + entry + ", tx=" + tx + ']');
                }
                break;
            } catch (GridCacheEntryRemovedException ignored) {
                assert entry.obsoleteVersion() != null : "Obsolete flag not set on removed entry: " + entry;
                if (log.isDebugEnabled())
                    log.debug("Received entry removed exception (will retry on renewed entry): " + entry);
                if (tx != null) {
                    tx.clearEntry(txKey);
                    if (log.isDebugEnabled())
                        log.debug("Cleared removed entry from remote transaction (will retry) [entry=" + entry + ", tx=" + tx + ']');
                }
            }
        }
    }
    if (tx != null && tx.empty()) {
        if (log.isDebugEnabled())
            log.debug("Rolling back remote DHT transaction because it is empty [req=" + req + ", res=" + res + ']');
        tx.rollbackRemoteTx();
        tx = null;
    }
    return tx;
}
Also used : GridCacheEntryInfo(org.apache.ignite.internal.processors.cache.GridCacheEntryInfo) GridDistributedCacheEntry(org.apache.ignite.internal.processors.cache.distributed.GridDistributedCacheEntry) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) IgniteTxKey(org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey) IgniteTxRollbackCheckedException(org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) Nullable(org.jetbrains.annotations.Nullable)

Example 15 with GridCacheEntryInfo

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

the class GridDhtTxPrepareResponse method finishUnmarshal.

/** {@inheritDoc} */
@Override
public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException {
    super.finishUnmarshal(ctx, ldr);
    if (nearEvicted != null) {
        for (IgniteTxKey key : nearEvicted) {
            GridCacheContext cctx = ctx.cacheContext(key.cacheId());
            key.finishUnmarshal(cctx, ldr);
        }
    }
    if (preloadEntries != null) {
        for (GridCacheEntryInfo info : preloadEntries) {
            GridCacheContext cctx = ctx.cacheContext(info.cacheId());
            info.unmarshal(cctx, ldr);
        }
    }
}
Also used : GridCacheEntryInfo(org.apache.ignite.internal.processors.cache.GridCacheEntryInfo) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) IgniteTxKey(org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey)

Aggregations

GridCacheEntryInfo (org.apache.ignite.internal.processors.cache.GridCacheEntryInfo)22 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)10 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)10 ClusterNode (org.apache.ignite.cluster.ClusterNode)8 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)8 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)8 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)6 Collection (java.util.Collection)5 Map (java.util.Map)5 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)5 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)5 ClusterTopologyServerNotFoundException (org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException)4 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)4 GridDhtInvalidPartitionException (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException)4 GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition)4 ArrayList (java.util.ArrayList)3 EntryGetResult (org.apache.ignite.internal.processors.cache.EntryGetResult)3 GridCacheMessage (org.apache.ignite.internal.processors.cache.GridCacheMessage)3 IgniteTxKey (org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey)3 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)3