Search in sources :

Example 16 with RebalanceResults

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);
    }
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) PartitionMemberInfo(org.apache.geode.cache.partition.PartitionMemberInfo) VM(org.apache.geode.test.dunit.VM) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) PartitionRebalanceInfo(org.apache.geode.cache.partition.PartitionRebalanceInfo) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Region(org.apache.geode.cache.Region) Host(org.apache.geode.test.dunit.Host) ResourceManager(org.apache.geode.cache.control.ResourceManager) RebalanceResults(org.apache.geode.cache.control.RebalanceResults) PartitionRegionInfo(org.apache.geode.cache.partition.PartitionRegionInfo) Cache(org.apache.geode.cache.Cache)

Example 17 with RebalanceResults

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);
    }
}
Also used : RebalanceOperation(org.apache.geode.cache.control.RebalanceOperation) ResourceManager(org.apache.geode.cache.control.ResourceManager) RebalanceResults(org.apache.geode.cache.control.RebalanceResults)

Example 18 with RebalanceResults

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);
    }
}
Also used : RebalanceResults(org.apache.geode.cache.control.RebalanceResults) CacheClosedException(org.apache.geode.cache.CacheClosedException)

Example 19 with RebalanceResults

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;
}
Also used : GemFireException(org.apache.geode.GemFireException) Future(java.util.concurrent.Future) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) RebalanceResults(org.apache.geode.cache.control.RebalanceResults) InternalGemFireError(org.apache.geode.InternalGemFireError)

Example 20 with RebalanceResults

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;
}
Also used : GemFireException(org.apache.geode.GemFireException) Future(java.util.concurrent.Future) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) RebalanceResults(org.apache.geode.cache.control.RebalanceResults) InternalGemFireError(org.apache.geode.InternalGemFireError)

Aggregations

RebalanceResults (org.apache.geode.cache.control.RebalanceResults)38 Cache (org.apache.geode.cache.Cache)26 Host (org.apache.geode.test.dunit.Host)26 VM (org.apache.geode.test.dunit.VM)26 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)25 Region (org.apache.geode.cache.Region)22 ResourceManager (org.apache.geode.cache.control.ResourceManager)22 PartitionRebalanceInfo (org.apache.geode.cache.partition.PartitionRebalanceInfo)21 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)21 BucketRegion (org.apache.geode.internal.cache.BucketRegion)20 PartitionRegionInfo (org.apache.geode.cache.partition.PartitionRegionInfo)19 Set (java.util.Set)18 AttributesFactory (org.apache.geode.cache.AttributesFactory)18 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)18 PartitionMemberInfo (org.apache.geode.cache.partition.PartitionMemberInfo)18 HashSet (java.util.HashSet)16 TreeSet (java.util.TreeSet)16 PartitionAttributes (org.apache.geode.cache.PartitionAttributes)16 RebalanceOperation (org.apache.geode.cache.control.RebalanceOperation)11 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)10