public CacheLocality(Cache<?, ?> cache) { DistributionManager dist = cache.getAdvancedCache().getDistributionManager(); this.locality = (dist != null) ? new ConsistentHashLocality(dist.getCacheTopology()) : new SimpleLocality(true); }
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 Membership getMembership() { if (this.isSingleton()) { return new SingletonMembership(this.getLocalMember()); } Transport transport = this.cache.getCacheManager().getTransport(); DistributionManager dist = this.cache.getAdvancedCache().getDistributionManager(); return (dist != null) ? new CacheMembership(transport.getAddress(), dist.getCacheTopology(), this) : new CacheMembership(transport, this); }
@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(); }
private int currentTopologyId(Cache cache) { return TestingUtil.extractComponent(cache, DistributionManager.class).getCacheTopology().getTopologyId(); } }
public void testDistributionFromSecondaryOwner() throws Exception { Object key = "testDistributionFromSecondaryOwner"; doTestDistribution(key, cacheManagers.stream() .map(cm -> cm.<Object, Integer>getCache(DIST).getAdvancedCache()) // owner... .filter(cache -> cache.getDistributionManager().getCacheTopology().getDistribution(key).isWriteBackup()) .findAny() .get()); }
@Override public boolean shouldModifyIndexes(FlagAffectedCommand command, InvocationContext ctx, DistributionManager distributionManager, RpcManager rpcManager, Object key) { if (key == null || distributionManager == null) { return true; } DistributionInfo info = distributionManager.getCacheTopology().getDistribution(key); // If this is a backup node we should modify the entry in the remote context return info.isPrimary() || info.isWriteOwner() && (ctx.isInTxScope() || !ctx.isOriginLocal() || command != null && command.hasAnyFlag(FlagBitSets.PUT_FOR_STATE_TRANSFER)); } },
private void checkRehashed(DistributionManager dm, List<Cache<Object,Object>> caches, List<Address> addresses) { TestingUtil.waitForNoRebalance(caches); assertNull(dm.getCacheTopology().getPendingCH()); ConsistentHash ch = dm.getCacheTopology().getCurrentCH(); assertEquals(addresses, ch.getMembers()); for (int i = 0; i < ch.getNumSegments(); i++) { assertEquals(ch.getNumOwners(), ch.locateOwnersForSegment(i).size()); } } }
public void assertActualMembers() { Set<org.infinispan.remoting.transport.Address> expected = cachesInThisPartition().stream() .map(c -> c.getAdvancedCache().getRpcManager().getAddress()) .collect(Collectors.toSet()); for (Cache c : cachesInThisPartition()) { eventuallyEquals(expected, () -> new HashSet<>(c.getAdvancedCache().getDistributionManager().getCacheTopology().getActualMembers())); } }
protected void assertMapsToAddress(Object o, Address addr) { LocalizedCacheTopology cacheTopology = caches.get(0).getAdvancedCache().getDistributionManager().getCacheTopology(); List<Address> addresses = cacheTopology.getDistribution(o).writeOwners(); assertEquals("Expected key " + o + " to map to address " + addr + ". List of addresses is" + addresses, true, addresses.contains(addr)); }
@Override public TestCache create(String groupName, List<Cache<GroupKey, String>> cacheList) { for (Cache<GroupKey, String> cache : cacheList) { DistributionManager distributionManager = TestingUtil.extractComponent(cache, DistributionManager.class); DistributionInfo distributionInfo = distributionManager.getCacheTopology().getDistribution(groupName); if (distributionInfo.isPrimary()) { return new TestCache(cache, cache.getAdvancedCache()); } } throw new IllegalStateException("didn't find a cache... should never happen!"); } },
private CacheTopology getCounterCacheTopology(EmbeddedCacheManager cacheManager) { AdvancedCache<?, ?> cache = cacheManager.getCache(CounterModuleLifecycle.COUNTER_CACHE_NAME).getAdvancedCache(); return cache.getCacheConfiguration().clustering().cacheMode().isClustered() ? cache.getComponentRegistry().getDistributionManager().getCacheTopology() : null; //local cache }
private void waitForStateTransfer(int expectedTopologyId, Cache... caches) { waitForNoRebalance(caches); for (Cache c : caches) { CacheTopology cacheTopology = c.getAdvancedCache().getDistributionManager().getCacheTopology(); assertEquals(String.format("Wrong topology on cache %s, expected %d and got %s", c, expectedTopologyId, cacheTopology), expectedTopologyId, cacheTopology.getTopologyId()); } }
public void testSequence() { TriangleOrderManager triangleOrderManager = new TriangleOrderManager(4); DistributionManager mockDistributionManager = mock(DistributionManager.class); when(mockDistributionManager.getCacheTopology()).thenReturn(mockCacheTopology(0)); TestingUtil.inject(triangleOrderManager, mockDistributionManager); assertEquals(1, triangleOrderManager.next(0, 0)); assertEquals(1, triangleOrderManager.next(1, 0)); assertEquals(2, triangleOrderManager.next(1, 0)); }
@Override public Object visitGetCacheEntryCommand(InvocationContext ctx, GetCacheEntryCommand command) throws Throwable { assertNotNull(stateTransferLock); log.tracef("Waiting for topology %d before executing %s", expectedTopologyId, command); CompletableFuture<Void> topologyFuture = stateTransferLock.topologyFuture(expectedTopologyId); if (topologyFuture != null) { topologyFuture.get(10, TimeUnit.SECONDS); } assertEquals(expectedTopologyId, distributionManager.getCacheTopology().getTopologyId()); return invokeNext(ctx, command); } }
private boolean isPrimaryOwner(VisitableCommand cmd) { if (cmd instanceof DataCommand) { return cache.getAdvancedCache().getDistributionManager().getCacheTopology() .getDistribution(((DataCommand) cmd).getKey()).isPrimary(); } else { return true; } }
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; }
@Test (dependsOnMethods = "testServersDropped") public void testCollocatedKey() { LocalizedCacheTopology cacheTopology = manager(0).getCache(cacheName).getAdvancedCache().getDistributionManager().getCacheTopology(); for (int i = 0; i < 1000; i++) { List<Address> addresses = cacheTopology.getDistribution(i).writeOwners(); Object collocatedKey = keyAffinityService.getCollocatedKey(i); List<Address> addressList = cacheTopology.getDistribution(collocatedKey).writeOwners(); assertEquals(addresses, addressList); } }