/** {@inheritDoc} */ @Override public boolean isLocked(K key) { KeyCacheObject cacheKey = ctx.toCacheKeyObject(key); return ctx.mvcc().isLockedByThread(ctx.txKey(cacheKey), -1); }
/** * * @param key Entry key. * @return Entry or <tt>null</tt>. */ @Nullable public final GridCacheEntryEx peekEx(Object key) { return entry0(ctx.toCacheKeyObject(key), ctx.affinity().affinityTopologyVersion(), false, false); }
/** * @return {@code true} If this is a replicated cache and we are on a data node. */ public boolean isReplicatedAffinityNode() { return isReplicated() && affinityNode(); }
/** * Constructor of full cache context. * * @param cctx Cache context. * @param clientCache Client cache or not. */ public GridCacheContextInfo(GridCacheContext<K, V> cctx, boolean clientCache) { config = cctx.config(); dynamicDeploymentId = null; groupId = cctx.groupId(); cacheId = cctx.cacheId(); this.clientCache = clientCache; this.cctx = cctx; }
/** {@inheritDoc} */ @Override protected void start0() throws IgniteCheckedException { // Append cache name to the topic. topicPrefix = "CONTINUOUS_QUERY" + (cctx.name() == null ? "" : "_" + cctx.name()); if (cctx.affinityNode()) { cctx.io().addCacheHandler(cctx.cacheId(), CacheContinuousQueryBatchAck.class, new CI2<UUID, CacheContinuousQueryBatchAck>() { @Override public void apply(UUID uuid, CacheContinuousQueryBatchAck msg) { CacheContinuousQueryListener lsnr = lsnrs.get(msg.routineId()); if (lsnr != null) lsnr.cleanupBackupQueue(msg.updateCntrs()); } }); cancelableTask = cctx.time().schedule(new BackupCleaner(lsnrs, cctx.kernalContext()), BACKUP_ACK_FREQ, BACKUP_ACK_FREQ); } }
/** */ private boolean isLocalBackup(EnlistOperation op, KeyCacheObject key) { if (!cctx.affinityNode() || op == EnlistOperation.LOCK) return false; else if (cctx.isReplicated()) return true; return cctx.topology().nodes(key.partition(), tx.topologyVersion()).indexOf(cctx.localNode()) > 0; }
/** {@inheritDoc} */ @Override public void writeExternal(ObjectOutput out) throws IOException { out.writeObject(cctx.kernalContext()); U.writeString(out, name()); U.writeString(out, cctx.group().name()); }
/** * @param ctx Context. * @return Managers present in both, DHT and Near caches. */ @SuppressWarnings("IfMayBeConditional") private Collection<GridCacheManager> dhtExcludes(GridCacheContext ctx) { if (ctx.config().getCacheMode() == LOCAL || !isNearEnabled(ctx)) return Collections.emptyList(); else return F.asList(ctx.queries(), ctx.continuousQueries(), ctx.store()); }
/** * @param expVer Expected topology version. * @param curVer Current topology version. * @return {@code True} if cache affinity changed and operation should be remapped. */ protected final boolean needRemap(AffinityTopologyVersion expVer, AffinityTopologyVersion curVer, Collection<KeyCacheObject> keys) { if (curVer.equals(expVer)) return false; AffinityTopologyVersion lastAffChangedTopVer = ctx.shared().exchange().lastAffinityChangedTopologyVersion(expVer); if (curVer.compareTo(lastAffChangedTopVer) >= 0 && curVer.compareTo(expVer) <= 0) return false; // TODO IGNITE-7164 check mvcc crd for mvcc enabled txs. Collection<ClusterNode> cacheNodes0 = ctx.discovery().cacheGroupAffinityNodes(ctx.groupId(), expVer); Collection<ClusterNode> cacheNodes1 = ctx.discovery().cacheGroupAffinityNodes(ctx.groupId(), curVer); if (!cacheNodes0.equals(cacheNodes1) || ctx.affinity().affinityTopologyVersion().compareTo(curVer) < 0) return true; try { List<List<ClusterNode>> aff1 = ctx.affinity().assignments(expVer); List<List<ClusterNode>> aff2 = ctx.affinity().assignments(curVer); return !aff1.equals(aff2); } catch (IllegalStateException ignored) { return true; } }
/** * Releases the partition that was reserved by a call to * {@link #reserveForFastLocalGet(int, AffinityTopologyVersion)}. * * @param part Partition to release. * @param topVer Topology version. */ public void releaseForFastLocalGet(int part, AffinityTopologyVersion topVer) { assert affinityNode(); if (!isReplicated() || group().persistenceEnabled()) { GridDhtLocalPartition locPart = topology().localPartition(part, topVer, false); assert locPart != null && locPart.state() == OWNING : "partition evicted after reserveForFastLocalGet " + "[part=" + part + ", locPart=" + locPart + ", topVer=" + topVer + ']'; locPart.release(); } }
/** * @param cctx Cache context. */ private void addCacheContext(GridCacheContext cctx) { assert cacheType.userCache() == cctx.userCache() : cctx.name(); assert grpId == cctx.groupId() : cctx.name(); final boolean add; synchronized (this) { List<GridCacheContext> copy = new ArrayList<>(caches); assert sharedGroup() || copy.isEmpty(); add = copy.add(cctx); caches = Collections.unmodifiableList(copy); } assert add : cctx.name(); if (!qryEnabled && QueryUtils.isEnabled(cctx.config())) qryEnabled = true; if (!drEnabled && cctx.isDrEnabled()) drEnabled = true; }
/** {@inheritDoc} */ @Override void clear() { assert isDone() : this; GridCacheDistributedQueryManager<K, V> qryMgr = (GridCacheDistributedQueryManager<K, V>)cctx.queries(); if (qryMgr != null) qryMgr.removeQueryFuture(reqId); } }
/** */ protected GridNearTxLocal checkCurrentTx() { if (!ctx.mvccEnabled()) return ctx.tm().threadLocalTx(ctx); try { return MvccUtils.currentTx(ctx.kernalContext(), null); } catch (MvccUtils.UnsupportedTxModeException | MvccUtils.NonMvccTransactionException e) { throw new TransactionException(e.getMessage()); } }
/** * @param ctx Context. * @param ldr Loader. * @throws IgniteCheckedException If failed. */ public void unmarshalValue(GridCacheContext<?, ?> ctx, ClassLoader ldr) throws IgniteCheckedException { if (val != null) val.finishUnmarshal(ctx.cacheObjectContext(), ldr); }
/** * @param type Event type. * @return {@code True} if event is recordable. */ public boolean isRecordable(int type) { GridCacheContext cctx0 = cctx; // Event recording is impossible in recovery mode. if (cctx0 != null && cctx0.kernalContext().recoveryMode()) return false; return cctx0 != null && cctx0.userCache() && cctx0.gridEvents().isRecordable(type) && !cctx0.config().isEventsDisabled(); }
/** {@inheritDoc} */ @Override public void unlockAll( Collection<? extends K> keys ) throws IgniteCheckedException { AffinityTopologyVersion topVer = ctx.affinity().affinityTopologyVersion(); for (K key : keys) { GridLocalCacheEntry entry = peekExx(ctx.toCacheKeyObject(key)); if (entry != null && ctx.isAll(entry, CU.empty0())) { entry.releaseLocal(); entry.touch(); } } }
/** */ private static Optional<IgniteCacheOffheapManager.CacheDataStore> dataStore( GridCacheContext<?, ?> cctx, Object key) { int p = cctx.affinity().partition(key); IgniteCacheOffheapManager offheap = cctx.offheap(); return StreamSupport.stream(offheap.cacheDataStores().spliterator(), false) .filter(ds -> ds.partId() == p) .findFirst(); } }
@Override public IgniteInternalFuture<V> apply() { return getAsync0(ctx.toCacheKeyObject(key), forcePrimary, subjId0, taskName, deserializeBinary, recovery, expiryPlc, skipVals, skipStore, needVer); } });