/** {@inheritDoc} */ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { ctx = (GridCacheContext<K, V>)in.readObject(); delegate = (IgniteInternalCache<K, V>)in.readObject(); opCtx = (CacheOperationContext)in.readObject(); gate = ctx.gate(); aff = new GridCacheAffinityProxy<>(ctx, ctx.cache().affinity()); }
/** * @param ctx Context. * @param delegate Delegate object. * @param opCtx Optional operation context which will be passed to gateway. */ public GridCacheProxyImpl( GridCacheContext<K, V> ctx, IgniteInternalCache<K, V> delegate, @Nullable CacheOperationContext opCtx ) { assert ctx != null; assert delegate != null; this.ctx = ctx; this.delegate = delegate; this.opCtx = opCtx; gate = ctx.gate(); aff = new GridCacheAffinityProxy<>(ctx, ctx.cache().affinity()); }
@Override public <K> Affinity<K> affinity(String cacheName) { CU.validateCacheName(cacheName); checkClusterState(); GridCacheAdapter<K, ?> cache = ctx.cache().internalCache(cacheName); if (cache != null) return cache.affinity(); return ctx.affinity().affinityProxy(cacheName); }
/** * @param key Key. * @param idx Node index. * @return {@code True} if key belongs to node with index idx. */ protected boolean belongs(String key, int idx) { return context(idx).cache().affinity().isPrimaryOrBackup(context(idx).localNode(), key); }
/** * @throws Exception If failed. */ @Test public void testSystemCacheOnClientNode() throws Exception { startGrids(2); final IgniteKernal ignite = (IgniteKernal)ignite(1); assertTrue(ignite.configuration().isClientMode()); GridCacheAdapter utilityCache = ((IgniteKernal)ignite(0)).internalCache(CU.UTILITY_CACHE_NAME); Collection<ClusterNode> affNodes = utilityCache.affinity().mapKeyToPrimaryAndBackups(1); assertEquals(1, affNodes.size()); assertTrue(affNodes.contains(ignite(0).cluster().localNode())); } }
/** * Create data transfer object for given cache. * * @param ca Internal cache. * @param collectMetrics Collect cache metrics flag. * @throws IgniteCheckedException If failed to create data transfer object. */ public VisorCache(IgniteEx ignite, GridCacheAdapter ca, boolean collectMetrics) throws IgniteCheckedException { assert ca != null; GridCacheContext cctx = ca.context(); CacheConfiguration cfg = ca.configuration(); name = ca.name(); dynamicDeploymentId = cctx.dynamicDeploymentId(); mode = cfg.getCacheMode(); primarySize = ca.localSizeLong(PEEK_ONHEAP_PRIMARY); backupSize = ca.localSizeLong(PEEK_ONHEAP_BACKUP); nearSize = ca.nearSize(); size = primarySize + backupSize + nearSize; partitions = ca.affinity().partitions(); near = cctx.isNear(); if (collectMetrics) metrics = new VisorCacheMetrics(ignite, name); sys = ignite.context().cache().systemCache(name); statisticsEnabled = ca.clusterMetrics().isStatisticsEnabled(); }
/** {@inheritDoc} */ @SuppressWarnings({"unchecked", "ConstantConditions"}) @Override protected void beforeTest() throws Exception { super.beforeTest(); // Start nodes. TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); victim = Ignition.start(config(NODE_1_NAME, ipFinder)); attacker = Ignition.start(config(NODE_2_NAME, ipFinder)); // Check if we selected victim correctly. if (F.eq(dataCache(victim).affinity().mapKeyToNode(DATA_KEY).id(), attacker.cluster().localNode().id())) { Ignite tmp = victim; victim = attacker; attacker = tmp; } }
if (cache.affinity().isPrimaryOrBackup(grid.localNode(), key)) { if (cache instanceof GridNearCacheAdapter) cache = ((GridNearCacheAdapter<Object, Object>)cache).dht();
boolean expectDht = near.affinity().isPrimaryOrBackup(ignite.cluster().localNode(), key);
/** {@inheritDoc} */ @SuppressWarnings({"unchecked"}) @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { ctx = (GridCacheContext<K, V>)in.readObject(); delegate = (IgniteInternalCache<K, V>)in.readObject(); opCtx = (CacheOperationContext)in.readObject(); gate = ctx.gate(); aff = new GridCacheAffinityProxy<>(ctx, ctx.cache().affinity()); }
/** * @param ctx Context. * @param delegate Delegate object. * @param opCtx Optional operation context which will be passed to gateway. */ public GridCacheProxyImpl( GridCacheContext<K, V> ctx, IgniteInternalCache<K, V> delegate, @Nullable CacheOperationContext opCtx ) { assert ctx != null; assert delegate != null; this.ctx = ctx; this.delegate = delegate; this.opCtx = opCtx; gate = ctx.gate(); aff = new GridCacheAffinityProxy<>(ctx, ctx.cache().affinity()); }
@Override public <K> Affinity<K> affinity(String cacheName) { CU.validateCacheName(cacheName); checkClusterState(); GridCacheAdapter<K, ?> cache = ctx.cache().internalCache(cacheName); if (cache != null) return cache.affinity(); return ctx.affinity().affinityProxy(cacheName); }
/** * Create data transfer object for given cache. * * @param ca Internal cache. * @param collectMetrics Collect cache metrics flag. * @throws IgniteCheckedException If failed to create data transfer object. */ public VisorCache(IgniteEx ignite, GridCacheAdapter ca, boolean collectMetrics) throws IgniteCheckedException { assert ca != null; GridCacheContext cctx = ca.context(); CacheConfiguration cfg = ca.configuration(); name = ca.name(); dynamicDeploymentId = cctx.dynamicDeploymentId(); mode = cfg.getCacheMode(); primarySize = ca.localSizeLong(PEEK_ONHEAP_PRIMARY); backupSize = ca.localSizeLong(PEEK_ONHEAP_BACKUP); nearSize = ca.nearSize(); size = primarySize + backupSize + nearSize; partitions = ca.affinity().partitions(); near = cctx.isNear(); if (collectMetrics) metrics = new VisorCacheMetrics(ignite, name); sys = ignite.context().cache().systemCache(name); }