Search in sources :

Example 6 with CachePerfStats

use of org.apache.geode.internal.cache.CachePerfStats in project geode by apache.

the class OffHeapRegionEntryHelperJUnitTest method addressToObjectShouldReturnDecompressedValueFromChunkIfAskedToDecompress.

@Test
public void addressToObjectShouldReturnDecompressedValueFromChunkIfAskedToDecompress() {
    byte[] data = ByteBuffer.allocate(Long.SIZE / Byte.SIZE).putLong(Long.MAX_VALUE).array();
    boolean isSerialized = false;
    boolean isCompressed = true;
    OffHeapStoredObject chunk = (OffHeapStoredObject) ma.allocateAndInitialize(data, isSerialized, isCompressed);
    // create the mock context
    RegionEntryContext regionContext = mock(RegionEntryContext.class);
    CachePerfStats cacheStats = mock(CachePerfStats.class);
    Compressor compressor = mock(Compressor.class);
    long startTime = 10000L;
    // mock required things
    when(regionContext.getCompressor()).thenReturn(compressor);
    when(compressor.decompress(data)).thenReturn(data);
    when(regionContext.getCachePerfStats()).thenReturn(cacheStats);
    when(cacheStats.startDecompression()).thenReturn(startTime);
    Object actual = OffHeapRegionEntryHelper.addressToObject(chunk.getAddress(), true, regionContext);
    assertThat(actual).isInstanceOf(byte[].class);
    assertThat(actual).isEqualTo(data);
}
Also used : CachePerfStats(org.apache.geode.internal.cache.CachePerfStats) Compressor(org.apache.geode.compression.Compressor) RegionEntryContext(org.apache.geode.internal.cache.RegionEntryContext) UnitTest(org.apache.geode.test.junit.categories.UnitTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with CachePerfStats

use of org.apache.geode.internal.cache.CachePerfStats in project geode by apache.

the class MemberHealthEvaluator method checkCacheRequiredRolesMeet.

/**
   * The function keeps updating the health of the cache based on roles required by the regions and
   * their reliability policies.
   */
private void checkCacheRequiredRolesMeet(List status) {
    try {
        InternalCache cache = (InternalCache) CacheFactory.getAnyInstance();
        CachePerfStats cPStats = cache.getCachePerfStats();
        if (cPStats.getReliableRegionsMissingFullAccess() > 0) {
            // health is okay.
            int numRegions = cPStats.getReliableRegionsMissingFullAccess();
            status.add(okayHealth(LocalizedStrings.MemberHealthEvaluator_THERE_ARE_0_REGIONS_MISSING_REQUIRED_ROLES_BUT_ARE_CONFIGURED_FOR_FULL_ACCESS.toLocalizedString(numRegions)));
        } else if (cPStats.getReliableRegionsMissingLimitedAccess() > 0) {
            // health is poor
            int numRegions = cPStats.getReliableRegionsMissingLimitedAccess();
            status.add(poorHealth(LocalizedStrings.MemberHealthEvaluator_THERE_ARE_0_REGIONS_MISSING_REQUIRED_ROLES_AND_CONFIGURED_WITH_LIMITED_ACCESS.toLocalizedString(numRegions)));
        } else if (cPStats.getReliableRegionsMissingNoAccess() > 0) {
            // health is poor
            int numRegions = cPStats.getReliableRegionsMissingNoAccess();
            status.add(poorHealth(LocalizedStrings.MemberHealthEvaluator_THERE_ARE_0_REGIONS_MISSING_REQUIRED_ROLES_AND_CONFIGURED_WITHOUT_ACCESS.toLocalizedString(numRegions)));
        }
    } catch (CancelException ignore) {
    }
}
Also used : CachePerfStats(org.apache.geode.internal.cache.CachePerfStats) InternalCache(org.apache.geode.internal.cache.InternalCache) CancelException(org.apache.geode.CancelException)

Example 8 with CachePerfStats

use of org.apache.geode.internal.cache.CachePerfStats in project geode by apache.

the class AbstractGatewaySender method initializeEventIdIndexMetaDataRegion.

@SuppressWarnings({ "rawtypes", "unchecked", "deprecation" })
private static synchronized Region<String, Integer> initializeEventIdIndexMetaDataRegion(AbstractGatewaySender sender) {
    final InternalCache cache = sender.getCache();
    Region<String, Integer> region = cache.getRegion(META_DATA_REGION_NAME);
    if (region == null) {
        // Create region attributes (must be done this way to use InternalRegionArguments)
        AttributesFactory factory = new AttributesFactory();
        factory.setScope(Scope.DISTRIBUTED_ACK);
        factory.setDataPolicy(DataPolicy.REPLICATE);
        RegionAttributes ra = factory.create();
        // Create a stats holder for the meta data stats
        final HasCachePerfStats statsHolder = new HasCachePerfStats() {

            public CachePerfStats getCachePerfStats() {
                return new CachePerfStats(cache.getDistributedSystem(), META_DATA_REGION_NAME);
            }
        };
        // Create internal region arguments
        InternalRegionArguments ira = new InternalRegionArguments().setIsUsedForMetaRegion(true).setCachePerfStatsHolder(statsHolder);
        // Create the region
        try {
            region = cache.createVMRegion(META_DATA_REGION_NAME, ra, ira);
        } catch (RegionExistsException e) {
            region = cache.getRegion(META_DATA_REGION_NAME);
        } catch (Exception e) {
            throw new IllegalStateException(LocalizedStrings.AbstractGatewaySender_META_REGION_CREATION_EXCEPTION_0.toLocalizedString(sender), e);
        }
    }
    return region;
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) HasCachePerfStats(org.apache.geode.internal.cache.HasCachePerfStats) HasCachePerfStats(org.apache.geode.internal.cache.HasCachePerfStats) CachePerfStats(org.apache.geode.internal.cache.CachePerfStats) InternalCache(org.apache.geode.internal.cache.InternalCache) InternalRegionArguments(org.apache.geode.internal.cache.InternalRegionArguments) RegionExistsException(org.apache.geode.cache.RegionExistsException) RegionExistsException(org.apache.geode.cache.RegionExistsException) BucketMovedException(org.apache.geode.internal.cache.execute.BucketMovedException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) CancelException(org.apache.geode.CancelException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) GatewayCancelledException(org.apache.geode.distributed.GatewayCancelledException)

Example 9 with CachePerfStats

use of org.apache.geode.internal.cache.CachePerfStats in project geode by apache.

the class MemberMBeanBridge method init.

public MemberMBeanBridge init() {
    CachePerfStats cachePerfStats = this.cache.getCachePerfStats();
    addCacheStats(cachePerfStats);
    addFunctionStats(system.getFunctionServiceStats());
    if (system.getDistributionManager().getStats() instanceof DistributionStats) {
        DistributionStats distributionStats = (DistributionStats) system.getDistributionManager().getStats();
        addDistributionStats(distributionStats);
    }
    if (PureJavaMode.osStatsAreAvailable()) {
        Statistics[] systemStats = null;
        if (HostStatHelper.isSolaris()) {
            systemStats = system.findStatisticsByType(SolarisSystemStats.getType());
        } else if (HostStatHelper.isLinux()) {
            systemStats = system.findStatisticsByType(LinuxSystemStats.getType());
        } else if (HostStatHelper.isOSX()) {
            // @TODO once OSX stats are implemented
            systemStats = null;
        } else if (HostStatHelper.isWindows()) {
            systemStats = system.findStatisticsByType(WindowsSystemStats.getType());
        }
        if (systemStats != null) {
            systemStat = systemStats[0];
        }
    }
    MemoryAllocator allocator = this.cache.getOffHeapStore();
    if ((null != allocator)) {
        OffHeapMemoryStats offHeapStats = allocator.getStats();
        if (null != offHeapStats) {
            addOffHeapStats(offHeapStats);
        }
    }
    addSystemStats();
    addVMStats();
    initializeStats();
    return this;
}
Also used : MemoryAllocator(org.apache.geode.internal.offheap.MemoryAllocator) OffHeapMemoryStats(org.apache.geode.internal.offheap.OffHeapMemoryStats) CachePerfStats(org.apache.geode.internal.cache.CachePerfStats) Statistics(org.apache.geode.Statistics) LRUStatistics(org.apache.geode.internal.cache.lru.LRUStatistics) DistributionStats(org.apache.geode.distributed.internal.DistributionStats)

Example 10 with CachePerfStats

use of org.apache.geode.internal.cache.CachePerfStats in project geode by apache.

the class TXJUnitTest method testNoopInvalidates.

@Test
public void testNoopInvalidates() throws CacheException {
    final CachePerfStats stats = this.cache.getCachePerfStats();
    TransactionListener tl = new TransactionListenerAdapter() {

        @Override
        public void afterRollback(TransactionEvent event) {
            te = event;
        }
    };
    this.txMgr.addListener(tl);
    // Make sure invalidates done on invalid entries are noops
    {
        // distributed invalidate
        // first make sure invalidate is counted as a change
        int txRollbackChanges = stats.getTxRollbackChanges();
        this.region.create("key1", "value1");
        this.txMgr.begin();
        this.region.invalidate("key1");
        this.txMgr.rollback();
        assertEquals(txRollbackChanges + 1, stats.getTxRollbackChanges());
        assertEquals(1, te.getEvents().size());
        this.region.destroy("key1");
        this.region.create("key1", "value1");
        this.txMgr.begin();
        this.region.invalidate("key1");
        this.txMgr.commit();
        assertEquals(1, te.getEvents().size());
        this.region.destroy("key1");
        // now make sure a committed entry that is invalid is not counted as a change
        txRollbackChanges = stats.getTxRollbackChanges();
        this.region.create("key1", "value1");
        this.region.invalidate("key1");
        this.txMgr.begin();
        this.region.invalidate("key1");
        this.txMgr.rollback();
        assertEquals(txRollbackChanges, stats.getTxRollbackChanges());
        assertEquals(0, te.getEvents().size());
        this.region.destroy("key1");
        this.region.create("key1", "value1");
        this.region.invalidate("key1");
        this.txMgr.begin();
        this.region.invalidate("key1");
        this.txMgr.commit();
        assertEquals(0, te.getEvents().size());
        this.region.destroy("key1");
        // now make sure that multiple invalidates of same entry are a single change
        txRollbackChanges = stats.getTxRollbackChanges();
        this.region.create("key1", "value1");
        this.txMgr.begin();
        this.region.invalidate("key1");
        this.region.invalidate("key1");
        this.region.invalidate("key1");
        this.txMgr.rollback();
        assertEquals(txRollbackChanges + 1, stats.getTxRollbackChanges());
        assertEquals(1, te.getEvents().size());
        this.region.destroy("key1");
        this.region.create("key1", "value1");
        this.txMgr.begin();
        this.region.invalidate("key1");
        this.region.invalidate("key1");
        this.region.invalidate("key1");
        this.txMgr.commit();
        assertEquals(1, te.getEvents().size());
        this.region.destroy("key1");
    }
    {
        // local invalidate
        // first make sure invalidate is counted as a change
        int txRollbackChanges = stats.getTxRollbackChanges();
        this.region.create("key1", "value1");
        this.txMgr.begin();
        this.region.localInvalidate("key1");
        this.txMgr.rollback();
        assertEquals(txRollbackChanges + 1, stats.getTxRollbackChanges());
        this.region.destroy("key1");
        // now make sure a committed entry that is invalid is not counted as a change
        txRollbackChanges = stats.getTxRollbackChanges();
        this.region.create("key1", "value1");
        this.region.localInvalidate("key1");
        this.txMgr.begin();
        this.region.localInvalidate("key1");
        this.txMgr.rollback();
        assertEquals(txRollbackChanges, stats.getTxRollbackChanges());
        this.region.destroy("key1");
        // now make sure that multiple localInvalidates of same entry are a single change
        txRollbackChanges = stats.getTxRollbackChanges();
        this.region.create("key1", "value1");
        this.txMgr.begin();
        this.region.localInvalidate("key1");
        this.region.localInvalidate("key1");
        this.region.localInvalidate("key1");
        this.txMgr.rollback();
        assertEquals(txRollbackChanges + 1, stats.getTxRollbackChanges());
        this.region.destroy("key1");
    }
}
Also used : TransactionListener(org.apache.geode.cache.TransactionListener) TransactionListenerAdapter(org.apache.geode.cache.util.TransactionListenerAdapter) TransactionEvent(org.apache.geode.cache.TransactionEvent) CachePerfStats(org.apache.geode.internal.cache.CachePerfStats) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

CachePerfStats (org.apache.geode.internal.cache.CachePerfStats)21 Test (org.junit.Test)15 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)7 Compressor (org.apache.geode.compression.Compressor)6 RegionEntryContext (org.apache.geode.internal.cache.RegionEntryContext)6 UnitTest (org.apache.geode.test.junit.categories.UnitTest)6 AttributesFactory (org.apache.geode.cache.AttributesFactory)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 IOException (java.io.IOException)2 List (java.util.List)2 Properties (java.util.Properties)2 CancelException (org.apache.geode.CancelException)2 CacheException (org.apache.geode.cache.CacheException)2 CommitConflictException (org.apache.geode.cache.CommitConflictException)2 EntryEvent (org.apache.geode.cache.EntryEvent)2 RegionAttributes (org.apache.geode.cache.RegionAttributes)2 RegionExistsException (org.apache.geode.cache.RegionExistsException)2 TransactionEvent (org.apache.geode.cache.TransactionEvent)2 TransactionListener (org.apache.geode.cache.TransactionListener)2 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)2