@Override public KeyCacheObject apply(GridCacheEntryEx e) { return e.key(); }
/** {@inheritDoc} */ @Override public int hashCode() { return cached.key().hashCode(); }
/** * @param entry Entry. * @param nodes Nodes. * @param map Map. */ private void map(GridCacheEntryEx entry, @Nullable Iterable<? extends ClusterNode> nodes, Map<ClusterNode, List<KeyCacheObject>> map) { if (nodes != null) { for (ClusterNode n : nodes) { List<KeyCacheObject> keys = map.get(n); if (keys == null) map.put(n, keys = new LinkedList<>()); keys.add(entry.key()); } } }
/** {@inheritDoc} */ @Override public void incrementPublicSize(CacheMapHolder hld, GridCacheEntryEx e) { localPartition(e.context(), e.key(), AffinityTopologyVersion.NONE, true).incrementPublicSize(hld, e); }
/** {@inheritDoc} */ @Override public void decrementPublicSize(CacheMapHolder hld, GridCacheEntryEx e) { localPartition(e.context(), e.key(), AffinityTopologyVersion.NONE, true).decrementPublicSize(hld, e); }
/** {@inheritDoc} */ @Override public boolean removeEntry(GridCacheEntryEx entry) { GridDhtLocalPartition part = localPartition(entry.context(), entry.key(), AffinityTopologyVersion.NONE, false); if (part == null) return false; return part.removeEntry(entry); }
/** {@inheritDoc} */ @Override public K getKey() throws IllegalStateException { return cached.key().value(cached.context().cacheObjectContext(), false); }
/** {@inheritDoc} */ @Override public void onDeferredDelete(GridCacheEntryEx entry, GridCacheVersion ver) { assert entry.isNear(); try { T2<KeyCacheObject, GridCacheVersion> evicted = rmvQueue.add(new T2<>(entry.key(), ver)); if (evicted != null) removeVersionedEntry(evicted.get1(), evicted.get2()); } catch (InterruptedException ignore) { if (log.isDebugEnabled()) log.debug("Failed to enqueue deleted entry [key=" + entry.key() + ", ver=" + ver + ']'); Thread.currentThread().interrupt(); } } }
/** * @param entry Entry to check. * @param req Update request. * @param res Update response. If filter evaluation failed, key will be added to failed keys and method will return * false. * @return {@code True} if filter evaluation succeeded. */ private boolean checkFilter(GridCacheEntryEx entry, GridNearAtomicAbstractUpdateRequest req, GridNearAtomicUpdateResponse res) { try { return ctx.isAllLocked(entry, req.filter()); } catch (IgniteCheckedException e) { res.addFailedKey(entry.key(), e); return false; } }
/** * @param entry Removes entry from cache if currently mapped value is the same as passed. */ public final void removeEntry(GridCacheEntryEx entry) { boolean rmvd = map.removeEntry(entry); if (log.isDebugEnabled()) { if (rmvd) log.debug("Removed entry from cache: " + entry); else log.debug("Remove will not be done for key (entry got replaced or removed): " + entry.key()); } }
/** {@inheritDoc} */ @Override public boolean evict(@Nullable GridCacheEntryEx entry, @Nullable GridCacheVersion obsoleteVer, boolean explicit, @Nullable CacheEntryPredicate[] filter) throws IgniteCheckedException { assert entry == null || entry.context() == cctx : "Entry from another cache context passed to eviction manager: [" + "entry=" + entry + ", cctx=" + cctx + ", entryCtx=" + entry.context() + "]"; if (entry == null) return true; // Do not evict internal entries. if (entry.key() instanceof GridCacheInternal) return false; if (!cctx.isNear() && !explicit && !firstEvictWarn) warnFirstEvict(); if (obsoleteVer == null) obsoleteVer = cctx.versions().next(); // Do not touch entry if not evicted: // 1. If it is call from policy, policy tracks it on its own. // 2. If it is explicit call, entry is touched on tx commit. return evict0(cctx.cache(), entry, obsoleteVer, filter, explicit); }
/** {@inheritDoc} */ @Override public void onDeferredDelete(GridCacheEntryEx entry, GridCacheVersion ver) { assert entry.isDht(); GridDhtLocalPartition part = topology().localPartition(entry.partition(), AffinityTopologyVersion.NONE, false); if (part != null) part.onDeferredDelete(entry.context().cacheId(), entry.key(), ver); }
/** {@inheritDoc} */ @Override public String toString() { GridCacheMvccCandidate prev = previous(); GridCacheMvccCandidate next = next(); return S.toString(GridCacheMvccCandidate.class, this, "key", parent == null ? null : parent.key(), true, "masks", Mask.toString(flags()), false, "prevVer", prev == null ? null : prev.version(), false, "nextVer", next == null ? null : next.version(), false); }
/** * @param ldr Class loader. * @param keys Keys. * @param cache Cache. */ private void addEntries(ClassLoader ldr, Collection<KeyCacheObject> keys, GridCacheAdapter cache) { GridCacheContext cacheCtx = cache.context(); for (GridCacheEntryEx e : (Iterable<GridCacheEntryEx>)cache.entries()) { boolean undeploy = cacheCtx.isNear() ? undeploy(ldr, e, cacheCtx.near()) || undeploy(ldr, e, cacheCtx.near().dht()) : undeploy(ldr, e, cacheCtx.cache()); if (undeploy) keys.add(e.key()); } }
/** {@inheritDoc} */ @Override public int size() { try { GridCacheContext<Object, Object> cctx = cached.context(); KeyCacheObject key = cached.key(); byte[] keyBytes = key.valueBytes(cctx.cacheObjectContext()); byte[] valBytes = null; CacheObject cacheObj = cached.valueBytes(); if (cacheObj != null) valBytes = cacheObj.valueBytes(cctx.cacheObjectContext()); return valBytes == null ? keyBytes.length : keyBytes.length + valBytes.length; } catch (GridCacheEntryRemovedException ignored) { return 0; } catch (IgniteCheckedException e) { throw new IgniteException(e); } }
@Override public void applyx(GridCacheEntryEx entry, GridCacheVersion obsoleteVer) { boolean touch = !entry.isNear(); while (true) { try { if (log.isTraceEnabled()) log.trace("Trying to remove expired entry from cache: " + entry); if (entry.onTtlExpired(obsoleteVer)) touch = false; break; } catch (GridCacheEntryRemovedException ignore) { entry = entry.context().cache().entryEx(entry.key()); touch = true; } } if (touch) entry.touch(); } };
/** {@inheritDoc} */ @Override public void batchEvict(Collection<?> keys, @Nullable GridCacheVersion obsoleteVer) throws IgniteCheckedException { boolean recordable = cctx.events().isRecordable(EVT_CACHE_ENTRY_EVICTED); GridCacheAdapter cache = cctx.cache(); // Get all participating entries to avoid deadlock. for (Object k : keys) { KeyCacheObject cacheKey = cctx.toCacheKeyObject(k); GridCacheEntryEx entry = cache.peekEx(cacheKey); if (entry != null && entry.evictInternal(GridCacheVersionManager.EVICT_VER, null, false)) { if (plcEnabled) notifyPolicy(entry); if (recordable) cctx.events().addEvent(entry.partition(), entry.key(), cctx.nodeId(), null, null, null, EVT_CACHE_ENTRY_EVICTED, null, false, entry.rawGet(), entry.hasValue(), null, null, null, false); } } }
/** {@inheritDoc} */ @Override protected final void checkThreadChain(GridCacheMvccCandidate owner) { assert !lockedByCurrentThread(); assert owner != null; assert owner.owner() || owner.used() : "Neither owner or used flags are set on ready local candidate: " + owner; if (owner.local() && owner.next() != null) { for (GridCacheMvccCandidate cand = owner.next(); cand != null; cand = cand.next()) { assert cand.local() : "Remote candidate cannot be part of thread chain: " + cand; // Allow next lock in the thread to proceed. if (!cand.used()) { GridCacheContext cctx0 = cand.parent().context(); GridDistributedCacheEntry e = (GridDistributedCacheEntry)cctx0.cache().peekEx(cand.parent().key()); if (e != null) e.recheck(); break; } } } }
/** {@inheritDoc} */ @Override protected void afterTest() throws Exception { for (int i = 0; i < gridCount(); i++) { GridCacheAdapter<Object, Object> c = ((IgniteKernal)grid(i)).internalCache(DEFAULT_CACHE_NAME); for (GridCacheEntryEx e : c.map().entries(c.context().cacheId())) { Object key = e.key().value(c.context().cacheObjectContext(), false); Object val = CU.value(e.rawGet(), c.context(), false); if (key instanceof BinaryObject) assert ((BinaryObjectImpl)key).detached() : val; if (val instanceof BinaryObject) assert ((BinaryObjectImpl)val).detached() : val; } } IgniteCache<Object, Object> c = jcache(0); for (int i = 0; i < ENTRY_CNT; i++) c.remove(i); assertEquals(0, c.size()); }