Search in sources :

Example 1 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 2 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 3 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)

Example 4 with RebalanceResults

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

the class PartitionedRegionStatsDUnitTest method testDataStoreEntryCount2WithRebalance.

@Test
public void testDataStoreEntryCount2WithRebalance() throws InterruptedException {
    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(2), "A");
            region.put(Long.valueOf(3), "A");
            region.put(Long.valueOf(4), "A");
            region.put(Long.valueOf(5), "A");
        }
    });
    vm1.invoke(createPrRegion);
    validateEntryCount(vm0, 3);
    validateEntryCount(vm1, 3);
}
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 5 with RebalanceResults

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

the class RebalanceOperationDUnitTest method moveBucketsWithUnrecoveredValuesRedundancy.

/**
   * Test to ensure that we wait for in progress write operations before moving a primary.
   * 
   * @throws CancellationException
   */
public void moveBucketsWithUnrecoveredValuesRedundancy(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() {
            System.setProperty(DiskStoreImpl.RECOVER_VALUE_PROPERTY_NAME, "false");
            try {
                Cache cache = getCache();
                if (cache.findDiskStore("store") == null) {
                    cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).setMaxOplogSize(1).create("store");
                }
                AttributesFactory attr = new AttributesFactory();
                PartitionAttributesFactory paf = new PartitionAttributesFactory();
                attr.setDiskStoreName("store");
                attr.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
                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());
            } finally {
                System.setProperty(DiskStoreImpl.RECOVER_VALUE_PROPERTY_NAME, "true");
            }
        }
    };
    // 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");
        }
    });
    final long[] bucketSizes = (long[]) vm0.invoke(new SerializableCallable("get sizes and close cache") {

        public Object call() {
            PartitionedRegion region = (PartitionedRegion) getCache().getRegion("region1");
            PartitionedRegionDataStore dataStore = region.getDataStore();
            long[] bucketSizes = new long[7];
            for (int i = 1; i <= 6; i++) {
                BucketRegion bucket = dataStore.getLocalBucketById(i);
                bucketSizes[i] = bucket.getTotalBytes();
                assertEquals(0, bucket.getNumOverflowBytesOnDisk());
                assertEquals(0, bucket.getNumOverflowOnDisk());
                assertEquals(1, bucket.getNumEntriesInVM());
            }
            getCache().close();
            return bucketSizes;
        }
    });
    // now recover the region
    vm0.invoke(createPrRegion);
    vm0.invoke(new SerializableRunnable("check sizes") {

        public void run() {
            PartitionedRegion region = (PartitionedRegion) getCache().getRegion("region1");
            PartitionedRegionDataStore dataStore = region.getDataStore();
            for (int i = 1; i <= 6; i++) {
                BucketRegion bucket = dataStore.getLocalBucketById(i);
                assertEquals(1, bucket.getNumOverflowOnDisk());
                assertEquals(0, bucket.getNumEntriesInVM());
                // the size recorded on disk is not the same is the in memory size, apparently
                assertTrue("Bucket size was " + bucket.getNumOverflowBytesOnDisk(), 1 < bucket.getNumOverflowBytesOnDisk());
                assertEquals(bucket.getNumOverflowBytesOnDisk(), bucket.getTotalBytes());
            }
        }
    });
    // 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("Transfered Bytes = " + results.getTotalBucketTransferBytes(), 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);
        SerializableRunnable checkBug40228Fixed = new SerializableRunnable("checkBug40228Fixed") {

            public void run() {
                Cache cache = getCache();
                Bug40228Loader loader = (Bug40228Loader) cache.getRegion("region1").getAttributes().getCacheLoader();
                assertFalse(loader.isClosed());
                // check to make sure that closing the PR closes the cache loader
                cache.getRegion("region1").close();
                assertTrue(loader.isClosed());
            }
        };
        vm0.invoke(checkBug40228Fixed);
        vm1.invoke(checkBug40228Fixed);
    }
}
Also used : 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) PartitionedRegionDataStore(org.apache.geode.internal.cache.PartitionedRegionDataStore) 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) BucketRegion(org.apache.geode.internal.cache.BucketRegion) PartitionMemberInfo(org.apache.geode.cache.partition.PartitionMemberInfo) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Region(org.apache.geode.cache.Region) RebalanceResults(org.apache.geode.cache.control.RebalanceResults) PartitionRegionInfo(org.apache.geode.cache.partition.PartitionRegionInfo) Cache(org.apache.geode.cache.Cache)

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