Search in sources :

Example 1 with IgniteInternalTx

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

the class GridCacheMapEntry method innerGet0.

/** {@inheritDoc} */
@SuppressWarnings({ "unchecked", "RedundantTypeArguments", "TooBroadScope" })
private Object innerGet0(GridCacheVersion nextVer, IgniteInternalTx tx, boolean readThrough, boolean evt, boolean updateMetrics, UUID subjId, Object transformClo, String taskName, @Nullable IgniteCacheExpiryPolicy expiryPlc, boolean retVer, boolean keepBinary, boolean reserveForLoad, @Nullable ReaderArguments readerArgs) throws IgniteCheckedException, GridCacheEntryRemovedException {
    assert !(retVer && readThrough);
    assert !(reserveForLoad && readThrough);
    // Disable read-through if there is no store.
    if (readThrough && !cctx.readThrough())
        readThrough = false;
    GridCacheVersion startVer;
    GridCacheVersion resVer = null;
    boolean obsolete = false;
    boolean deferred = false;
    GridCacheVersion ver0 = null;
    Object res = null;
    synchronized (this) {
        checkObsolete();
        boolean valid = valid(tx != null ? tx.topologyVersion() : cctx.affinity().affinityTopologyVersion());
        CacheObject val;
        if (valid) {
            val = this.val;
            if (val == null) {
                if (isStartVersion()) {
                    unswap(true, false);
                    val = this.val;
                }
            }
            if (val != null) {
                long expireTime = expireTimeExtras();
                if (expireTime > 0 && (expireTime - U.currentTimeMillis() <= 0)) {
                    if (onExpired((CacheObject) cctx.unwrapTemporary(val), null)) {
                        val = null;
                        evt = false;
                        if (cctx.deferredDelete()) {
                            deferred = true;
                            ver0 = ver;
                        } else
                            obsolete = true;
                    }
                }
            }
        } else
            val = null;
        CacheObject ret = val;
        if (ret == null) {
            if (updateMetrics && cctx.cache().configuration().isStatisticsEnabled())
                cctx.cache().metrics0().onRead(false);
        } else {
            if (updateMetrics && cctx.cache().configuration().isStatisticsEnabled())
                cctx.cache().metrics0().onRead(true);
        }
        if (evt && cctx.events().isRecordable(EVT_CACHE_OBJECT_READ)) {
            transformClo = EntryProcessorResourceInjectorProxy.unwrap(transformClo);
            GridCacheMvcc mvcc = mvccExtras();
            cctx.events().addEvent(partition(), key, tx, mvcc != null ? mvcc.anyOwner() : null, EVT_CACHE_OBJECT_READ, ret, ret != null, ret, ret != null, subjId, transformClo != null ? transformClo.getClass().getName() : null, taskName, keepBinary);
            // No more notifications.
            evt = false;
        }
        if (ret != null && expiryPlc != null)
            updateTtl(expiryPlc);
        if (retVer) {
            resVer = (isNear() && cctx.transactional()) ? ((GridNearCacheEntry) this).dhtVersion() : this.ver;
            if (resVer == null)
                ret = null;
        }
        // Cache version for optimistic check.
        startVer = ver;
        addReaderIfNeed(readerArgs);
        if (ret != null) {
            assert !obsolete;
            assert !deferred;
            // If return value is consistent, then done.
            res = retVer ? entryGetResult(ret, resVer, false) : ret;
        } else if (reserveForLoad && !obsolete) {
            assert !readThrough;
            assert retVer;
            boolean reserve = !evictionDisabled();
            if (reserve)
                flags |= IS_EVICT_DISABLED;
            res = entryGetResult(null, resVer, reserve);
        }
    }
    if (obsolete) {
        onMarkedObsolete();
        throw new GridCacheEntryRemovedException();
    }
    if (deferred)
        cctx.onDeferredDelete(this, ver0);
    if (res != null)
        return res;
    CacheObject ret = null;
    if (readThrough) {
        IgniteInternalTx tx0 = null;
        if (tx != null && tx.local()) {
            if (cctx.isReplicated() || cctx.isColocated() || tx.near())
                tx0 = tx;
            else if (tx.dht()) {
                GridCacheVersion ver = tx.nearXidVersion();
                tx0 = cctx.dht().near().context().tm().tx(ver);
            }
        }
        Object storeVal = readThrough(tx0, key, false, subjId, taskName);
        ret = cctx.toCacheObject(storeVal);
    }
    if (ret == null && !evt)
        return null;
    synchronized (this) {
        long ttl = ttlExtras();
        // If version matched, set value.
        if (startVer.equals(ver)) {
            if (ret != null) {
                // Detach value before index update.
                ret = cctx.kernalContext().cacheObjects().prepareForCache(ret, cctx);
                nextVer = nextVer != null ? nextVer : nextVersion();
                long expTime = CU.toExpireTime(ttl);
                // Update indexes before actual write to entry.
                storeValue(ret, expTime, nextVer, null);
                update(ret, expTime, ttl, nextVer, true);
                if (cctx.deferredDelete() && deletedUnlocked() && !isInternal() && !detached())
                    deletedUnlocked(false);
                assert readerArgs == null;
            }
            if (evt && cctx.events().isRecordable(EVT_CACHE_OBJECT_READ)) {
                transformClo = EntryProcessorResourceInjectorProxy.unwrap(transformClo);
                GridCacheMvcc mvcc = mvccExtras();
                cctx.events().addEvent(partition(), key, tx, mvcc != null ? mvcc.anyOwner() : null, EVT_CACHE_OBJECT_READ, ret, ret != null, null, false, subjId, transformClo != null ? transformClo.getClass().getName() : null, taskName, keepBinary);
            }
        }
    }
    assert ret == null || !retVer;
    return ret;
}
Also used : GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) GridNearCacheEntry(org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheEntry) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx)

Example 2 with IgniteInternalTx

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

the class GridCacheMapEntry method wrap.

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public <K, V> Cache.Entry<K, V> wrap() {
    try {
        IgniteInternalTx tx = cctx.tm().userTx();
        CacheObject val;
        if (tx != null) {
            GridTuple<CacheObject> peek = tx.peek(cctx, false, key);
            val = peek == null ? rawGet() : peek.get();
        } else
            val = rawGet();
        return new CacheEntryImpl<>(key.<K>value(cctx.cacheObjectContext(), false), CU.<V>value(val, cctx, false), ver);
    } catch (GridCacheFilterFailedException ignored) {
        throw new IgniteException("Should never happen.");
    }
}
Also used : IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) IgniteException(org.apache.ignite.IgniteException)

Example 3 with IgniteInternalTx

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

the class GridCacheMapEntry method visitable.

/**
     * @param filter Entry filter.
     * @return {@code True} if entry is visitable.
     */
public final boolean visitable(CacheEntryPredicate[] filter) {
    boolean rmv = false;
    try {
        synchronized (this) {
            if (obsoleteOrDeleted())
                return false;
            if (checkExpired()) {
                rmv = markObsolete0(cctx.versions().next(this.ver), true, null);
                return false;
            }
        }
        if (filter != CU.empty0() && !cctx.isAll(this, filter))
            return false;
    } catch (IgniteCheckedException e) {
        U.error(log, "An exception was thrown while filter checking.", e);
        RuntimeException ex = e.getCause(RuntimeException.class);
        if (ex != null)
            throw ex;
        Error err = e.getCause(Error.class);
        if (err != null)
            throw err;
        return false;
    } finally {
        if (rmv) {
            onMarkedObsolete();
            cctx.cache().removeEntry(this);
        }
    }
    IgniteInternalTx tx = cctx.tm().localTxx();
    if (tx != null) {
        IgniteTxEntry e = tx.entry(txKey());
        boolean rmvd = e != null && e.op() == DELETE;
        return !rmvd;
    }
    return true;
}
Also used : IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx)

Example 4 with IgniteInternalTx

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

the class GridCacheMultiTxFuture method init.

/**
     * Initializes this future.
     */
public void init() {
    if (remainingTxs == null) {
        remainingTxs = Collections.emptySet();
        onDone(true);
    } else {
        assert !remainingTxs.isEmpty();
        for (final IgniteInternalTx tx : remainingTxs) {
            if (!tx.done()) {
                tx.finishFuture().listen(new CI1<IgniteInternalFuture<IgniteInternalTx>>() {

                    @Override
                    public void apply(IgniteInternalFuture<IgniteInternalTx> t) {
                        remainingTxs.remove(tx);
                        checkRemaining();
                    }
                });
            } else
                remainingTxs.remove(tx);
        }
        checkRemaining();
    }
}
Also used : IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture)

Example 5 with IgniteInternalTx

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

the class GridCacheMvcc method salvageRemote.

/**
     * For all remote candidates standing behind the candidate being salvaged marks their transactions
     * as system invalidate and marks these candidates as owned and used.
     *
     * @param ver Version to salvage.
     */
public void salvageRemote(GridCacheVersion ver) {
    assert ver != null;
    GridCacheMvccCandidate cand = candidate(rmts, ver);
    if (cand != null) {
        assert rmts != null;
        assert !rmts.isEmpty();
        for (Iterator<GridCacheMvccCandidate> iter = rmts.iterator(); iter.hasNext(); ) {
            GridCacheMvccCandidate rmt = iter.next();
            // For salvaged candidate doneRemote will be called explicitly.
            if (rmt == cand)
                break;
            // Only Near and DHT remote candidates should be released.
            assert !rmt.nearLocal();
            IgniteInternalTx tx = cctx.tm().tx(rmt.version());
            if (tx != null) {
                tx.systemInvalidate(true);
                rmt.setOwner();
                rmt.setUsed();
            } else
                iter.remove();
        }
    }
}
Also used : IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx)

Aggregations

IgniteInternalTx (org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx)29 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)8 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)7 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)5 IgniteException (org.apache.ignite.IgniteException)3 IgfsPath (org.apache.ignite.igfs.IgfsPath)3 IgniteTxManager (org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager)3 TransactionProxyImpl (org.apache.ignite.internal.processors.cache.transactions.TransactionProxyImpl)3 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)3 HashMap (java.util.HashMap)2 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)2 IgniteKernal (org.apache.ignite.internal.IgniteKernal)2 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)2 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)2 GridCacheMvccCandidate (org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate)2 GridCacheReturn (org.apache.ignite.internal.processors.cache.GridCacheReturn)2 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)2 IgniteTxEntry (org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry)2 IgniteTxHeuristicCheckedException (org.apache.ignite.internal.transactions.IgniteTxHeuristicCheckedException)2