Search in sources :

Example 11 with ResourceManager

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

the class MemoryMonitorJUnitTest method testCriticalHeapThreshold.

@Test
public void testCriticalHeapThreshold() throws Exception {
    final int toohigh = 101;
    final int toolow = -1;
    final float disabled = 0.0f;
    final float justright = 92.5f;
    final ResourceManager rm = this.cache.getResourceManager();
    long usageThreshold = -1;
    int once = 0;
    for (MemoryPoolMXBean p : ManagementFactory.getMemoryPoolMXBeans()) {
        if (p.isUsageThresholdSupported() && HeapMemoryMonitor.isTenured(p)) {
            usageThreshold = p.getUsageThreshold();
            once++;
        }
    }
    assertEquals("Expected only one pool to be assigned", 1, once);
    // Default test, current default is disabled
    assertEquals(rm.getCriticalHeapPercentage(), MemoryThresholds.DEFAULT_CRITICAL_PERCENTAGE, 0.01);
    NotificationEmitter emitter = (NotificationEmitter) ManagementFactory.getMemoryMXBean();
    try {
        emitter.removeNotificationListener(InternalResourceManager.getInternalResourceManager(cache).getHeapMonitor());
        assertTrue("Expected that the resource manager was not registered", false);
    } catch (ListenerNotFoundException expected) {
    }
    try {
        rm.setCriticalHeapPercentage(toohigh);
        assertTrue("Expected illegal argument exception for value " + toohigh, false);
    } catch (IllegalArgumentException toohi) {
    }
    try {
        rm.setCriticalHeapPercentage(toolow);
        assertTrue("Expected illegal argument exception for value " + toolow, false);
    } catch (IllegalArgumentException toohi) {
    }
    rm.setCriticalHeapPercentage(justright);
    emitter = (NotificationEmitter) ManagementFactory.getMemoryMXBean();
    {
        InternalResourceManager irm = InternalResourceManager.getInternalResourceManager(cache);
        HeapMemoryMonitor hmm = irm.getHeapMonitor();
        // Expect no exception for removal (it was installed during set)
        hmm.stopMonitoring();
    }
    assertEquals(rm.getCriticalHeapPercentage(), justright, 0.01);
    rm.setCriticalHeapPercentage(disabled);
    assertEquals(rm.getCriticalHeapPercentage(), disabled, 0.01);
    emitter = (NotificationEmitter) ManagementFactory.getMemoryMXBean();
    try {
        emitter.removeNotificationListener(InternalResourceManager.getInternalResourceManager(cache).getHeapMonitor());
        assertTrue("Expected that the resource manager was not registered", false);
    } catch (ListenerNotFoundException expected) {
    }
    // Assert the threshold was reset
    for (MemoryPoolMXBean p : ManagementFactory.getMemoryPoolMXBeans()) {
        if (HeapMemoryMonitor.isTenured(p)) {
            assertEquals(usageThreshold, p.getUsageThreshold());
        }
    }
}
Also used : NotificationEmitter(javax.management.NotificationEmitter) ListenerNotFoundException(javax.management.ListenerNotFoundException) ResourceManager(org.apache.geode.cache.control.ResourceManager) MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 12 with ResourceManager

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

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

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

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

the class ResourceManagerValidator method validateJavaStartupParameters.

public static void validateJavaStartupParameters(GemFireCache cache) {
    // Get the input arguments
    ResourceManager rm = cache.getResourceManager();
    RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
    List<String> inputArguments = runtimeBean.getInputArguments();
    if (cache.getLogger().fineEnabled()) {
        cache.getLogger().fine("Full input java arguments: " + inputArguments);
    }
    // Validate the arguments based on VM vendor
    String vmVendor = runtimeBean.getVmVendor();
    if (vmVendor.startsWith("Sun") || vmVendor.startsWith("Apple")) {
        // java.vm.vendor = Sun Microsystems Inc. || java.vm.vendor = Apple Inc.
        validateSunArguments(cache, rm, inputArguments);
    } else if (vmVendor.startsWith("IBM")) {
    // java.vm.vendor = IBM Corporation
    // TODO validate IBM input arguments
    } else if (vmVendor.startsWith("BEA")) {
    // java.vm.vendor = BEA Systems, Inc.
    // TODO validate JRockit input arguments
    }
}
Also used : ResourceManager(org.apache.geode.cache.control.ResourceManager) RuntimeMXBean(java.lang.management.RuntimeMXBean)

Aggregations

ResourceManager (org.apache.geode.cache.control.ResourceManager)31 RebalanceResults (org.apache.geode.cache.control.RebalanceResults)22 Cache (org.apache.geode.cache.Cache)20 PartitionRegionInfo (org.apache.geode.cache.partition.PartitionRegionInfo)19 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)19 Region (org.apache.geode.cache.Region)18 PartitionRebalanceInfo (org.apache.geode.cache.partition.PartitionRebalanceInfo)18 BucketRegion (org.apache.geode.internal.cache.BucketRegion)18 Host (org.apache.geode.test.dunit.Host)18 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)18 VM (org.apache.geode.test.dunit.VM)18 PartitionMemberInfo (org.apache.geode.cache.partition.PartitionMemberInfo)16 HashSet (java.util.HashSet)15 Set (java.util.Set)15 TreeSet (java.util.TreeSet)14 AttributesFactory (org.apache.geode.cache.AttributesFactory)13 PartitionAttributes (org.apache.geode.cache.PartitionAttributes)13 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)13 Test (org.junit.Test)8 RebalanceOperation (org.apache.geode.cache.control.RebalanceOperation)7