Search in sources :

Example 1 with BucketCountLoadProbe

use of org.apache.geode.internal.cache.partitioned.BucketCountLoadProbe 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)

Aggregations

HashSet (java.util.HashSet)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 AttributesFactory (org.apache.geode.cache.AttributesFactory)1 Cache (org.apache.geode.cache.Cache)1 PartitionAttributes (org.apache.geode.cache.PartitionAttributes)1 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)1 Region (org.apache.geode.cache.Region)1 RebalanceResults (org.apache.geode.cache.control.RebalanceResults)1 ResourceManager (org.apache.geode.cache.control.ResourceManager)1 PartitionMemberInfo (org.apache.geode.cache.partition.PartitionMemberInfo)1 PartitionRebalanceInfo (org.apache.geode.cache.partition.PartitionRebalanceInfo)1 PartitionRegionInfo (org.apache.geode.cache.partition.PartitionRegionInfo)1 BucketRegion (org.apache.geode.internal.cache.BucketRegion)1 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)1 BucketCountLoadProbe (org.apache.geode.internal.cache.partitioned.BucketCountLoadProbe)1 LoadProbe (org.apache.geode.internal.cache.partitioned.LoadProbe)1 Host (org.apache.geode.test.dunit.Host)1 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)1 VM (org.apache.geode.test.dunit.VM)1