@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(); }
protected MagicKey getKeyForCache(Cache<?, ?> primary, Cache<?, ?>... backup) { if (cacheMode == null || !cacheMode.isScattered()) { return new MagicKey(primary, backup); } else { return new MagicKey(primary); } }
protected <K, V> AdvancedCache<K, V> getCacheFromPreferredPartition(AdvancedCache... caches) { Map<Address, CacheStatusResponse> statusResponses = Arrays.stream(caches).collect(Collectors.toMap(this::address, this::getCacheStatus)); LostDataCheck lostDataCheck = cacheMode.isScattered() ? ClusterTopologyManagerImpl::scatteredLostDataCheck : ClusterTopologyManagerImpl::distLostDataCheck; CacheTopology preferredTopology = new PreferAvailabilityStrategy(null, null, lostDataCheck) .computePreferredTopology(statusResponses); if (trace) log.tracef("getCacheFromPreferredPartition: partition=%s", preferredTopology.getMembers()); return Arrays.stream(caches) .filter(c -> address(c).equals(preferredTopology.getMembers().get(0))) .findFirst().get(); }
@Override protected int[][] assignOwners(int numSegments, int numOwners, List<Address> members) { if (cacheMode.isDistributed()) { assertEquals(2, numOwners); switch (members.size()) { case 1: return new int[][]{{0}}; case 2: return new int[][]{{0, 1}}; default: return new int[][]{{members.size() - 1, 0}}; } } else if (cacheMode.isScattered()) { return new int[][]{{0}}; } else { throw new IllegalStateException(); } } }
private MagicKey createKey(Cache<Object, String> primaryOwner, Cache<Object, String> backupOwner) { if (cacheMode.isScattered()) { return new MagicKey(primaryOwner); } else { return new MagicKey(primaryOwner, backupOwner); } }
public Class<? extends DDAsyncInterceptor> ewi() { Class<? extends DDAsyncInterceptor> after; if (cacheMode.isScattered()) { after = biasAcquisition == BiasAcquisition.NEVER ? RetryingEntryWrappingInterceptor.class : BiasedEntryWrappingInterceptor.class; } else if (Configurations.isTxVersioned(cache(0).getCacheConfiguration())) { after = VersionedEntryWrappingInterceptor.class; } else { after = EntryWrappingInterceptor.class; } return after; }
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; }
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 (cacheMode.isScattered()) {
private <K> void assertExistence(final K key) { LocalizedCacheTopology cacheTopology = cache(addresses[0]).getAdvancedCache().getDistributionManager().getCacheTopology(); final List<Address> addresses = cacheTopology.getDistribution(key).writeOwners(); log.debug(key + " should be present on = " + addresses); eventuallyEquals(2, () -> caches().stream().mapToInt(c -> c.getAdvancedCache().getDataContainer().containsKey(key) ? 1 : 0).sum()); for (Cache<? super K, ?> c : caches()) { if (cacheMode.isScattered()) { eventuallyEquals("Failure for key " + key + " on cache " + address(c), true, () -> addresses.contains(address(c)) ? c.getAdvancedCache().getDataContainer().containsKey(key) : true); } else { eventuallyEquals("Failure for key " + key + " on cache " + address(c), addresses.contains(address(c)), () -> c.getAdvancedCache().getDataContainer().containsKey(key)); } } }
String key = "key" + j; if (!dm.getLocality(key).isLocal()) { if (!cacheMode.isScattered()) { assertFalse("Key '" + key + "' is not owned by node " + address(i) + " but it still appears there", dataContainer.containsKey(key)); assertTrue("Key " + key + " is missing from the shared store", store.keySet().contains(key)); if (cacheMode.isScattered()) {
private void testPutMapCommand(boolean sync, boolean putOnPrimary) throws Exception { MagicKey key = new MagicKey("key", cache(0)); if (sync) { cache(putOnPrimary ? 0 : 1).putAll(Collections.singletonMap(key, "value")); } else { Future<Void> f = cache(putOnPrimary ? 0 : 1).putAllAsync(Collections.singletonMap(key, "value")); assertNotNull(f); assertNull(f.get()); assertTrue(f.isDone()); assertFalse(f.isCancelled()); } if (cacheMode.isScattered()) { int hasValue = 0; for (Cache c : caches()) { Object value = c.getAdvancedCache().withFlags(Flag.SKIP_REMOTE_LOOKUP, Flag.SKIP_OWNERSHIP_CHECK).get(key); if ("value".equals(value)) { hasValue++; } else assertNull(value); } assertEquals(2, hasValue); } else { assertEquals("value", cache(0).getAdvancedCache().withFlags(Flag.SKIP_REMOTE_LOOKUP).get(key)); assertEquals("value", cache(1).getAdvancedCache().withFlags(Flag.SKIP_REMOTE_LOOKUP).get(key)); assertEquals("value", cache(2).getAdvancedCache().withFlags(Flag.SKIP_REMOTE_LOOKUP).get(key)); } } }
@Override protected void createCacheManagers() { GlobalConfigurationBuilder gcb = GlobalConfigurationBuilder.defaultClusteredBuilder(); if (useTriangle == Boolean.FALSE) { gcb.addModule(PrivateGlobalConfigurationBuilder.class).serverMode(true); } ConfigurationBuilder dcc = getDefaultClusteredCacheConfig(cacheMode, false); if (!cacheMode.isScattered()) { dcc.clustering().hash().numOwners(3).l1().disable(); } if (biasAcquisition != null) { dcc.clustering().biasAcquisition(biasAcquisition); } createCluster(gcb, dcc, 3); waitForClusterToForm(); }
if (cacheMode.isScattered()) { if (cacheMode.isScattered() && !expireOnPrimary) { assertEquals(key.toString(), expiredValue); } else {
protected ConfigurationBuilder createCacheConfigBuilder() { ConfigurationBuilder c = getDefaultClusteredCacheConfig(cacheMode, transactional); if (!cacheMode.isScattered()) { c.clustering().hash().numOwners(100); } c.clustering().hash().numSegments(4); if (lockingMode != null) { c.transaction().lockingMode(lockingMode); } if (totalOrder != null && totalOrder) { c.transaction().transactionProtocol(TransactionProtocol.TOTAL_ORDER); } if (biasAcquisition != null) { c.clustering().biasAcquisition(biasAcquisition); } return c; }
@Override protected void createCacheManagers() throws Throwable { builderUsed = new ConfigurationBuilder(); builderUsed.clustering().cacheMode(cacheMode); if (!cacheMode.isScattered()) { builderUsed.clustering().hash().numOwners(NUM_OWNERS); } builderUsed.clustering().stateTransfer().chunkSize(25000); // This is increased just for the put all command when doing full tracing builderUsed.clustering().remoteTimeout(12000); if (transactional) { builderUsed.transaction().transactionMode(TransactionMode.TRANSACTIONAL); } if (biasAcquisition != null) { builderUsed.clustering().biasAcquisition(biasAcquisition); } if (enableStore) { builderUsed.persistence() .addStore(DummyInMemoryStoreConfigurationBuilder.class) .shared(true) .storeName(PutMapCommandStressTest.class.toString()); } createClusteredCaches(CACHE_COUNT, CACHE_NAME, builderUsed); }
@Override protected void createCacheManagers() throws Throwable { builderUsed = new ConfigurationBuilder(); HashConfigurationBuilder hashConfiguration = builderUsed.clustering().cacheMode(cacheMode).hash().numSegments(3); if (!cacheMode.isReplicated()) { BaseControlledConsistentHashFactory<? extends ConsistentHash> chf = cacheMode.isScattered() ? new TestScatteredConsistentHashFactory() : new TestDefaultConsistentHashFactory(); hashConfiguration.consistentHashFactory(chf); } if (transactional) { builderUsed.transaction().transactionMode(TransactionMode.TRANSACTIONAL); } if (cacheMode.isClustered()) { builderUsed.clustering().stateTransfer().chunkSize(50); enhanceConfiguration(builderUsed); createClusteredCaches(3, CACHE_NAME, builderUsed); } else { enhanceConfiguration(builderUsed); EmbeddedCacheManager cm = TestCacheManagerFactory.createCacheManager(builderUsed); cacheManagers.add(cm); cm.defineConfiguration(CACHE_NAME, builderUsed.build()); } }
private ConfigurationBuilder createConfigurationBuilder() { ConfigurationBuilder builder = getDefaultClusteredCacheConfig(cacheMode, false); builder.clustering().stateTransfer().fetchInMemoryState(true); builder.clustering().hash().groups().enabled(true); builder.clustering().hash().numSegments(1); if (cacheMode.isScattered()) { builder.clustering().hash().consistentHashFactory(new CustomConsistentHashFactory(new BaseControlledConsistentHashFactory.ScatteredTrait(), cacheMode)); } else { builder.clustering().hash().consistentHashFactory(new CustomConsistentHashFactory(new BaseControlledConsistentHashFactory.DefaultTrait(), cacheMode)); } return builder; }
private <K, V> CacheHelper<K, V> create(List<Cache<K, V>> cacheList) { CacheHelper<K, V> cacheHelper = new CacheHelper<>(); for (Cache<K, V> cache : cacheList) { ClusteringDependentLogic clusteringDependentLogic = extractComponent(cache, ClusteringDependentLogic.class); DistributionInfo distributionInfo = clusteringDependentLogic.getCacheTopology().getDistribution(key); log.debugf("owners for key %s are %s", key, distributionInfo.writeOwners()); if (distributionInfo.isPrimary()) { log.debug("Cache " + address(cache) + " is the primary owner"); assertTrue(cacheHelper.addCache(Ownership.PRIMARY, cache)); } else if (distributionInfo.isWriteBackup()) { log.debug("Cache " + address(cache) + " is the backup owner"); assertTrue(cacheHelper.addCache(Ownership.BACKUP, cache)); } else { log.debug("Cache " + address(cache) + " is the non owner"); assertTrue(cacheHelper.addCache(Ownership.NON_OWNER, cache) || cacheMode.isScattered()); } } return cacheHelper; }