StateConsumer stateConsumer = extractComponent(c, StateConsumer.class);
StateTransferLock stateTransferLock = extractComponent(c, StateTransferLock.class);
DefaultRebalancePolicy rebalancePolicy = (DefaultRebalancePolicy) TestingUtil.extractGlobalComponent(c.getCacheManager(), RebalancePolicy.class);
Address cacheAddress = c.getAdvancedCache().getRpcManager().getAddress();
while (true) {
CacheTopology cacheTopology = stateTransferManager.getCacheTopology();
boolean chContainsAllMembers = cacheTopology.getCurrentCH().getMembers().size() == caches.length;
boolean chIsBalanced = cacheTopology.getPendingCH() == null && rebalancePolicy.isBalanced(cacheTopology.getCurrentCH());
if (chContainsAllMembers && chIsBalanced) {
// This is the part where we wait for the old entries to be invalidated
// because the "transaction data received" flag is only set after the invalidation.
try {
stateTransferLock.waitForTransactionData(cacheTopology.getTopologyId());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
break;
}
if (System.currentTimeMillis() > giveup) {
String message;
if (!chContainsAllMembers) {
Address[] addresses = new Address[caches.length];
for (int i = 0; i < caches.length; i++) {
addresses[i] = caches[i].getCacheManager().getAddress();
}
message = String.format("Timed out waiting for rebalancing to complete on node %s, " +
"expected member list is %s, current member list is %s!",
cacheAddress, Arrays.toString(addresses), cacheTopology.getCurrentCH().getMembers());
} else {
message = String.format("Timed out waiting for rebalancing to complete on node %s, " +
"current topology is %s", c.getCacheManager().getAddress(), cacheTopology);
}
log.error(message);