Search in sources :

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

Example 5 with CachePerfStats

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

the class TXJUnitTest method testStats.

@Test
public void testStats() throws CacheException {
    final int SLEEP_MS = 250;
    // final int OP_TIME = 0; // ns // changed form 10 to 0 because on fater platforms
    // and low resolution clocks this test will fail.
    final CachePerfStats stats = this.cache.getCachePerfStats();
    class statsValidator {

        private long txSuccessLifeTime;

        private long txFailedLifeTime;

        private long txRollbackLifeTime;

        private int txCommits;

        private int txFailures;

        private int txRollbacks;

        private long txCommitTime;

        private long txFailureTime;

        private long txRollbackTime;

        private int txCommitChanges;

        private int txFailureChanges;

        private int txRollbackChanges;

        private CachePerfStats stats;

        private statsValidator(CachePerfStats stats) {
            this.stats = stats;
        }

        private void reset() {
            this.txSuccessLifeTime = this.stats.getTxSuccessLifeTime();
            this.txFailedLifeTime = this.stats.getTxFailedLifeTime();
            this.txRollbackLifeTime = this.stats.getTxRollbackLifeTime();
            this.txCommits = this.stats.getTxCommits();
            this.txFailures = this.stats.getTxFailures();
            this.txRollbacks = this.stats.getTxRollbacks();
            this.txCommitTime = this.stats.getTxCommitTime();
            this.txFailureTime = this.stats.getTxFailureTime();
            this.txRollbackTime = this.stats.getTxRollbackTime();
            this.txCommitChanges = this.stats.getTxCommitChanges();
            this.txFailureChanges = this.stats.getTxFailureChanges();
            this.txRollbackChanges = this.stats.getTxRollbackChanges();
        }

        private void setTxSuccessLifeTime(long txSuccessLifeTime) {
            this.txSuccessLifeTime = txSuccessLifeTime;
        }

        private void setTxFailedLifeTime(long txFailedLifeTime) {
            this.txFailedLifeTime = txFailedLifeTime;
        }

        private void setTxRollbackLifeTime(long txRollbackLifeTime) {
            this.txRollbackLifeTime = txRollbackLifeTime;
        }

        private void setTxCommits(int txCommits) {
            this.txCommits = txCommits;
        }

        private void setTxFailures(int txFailures) {
            this.txFailures = txFailures;
        }

        private void setTxRollbacks(int txRollbacks) {
            this.txRollbacks = txRollbacks;
        }

        private void setTxCommitTime(long txCommitTime) {
            this.txCommitTime = txCommitTime;
        }

        private void setTxFailureTime(long txFailureTime) {
            this.txFailureTime = txFailureTime;
        }

        private void setTxRollbackTime(long txRollbackTime) {
            this.txRollbackTime = txRollbackTime;
        }

        private void setTxCommitChanges(int txCommitChanges) {
            this.txCommitChanges = txCommitChanges;
        }

        private void setTxFailureChanges(int txFailureChanges) {
            this.txFailureChanges = txFailureChanges;
        }

        private void setTxRollbackChanges(int txRollbackChanges) {
            this.txRollbackChanges = txRollbackChanges;
        }

        private void assertValid() {
            assertEquals(this.txRollbacks, this.stats.getTxRollbacks());
            assertEquals(this.txRollbackChanges, this.stats.getTxRollbackChanges());
            if (Boolean.getBoolean(DistributionConfig.GEMFIRE_PREFIX + "cache.enable-time-statistics")) {
                assertTrue(this.txRollbackTime <= this.stats.getTxRollbackTime());
                // assertTrue(this.txRollbackLifeTime+((SLEEP_MS-10)*1000000) <=
                // this.stats.getTxRollbackLifeTime());
                assertTrue("RollbackLifeTime " + this.txRollbackLifeTime + " is not <= " + this.stats.getTxRollbackLifeTime(), this.txRollbackLifeTime <= this.stats.getTxRollbackLifeTime());
                assertTrue(this.txCommitTime <= this.stats.getTxCommitTime());
                assertTrue(this.txSuccessLifeTime <= this.stats.getTxSuccessLifeTime());
                assertTrue(this.txFailureTime <= this.stats.getTxFailureTime());
                assertTrue("FailedLifeTime " + this.txFailedLifeTime + " is not <= " + this.stats.getTxFailedLifeTime(), this.txFailedLifeTime <= this.stats.getTxFailedLifeTime());
            }
            assertEquals(this.txCommits, this.stats.getTxCommits());
            assertEquals(this.txCommitChanges, this.stats.getTxCommitChanges());
            assertEquals(this.txFailures, this.stats.getTxFailures());
            assertEquals(this.txFailureChanges, this.stats.getTxFailureChanges());
        }
    }
    statsValidator statsVal = new statsValidator(stats);
    // Zero and non-zero rollback stats test
    int i;
    long testRollbackLifeTime = 0, testTotalTx = 0;
    for (i = 0; i < 2; ++i) {
        statsVal.reset();
        statsVal.setTxRollbacks(stats.getTxRollbacks() + 1);
        statsVal.setTxRollbackLifeTime(stats.getTxRollbackLifeTime() + ((SLEEP_MS - 20) * 1000000));
        final long beforeBegin = NanoTimer.getTime();
        this.txMgr.begin();
        final long afterBegin = NanoTimer.getTime();
        pause(SLEEP_MS);
        if (i > 0) {
            statsVal.setTxRollbackChanges(stats.getTxRollbackChanges() + 2);
            this.region.put("stats1", "stats rollback1");
            this.region.put("stats2", "stats rollback2");
        }
        statsVal.setTxRollbackTime(stats.getTxRollbackTime());
        final long beforeRollback = NanoTimer.getTime();
        this.txMgr.rollback();
        final long afterRollback = NanoTimer.getTime();
        final long statsRollbackLifeTime = stats.getTxRollbackLifeTime();
        testRollbackLifeTime += beforeRollback - afterBegin;
        // bruce - time based stats are disabled by default
        String p = (String) cache.getDistributedSystem().getProperties().get(DistributionConfig.GEMFIRE_PREFIX + "enable-time-statistics");
        if (p != null && Boolean.getBoolean(p)) {
            assertTrue("Local RollbackLifeTime assertion:  " + testRollbackLifeTime + " is not <= " + statsRollbackLifeTime, testRollbackLifeTime <= statsRollbackLifeTime);
        }
        testTotalTx += afterRollback - beforeBegin;
        final long totalTXMinusRollback = testTotalTx - stats.getTxRollbackTime();
        if (Boolean.getBoolean(DistributionConfig.GEMFIRE_PREFIX + "cache.enable-time-statistics")) {
            assertTrue("Total Tx Minus Rollback assertion:  " + totalTXMinusRollback + " is not >= " + statsRollbackLifeTime, totalTXMinusRollback >= statsRollbackLifeTime);
        }
        statsVal.assertValid();
    }
    // Zero and non-zero commit stats test
    for (i = 0; i < 2; ++i) {
        statsVal.reset();
        statsVal.setTxCommits(stats.getTxCommits() + 1);
        statsVal.setTxSuccessLifeTime(stats.getTxSuccessLifeTime() + ((SLEEP_MS - 10) * 1000000));
        this.txMgr.begin();
        pause(SLEEP_MS);
        if (i > 0) {
            statsVal.setTxCommitChanges(stats.getTxCommitChanges() + 2);
            this.region.put("stats1", "commit1");
            this.region.put("stats2", "commit2");
        }
        try {
            statsVal.setTxCommitTime(stats.getTxCommitTime());
            this.txMgr.commit();
        } catch (CommitConflictException ex) {
            fail("unexpected " + ex);
        }
        statsVal.assertValid();
    }
    // Non-zero failed commit stats
    TXManagerImpl txMgrImpl = (TXManagerImpl) this.txMgr;
    statsVal.reset();
    statsVal.setTxFailures(stats.getTxFailures() + 1);
    statsVal.setTxFailureChanges(stats.getTxFailureChanges() + 2);
    statsVal.setTxFailedLifeTime(stats.getTxFailedLifeTime() + ((SLEEP_MS - 20) * 1000000));
    this.region.put("stats3", "stats fail3");
    this.txMgr.begin();
    this.region.put("stats1", "stats fail1");
    this.region.put("stats2", "stats fail2");
    try {
        this.region.create("stats3", "try stats3");
        fail("expected EntryExistsException");
    } catch (EntryExistsException ok) {
    }
    // begin other tx simulation
    TXStateProxy tx = txMgrImpl.internalSuspend();
    this.region.put("stats1", "stats success1");
    this.region.put("stats2", "stats success2");
    txMgrImpl.internalResume(tx);
    // end other tx simulation
    pause(SLEEP_MS);
    try {
        statsVal.setTxFailureTime(stats.getTxFailureTime());
        this.txMgr.commit();
        fail("expected CommitConflictException");
    } catch (CommitConflictException ex) {
    // expected failure
    }
    statsVal.assertValid();
}
Also used : CommitConflictException(org.apache.geode.cache.CommitConflictException) TXManagerImpl(org.apache.geode.internal.cache.TXManagerImpl) TXStateProxy(org.apache.geode.internal.cache.TXStateProxy) CachePerfStats(org.apache.geode.internal.cache.CachePerfStats) EntryExistsException(org.apache.geode.cache.EntryExistsException) 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