public static boolean hasOwners(Object key, Cache<?, ?> primaryOwner, Cache<?, ?>... backupOwners) { DistributionManager dm = primaryOwner.getAdvancedCache().getDistributionManager(); List<Address> ownerAddresses = dm.locate(key); if (!addressOf(primaryOwner).equals(ownerAddresses.get(0))) return false; for (int i = 0; i < backupOwners.length; i++) { if (!ownerAddresses.contains(addressOf(backupOwners[i]))) return false; } return true; }
public static boolean isOwner(Cache<?, ?> c, Object key) { DistributionManager dm = c.getAdvancedCache().getDistributionManager(); List<Address> ownerAddresses = dm.locate(key); return ownerAddresses.contains(addressOf(c)); }
List<Address> addresses = manager.locate(sessionId);
public void testRepeatedRemoteGet() { String key = "key"; List<Address> owners = cache(0).getAdvancedCache().getDistributionManager().locate(key); Cache<Object, Object> nonOwnerCache = caches().stream() .filter(c -> !owners.contains(address(c))) .findAny() .orElse(null); cache(0).put(key, "value"); for (int i = 0; i < 50000; i++) { assertEquals("value", nonOwnerCache.get(key)); } } }
public void testInvalidation() throws Exception { assertEquals(Collections.singletonList(address(0)), advancedCache(0).getDistributionManager().locate(k0)); assertEquals(Collections.singletonList(address(0)), advancedCache(1).getDistributionManager().locate(k0)); advancedCache(1).put(k0, "k1"); assertTrue(advancedCache(1).getDataContainer().containsKey(k0)); assertTrue(advancedCache(0).getDataContainer().containsKey(k0)); tm(0).begin(); cache(0).put(k0, "v2"); tm(0).commit(); assertFalse(advancedCache(1).getDataContainer().containsKey(k0)); }
public void testRemoteGet() { Cache<MagicKey, String> c1 = cache(0); Cache<MagicKey, String> c2 = cache(1); Cache<MagicKey, String> c3 = cache(2); MagicKey k = new MagicKey(c1, c2); List<Address> owners = c1.getAdvancedCache().getDistributionManager().locate(k); assert owners.size() == 2: "Key should have 2 owners"; Cache<MagicKey, String> owner1 = getCacheForAddress(owners.get(0)); assert owner1 == c1; Cache<MagicKey, String> owner2 = getCacheForAddress(owners.get(1)); assert owner2 == c2; Cache<MagicKey, String> nonOwner = getNonOwner(owners); assert nonOwner == c3; owner1.put(k, "value"); assert "value".equals(nonOwner.get(k)); }
public void testSinglePhaseCommit() throws Exception { final Object k0_1 = getKeyForCache(0); final Object k0_2 = getKeyForCache(0); final List<Address> members = advancedCache(0).getRpcManager().getTransport().getMembers(); assert advancedCache(0).getDistributionManager().locate(k0_1).containsAll(members); assert advancedCache(0).getDistributionManager().locate(k0_2).containsAll(members); TxCountInterceptor interceptor0 = new TxCountInterceptor(); TxCountInterceptor interceptor1 = new TxCountInterceptor(); advancedCache(0).addInterceptor(interceptor0, 1); advancedCache(1).addInterceptor(interceptor1, 2); tm(2).begin(); cache(2).put(k0_1, "v"); cache(2).put(k0_2, "v"); tm(2).commit(); assertEquals(interceptor0.lockCount, 2); assertEquals(interceptor1.lockCount, 2); assertEquals(interceptor0.prepareCount, 1); assertEquals(interceptor1.prepareCount, 1); assertEquals(interceptor0.commitCount, 0); assertEquals(interceptor1.commitCount, 0); }
public void testKeyAffinityServiceFails() { log.trace("Test keys for cache2."); for (int i = 0; i < KEY_QUEUE_SIZE; i++) { Object keyForAddress = keyAffinityService2.getKeyForAddress(manager2.getAddress()); assertTrue(cache1.getDistributionManager().locate(keyForAddress).contains(manager2.getAddress())); } log.trace("Test keys for cache1."); for (int i = 0; i < KEY_QUEUE_SIZE; i++) { Object keyForAddress = keyAffinityService1.getKeyForAddress(manager1.getAddress()); List<Address> locate = cache1.getDistributionManager().locate(keyForAddress); assertTrue("For key " + keyForAddress + " Locate " + locate + " should contain " + manager1.getAddress(), locate.contains(manager1.getAddress())); } } }
@Override public Result execute(Session session) throws StatementException { Cache<Object, Object> cache = session.getCache(keyData.getCacheName()); Codec codec = session.getCodec(); if (options.size() > 0) { for (Option option : options) { switch (option.toEnum(Options.class)) { case CODEC: { if (option.getParameter() == null) { throw log.missingOptionParameter(option.getName()); } else { codec = session.getCodec(option.getParameter()); } } } } } DistributionManager distributionManager = cache.getAdvancedCache().getDistributionManager(); if(distributionManager!=null) { Object key = keyData.getKey(); List<Address> addresses = distributionManager.locate(codec.encodeKey(key)); return new StringResult(addresses.toString()); } else { throw log.cacheNotDistributed(); } }
private void checkCorrectness(int i) { if (checkCorrectness) { log.tracef("Checking correctness for iteration %s", i); print("Checking correctness"); List<Address> owners = advancedCache(0).getDistributionManager().locate("k"); if (!checkOwners(owners)) { correctness.set(false); } for (int q = 0; q < nodes; q++) { print(q, cache(0).get("k")); } Object expectedValue = cache(0).get("k"); log.tracef("Original value read from cache 0 is %s", expectedValue); for (int j = 0; j < nodes; j++) { Object actualValue = cache(j).get("k"); boolean areEquals = expectedValue == null ? actualValue == null : expectedValue.equals(actualValue); print("Are " + actualValue + " and " + expectedValue + " equals ? " + areEquals); if (!areEquals) { correctness.set(false); print("Consistency error. On cache 0 we had " + expectedValue + " and on " + j + " we had " + actualValue); log.trace("Consistency error. On cache 0 we had " + expectedValue + " and on " + j + " we had " + actualValue); } } } }
boolean isLocalNodeBackupOwner = localCache.getDistributionManager().locate(KEY).indexOf(localCache.getCacheManager().getAddress()) > 0; CountDownLatch insertLatch = new CountDownLatch(isLocalNodeBackupOwner ? 3 : 2); ExpectingInterceptor.get(localCache).when((ctx, cmd) -> cmd instanceof PutKeyValueCommand).countDown(insertLatch);
public void testMultipleLocksInSameTx() throws Exception { final Object k1 = getKeyForCache(1); final Object k2 = getKeyForCache(2); assertEquals(advancedCache(0).getDistributionManager().locate(k1).get(0), address(1)); log.tracef("k1=%s, k2=%s", k1, k2); tm(0).begin(); cache(0).put(k1, "v"); cache(0).put(k2, "v"); assert !lockManager(0).isLocked(k1); assert lockManager(1).isLocked(k1); assert !lockManager(2).isLocked(k1); assert !lockManager(0).isLocked(k2); assert !lockManager(1).isLocked(k2); assert lockManager(2).isLocked(k2); tm(0).commit(); assertNotLocked(k1); assertNotLocked(k2); assertValue(k1, false); assertValue(k2, false); }
public void testMultipleLocksInSameTx() throws Exception { final Object k1 = getKeyForCache(1); final Object k2 = getKeyForCache(2); assertEquals(advancedCache(0).getDistributionManager().locate(k1).get(0), address(1)); log.tracef("k1=%s, k2=%s", k1, k2); tm(0).begin(); cache(0).put(k1, "v"); cache(0).put(k2, "v"); EmbeddedTransaction dtm = (EmbeddedTransaction) tm(0).getTransaction(); dtm.runPrepare(); assert !lockManager(0).isLocked(k1); assert lockManager(1).isLocked(k1); assert !lockManager(2).isLocked(k1); assert !lockManager(0).isLocked(k2); assert !lockManager(1).isLocked(k2); assert lockManager(2).isLocked(k2); dtm.runCommit(false); assertNotLocked(k1); assertNotLocked(k2); assertValue(k1, false); assertValue(k2, false); }
public void testRemoteGet() { final String key1 = this.getClass().getName() + "K1"; List<Address> owners = cache(0).getAdvancedCache().getDistributionManager().locate(key1);
.before("tx1:block_rollback_on_backup").after("tx1:after_rollback_on_backup"); assertEquals(Arrays.asList(address(1), address(2)), advancedCache(0).getDistributionManager().locate(TEST_KEY)); Future<Object> lockCheckFuture = fork(() -> { sequencer.enter("tx1:resume_rollback_on_backup");
assertEquals(Arrays.asList(address(0), address(1), address(2)), advancedCache(0).getDistributionManager().locate(key)); Cache<Object, Object> primaryOwnerCache = cache(0); final Cache<Object, Object> newBackupOwnerCache = cache(3);
.after("tx1:after_rollback_on_backup"); assertEquals(Arrays.asList(address(1), address(2)), advancedCache(0).getDistributionManager().locate(TEST_KEY)); sequencer.advance("tx1:begin");
assertEquals(Arrays.asList(address(1), address(2)), advancedCache(0).getDistributionManager().locate(TEST_KEY)); sequencer.advance("main:start");