Node locatePrimaryOwner(String sessionId) { DistributionManager dist = this.cache.getAdvancedCache().getDistributionManager(); Address address = (dist != null) ? dist.getCacheTopology().getDistribution(new Key<>(sessionId)).primary() : null; Node node = (address != null) ? this.memberFactory.createNode(address) : null; return (node != null) ? node : this.group.getLocalMember(); }
@Override public String locate(String sessionId) { DistributionManager dist = this.cache.getAdvancedCache().getDistributionManager(); Address address = (dist != null) && !this.cache.getCacheConfiguration().clustering().cacheMode().isScattered() ? dist.getCacheTopology().getDistribution(new Key<>(sessionId)).primary() : this.cache.getCacheManager().getAddress(); Node node = (address != null) ? this.factory.createNode(address) : null; Map.Entry<String, Void> entry = (node != null) ? this.registry.getEntry(node) : null; if (entry == null) { entry = this.registry.getEntry(this.registry.getGroup().getLocalMember()); } return (entry != null) ? entry.getKey() : null; } }
Node locatePrimaryOwner(I id) { DistributionManager dist = this.cache.getAdvancedCache().getDistributionManager(); Address address = (dist != null) && !this.cache.getCacheConfiguration().clustering().cacheMode().isScattered() ? dist.getCacheTopology().getDistribution(new Key<>(id)).primary() : null; Node member = (address != null) ? this.nodeFactory.createNode(address) : null; return (member != null) ? member : this.registry.getGroup().getLocalMember(); }
if (di.primary().equals(ownerAddress)) { return valueToTest;
private Address owner(Object key) { return advancedCache(0).getDistributionManager().getCacheTopology().getDistribution(key).primary(); }
private Address owner(Object key) { return advancedCache(0).getDistributionManager().getCacheTopology().getDistribution(key).primary(); }
private Address getOwnerAddress(Cache cache, Object key) { DistributionManager dist = cache.getAdvancedCache().getDistributionManager(); Address address = (dist != null) && !cache.getCacheConfiguration().clustering().cacheMode().isScattered() ? dist.getCacheTopology().getDistribution(key).primary() : cache.getCacheManager().getAddress(); return address; }
private Cache<String, Foo> getKeyLocation(String key) { Address cache1Address = cache1.getAdvancedCache().getRpcManager().getAddress(); LocalizedCacheTopology cacheTopology = cache1.getAdvancedCache().getDistributionManager().getCacheTopology(); DistributionInfo distribution = cacheTopology.getDistribution(key); Address primary = distribution.primary(); return primary.equals(cache1Address) ? cache1 : cache2; }
Node locatePrimaryOwner(I id) { DistributionManager dist = this.cache.getAdvancedCache().getDistributionManager(); Address address = (dist != null) && !this.cache.getCacheConfiguration().clustering().cacheMode().isScattered() ? dist.getCacheTopology().getDistribution(new Key<>(id)).primary() : null; Node member = (address != null) ? this.nodeFactory.createNode(address) : null; return (member != null) ? member : this.registry.getGroup().getLocalMember(); }
protected Object createSameHashCodeKey(String name) { final Address address = cache.getAdvancedCache().getRpcManager().getAddress(); DistributionManager distributionManager = cache.getAdvancedCache().getDistributionManager(); int hashCode = 0; SameHashCodeKey key = new SameHashCodeKey(name, hashCode); while (!distributionManager.getCacheTopology().getDistribution(key).primary().equals(address)) { hashCode++; key = new SameHashCodeKey(name, hashCode); } return key; }
private Optional<Cache<Object, Person>> findCache(Ownership ownership, Object key) { List<Cache<Object, Person>> caches = caches(); ClusteringDependentLogic cdl = cache1.getAdvancedCache().getComponentRegistry().getComponent(ClusteringDependentLogic.class); DistributionInfo distribution = cdl.getCacheTopology().getDistribution(key); Predicate<Cache<?, ?>> predicate = null; switch (ownership) { case PRIMARY: predicate = c -> c.getAdvancedCache().getRpcManager().getAddress().equals(distribution.primary()); break; case BACKUP: predicate = c -> distribution.writeBackups().contains(c.getAdvancedCache().getRpcManager().getAddress()); break; case NON_OWNER: predicate = c -> !distribution.writeOwners().contains(c.getAdvancedCache().getRpcManager().getAddress()); } return caches.stream().filter(predicate).findFirst(); }
@Override protected Object createSameHashCodeKey(String name) { final Cache otherCache = otherCacheManager.getCache(); final Address address = otherCache.getAdvancedCache().getRpcManager().getAddress(); DistributionManager distributionManager = otherCache.getAdvancedCache().getDistributionManager(); int hashCode = 0; SameHashCodeKey key = new SameHashCodeKey(name, hashCode); while (!distributionManager.getCacheTopology().getDistribution(key).primary().equals(address)) { hashCode++; key = new SameHashCodeKey(name, hashCode); } return key; } }
clusterListener.events.size() >= 1 && clusterListener.events.size() <= 5); Address cache0primary = cache0.getAdvancedCache().getDistributionManager().getCacheTopology().getDistribution(key).primary(); Address cache2primary = cache2.getAdvancedCache().getDistributionManager().getCacheTopology().getDistribution(key).primary();
protected <K, V> Cache<K, V> getLockOwner(Object key, String cacheName) { Configuration c = getCache(0, cacheName).getCacheConfiguration(); if (c.clustering().cacheMode().isInvalidation()) { return getCache(0, cacheName); //for replicated caches only the coordinator acquires lock } else if (!c.clustering().cacheMode().isClustered()) { throw new IllegalStateException("This is not a clustered cache!"); } else { Address address = getCache(0, cacheName).getAdvancedCache().getDistributionManager().getCacheTopology() .getDistribution(key).primary(); for (Cache<K, V> cache : this.<K, V>caches(cacheName)) { if (cache.getAdvancedCache().getRpcManager().getTransport().getAddress().equals(address)) { return cache; } } throw new IllegalStateException(); } }
private void introduceCacheConflicts() { LocalizedCacheTopology topology = getCache(0).getDistributionManager().getCacheTopology(); for (int i = 0; i < NUMBER_OF_CACHE_ENTRIES; i += INCONSISTENT_VALUE_INCREMENT) { Address primary = topology.getDistribution(i).primary(); AdvancedCache<Object, Object> primaryCache = manager(primary).getCache(CACHE_NAME).getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL); if (i % NULL_VALUE_FREQUENCY == 0) primaryCache.remove(i); else primaryCache.put(i, "INCONSISTENT"); } }
Object key = k(method, i); cache(LON, 0).put(key, VALUE); if (topology.getDistribution(key).primary().equals(coordLON)) { keysOnCoordinator.add(key);
private void doTest(Operation operation, boolean init) throws Exception { final MagicKey key = new MagicKey(cache(1), cache(2)); if (init) { cache(0).put(key, "v1"); assertInAllCache(key, "v1"); } BlockingLocalTopologyManager bltm0 = replaceTopologyManagerDefaultCache(manager(0)); BlockingLocalTopologyManager bltm1 = replaceTopologyManagerDefaultCache(manager(1)); killMember(2, null, false); //CH_UPDATE + REBALANCE_START + CH_UPDATE(blocked) bltm0.expectRebalanceStartAfterLeave().unblock(); bltm1.expectRebalanceStartAfterLeave().unblock(); bltm0.expectPhaseConfirmation().unblock(); bltm1.expectPhaseConfirmation().unblock(); //check if we are in the correct state LocalizedCacheTopology cacheTopology = TestingUtil.extractComponent(cache(0), DistributionManager.class).getCacheTopology(); DistributionInfo distributionInfo = cacheTopology.getDistribution(key); assertFalse(distributionInfo.isReadOwner()); assertTrue(distributionInfo.isWriteOwner()); assertEquals(address(1), distributionInfo.primary()); operation.put(key, "v2", cache(1)); BlockingLocalTopologyManager.finishRebalance(CacheTopology.Phase.READ_ALL_WRITE_ALL, bltm0, bltm1); waitForClusterToForm(); //let the cluster finish the state transfer assertInAllCache(key, "v2"); }