use of org.apache.geode.cache.control.RebalanceResults in project geode by apache.
the class RebalanceOperationDUnitTest method recoverRedundancyBalancing.
public void recoverRedundancyBalancing(final boolean simulate) {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
final DistributedMember member1 = createPrRegion(vm0, "region1", 200, null);
vm0.invoke(new SerializableRunnable("createSomeBuckets") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion("region1");
for (int i = 0; i < 12; i++) {
region.put(Integer.valueOf(i), "A");
}
}
});
SerializableRunnable checkRedundancy = new SerializableRunnable("checkRedundancy") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion("region1");
PartitionRegionInfo details = PartitionRegionHelper.getPartitionRegionInfo(region);
assertEquals(12, details.getCreatedBucketCount());
assertEquals(0, details.getActualRedundantCopies());
assertEquals(12, details.getLowRedundancyBucketCount());
}
};
vm0.invoke(checkRedundancy);
// Now create the region in 2 more VMs with half the localMaxMemory
createPrRegion(vm1, "region1", 100, null);
createPrRegion(vm2, "region1", 100, null);
vm0.invoke(checkRedundancy);
// Now simulate a rebalance
vm0.invoke(new SerializableRunnable("rebalance") {
public void run() {
Cache cache = getCache();
ResourceManager manager = cache.getResourceManager();
RebalanceResults results = doRebalance(simulate, manager);
assertEquals(12, results.getTotalBucketCreatesCompleted());
assertEquals(6, results.getTotalPrimaryTransfersCompleted());
assertEquals(0, results.getTotalBucketTransferBytes());
assertEquals(0, results.getTotalBucketTransfersCompleted());
Set<PartitionRebalanceInfo> detailSet = results.getPartitionRebalanceDetails();
assertEquals(1, detailSet.size());
PartitionRebalanceInfo details = detailSet.iterator().next();
assertEquals(12, details.getBucketCreatesCompleted());
assertEquals(6, details.getPrimaryTransfersCompleted());
assertEquals(0, details.getBucketTransferBytes());
assertEquals(0, details.getBucketTransfersCompleted());
Set<PartitionMemberInfo> afterDetails = details.getPartitionMemberDetailsAfter();
assertEquals(3, afterDetails.size());
for (PartitionMemberInfo memberDetails : afterDetails) {
// We have 1 member with a size of 200 and two members with size 100
if (memberDetails.getDistributedMember().equals(member1)) {
assertEquals(12, memberDetails.getBucketCount());
assertEquals(6, memberDetails.getPrimaryCount());
} else {
assertEquals(6, memberDetails.getBucketCount());
assertEquals(3, memberDetails.getPrimaryCount());
}
}
if (!simulate) {
verifyStats(manager, results);
}
}
});
if (!simulate) {
SerializableRunnable checkRedundancyFixed = new SerializableRunnable("checkLowRedundancy") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion("region1");
PartitionRegionInfo details = PartitionRegionHelper.getPartitionRegionInfo(region);
assertEquals(12, details.getCreatedBucketCount());
assertEquals(1, details.getActualRedundantCopies());
assertEquals(0, details.getLowRedundancyBucketCount());
}
};
vm0.invoke(checkRedundancyFixed);
vm1.invoke(checkRedundancyFixed);
vm2.invoke(checkRedundancyFixed);
}
}
use of org.apache.geode.cache.control.RebalanceResults in project geode by apache.
the class FixedPartitioningTestBase method doRebalance.
public static void doRebalance() {
ResourceManager manager = cache.getResourceManager();
RebalanceOperation operation = manager.createRebalanceFactory().start();
try {
RebalanceResults result = operation.getResults();
} catch (InterruptedException e) {
org.apache.geode.test.dunit.Assert.fail("Not expecting exception", e);
}
}
use of org.apache.geode.cache.control.RebalanceResults in project geode by apache.
the class PeerToPeerCache method rebalanceCache.
@Override
protected void rebalanceCache() {
try {
getLogger().info("Rebalancing: " + this.cache);
RebalanceResults results = RegionHelper.rebalanceCache(this.cache);
if (getLogger().isDebugEnabled()) {
getLogger().debug("Done rebalancing: " + this.cache);
getLogger().debug(RegionHelper.getRebalanceResultsMessage(results));
}
} catch (Exception e) {
getLogger().warn("Rebalance failed because of the following exception:", e);
}
}
use of org.apache.geode.cache.control.RebalanceResults in project geode by apache.
the class RebalanceOperationImpl method getResults.
public RebalanceResults getResults() throws CancellationException, InterruptedException {
RebalanceResultsImpl results = new RebalanceResultsImpl();
List<Future<RebalanceResults>> frlist = getFutureList();
for (Future<RebalanceResults> fr : frlist) {
try {
RebalanceResults rr = fr.get();
results.addDetails((RebalanceResultsImpl) rr);
} catch (ExecutionException e) {
if (e.getCause() instanceof GemFireException) {
throw (GemFireException) e.getCause();
} else if (e.getCause() instanceof InternalGemFireError) {
throw (InternalGemFireError) e.getCause();
} else {
throw new InternalGemFireError(e.getCause());
}
}
}
return results;
}
use of org.apache.geode.cache.control.RebalanceResults in project geode by apache.
the class RebalanceOperationImpl method getResults.
public RebalanceResults getResults(long timeout, TimeUnit unit) throws CancellationException, TimeoutException, InterruptedException {
long endTime = unit.toNanos(timeout) + System.nanoTime();
RebalanceResultsImpl results = new RebalanceResultsImpl();
List<Future<RebalanceResults>> frlist = getFutureList();
for (Future<RebalanceResults> fr : frlist) {
try {
long waitTime = endTime - System.nanoTime();
RebalanceResults rr = fr.get(waitTime, TimeUnit.NANOSECONDS);
results.addDetails((RebalanceResultsImpl) rr);
} catch (ExecutionException e) {
if (e.getCause() instanceof GemFireException) {
throw (GemFireException) e.getCause();
} else if (e.getCause() instanceof InternalGemFireError) {
throw (InternalGemFireError) e.getCause();
} else {
throw new InternalGemFireError(e.getCause());
}
}
}
return results;
}
Aggregations