@Override public boolean shouldModifyIndexes(FlagAffectedCommand command, InvocationContext ctx, DistributionManager distributionManager, RpcManager rpcManager, Object key) { return command instanceof ClearCommand || !(command.hasAnyFlag(FlagBitSets.SKIP_INDEXING)) && (distributionManager == null || distributionManager.getCacheTopology().getDistribution(key).isWriteOwner()); } },
@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)); } },
@Override public TestCache create(String groupName, List<Cache<GroupKey, String>> cacheList) { Cache<GroupKey, String> primaryOwner = null; AdvancedCache<GroupKey, String> backupOwner = null; for (Cache<GroupKey, String> cache : cacheList) { DistributionManager distributionManager = TestingUtil.extractComponent(cache, DistributionManager.class); DistributionInfo distributionInfo = distributionManager.getCacheTopology().getDistribution(groupName); if (primaryOwner == null && distributionInfo.isPrimary()) { primaryOwner = cache; } else if (backupOwner == null && distributionInfo.isWriteOwner()) { backupOwner = cache.getAdvancedCache(); } if (primaryOwner != null && backupOwner != null) { return new TestCache(primaryOwner, backupOwner); } } throw new IllegalStateException("didn't find a cache... should never happen!"); } },
@Override public TestCache create(String groupName, List<Cache<GroupKey, String>> cacheList) { Cache<GroupKey, String> primaryOwner = null; AdvancedCache<GroupKey, String> nonOwner = null; for (Cache<GroupKey, String> cache : cacheList) { DistributionManager distributionManager = TestingUtil.extractComponent(cache, DistributionManager.class); DistributionInfo distributionInfo = distributionManager.getCacheTopology().getDistribution(groupName); if (primaryOwner == null && distributionInfo.isPrimary()) { primaryOwner = cache; } else if (nonOwner == null && !distributionInfo.isWriteOwner()) { nonOwner = cache.getAdvancedCache(); } if (primaryOwner != null && nonOwner != null) { return new TestCache(primaryOwner, nonOwner); } } throw new IllegalStateException("didn't find a cache... should never happen!"); } };
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"); }