/** Clears swap entries for evicted partition. */ private void clearSwap() { assert state() == EVICTED; assert !GridQueryProcessor.isEnabled(cctx.config()) : "Indexing needs to have unswapped values."; try { GridCloseableIterator<Map.Entry<byte[], GridCacheSwapEntry>> it = cctx.swap().iterator(id); boolean isLocStore = cctx.store().isLocal(); if (it != null) { // We can safely remove these values because no entries will be created for evicted // partition. while (it.hasNext()) { Map.Entry<byte[], GridCacheSwapEntry> entry = it.next(); byte[] keyBytes = entry.getKey(); KeyCacheObject key = cctx.toCacheKeyObject(keyBytes); cctx.swap().remove(key); if (isLocStore) cctx.store().remove(null, key.value(cctx.cacheObjectContext(), false)); } } } catch (IgniteCheckedException e) { U.error(log, "Failed to clear swap for evicted partition: " + this, e); } }
/** * @param key Key. * @param val Value. * @param ver Cache version. * @param p Optional predicate. * @param topVer Topology version. * @param replicate Replication flag. * @param plc Expiry policy. */ private void loadEntry( KeyCacheObject key, Object val, GridCacheVersion ver, @Nullable IgniteBiPredicate<K, V> p, AffinityTopologyVersion topVer, boolean replicate, @Nullable ExpiryPolicy plc) { if (p != null && !p.apply(key.<K>value(ctx.cacheObjectContext(), false), (V) val)) return; try { GridDhtLocalPartition part = top.localPartition(ctx.affinity().partition(key), AffinityTopologyVersion.NONE, true); // Reserve to make sure that partition does not get unloaded. if (part.reserve()) { GridCacheEntryEx entry = null; try { long ttl = CU.ttlForLoad(plc); if (ttl == CU.TTL_ZERO) return; CacheObject cacheVal = ctx.toCacheObject(val); entry = entryEx(key, false); entry.initialValue( cacheVal, ver, ttl, CU.EXPIRE_TIME_CALCULATE, false, topVer, replicate ? DR_LOAD : DR_NONE, false); } catch (IgniteCheckedException e) { throw new IgniteException("Failed to put cache value: " + entry, e); } catch (GridCacheEntryRemovedException ignore) { if (log.isDebugEnabled()) log.debug("Got removed entry during loadCache (will ignore): " + entry); } finally { if (entry != null) entry.context().evicts().touch(entry, topVer); part.release(); } } else if (log.isDebugEnabled()) log.debug("Will node load entry into cache (partition is invalid): " + part); } catch (GridDhtInvalidPartitionException e) { if (log.isDebugEnabled()) log.debug( "Ignoring entry for partition that does not belong [key=" + key + ", val=" + val + ", err=" + e + ']'); } }