Search in sources :

Example 11 with PartitionRebalanceInfo

use of org.apache.geode.cache.partition.PartitionRebalanceInfo in project geode by apache.

the class RebalanceOperationDUnitTest method balanceBucketsByCount.

/**
   * Check to make sure that we balance buckets between two hosts with no redundancy.
   * 
   * @param simulate
   */
public void balanceBucketsByCount(final boolean simulate) {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    LoadProbe oldProbe = setLoadProbe(vm0, new BucketCountLoadProbe());
    try {
        SerializableRunnable createPrRegion = new SerializableRunnable("createRegion") {

            public void run() {
                Cache cache = getCache();
                AttributesFactory attr = new AttributesFactory();
                PartitionAttributesFactory paf = new PartitionAttributesFactory();
                paf.setRedundantCopies(0);
                paf.setRecoveryDelay(-1);
                paf.setStartupRecoveryDelay(-1);
                PartitionAttributes prAttr = paf.create();
                attr.setPartitionAttributes(prAttr);
                attr.setCacheLoader(new Bug40228Loader());
                cache.createRegion("region1", attr.create());
            }
        };
        // Create the region in only 1 VM
        vm0.invoke(createPrRegion);
        // Create some buckets with very uneven sizes
        vm0.invoke(new SerializableRunnable("createSomeBuckets") {

            public void run() {
                Cache cache = getCache();
                Region region = cache.getRegion("region1");
                region.put(Integer.valueOf(1), new byte[1024 * 1024]);
                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");
            }
        });
        // Create the region in the other VM (should have no effect)
        vm1.invoke(createPrRegion);
        // 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());
                assertEquals(3, results.getTotalBucketTransfersCompleted());
                assertTrue(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());
                assertTrue(0 < details.getBucketTransferBytes());
                assertEquals(3, details.getBucketTransfersCompleted());
                Set<PartitionMemberInfo> afterDetails = details.getPartitionMemberDetailsAfter();
                assertEquals(2, afterDetails.size());
                for (PartitionMemberInfo memberDetails : afterDetails) {
                    assertEquals(3, memberDetails.getBucketCount());
                    assertEquals(3, memberDetails.getPrimaryCount());
                }
                if (!simulate) {
                    verifyStats(manager, results);
                }
            }
        });
        if (!simulate) {
            SerializableRunnable checkRedundancyFixed = new SerializableRunnable("checkRedundancyFixed") {

                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(0, details.getLowRedundancyBucketCount());
                    assertEquals(2, details.getPartitionMemberInfo().size());
                    for (PartitionMemberInfo memberDetails : details.getPartitionMemberInfo()) {
                        assertEquals(3, memberDetails.getBucketCount());
                        assertEquals(3, memberDetails.getPrimaryCount());
                    }
                    // check to make sure that moving buckets didn't close the cache loader
                    Bug40228Loader loader = (Bug40228Loader) cache.getRegion("region1").getAttributes().getCacheLoader();
                    assertFalse(loader.isClosed());
                }
            };
            vm0.invoke(checkRedundancyFixed);
            vm1.invoke(checkRedundancyFixed);
        }
    } finally {
        setLoadProbe(vm0, oldProbe);
    }
}
Also used : BucketCountLoadProbe(org.apache.geode.internal.cache.partitioned.BucketCountLoadProbe) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) PartitionRebalanceInfo(org.apache.geode.cache.partition.PartitionRebalanceInfo) Host(org.apache.geode.test.dunit.Host) ResourceManager(org.apache.geode.cache.control.ResourceManager) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) PartitionMemberInfo(org.apache.geode.cache.partition.PartitionMemberInfo) VM(org.apache.geode.test.dunit.VM) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Region(org.apache.geode.cache.Region) LoadProbe(org.apache.geode.internal.cache.partitioned.LoadProbe) BucketCountLoadProbe(org.apache.geode.internal.cache.partitioned.BucketCountLoadProbe) RebalanceResults(org.apache.geode.cache.control.RebalanceResults) PartitionRegionInfo(org.apache.geode.cache.partition.PartitionRegionInfo) Cache(org.apache.geode.cache.Cache)

Example 12 with PartitionRebalanceInfo

use of org.apache.geode.cache.partition.PartitionRebalanceInfo 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 13 with PartitionRebalanceInfo

use of org.apache.geode.cache.partition.PartitionRebalanceInfo 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;
        }
    }
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Set(java.util.Set) PartitionRebalanceInfo(org.apache.geode.cache.partition.PartitionRebalanceInfo) RebalanceResults(org.apache.geode.cache.control.RebalanceResults) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 14 with PartitionRebalanceInfo

use of org.apache.geode.cache.partition.PartitionRebalanceInfo in project geode by apache.

the class RebalanceFunction method execute.

@Override
public void execute(FunctionContext context) {
    RebalanceOperation op = null;
    String[] str = new String[0];
    Cache cache = CacheFactory.getAnyInstance();
    ResourceManager manager = cache.getResourceManager();
    Object[] args = (Object[]) context.getArguments();
    String simulate = ((String) args[0]);
    Set<String> includeRegionNames = (Set<String>) args[1];
    Set<String> excludeRegionNames = (Set<String>) args[2];
    RebalanceFactory rbFactory = manager.createRebalanceFactory();
    rbFactory.excludeRegions(excludeRegionNames);
    rbFactory.includeRegions(includeRegionNames);
    RebalanceResults results = null;
    if (simulate.equals("true")) {
        op = rbFactory.simulate();
    } else {
        op = rbFactory.start();
    }
    try {
        results = op.getResults();
        logger.info("Starting RebalanceFunction got results = {}", results);
        StringBuilder str1 = new StringBuilder();
        str1.append(results.getTotalBucketCreateBytes() + "," + results.getTotalBucketCreateTime() + "," + results.getTotalBucketCreatesCompleted() + "," + results.getTotalBucketTransferBytes() + "," + results.getTotalBucketTransferTime() + "," + results.getTotalBucketTransfersCompleted() + "," + results.getTotalPrimaryTransferTime() + "," + results.getTotalPrimaryTransfersCompleted() + "," + results.getTotalTime() + ",");
        Set<PartitionRebalanceInfo> regns1 = results.getPartitionRebalanceDetails();
        Iterator it = regns1.iterator();
        while (it.hasNext()) {
            PartitionRebalanceInfo rgn = (PartitionRebalanceInfo) it.next();
            str1.append(rgn.getRegionPath() + ",");
        }
        logger.info("Starting RebalanceFunction str1={}", str1);
        context.getResultSender().lastResult(str1.toString());
    } catch (CancellationException e) {
        logger.info("Starting RebalanceFunction CancellationException: ", e.getMessage(), e);
        context.getResultSender().lastResult("CancellationException1 " + e.getMessage());
    } catch (InterruptedException e) {
        logger.info("Starting RebalanceFunction InterruptedException: {}", e.getMessage(), e);
        context.getResultSender().lastResult("InterruptedException2 " + e.getMessage());
    }
}
Also used : RebalanceOperation(org.apache.geode.cache.control.RebalanceOperation) Set(java.util.Set) PartitionRebalanceInfo(org.apache.geode.cache.partition.PartitionRebalanceInfo) ResourceManager(org.apache.geode.cache.control.ResourceManager) RebalanceFactory(org.apache.geode.cache.control.RebalanceFactory) CancellationException(java.util.concurrent.CancellationException) Iterator(java.util.Iterator) RebalanceResults(org.apache.geode.cache.control.RebalanceResults) Cache(org.apache.geode.cache.Cache)

Example 15 with PartitionRebalanceInfo

use of org.apache.geode.cache.partition.PartitionRebalanceInfo in project geode by apache.

the class DataCommands method buildResultForRebalance.

private CompositeResultData buildResultForRebalance(CompositeResultData rebalanceResultData, RebalanceResults results, int index, boolean simulate, InternalCache cache) {
    Set<PartitionRebalanceInfo> regions = results.getPartitionRebalanceDetails();
    Iterator iterator = regions.iterator();
    // add only if there are valid number of regions
    if (regions.size() > 0 && StringUtils.isNotEmpty(((PartitionRebalanceInfo) iterator.next()).getRegionPath())) {
        final TabularResultData resultData = rebalanceResultData.addSection().addTable("Table" + index);
        String newLine = System.getProperty("line.separator");
        StringBuilder resultStr = new StringBuilder();
        resultStr.append(newLine);
        resultData.accumulate("Rebalanced Stats", CliStrings.REBALANCE__MSG__TOTALBUCKETCREATEBYTES);
        resultData.accumulate("Value", results.getTotalBucketCreateBytes());
        resultStr.append(CliStrings.REBALANCE__MSG__TOTALBUCKETCREATEBYTES).append(" = ").append(results.getTotalBucketCreateBytes()).append(newLine);
        resultData.accumulate("Rebalanced Stats", CliStrings.REBALANCE__MSG__TOTALBUCKETCREATETIM);
        resultData.accumulate("Value", results.getTotalBucketCreateTime());
        resultStr.append(CliStrings.REBALANCE__MSG__TOTALBUCKETCREATETIM).append(" = ").append(results.getTotalBucketCreateTime()).append(newLine);
        resultData.accumulate("Rebalanced Stats", CliStrings.REBALANCE__MSG__TOTALBUCKETCREATESCOMPLETED);
        resultData.accumulate("Value", results.getTotalBucketCreatesCompleted());
        resultStr.append(CliStrings.REBALANCE__MSG__TOTALBUCKETCREATESCOMPLETED).append(" = ").append(results.getTotalBucketCreatesCompleted()).append(newLine);
        resultData.accumulate("Rebalanced Stats", CliStrings.REBALANCE__MSG__TOTALBUCKETTRANSFERBYTES);
        resultData.accumulate("Value", results.getTotalBucketTransferBytes());
        resultStr.append(CliStrings.REBALANCE__MSG__TOTALBUCKETTRANSFERBYTES).append(" = ").append(results.getTotalBucketTransferBytes()).append(newLine);
        resultData.accumulate("Rebalanced Stats", CliStrings.REBALANCE__MSG__TOTALBUCKETTRANSFERTIME);
        resultData.accumulate("Value", results.getTotalBucketTransferTime());
        resultStr.append(CliStrings.REBALANCE__MSG__TOTALBUCKETTRANSFERTIME).append(" = ").append(results.getTotalBucketTransferTime()).append(newLine);
        resultData.accumulate("Rebalanced Stats", CliStrings.REBALANCE__MSG__TOTALBUCKETTRANSFERSCOMPLETED);
        resultData.accumulate("Value", results.getTotalBucketTransfersCompleted());
        resultStr.append(CliStrings.REBALANCE__MSG__TOTALBUCKETTRANSFERSCOMPLETED).append(" = ").append(results.getTotalBucketTransfersCompleted()).append(newLine);
        resultData.accumulate("Rebalanced Stats", CliStrings.REBALANCE__MSG__TOTALPRIMARYTRANSFERTIME);
        resultData.accumulate("Value", results.getTotalPrimaryTransferTime());
        resultStr.append(CliStrings.REBALANCE__MSG__TOTALPRIMARYTRANSFERTIME).append(" = ").append(results.getTotalPrimaryTransferTime()).append(newLine);
        resultData.accumulate("Rebalanced Stats", CliStrings.REBALANCE__MSG__TOTALPRIMARYTRANSFERSCOMPLETED);
        resultData.accumulate("Value", results.getTotalPrimaryTransfersCompleted());
        resultStr.append(CliStrings.REBALANCE__MSG__TOTALPRIMARYTRANSFERSCOMPLETED).append(" = ").append(results.getTotalPrimaryTransfersCompleted()).append(newLine);
        resultData.accumulate("Rebalanced Stats", CliStrings.REBALANCE__MSG__TOTALTIME);
        resultData.accumulate("Value", results.getTotalTime());
        resultStr.append(CliStrings.REBALANCE__MSG__TOTALTIME).append(" = ").append(results.getTotalTime()).append(newLine);
        Iterator<PartitionRebalanceInfo> it = regions.iterator();
        String headerText;
        if (simulate) {
            headerText = "Simulated partition regions ";
        } else {
            headerText = "Rebalanced partition regions ";
        }
        while (it.hasNext()) {
            PartitionRebalanceInfo rgn = it.next();
            headerText = headerText + " " + rgn.getRegionPath();
        }
        resultData.setHeader(resultData.getHeader() + headerText);
        cache.getLogger().info(headerText + resultStr);
    }
    return rebalanceResultData;
}
Also used : TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) PartitionRebalanceInfo(org.apache.geode.cache.partition.PartitionRebalanceInfo) Iterator(java.util.Iterator)

Aggregations

PartitionRebalanceInfo (org.apache.geode.cache.partition.PartitionRebalanceInfo)25 RebalanceResults (org.apache.geode.cache.control.RebalanceResults)21 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)21 Cache (org.apache.geode.cache.Cache)20 Region (org.apache.geode.cache.Region)19 BucketRegion (org.apache.geode.internal.cache.BucketRegion)19 Host (org.apache.geode.test.dunit.Host)19 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)19 VM (org.apache.geode.test.dunit.VM)19 Set (java.util.Set)18 ResourceManager (org.apache.geode.cache.control.ResourceManager)18 PartitionMemberInfo (org.apache.geode.cache.partition.PartitionMemberInfo)18 PartitionRegionInfo (org.apache.geode.cache.partition.PartitionRegionInfo)18 HashSet (java.util.HashSet)16 TreeSet (java.util.TreeSet)16 AttributesFactory (org.apache.geode.cache.AttributesFactory)13 PartitionAttributes (org.apache.geode.cache.PartitionAttributes)13 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)13 DistributedMember (org.apache.geode.distributed.DistributedMember)7 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)7