Search in sources :

Example 6 with RebalanceOperation

use of org.apache.geode.cache.control.RebalanceOperation 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 7 with RebalanceOperation

use of org.apache.geode.cache.control.RebalanceOperation in project geode by apache.

the class MyGatewayEventSubstitutionFilter method doRebalance.

/**
   * Do a rebalance and verify balance was improved. If evictionPercentage > 0 (the default) then we
   * have heapLRU and this can cause simulate and rebalance results to differ if eviction kicks in
   * between. (See BUG 44899).
   */
public static void doRebalance() {
    ResourceManager resMan = cache.getResourceManager();
    boolean heapEviction = (resMan.getEvictionHeapPercentage() > 0);
    RebalanceFactory factory = resMan.createRebalanceFactory();
    try {
        RebalanceResults simulateResults = null;
        if (!heapEviction) {
            LogWriterUtils.getLogWriter().info("Calling rebalance simulate");
            RebalanceOperation simulateOp = factory.simulate();
            simulateResults = simulateOp.getResults();
        }
        LogWriterUtils.getLogWriter().info("Starting rebalancing");
        RebalanceOperation rebalanceOp = factory.start();
        RebalanceResults rebalanceResults = rebalanceOp.getResults();
    } catch (InterruptedException e) {
        Assert.fail("Interrupted", e);
    }
}
Also used : RebalanceFactory(org.apache.geode.cache.control.RebalanceFactory) RebalanceOperation(org.apache.geode.cache.control.RebalanceOperation) InternalResourceManager(org.apache.geode.internal.cache.control.InternalResourceManager) ResourceManager(org.apache.geode.cache.control.ResourceManager) RebalanceResults(org.apache.geode.cache.control.RebalanceResults)

Example 8 with RebalanceOperation

use of org.apache.geode.cache.control.RebalanceOperation in project geode by apache.

the class PartitionedRegionStatsDUnitTest method testDataStoreEntryCountWithRebalance.

@Test
public void testDataStoreEntryCountWithRebalance() throws InterruptedException {
    // Ok, first problem, GC'd tombstone is counted as an entry
    // To test
    // - modifying a tombstone
    // - modifying and doing tombstone GC?
    final Host host = Host.getHost(0);
    final VM vm0 = host.getVM(0);
    final 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(0);
            PartitionAttributes prAttr = paf.create();
            attr.setPartitionAttributes(prAttr);
            cache.createRegion("region1", attr.create());
            RebalanceOperation op = cache.getResourceManager().createRebalanceFactory().start();
            try {
                RebalanceResults results = op.getResults();
            } catch (Exception e) {
                Assert.fail("ex", e);
            }
        }
    };
    vm0.invoke(createPrRegion);
    vm0.invoke(new SerializableRunnable("Put some data") {

        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion("region1");
            region.put(Long.valueOf(0), "A");
            region.put(Long.valueOf(1), "A");
            region.put(Long.valueOf(113), "A");
            region.put(Long.valueOf(114), "A");
            region.destroy(Long.valueOf(0));
            region.destroy(Long.valueOf(1));
        }
    });
    vm1.invoke(createPrRegion);
    validateEntryCount(vm0, 1);
    validateEntryCount(vm1, 1);
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) RebalanceOperation(org.apache.geode.cache.control.RebalanceOperation) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) Region(org.apache.geode.cache.Region) Host(org.apache.geode.test.dunit.Host) RebalanceResults(org.apache.geode.cache.control.RebalanceResults) CancellationException(java.util.concurrent.CancellationException) CacheException(org.apache.geode.cache.CacheException) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 9 with RebalanceOperation

use of org.apache.geode.cache.control.RebalanceOperation 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 10 with RebalanceOperation

use of org.apache.geode.cache.control.RebalanceOperation in project geode by apache.

the class TestFunction method executeWithLastResult.

private void executeWithLastResult(FunctionContext context) {
    RegionFunctionContext rfContext = (RegionFunctionContext) context;
    final PartitionedRegion pr = (PartitionedRegion) rfContext.getDataSet();
    ResourceManager resMan = pr.getCache().getResourceManager();
    RebalanceFactory factory = resMan.createRebalanceFactory();
    RebalanceOperation rebalanceOp = factory.start();
    try {
        RebalanceResults rebalanceResults = rebalanceOp.getResults();
    } catch (CancellationException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    context.getResultSender().lastResult((Serializable) context.getArguments());
}
Also used : RebalanceFactory(org.apache.geode.cache.control.RebalanceFactory) RebalanceOperation(org.apache.geode.cache.control.RebalanceOperation) CancellationException(java.util.concurrent.CancellationException) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) RegionFunctionContext(org.apache.geode.cache.execute.RegionFunctionContext) ResourceManager(org.apache.geode.cache.control.ResourceManager) RebalanceResults(org.apache.geode.cache.control.RebalanceResults)

Aggregations

RebalanceOperation (org.apache.geode.cache.control.RebalanceOperation)16 RebalanceResults (org.apache.geode.cache.control.RebalanceResults)11 CancellationException (java.util.concurrent.CancellationException)7 Cache (org.apache.geode.cache.Cache)7 ResourceManager (org.apache.geode.cache.control.ResourceManager)7 Host (org.apache.geode.test.dunit.Host)7 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)7 VM (org.apache.geode.test.dunit.VM)7 RebalanceFactory (org.apache.geode.cache.control.RebalanceFactory)6 Region (org.apache.geode.cache.Region)5 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)5 Test (org.junit.Test)5 AttributesFactory (org.apache.geode.cache.AttributesFactory)4 PartitionAttributes (org.apache.geode.cache.PartitionAttributes)4 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)4 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)4 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)3 TimeoutException (java.util.concurrent.TimeoutException)2 CacheException (org.apache.geode.cache.CacheException)2 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)2