Search in sources :

Example 31 with GridDhtInvalidPartitionException

use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtInvalidPartitionException in project ignite by apache.

the class GridDhtColocatedCache method loadAsync.

/**
 * @param keys Keys to load.
 * @param readThrough Read through flag.
 * @param forcePrimary Force get from primary node flag.
 * @param topVer Topology version.
 * @param taskName Task name.
 * @param deserializeBinary Deserialize binary flag.
 * @param expiryPlc Expiry policy.
 * @param skipVals Skip values flag.
 * @param needVer If {@code true} returns values as tuples containing value and version.
 * @param keepCacheObj Keep cache objects flag.
 * @param txLbl Transaction label.
 * @param mvccSnapshot Mvcc snapshot.
 * @return Load future.
 */
public final IgniteInternalFuture<Map<K, V>> loadAsync(@Nullable Collection<KeyCacheObject> keys, boolean readThrough, boolean forcePrimary, AffinityTopologyVersion topVer, String taskName, boolean deserializeBinary, boolean recovery, @Nullable IgniteCacheExpiryPolicy expiryPlc, boolean skipVals, boolean needVer, boolean keepCacheObj, @Nullable String txLbl, @Nullable MvccSnapshot mvccSnapshot) {
    assert (mvccSnapshot == null) == !ctx.mvccEnabled();
    if (keys == null || keys.isEmpty())
        return new GridFinishedFuture<>(Collections.<K, V>emptyMap());
    if (expiryPlc == null)
        expiryPlc = expiryPolicy(null);
    // Optimization: try to resolve value locally and escape 'get future' creation.
    if (!forcePrimary && ctx.config().isReadFromBackup() && ctx.affinityNode() && ctx.topology().lostPartitions().isEmpty()) {
        ctx.shared().database().checkpointReadLock();
        try {
            Map<K, V> locVals = null;
            boolean success = true;
            boolean readNoEntry = ctx.readNoEntry(expiryPlc, false);
            boolean evt = !skipVals;
            for (KeyCacheObject key : keys) {
                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 || expireTime > U.currentTimeMillis()) {
                            if (locVals == null)
                                locVals = U.newHashMap(keys.size());
                            ctx.addResult(locVals, key, row.value(), skipVals, keepCacheObj, deserializeBinary, true, null, row.version(), 0, 0, needVer, U.deploymentClassLoader(ctx.kernalContext(), U.contextDeploymentClassLoaderId(ctx.kernalContext())));
                            if (evt) {
                                ctx.events().readEvent(key, null, txLbl, row.value(), taskName, !deserializeBinary);
                            }
                        } else
                            success = false;
                    } else
                        success = false;
                } else {
                    GridCacheEntryEx entry = null;
                    while (true) {
                        try {
                            entry = entryEx(key);
                            // If our DHT cache do has value, then we peek it.
                            if (entry != null) {
                                boolean isNew = entry.isNewLocked();
                                EntryGetResult getRes = null;
                                CacheObject v = null;
                                GridCacheVersion ver = null;
                                if (needVer) {
                                    getRes = entry.innerGetVersioned(null, null, /*update-metrics*/
                                    false, /*event*/
                                    evt, null, taskName, expiryPlc, !deserializeBinary, null);
                                    if (getRes != null) {
                                        v = getRes.value();
                                        ver = getRes.version();
                                    }
                                } else {
                                    v = entry.innerGet(null, null, /*read-through*/
                                    false, /*update-metrics*/
                                    false, /*event*/
                                    evt, null, taskName, expiryPlc, !deserializeBinary);
                                }
                                // Entry was not in memory or in swap, so we remove it from cache.
                                if (v == null) {
                                    GridCacheVersion obsoleteVer = nextVersion();
                                    if (isNew && entry.markObsoleteIfEmpty(obsoleteVer))
                                        removeEntry(entry);
                                    success = false;
                                } else {
                                    if (locVals == null)
                                        locVals = U.newHashMap(keys.size());
                                    ctx.addResult(locVals, key, v, skipVals, keepCacheObj, deserializeBinary, true, getRes, ver, 0, 0, needVer, U.deploymentClassLoader(ctx.kernalContext(), U.contextDeploymentClassLoaderId(ctx.kernalContext())));
                                }
                            } else
                                success = false;
                            // While.
                            break;
                        } catch (GridCacheEntryRemovedException ignored) {
                        // No-op, retry.
                        } catch (GridDhtInvalidPartitionException ignored) {
                            success = false;
                            // While.
                            break;
                        } finally {
                            if (entry != null)
                                entry.touch();
                        }
                    }
                }
                if (!success)
                    break;
                else if (!skipVals && ctx.statisticsEnabled())
                    ctx.cache().metrics0().onRead(true);
            }
            if (success) {
                sendTtlUpdateRequest(expiryPlc);
                return new GridFinishedFuture<>(locVals);
            }
        } catch (IgniteCheckedException e) {
            return new GridFinishedFuture<>(e);
        } finally {
            ctx.shared().database().checkpointReadUnlock();
        }
    }
    if (expiryPlc != null)
        expiryPlc.reset();
    // Either reload or not all values are available locally.
    GridPartitionedGetFuture<K, V> fut = new GridPartitionedGetFuture<>(ctx, keys, readThrough, forcePrimary, taskName, deserializeBinary, recovery, expiryPlc, skipVals, needVer, keepCacheObj, txLbl, mvccSnapshot, null);
    fut.init(topVer);
    return fut;
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) GridDhtInvalidPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtInvalidPartitionException) GridPartitionedGetFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridPartitionedGetFuture) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) EntryGetResult(org.apache.ignite.internal.processors.cache.EntryGetResult) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 32 with GridDhtInvalidPartitionException

use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtInvalidPartitionException in project ignite by apache.

the class SchemaIndexCachePartitionWorker method processKey.

/**
 * Process single key.
 *
 * @param key Key.
 * @throws IgniteCheckedException If failed.
 */
private void processKey(KeyCacheObject key) throws IgniteCheckedException {
    assert nonNull(key);
    while (!stop()) {
        try {
            checkCancelled();
            GridCacheEntryEx entry = cctx.cache().entryEx(key);
            try {
                entry.updateIndex(wrappedClo);
            } finally {
                entry.touch();
            }
            break;
        } catch (GridDhtInvalidPartitionException ignore) {
            break;
        } catch (GridCacheEntryRemovedException ignored) {
        // No-op.
        }
    }
}
Also used : GridDhtInvalidPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtInvalidPartitionException) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)

Example 33 with GridDhtInvalidPartitionException

use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtInvalidPartitionException in project ignite by apache.

the class IgniteCacheExpiryPolicyAbstractTest method checkTtl.

/**
 * @param key Key.
 * @param ttl TTL.
 * @param wait If {@code true} waits for ttl update.
 * @throws Exception If failed.
 */
private void checkTtl(Object key, final long ttl, boolean wait) throws Exception {
    boolean found = false;
    for (int i = 0; i < gridCount(); i++) {
        IgniteKernal grid = (IgniteKernal) grid(i);
        GridCacheAdapter<Object, Object> cache = grid.context().cache().internalCache(DEFAULT_CACHE_NAME);
        if (cache.context().isNear())
            cache = cache.context().near().dht();
        while (true) {
            try {
                GridCacheEntryEx e = cache.entryEx(key);
                if (e != null && e.deleted()) {
                    assertEquals(0, e.ttl());
                    assertFalse("Invalid entry [e=" + e + ", node=" + i + ']', cache.affinity().isPrimaryOrBackup(grid.localNode(), key));
                    continue;
                }
                if (e == null)
                    assertTrue("Not found " + key, !cache.affinity().isPrimaryOrBackup(grid.localNode(), key));
                else {
                    e.unswap();
                    found = true;
                    if (ttl > 0) {
                        assertTrue("Unexpected expiration time, key: " + key + " expirationtime: " + e.expireTime(), e.expireTime() > 0);
                    } else
                        assertEquals(0, e.expireTime());
                }
                break;
            } catch (GridCacheEntryRemovedException ignore) {
            // Retry.
            } catch (GridDhtInvalidPartitionException ignore) {
                // No need to check.
                break;
            }
        }
    }
    assertTrue(found);
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridDhtInvalidPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtInvalidPartitionException) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)

Aggregations

GridDhtInvalidPartitionException (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtInvalidPartitionException)33 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)22 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)18 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)18 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)14 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)13 GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)11 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)10 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)6 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)6 CacheDataRow (org.apache.ignite.internal.processors.cache.persistence.CacheDataRow)6 Nullable (org.jetbrains.annotations.Nullable)6 Map (java.util.Map)5 ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)4 ClusterNode (org.apache.ignite.cluster.ClusterNode)4 EntryGetResult (org.apache.ignite.internal.processors.cache.EntryGetResult)4 GridCacheEntryInfo (org.apache.ignite.internal.processors.cache.GridCacheEntryInfo)4 GridDhtPartitionTopology (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology)4 HashSet (java.util.HashSet)3