Search in sources :

Example 1 with IgniteTxLocalAdapter

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

the class GridCacheAdapter method getAllAsync0.

/**
 * @param keys Keys.
 * @param readerArgs Near cache reader will be added if not null.
 * @param readThrough Read-through flag.
 * @param checkTx Check local transaction flag.
 * @param subjId Subject ID.
 * @param taskName Task name/
 * @param deserializeBinary Deserialize binary flag.
 * @param expiry Expiry policy.
 * @param skipVals Skip values flag.
 * @param keepCacheObjects Keep cache objects.
 * @param needVer If {@code true} returns values as tuples containing value and version.
 * @return Future.
 */
protected final <K1, V1> IgniteInternalFuture<Map<K1, V1>> getAllAsync0(@Nullable final Collection<KeyCacheObject> keys, @Nullable final ReaderArguments readerArgs, final boolean readThrough, boolean checkTx, @Nullable final UUID subjId, final String taskName, final boolean deserializeBinary, @Nullable final IgniteCacheExpiryPolicy expiry, final boolean skipVals, final boolean keepCacheObjects, final boolean recovery, final boolean needVer) {
    if (F.isEmpty(keys))
        return new GridFinishedFuture<>(Collections.<K1, V1>emptyMap());
    GridNearTxLocal tx = null;
    if (checkTx) {
        try {
            checkJta();
        } catch (IgniteCheckedException e) {
            return new GridFinishedFuture<>(e);
        }
        tx = ctx.tm().threadLocalTx(ctx);
    }
    if (tx == null || tx.implicit()) {
        Map<KeyCacheObject, EntryGetResult> misses = null;
        Set<GridCacheEntryEx> newLocalEntries = null;
        final AffinityTopologyVersion topVer = tx == null ? ctx.affinity().affinityTopologyVersion() : tx.topologyVersion();
        try {
            int keysSize = keys.size();
            GridDhtTopologyFuture topFut = ctx.shared().exchange().lastFinishedFuture();
            Throwable ex = topFut != null ? topFut.validateCache(ctx, recovery, /*read*/
            true, null, keys) : null;
            if (ex != null)
                return new GridFinishedFuture<>(ex);
            final Map<K1, V1> map = keysSize == 1 ? (Map<K1, V1>) new IgniteBiTuple<>() : U.<K1, V1>newHashMap(keysSize);
            final boolean storeEnabled = !skipVals && readThrough && ctx.readThrough();
            boolean readNoEntry = ctx.readNoEntry(expiry, readerArgs != null);
            for (KeyCacheObject key : keys) {
                while (true) {
                    try {
                        EntryGetResult res = null;
                        boolean evt = !skipVals;
                        boolean updateMetrics = !skipVals;
                        GridCacheEntryEx entry = null;
                        boolean skipEntry = readNoEntry;
                        if (readNoEntry) {
                            CacheDataRow row = ctx.offheap().read(ctx, key);
                            if (row != null) {
                                long expireTime = row.expireTime();
                                if (expireTime != 0) {
                                    if (expireTime > U.currentTimeMillis()) {
                                        res = new EntryGetWithTtlResult(row.value(), row.version(), false, expireTime, 0);
                                    } else
                                        skipEntry = false;
                                } else
                                    res = new EntryGetResult(row.value(), row.version(), false);
                            }
                            if (res != null) {
                                if (evt) {
                                    ctx.events().readEvent(key, null, row.value(), subjId, taskName, !deserializeBinary);
                                }
                                if (updateMetrics && ctx.statisticsEnabled())
                                    ctx.cache().metrics0().onRead(true);
                            } else if (storeEnabled)
                                skipEntry = false;
                        }
                        if (!skipEntry) {
                            boolean isNewLocalEntry = this.map.getEntry(ctx, key) == null;
                            entry = entryEx(key);
                            if (entry == null) {
                                if (!skipVals && ctx.statisticsEnabled())
                                    ctx.cache().metrics0().onRead(false);
                                break;
                            }
                            if (isNewLocalEntry) {
                                if (newLocalEntries == null)
                                    newLocalEntries = new HashSet<>();
                                newLocalEntries.add(entry);
                            }
                            if (storeEnabled) {
                                res = entry.innerGetAndReserveForLoad(updateMetrics, evt, subjId, taskName, expiry, !deserializeBinary, readerArgs);
                                assert res != null;
                                if (res.value() == null) {
                                    if (misses == null)
                                        misses = new HashMap<>();
                                    misses.put(key, res);
                                    res = null;
                                }
                            } else {
                                res = entry.innerGetVersioned(null, null, updateMetrics, evt, subjId, null, taskName, expiry, !deserializeBinary, readerArgs);
                                if (res == null)
                                    ctx.evicts().touch(entry, topVer);
                            }
                        }
                        if (res != null) {
                            ctx.addResult(map, key, res, skipVals, keepCacheObjects, deserializeBinary, true, needVer);
                            if (entry != null && (tx == null || (!tx.implicit() && tx.isolation() == READ_COMMITTED)))
                                ctx.evicts().touch(entry, topVer);
                            if (keysSize == 1)
                                // Safe to return because no locks are required in READ_COMMITTED mode.
                                return new GridFinishedFuture<>(map);
                        }
                        break;
                    } catch (GridCacheEntryRemovedException ignored) {
                        if (log.isDebugEnabled())
                            log.debug("Got removed entry in getAllAsync(..) method (will retry): " + key);
                    }
                }
            }
            if (storeEnabled && misses != null) {
                final Map<KeyCacheObject, EntryGetResult> loadKeys = misses;
                final IgniteTxLocalAdapter tx0 = tx;
                final Collection<KeyCacheObject> loaded = new HashSet<>();
                return new GridEmbeddedFuture(ctx.closures().callLocalSafe(ctx.projectSafe(new GPC<Map<K1, V1>>() {

                    @Override
                    public Map<K1, V1> call() throws Exception {
                        ctx.store().loadAll(null, /*tx*/
                        loadKeys.keySet(), new CI2<KeyCacheObject, Object>() {

                            @Override
                            public void apply(KeyCacheObject key, Object val) {
                                EntryGetResult res = loadKeys.get(key);
                                if (res == null || val == null)
                                    return;
                                loaded.add(key);
                                CacheObject cacheVal = ctx.toCacheObject(val);
                                while (true) {
                                    GridCacheEntryEx entry = null;
                                    try {
                                        ctx.shared().database().ensureFreeSpace(ctx.dataRegion());
                                    } catch (IgniteCheckedException e) {
                                        // Wrap errors (will be unwrapped).
                                        throw new GridClosureException(e);
                                    }
                                    ctx.shared().database().checkpointReadLock();
                                    try {
                                        entry = entryEx(key);
                                        entry.unswap();
                                        EntryGetResult verVal = entry.versionedValue(cacheVal, res.version(), null, expiry, readerArgs);
                                        if (log.isDebugEnabled())
                                            log.debug("Set value loaded from store into entry [" + "oldVer=" + res.version() + ", newVer=" + verVal.version() + ", " + "entry=" + entry + ']');
                                        // Don't put key-value pair into result map if value is null.
                                        if (verVal.value() != null) {
                                            ctx.addResult(map, key, verVal, skipVals, keepCacheObjects, deserializeBinary, true, needVer);
                                        }
                                        if (tx0 == null || (!tx0.implicit() && tx0.isolation() == READ_COMMITTED))
                                            ctx.evicts().touch(entry, topVer);
                                        break;
                                    } catch (GridCacheEntryRemovedException ignore) {
                                        if (log.isDebugEnabled())
                                            log.debug("Got removed entry during getAllAsync (will retry): " + entry);
                                    } catch (IgniteCheckedException e) {
                                        // Wrap errors (will be unwrapped).
                                        throw new GridClosureException(e);
                                    } finally {
                                        ctx.shared().database().checkpointReadUnlock();
                                    }
                                }
                            }
                        });
                        clearReservationsIfNeeded(topVer, loadKeys, loaded, tx0);
                        return map;
                    }
                }), true), new C2<Map<K, V>, Exception, IgniteInternalFuture<Map<K, V>>>() {

                    @Override
                    public IgniteInternalFuture<Map<K, V>> apply(Map<K, V> map, Exception e) {
                        if (e != null) {
                            clearReservationsIfNeeded(topVer, loadKeys, loaded, tx0);
                            return new GridFinishedFuture<>(e);
                        }
                        if (tx0 == null || (!tx0.implicit() && tx0.isolation() == READ_COMMITTED)) {
                            Collection<KeyCacheObject> notFound = new HashSet<>(loadKeys.keySet());
                            notFound.removeAll(loaded);
                            // Touch entries that were not found in store.
                            for (KeyCacheObject key : notFound) {
                                GridCacheEntryEx entry = peekEx(key);
                                if (entry != null)
                                    ctx.evicts().touch(entry, topVer);
                            }
                        }
                        // There were no misses.
                        return new GridFinishedFuture<>(Collections.<K, V>emptyMap());
                    }
                }, new C2<Map<K1, V1>, Exception, Map<K1, V1>>() {

                    @Override
                    public Map<K1, V1> apply(Map<K1, V1> loaded, Exception e) {
                        if (e == null)
                            map.putAll(loaded);
                        return map;
                    }
                });
            } else
                // Misses can be non-zero only if store is enabled.
                assert misses == null;
            return new GridFinishedFuture<>(map);
        } catch (RuntimeException | AssertionError e) {
            if (misses != null) {
                for (KeyCacheObject key0 : misses.keySet()) ctx.evicts().touch(peekEx(key0), topVer);
            }
            if (newLocalEntries != null) {
                for (GridCacheEntryEx entry : newLocalEntries) removeEntry(entry);
            }
            return new GridFinishedFuture<>(e);
        } catch (IgniteCheckedException e) {
            return new GridFinishedFuture<>(e);
        }
    } else {
        return asyncOp(tx, new AsyncOp<Map<K1, V1>>(keys) {

            @Override
            public IgniteInternalFuture<Map<K1, V1>> op(GridNearTxLocal tx, AffinityTopologyVersion readyTopVer) {
                return tx.getAllAsync(ctx, readyTopVer, keys, deserializeBinary, skipVals, false, !readThrough, recovery, needVer);
            }
        }, ctx.operationContextPerCall(), /*retry*/
        false);
    }
}
Also used : IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) HashMap(java.util.HashMap) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) CI2(org.apache.ignite.internal.util.typedef.CI2) GridEmbeddedFuture(org.apache.ignite.internal.util.future.GridEmbeddedFuture) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) GridDhtTopologyFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTopologyFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteTxLocalAdapter(org.apache.ignite.internal.processors.cache.transactions.IgniteTxLocalAdapter) HashSet(java.util.HashSet) CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) IgniteTxRollbackCheckedException(org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException) InvalidObjectException(java.io.InvalidObjectException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) EntryProcessorException(javax.cache.processor.EntryProcessorException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) IOException(java.io.IOException) ObjectStreamException(java.io.ObjectStreamException) IgniteException(org.apache.ignite.IgniteException) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) NoSuchElementException(java.util.NoSuchElementException) IgniteTxHeuristicCheckedException(org.apache.ignite.internal.transactions.IgniteTxHeuristicCheckedException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) GridDhtInvalidPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException) Collection(java.util.Collection) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with IgniteTxLocalAdapter

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

the class ContentionClosure method call.

/**
 * {@inheritDoc}
 */
@Override
public ContentionInfo call() throws Exception {
    final IgniteTxManager tm = ignite.context().cache().context().tm();
    final Collection<IgniteInternalTx> activeTxs = tm.activeTransactions();
    ContentionInfo ci = new ContentionInfo();
    ci.setNode(ignite.localNode());
    ci.setEntries(new ArrayList<>());
    for (IgniteInternalTx tx : activeTxs) {
        if (ci.getEntries().size() == maxPrint)
            break;
        // Show only primary txs.
        if (tx.local()) {
            IgniteTxLocalAdapter tx0 = (IgniteTxLocalAdapter) tx;
            final IgniteTxLocalState state0 = tx0.txState();
            if (!(state0 instanceof IgniteTxStateImpl))
                continue;
            final IgniteTxStateImpl state = (IgniteTxStateImpl) state0;
            final Collection<IgniteTxEntry> entries = state.allEntriesCopy();
            IgniteTxEntry bad = null;
            int qSize = 0;
            for (IgniteTxEntry entry : entries) {
                Collection<GridCacheMvccCandidate> locs;
                GridCacheEntryEx cached = entry.cached();
                while (true) {
                    try {
                        locs = cached.localCandidates();
                        break;
                    } catch (GridCacheEntryRemovedException ignored) {
                        cached = entry.context().cache().entryEx(entry.key());
                    }
                }
                if (locs != null)
                    qSize += locs.size();
                final Collection<GridCacheMvccCandidate> rmts = cached.remoteMvccSnapshot();
                if (rmts != null)
                    qSize += rmts.size();
                if (qSize >= minQueueSize) {
                    bad = entry;
                    break;
                } else
                    qSize = 0;
            }
            if (bad != null) {
                StringBuilder b = new StringBuilder();
                b.append("TxEntry [cacheId=").append(bad.cacheId()).append(", key=").append(bad.key()).append(", queue=").append(qSize).append(", op=").append(bad.op()).append(", val=").append(bad.value()).append(", tx=").append(CU.txString(tx)).append(", other=[");
                final IgniteTxState st = tx.txState();
                if (st instanceof IgniteTxStateImpl) {
                    IgniteTxStateImpl st0 = (IgniteTxStateImpl) st;
                    final Collection<IgniteTxEntry> cp = st0.allEntriesCopy();
                    for (IgniteTxEntry entry : cp) {
                        if (entry == bad)
                            continue;
                        b.append(entry.toString()).append('\n');
                    }
                }
                b.append("]]");
                ci.getEntries().add(b.toString());
            }
        }
    }
    return ci;
}
Also used : IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) IgniteTxStateImpl(org.apache.ignite.internal.processors.cache.transactions.IgniteTxStateImpl) IgniteTxManager(org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager) IgniteTxState(org.apache.ignite.internal.processors.cache.transactions.IgniteTxState) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) IgniteTxLocalAdapter(org.apache.ignite.internal.processors.cache.transactions.IgniteTxLocalAdapter) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) IgniteTxLocalState(org.apache.ignite.internal.processors.cache.transactions.IgniteTxLocalState) GridCacheMvccCandidate(org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate)

Example 3 with IgniteTxLocalAdapter

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

the class GridCacheMapEntry method ttl.

/**
 * {@inheritDoc}
 */
@Override
public long ttl() throws GridCacheEntryRemovedException {
    IgniteTxLocalAdapter tx = currentTx();
    if (tx != null) {
        long entryTtl = tx.entryTtl(txKey());
        if (entryTtl > 0)
            return entryTtl;
    }
    lockEntry();
    try {
        checkObsolete();
        return ttlExtras();
    } finally {
        unlockEntry();
    }
}
Also used : IgniteTxLocalAdapter(org.apache.ignite.internal.processors.cache.transactions.IgniteTxLocalAdapter)

Example 4 with IgniteTxLocalAdapter

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

the class GridCacheMapEntry method expireTime.

/**
 * {@inheritDoc}
 */
@Override
public long expireTime() throws GridCacheEntryRemovedException {
    IgniteTxLocalAdapter tx = currentTx();
    if (tx != null) {
        long time = tx.entryExpireTime(txKey());
        if (time > 0)
            return time;
    }
    lockEntry();
    try {
        checkObsolete();
        return expireTimeExtras();
    } finally {
        unlockEntry();
    }
}
Also used : IgniteTxLocalAdapter(org.apache.ignite.internal.processors.cache.transactions.IgniteTxLocalAdapter)

Example 5 with IgniteTxLocalAdapter

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

the class GridCacheAdapter method getAllAsync0.

/**
 * @param keys Keys.
 * @param readerArgs Near cache reader will be added if not null.
 * @param readThrough Read-through flag.
 * @param checkTx Check local transaction flag.
 * @param taskName Task name/
 * @param deserializeBinary Deserialize binary flag.
 * @param expiry Expiry policy.
 * @param skipVals Skip values flag.
 * @param keepCacheObjects Keep cache objects.
 * @param needVer If {@code true} returns values as tuples containing value and version.
 * @param txLbl Transaction label.
 * @param mvccSnapshot MVCC snapshot.
 * @return Future.
 */
protected final <K1, V1> IgniteInternalFuture<Map<K1, V1>> getAllAsync0(@Nullable final Collection<KeyCacheObject> keys, @Nullable final ReaderArguments readerArgs, final boolean readThrough, boolean checkTx, final String taskName, final boolean deserializeBinary, @Nullable final IgniteCacheExpiryPolicy expiry, final boolean skipVals, final boolean keepCacheObjects, final boolean recovery, final ReadRepairStrategy readRepairStrategy, final boolean needVer, @Nullable String txLbl, MvccSnapshot mvccSnapshot) {
    if (F.isEmpty(keys))
        return new GridFinishedFuture<>(Collections.<K1, V1>emptyMap());
    GridNearTxLocal tx = null;
    if (checkTx) {
        try {
            checkJta();
        } catch (IgniteCheckedException e) {
            return new GridFinishedFuture<>(e);
        }
        tx = checkCurrentTx();
    }
    if (ctx.mvccEnabled() || tx == null || tx.implicit()) {
        assert (mvccSnapshot == null) == !ctx.mvccEnabled();
        Map<KeyCacheObject, EntryGetResult> misses = null;
        Set<GridCacheEntryEx> newLocalEntries = null;
        final AffinityTopologyVersion topVer = tx == null ? ctx.affinity().affinityTopologyVersion() : tx.topologyVersion();
        ctx.shared().database().checkpointReadLock();
        try {
            int keysSize = keys.size();
            GridDhtTopologyFuture topFut = ctx.shared().exchange().lastFinishedFuture();
            Throwable ex = topFut != null ? topFut.validateCache(ctx, recovery, /*read*/
            true, null, keys) : null;
            if (ex != null)
                return new GridFinishedFuture<>(ex);
            final Map<K1, V1> map = keysSize == 1 ? (Map<K1, V1>) new IgniteBiTuple<>() : U.<K1, V1>newHashMap(keysSize);
            final boolean storeEnabled = !skipVals && readThrough && ctx.readThrough();
            boolean readNoEntry = ctx.readNoEntry(expiry, readerArgs != null);
            for (KeyCacheObject key : keys) {
                while (true) {
                    try {
                        EntryGetResult res = null;
                        boolean evt = !skipVals;
                        boolean updateMetrics = !skipVals;
                        GridCacheEntryEx entry = null;
                        boolean skipEntry = readNoEntry;
                        if (readNoEntry) {
                            CacheDataRow row = mvccSnapshot != null ? ctx.offheap().mvccRead(ctx, key, mvccSnapshot) : ctx.offheap().read(ctx, key);
                            if (row != null) {
                                long expireTime = row.expireTime();
                                if (expireTime != 0) {
                                    if (expireTime > U.currentTimeMillis()) {
                                        res = new EntryGetWithTtlResult(row.value(), row.version(), false, expireTime, 0);
                                    } else
                                        skipEntry = false;
                                } else
                                    res = new EntryGetResult(row.value(), row.version(), false);
                            }
                            if (res != null) {
                                if (evt) {
                                    ctx.events().readEvent(key, null, txLbl, row.value(), taskName, !deserializeBinary);
                                }
                                if (updateMetrics && ctx.statisticsEnabled())
                                    ctx.cache().metrics0().onRead(true);
                            } else if (storeEnabled)
                                skipEntry = false;
                        }
                        if (!skipEntry) {
                            boolean isNewLocalEntry = this.map.getEntry(ctx, key) == null;
                            entry = entryEx(key);
                            if (entry == null) {
                                if (!skipVals && ctx.statisticsEnabled())
                                    ctx.cache().metrics0().onRead(false);
                                break;
                            }
                            if (isNewLocalEntry) {
                                if (newLocalEntries == null)
                                    newLocalEntries = new HashSet<>();
                                newLocalEntries.add(entry);
                            }
                            if (storeEnabled) {
                                res = entry.innerGetAndReserveForLoad(updateMetrics, evt, taskName, expiry, !deserializeBinary, readerArgs);
                                assert res != null;
                                if (res.value() == null) {
                                    if (misses == null)
                                        misses = new HashMap<>();
                                    misses.put(key, res);
                                    res = null;
                                }
                            } else {
                                res = entry.innerGetVersioned(null, null, updateMetrics, evt, null, taskName, expiry, !deserializeBinary, readerArgs);
                                if (res == null)
                                    entry.touch();
                            }
                        }
                        if (res != null) {
                            ctx.addResult(map, key, res, skipVals, keepCacheObjects, deserializeBinary, true, needVer);
                            if (entry != null && (tx == null || (!tx.implicit() && tx.isolation() == READ_COMMITTED)))
                                entry.touch();
                            if (keysSize == 1)
                                // Safe to return because no locks are required in READ_COMMITTED mode.
                                return new GridFinishedFuture<>(map);
                        }
                        break;
                    } catch (GridCacheEntryRemovedException ignored) {
                        if (log.isDebugEnabled())
                            log.debug("Got removed entry in getAllAsync(..) method (will retry): " + key);
                    }
                }
            }
            if (storeEnabled && misses != null) {
                final Map<KeyCacheObject, EntryGetResult> loadKeys = misses;
                final IgniteTxLocalAdapter tx0 = tx;
                final Collection<KeyCacheObject> loaded = new HashSet<>();
                return new GridEmbeddedFuture(ctx.closures().callLocalSafe(ctx.projectSafe(new GPC<Map<K1, V1>>() {

                    @Override
                    public Map<K1, V1> call() throws Exception {
                        ctx.store().loadAll(null, /*tx*/
                        loadKeys.keySet(), new CI2<KeyCacheObject, Object>() {

                            @Override
                            public void apply(KeyCacheObject key, Object val) {
                                EntryGetResult res = loadKeys.get(key);
                                if (res == null || val == null)
                                    return;
                                loaded.add(key);
                                CacheObject cacheVal = ctx.toCacheObject(val);
                                while (true) {
                                    GridCacheEntryEx entry = null;
                                    try {
                                        ctx.shared().database().ensureFreeSpace(ctx.dataRegion());
                                    } catch (IgniteCheckedException e) {
                                        // Wrap errors (will be unwrapped).
                                        throw new GridClosureException(e);
                                    }
                                    ctx.shared().database().checkpointReadLock();
                                    try {
                                        entry = entryEx(key);
                                        entry.unswap();
                                        GridCacheVersion newVer = nextVersion();
                                        EntryGetResult verVal = entry.versionedValue(cacheVal, res.version(), newVer, expiry, readerArgs);
                                        if (log.isDebugEnabled())
                                            log.debug("Set value loaded from store into entry [" + "oldVer=" + res.version() + ", newVer=" + verVal.version() + ", " + "entry=" + entry + ']');
                                        // Don't put key-value pair into result map if value is null.
                                        if (verVal.value() != null) {
                                            ctx.addResult(map, key, verVal, skipVals, keepCacheObjects, deserializeBinary, true, needVer);
                                        } else {
                                            ctx.addResult(map, key, new EntryGetResult(cacheVal, res.version()), skipVals, keepCacheObjects, deserializeBinary, false, needVer);
                                        }
                                        if (tx0 == null || (!tx0.implicit() && tx0.isolation() == READ_COMMITTED))
                                            entry.touch();
                                        break;
                                    } catch (GridCacheEntryRemovedException ignore) {
                                        if (log.isDebugEnabled())
                                            log.debug("Got removed entry during getAllAsync (will retry): " + entry);
                                    } catch (IgniteCheckedException e) {
                                        // Wrap errors (will be unwrapped).
                                        throw new GridClosureException(e);
                                    } finally {
                                        ctx.shared().database().checkpointReadUnlock();
                                    }
                                }
                            }
                        });
                        clearReservationsIfNeeded(topVer, loadKeys, loaded, tx0);
                        return map;
                    }
                }), true), new C2<Map<K, V>, Exception, IgniteInternalFuture<Map<K, V>>>() {

                    @Override
                    public IgniteInternalFuture<Map<K, V>> apply(Map<K, V> map, Exception e) {
                        if (e != null) {
                            clearReservationsIfNeeded(topVer, loadKeys, loaded, tx0);
                            return new GridFinishedFuture<>(e);
                        }
                        if (tx0 == null || (!tx0.implicit() && tx0.isolation() == READ_COMMITTED)) {
                            Collection<KeyCacheObject> notFound = new HashSet<>(loadKeys.keySet());
                            notFound.removeAll(loaded);
                            // Touch entries that were not found in store.
                            for (KeyCacheObject key : notFound) {
                                GridCacheEntryEx entry = peekEx(key);
                                if (entry != null)
                                    entry.touch();
                            }
                        }
                        // There were no misses.
                        return new GridFinishedFuture<>(Collections.<K, V>emptyMap());
                    }
                }, new C2<Map<K1, V1>, Exception, Map<K1, V1>>() {

                    @Override
                    public Map<K1, V1> apply(Map<K1, V1> loaded, Exception e) {
                        if (e == null)
                            map.putAll(loaded);
                        return map;
                    }
                });
            } else
                // Misses can be non-zero only if store is enabled.
                assert misses == null;
            return new GridFinishedFuture<>(map);
        } catch (RuntimeException | AssertionError e) {
            if (misses != null) {
                for (KeyCacheObject key0 : misses.keySet()) {
                    GridCacheEntryEx entry = peekEx(key0);
                    if (entry != null)
                        entry.touch();
                }
            }
            if (newLocalEntries != null) {
                for (GridCacheEntryEx entry : newLocalEntries) removeEntry(entry);
            }
            return new GridFinishedFuture<>(e);
        } catch (IgniteCheckedException e) {
            return new GridFinishedFuture<>(e);
        } finally {
            ctx.shared().database().checkpointReadUnlock();
        }
    } else {
        return asyncOp(tx, new AsyncOp<Map<K1, V1>>(keys) {

            @Override
            public IgniteInternalFuture<Map<K1, V1>> op(GridNearTxLocal tx, AffinityTopologyVersion readyTopVer) {
                return tx.getAllAsync(ctx, readyTopVer, keys, deserializeBinary, skipVals, false, !readThrough, recovery, readRepairStrategy, needVer);
            }
        }, ctx.operationContextPerCall(), /*retry*/
        false);
    }
}
Also used : IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) HashMap(java.util.HashMap) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) CI2(org.apache.ignite.internal.util.typedef.CI2) GridEmbeddedFuture(org.apache.ignite.internal.util.future.GridEmbeddedFuture) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) GridDhtTopologyFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTopologyFuture) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteTxLocalAdapter(org.apache.ignite.internal.processors.cache.transactions.IgniteTxLocalAdapter) HashSet(java.util.HashSet) CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) IgniteTxRollbackCheckedException(org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException) InvalidObjectException(java.io.InvalidObjectException) IgniteTxTimeoutCheckedException(org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) EntryProcessorException(javax.cache.processor.EntryProcessorException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) IOException(java.io.IOException) GridDhtInvalidPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtInvalidPartitionException) ObjectStreamException(java.io.ObjectStreamException) IgniteConsistencyViolationException(org.apache.ignite.internal.processors.cache.distributed.near.consistency.IgniteConsistencyViolationException) TransactionCheckedException(org.apache.ignite.internal.transactions.TransactionCheckedException) IgniteException(org.apache.ignite.IgniteException) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) NoSuchElementException(java.util.NoSuchElementException) IgniteTxHeuristicCheckedException(org.apache.ignite.internal.transactions.IgniteTxHeuristicCheckedException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) Collection(java.util.Collection) GridSerializableMap(org.apache.ignite.internal.util.GridSerializableMap) Map(java.util.Map) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap)

Aggregations

IgniteTxLocalAdapter (org.apache.ignite.internal.processors.cache.transactions.IgniteTxLocalAdapter)5 IOException (java.io.IOException)2 InvalidObjectException (java.io.InvalidObjectException)2 ObjectStreamException (java.io.ObjectStreamException)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 NoSuchElementException (java.util.NoSuchElementException)2 EntryProcessorException (javax.cache.processor.EntryProcessorException)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 IgniteException (org.apache.ignite.IgniteException)2 ClusterTopologyException (org.apache.ignite.cluster.ClusterTopologyException)2 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)2 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)2 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)2 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)2 ClusterTopologyServerNotFoundException (org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException)2 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)2 GridDhtTopologyFuture (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTopologyFuture)2