use of org.apache.geode.cache.control.RebalanceResults in project geode by apache.
the class RebalanceOperationDUnitTest method testMoveBucketsOverflowToDisk.
/**
* A test that the stats when overflowing entries to disk are correct and we still rebalance
* correctly
*/
@Test
public void testMoveBucketsOverflowToDisk() throws Throwable {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
VM vm3 = host.getVM(3);
SerializableRunnable createPrRegion = new SerializableRunnable("createRegion") {
public void run() {
Cache cache = getCache();
AttributesFactory attr = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(1);
paf.setRecoveryDelay(-1);
paf.setStartupRecoveryDelay(-1);
PartitionAttributes prAttr = paf.create();
attr.setPartitionAttributes(prAttr);
attr.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(1, EvictionAction.OVERFLOW_TO_DISK));
cache.createRegion("region1", attr.create());
}
};
// Create the region in two VMs
vm0.invoke(createPrRegion);
vm1.invoke(createPrRegion);
// Create some buckets
vm0.invoke(new SerializableRunnable("createSomeBuckets") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion("region1");
for (int i = 0; i < 12; i++) {
Map m = new HashMap();
for (int j = 0; j < 200; j++) {
m.put(Integer.valueOf(i + 113 * j), "A");
}
region.putAll(m);
}
}
});
// Do some puts and gets, to trigger eviction
SerializableRunnable doOps = new SerializableRunnable("doOps") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion("region1");
Random rand = new Random();
for (int count = 0; count < 5000; count++) {
int bucket = (int) (count % 12);
int key = rand.nextInt(20);
region.put(Integer.valueOf(bucket + 113 * key), "B");
}
for (int count = 0; count < 500; count++) {
int bucket = (int) (count % 12);
int key = rand.nextInt(20);
region.get(Integer.valueOf(bucket + 113 * key));
}
}
};
// Do some operations
vm0.invoke(doOps);
// Create the region in one more VM.
vm2.invoke(createPrRegion);
// Now do a rebalance
final Long totalSize = (Long) vm0.invoke(new SerializableCallable("simulateRebalance") {
public Object call() {
Cache cache = getCache();
ResourceManager manager = cache.getResourceManager();
RebalanceResults results = doRebalance(false, manager);
assertEquals(0, results.getTotalBucketCreatesCompleted());
// We don't know how many primaries will move, it depends on
// if the move bucket code moves the primary or a redundant bucket
// assertIndexDetailsEquals(0, results.getTotalPrimaryTransfersCompleted());
assertEquals(8, results.getTotalBucketTransfersCompleted());
assertTrue(0 < results.getTotalBucketTransferBytes());
Set<PartitionRebalanceInfo> detailSet = results.getPartitionRebalanceDetails();
assertEquals(1, detailSet.size());
PartitionRebalanceInfo details = detailSet.iterator().next();
assertEquals(0, details.getBucketCreatesCompleted());
assertTrue(0 < details.getBucketTransferBytes());
assertEquals(8, details.getBucketTransfersCompleted());
long totalSize = 0;
Set<PartitionMemberInfo> beforeDetails = details.getPartitionMemberDetailsAfter();
for (PartitionMemberInfo memberDetails : beforeDetails) {
totalSize += memberDetails.getSize();
}
long afterSize = 0;
Set<PartitionMemberInfo> afterDetails = details.getPartitionMemberDetailsAfter();
assertEquals(3, afterDetails.size());
for (PartitionMemberInfo memberDetails : afterDetails) {
assertEquals(8, memberDetails.getBucketCount());
assertEquals(4, memberDetails.getPrimaryCount());
afterSize += memberDetails.getSize();
}
assertEquals(totalSize, afterSize);
verifyStats(manager, results);
return Long.valueOf(totalSize);
}
});
SerializableRunnable checkBalance = new SerializableRunnable("checkBalance") {
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());
LogWriterUtils.getLogWriter().info("details=" + details.getPartitionMemberInfo());
long afterSize = 0;
for (PartitionMemberInfo memberDetails : details.getPartitionMemberInfo()) {
assertEquals(8, memberDetails.getBucketCount());
assertEquals(4, memberDetails.getPrimaryCount());
afterSize += memberDetails.getSize();
}
// assertIndexDetailsEquals(totalSize.longValue(), afterSize);
}
};
vm0.invoke(checkBalance);
vm1.invoke(checkBalance);
vm2.invoke(checkBalance);
// Create the region in one more VM.
vm3.invoke(createPrRegion);
// Do another rebalance
vm0.invoke(new SerializableCallable("simulateRebalance") {
public Object call() {
Cache cache = getCache();
ResourceManager manager = cache.getResourceManager();
RebalanceResults results = doRebalance(false, manager);
assertEquals(0, results.getTotalBucketCreatesCompleted());
// We don't know how many primaries will move, it depends on
// if the move bucket code moves the primary or a redundant bucket
// assertIndexDetailsEquals(0, results.getTotalPrimaryTransfersCompleted());
assertEquals(6, results.getTotalBucketTransfersCompleted());
assertTrue(0 < results.getTotalBucketTransferBytes());
Set<PartitionRebalanceInfo> detailSet = results.getPartitionRebalanceDetails();
assertEquals(1, detailSet.size());
PartitionRebalanceInfo details = detailSet.iterator().next();
assertEquals(0, details.getBucketCreatesCompleted());
assertTrue(0 < details.getBucketTransferBytes());
assertEquals(6, details.getBucketTransfersCompleted());
long totalSize = 0;
Set<PartitionMemberInfo> beforeDetails = details.getPartitionMemberDetailsAfter();
for (PartitionMemberInfo memberDetails : beforeDetails) {
totalSize += memberDetails.getSize();
}
long afterSize = 0;
Set<PartitionMemberInfo> afterDetails = details.getPartitionMemberDetailsAfter();
assertEquals(4, afterDetails.size());
for (PartitionMemberInfo memberDetails : afterDetails) {
assertEquals(6, memberDetails.getBucketCount());
// assertIndexDetailsEquals(3, memberDetails.getPrimaryCount());
afterSize += memberDetails.getSize();
}
assertEquals(totalSize, afterSize);
return Long.valueOf(totalSize);
}
});
checkBalance = new SerializableRunnable("checkBalance") {
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());
LogWriterUtils.getLogWriter().info("details=" + details.getPartitionMemberInfo());
long afterSize = 0;
for (PartitionMemberInfo memberDetails : details.getPartitionMemberInfo()) {
assertEquals(6, memberDetails.getBucketCount());
// assertIndexDetailsEquals(3, memberDetails.getPrimaryCount());
afterSize += memberDetails.getSize();
}
// assertIndexDetailsEquals(totalSize.longValue(), afterSize);
}
};
vm0.invoke(checkBalance);
vm1.invoke(checkBalance);
vm2.invoke(checkBalance);
}
use of org.apache.geode.cache.control.RebalanceResults in project geode by apache.
the class RebalanceOperationDUnitTest method recoverRedundancy.
public void recoverRedundancy(final boolean simulate) {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
SerializableRunnable createPrRegion = new SerializableRunnable("createRegion") {
public void run() {
Cache cache = getCache();
AttributesFactory attr = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(1);
paf.setRecoveryDelay(-1);
paf.setStartupRecoveryDelay(-1);
PartitionAttributes prAttr = paf.create();
attr.setPartitionAttributes(prAttr);
cache.createRegion("region1", attr.create());
}
};
// Create the region in only 1 VM
vm0.invoke(createPrRegion);
// Create some buckets
vm0.invoke(new SerializableRunnable("createSomeBuckets") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion("region1");
region.put(Integer.valueOf(1), "A");
region.put(Integer.valueOf(2), "A");
region.put(Integer.valueOf(3), "A");
region.put(Integer.valueOf(4), "A");
region.put(Integer.valueOf(5), "A");
region.put(Integer.valueOf(6), "A");
}
});
SerializableRunnable checkLowRedundancy = new SerializableRunnable("checkLowRedundancy") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion("region1");
PartitionRegionInfo details = PartitionRegionHelper.getPartitionRegionInfo(region);
assertEquals(6, details.getCreatedBucketCount());
assertEquals(0, details.getActualRedundantCopies());
assertEquals(6, details.getLowRedundancyBucketCount());
}
};
// make sure we can tell that the buckets have low redundancy
vm0.invoke(checkLowRedundancy);
// Create the region in the other VM (should have no effect)
vm1.invoke(createPrRegion);
// Make sure we still have low redundancy
vm0.invoke(checkLowRedundancy);
// Now simulate a rebalance
vm0.invoke(new SerializableRunnable("simulateRebalance") {
public void run() {
Cache cache = getCache();
ResourceManager manager = cache.getResourceManager();
RebalanceResults results = doRebalance(simulate, manager);
assertEquals(6, results.getTotalBucketCreatesCompleted());
assertEquals(3, 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(6, details.getBucketCreatesCompleted());
assertEquals(3, details.getPrimaryTransfersCompleted());
assertEquals(0, details.getBucketTransferBytes());
assertEquals(0, details.getBucketTransfersCompleted());
Set<PartitionMemberInfo> afterDetails = details.getPartitionMemberDetailsAfter();
assertEquals(2, afterDetails.size());
for (PartitionMemberInfo memberDetails : afterDetails) {
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(6, details.getCreatedBucketCount());
assertEquals(1, details.getActualRedundantCopies());
assertEquals(0, details.getLowRedundancyBucketCount());
}
};
vm0.invoke(checkRedundancyFixed);
vm1.invoke(checkRedundancyFixed);
} else {
// Make sure the simulation didn't do anything
vm0.invoke(checkLowRedundancy);
}
}
use of org.apache.geode.cache.control.RebalanceResults in project geode by apache.
the class RebalanceOperationDUnitTest method enforceIp.
public void enforceIp(final boolean simulate) {
Invoke.invokeInEveryVM(new SerializableRunnable() {
public void run() {
Properties props = new Properties();
props.setProperty(ENFORCE_UNIQUE_HOST, "true");
getSystem(props);
}
});
try {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
SerializableRunnable createPrRegion = new SerializableRunnable("createRegion") {
public void run() {
Cache cache = getCache();
AttributesFactory attr = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(1);
paf.setRecoveryDelay(-1);
paf.setStartupRecoveryDelay(-1);
PartitionAttributes prAttr = paf.create();
attr.setPartitionAttributes(prAttr);
cache.createRegion("region1", attr.create());
}
};
// Create the region in only 1 VM
vm0.invoke(createPrRegion);
// Create some buckets
vm0.invoke(new SerializableRunnable("createSomeBuckets") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion("region1");
region.put(Integer.valueOf(1), "A");
region.put(Integer.valueOf(2), "A");
region.put(Integer.valueOf(3), "A");
region.put(Integer.valueOf(4), "A");
region.put(Integer.valueOf(5), "A");
region.put(Integer.valueOf(6), "A");
}
});
SerializableRunnable checkLowRedundancy = new SerializableRunnable("checkLowRedundancy") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion("region1");
PartitionRegionInfo details = PartitionRegionHelper.getPartitionRegionInfo(region);
assertEquals(6, details.getCreatedBucketCount());
assertEquals(0, details.getActualRedundantCopies());
assertEquals(6, details.getLowRedundancyBucketCount());
}
};
// make sure we can tell that the buckets have low redundancy
vm0.invoke(checkLowRedundancy);
// Create the region in the other VM (should have no effect)
vm1.invoke(createPrRegion);
// Make sure we still have low redundancy
vm0.invoke(checkLowRedundancy);
// Now simulate a rebalance
vm0.invoke(new SerializableRunnable("simulateRebalance") {
public void run() {
Cache cache = getCache();
ResourceManager manager = cache.getResourceManager();
RebalanceResults results = doRebalance(simulate, manager);
assertEquals(0, results.getTotalBucketCreatesCompleted());
assertEquals(0, results.getTotalPrimaryTransfersCompleted());
// We actually *will* transfer buckets, because that improves
// the balance
assertEquals(3, results.getTotalBucketTransfersCompleted());
// assertIndexDetailsEquals(0, results.getTotalBucketTransferBytes());
Set<PartitionRebalanceInfo> detailSet = results.getPartitionRebalanceDetails();
assertEquals(1, detailSet.size());
PartitionRebalanceInfo details = detailSet.iterator().next();
assertEquals(0, details.getBucketCreatesCompleted());
assertEquals(0, details.getPrimaryTransfersCompleted());
assertEquals(3, details.getBucketTransfersCompleted());
// assertIndexDetailsEquals(0, details.getBucketTransferBytes());
if (!simulate) {
verifyStats(manager, results);
}
}
});
// Make sure we still have low redundancy
vm0.invoke(checkLowRedundancy);
vm1.invoke(checkLowRedundancy);
} finally {
disconnectFromDS();
Invoke.invokeInEveryVM(new SerializableRunnable() {
public void run() {
disconnectFromDS();
}
});
}
}
use of org.apache.geode.cache.control.RebalanceResults in project geode by apache.
the class RollingUpgrade2DUnitTest method rebalance.
public static void rebalance(Object cache) throws Exception {
RebalanceOperation op = ((GemFireCache) cache).getResourceManager().createRebalanceFactory().start();
// Wait until the rebalance is completex
RebalanceResults results = op.getResults();
Method getTotalTimeMethod = results.getClass().getMethod("getTotalTime");
getTotalTimeMethod.setAccessible(true);
System.out.println("Took " + results.getTotalTime() + " milliseconds\n");
System.out.println("Transfered " + results.getTotalBucketTransferBytes() + "bytes\n");
}
use of org.apache.geode.cache.control.RebalanceResults in project geode by apache.
the class RebalanceOperationImpl method submitRebalanceTask.
private Future<RebalanceResults> submitRebalanceTask(final PartitionedRegionRebalanceOp rebalanceOp, final long rebalanceStartTime) {
final InternalResourceManager manager = this.cache.getInternalResourceManager();
ScheduledExecutorService ex = manager.getExecutor();
synchronized (futureLock) {
// this update should happen inside this.futureLock
pendingTasks++;
try {
Future<RebalanceResults> future = ex.submit(new Callable<RebalanceResults>() {
public RebalanceResults call() {
try {
RebalanceResultsImpl results = new RebalanceResultsImpl();
SystemFailure.checkFailure();
cache.getCancelCriterion().checkCancelInProgress(null);
Set<PartitionRebalanceInfo> detailSet = null;
detailSet = rebalanceOp.execute();
for (PartitionRebalanceInfo details : detailSet) {
results.addDetails(details);
}
return results;
} catch (RuntimeException e) {
logger.debug("Unexpected exception in rebalancing: {}", e.getMessage(), e);
throw e;
} finally {
synchronized (RebalanceOperationImpl.this.futureLock) {
pendingTasks--;
if (pendingTasks == 0) {
// all threads done
manager.removeInProgressRebalance(RebalanceOperationImpl.this);
manager.getStats().endRebalance(rebalanceStartTime);
}
}
}
}
});
return future;
} catch (RejectedExecutionException e) {
cache.getCancelCriterion().checkCancelInProgress(null);
throw e;
}
}
}
Aggregations