Search in sources :

Example 1 with CacheMetricsMXBean

use of org.apache.ignite.mxbean.CacheMetricsMXBean in project ignite by apache.

the class CacheMetricsEnableRuntimeTest method testJmxStatisticsEnable.

/**
 * @param persistence Persistence.
 */
private void testJmxStatisticsEnable(boolean persistence) throws Exception {
    this.persistence = persistence;
    Ignite ig1 = startGrid(1);
    Ignite ig2 = startGrid(2);
    ig1.active(true);
    CacheConfiguration ccfg = ig1.cache(CACHE1).getConfiguration(CacheConfiguration.class);
    CacheConfiguration cacheCfg2 = new CacheConfiguration(ccfg);
    cacheCfg2.setName(CACHE2);
    cacheCfg2.setStatisticsEnabled(true);
    ig2.getOrCreateCache(cacheCfg2);
    CacheMetricsMXBean mxBeanCache1 = mxBean(2, CACHE1, CacheClusterMetricsMXBeanImpl.class);
    CacheMetricsMXBean mxBeanCache2 = mxBean(2, CACHE2, CacheClusterMetricsMXBeanImpl.class);
    CacheMetricsMXBean mxBeanCache1loc = mxBean(2, CACHE1, CacheLocalMetricsMXBeanImpl.class);
    mxBeanCache1.enableStatistics();
    mxBeanCache2.disableStatistics();
    assertCachesStatisticsMode(true, false);
    stopGrid(1);
    startGrid(3);
    assertCachesStatisticsMode(true, false);
    mxBeanCache1loc.disableStatistics();
    assertCachesStatisticsMode(false, false);
    mxBeanCache1.enableStatistics();
    mxBeanCache2.enableStatistics();
    // Start node 1 again.
    startGrid(1);
    assertCachesStatisticsMode(true, true);
    int gridIdx = 0;
    for (Ignite ignite : G.allGrids()) {
        gridIdx++;
        ignite.cache(CACHE1).put(gridIdx, gridIdx);
        ignite.cache(CACHE2).put(gridIdx, gridIdx);
        ignite.cache(CACHE1).get(gridIdx);
        ignite.cache(CACHE2).get(gridIdx);
    }
    assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            int cnt = G.allGrids().size();
            for (Ignite ignite : G.allGrids()) {
                CacheMetrics metrics1 = ignite.cache(CACHE1).metrics();
                CacheMetrics metrics2 = ignite.cache(CACHE2).metrics();
                if (metrics1.getCacheGets() < cnt || metrics2.getCacheGets() < cnt || metrics1.getCachePuts() < cnt || metrics2.getCachePuts() < cnt)
                    return false;
            }
            return true;
        }
    }, 10_000L));
    stopAllGrids();
    ig1 = startGrid(1);
    ig1.active(true);
    ig1.getOrCreateCache(cacheCfg2.setStatisticsEnabled(false));
    if (persistence)
        // cache1 - from local configuration, cache2 - restored from pds
        assertCachesStatisticsMode(false, true);
    else
        assertCachesStatisticsMode(false, false);
    mxBeanCache1 = mxBean(1, CACHE1, CacheLocalMetricsMXBeanImpl.class);
    mxBeanCache2 = mxBean(1, CACHE2, CacheLocalMetricsMXBeanImpl.class);
    mxBeanCache1.enableStatistics();
    mxBeanCache2.disableStatistics();
    startGrid(2);
    assertCachesStatisticsMode(true, false);
}
Also used : CacheMetrics(org.apache.ignite.cache.CacheMetrics) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) CacheMetricsMXBean(org.apache.ignite.mxbean.CacheMetricsMXBean) Ignite(org.apache.ignite.Ignite) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 2 with CacheMetricsMXBean

use of org.apache.ignite.mxbean.CacheMetricsMXBean in project ignite by apache.

the class CacheMetricsManageTest method testKeyCollisionsMetricDifferentTimeout.

/**
 * Tests metric change interval.
 */
@Test
public void testKeyCollisionsMetricDifferentTimeout() throws Exception {
    Assume.assumeFalse("https://issues.apache.org/jira/browse/IGNITE-9224", MvccFeatureChecker.forcedMvcc());
    backups = 2;
    useTestCommSpi = true;
    Ignite ig = startGridsMultiThreaded(3);
    int contCnt = (int) U.staticField(IgniteTxManager.class, "COLLISIONS_QUEUE_THRESHOLD") * 5;
    CountDownLatch txLatch = new CountDownLatch(contCnt);
    ig.cluster().active(true);
    client = true;
    Ignite cl = startGrid();
    IgniteTransactions txMgr = cl.transactions();
    CacheConfiguration<?, ?> dfltCacheCfg = getCacheConfiguration();
    dfltCacheCfg.setStatisticsEnabled(true);
    String cacheName = dfltCacheCfg.getName();
    IgniteCache<Integer, Integer> cache = ig.cache(cacheName);
    IgniteCache<Integer, Integer> cache0 = cl.cache(cacheName);
    final Integer keyId = primaryKey(cache);
    CountDownLatch blockOnce = new CountDownLatch(1);
    for (Ignite ig0 : G.allGrids()) {
        if (ig0.configuration().isClientMode())
            continue;
        TestRecordingCommunicationSpi commSpi0 = (TestRecordingCommunicationSpi) ig0.configuration().getCommunicationSpi();
        commSpi0.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

            @Override
            public boolean apply(ClusterNode node, Message msg) {
                if (msg instanceof GridNearTxFinishResponse && blockOnce.getCount() > 0) {
                    blockOnce.countDown();
                    return true;
                }
                return false;
            }
        });
    }
    IgniteInternalFuture f = GridTestUtils.runAsync(() -> {
        try (Transaction tx = txMgr.txStart(PESSIMISTIC, READ_COMMITTED)) {
            cache0.put(keyId, 0);
            tx.commit();
        }
    });
    blockOnce.await();
    GridCompoundFuture<?, ?> finishFut = new GridCompoundFuture<>();
    for (int i = 0; i < contCnt; ++i) {
        IgniteInternalFuture f0 = GridTestUtils.runAsync(() -> {
            try (Transaction tx = txMgr.txStart(PESSIMISTIC, READ_COMMITTED)) {
                cache0.put(keyId, 0);
                tx.commit();
                txLatch.countDown();
            }
        });
        finishFut.add(f0);
    }
    finishFut.markInitialized();
    for (Ignite ig0 : G.allGrids()) {
        TestRecordingCommunicationSpi commSpi0 = (TestRecordingCommunicationSpi) ig0.configuration().getCommunicationSpi();
        if (ig0.configuration().isClientMode())
            continue;
        commSpi0.stopBlock();
    }
    CacheMetricsMXBean mxBeanCache = mxBean(0, cacheName, CacheLocalMetricsMXBeanImpl.class);
    IgniteTxManager txManager = ((IgniteEx) ig).context().cache().context().tm();
    final TransactionsMXBean txMXBean1 = txMXBean(0);
    final TransactionsMXBean txMXBean2 = txMXBean(1);
    for (int i = 0; i < 10; ++i) {
        txMXBean1.setTxKeyCollisionsInterval(ThreadLocalRandom.current().nextInt(1000, 1100));
        txMXBean2.setTxKeyCollisionsInterval(ThreadLocalRandom.current().nextInt(1000, 1100));
        mxBeanCache.getTxKeyCollisions();
        mxBeanCache.clear();
        try {
            U.invoke(IgniteTxManager.class, txManager, "collectTxCollisionsInfo");
        } catch (IgniteCheckedException e) {
            fail(e.toString());
        }
        U.sleep(500);
    }
    f.get();
    finishFut.get();
    txLatch.await();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) Message(org.apache.ignite.plugin.extensions.communication.Message) CacheMetricsMXBean(org.apache.ignite.mxbean.CacheMetricsMXBean) IgniteTxManager(org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteTransactions(org.apache.ignite.IgniteTransactions) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture) GridNearTxFinishResponse(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxFinishResponse) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TransactionsMXBean(org.apache.ignite.mxbean.TransactionsMXBean) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Transaction(org.apache.ignite.transactions.Transaction) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 3 with CacheMetricsMXBean

use of org.apache.ignite.mxbean.CacheMetricsMXBean in project ignite by apache.

the class CacheMetricsManageTest method testJmxStatisticsEnable.

/**
 * @param persistence Persistence.
 */
private void testJmxStatisticsEnable(boolean persistence) throws Exception {
    this.persistence = persistence;
    Ignite ig1 = startGrid(1);
    Ignite ig2 = startGrid(2);
    ig1.cluster().active(true);
    CacheConfiguration<Object, Object> ccfg = ig1.cache(CACHE1).getConfiguration(CacheConfiguration.class);
    CacheConfiguration<Object, Object> cacheCfg2 = new CacheConfiguration<>(ccfg);
    cacheCfg2.setName(CACHE2);
    cacheCfg2.setStatisticsEnabled(true);
    ig2.getOrCreateCache(cacheCfg2);
    CacheMetricsMXBean mxBeanCache1 = mxBean(2, CACHE1, CacheClusterMetricsMXBeanImpl.class);
    CacheMetricsMXBean mxBeanCache2 = mxBean(2, CACHE2, CacheClusterMetricsMXBeanImpl.class);
    CacheMetricsMXBean mxBeanCache1loc = mxBean(2, CACHE1, CacheLocalMetricsMXBeanImpl.class);
    mxBeanCache1.enableStatistics();
    mxBeanCache2.disableStatistics();
    assertCachesStatisticsMode(true, false);
    stopGrid(1);
    startGrid(3);
    assertCachesStatisticsMode(true, false);
    mxBeanCache1loc.disableStatistics();
    assertCachesStatisticsMode(false, false);
    mxBeanCache1.enableStatistics();
    mxBeanCache2.enableStatistics();
    // Start node 1 again.
    startGrid(1);
    if (persistence)
        ig2.resetLostPartitions(Arrays.asList(CACHE1, CACHE2));
    assertCachesStatisticsMode(true, true);
    int gridIdx = 0;
    for (Ignite ignite : G.allGrids()) {
        gridIdx++;
        ignite.cache(CACHE1).put(gridIdx, gridIdx);
        ignite.cache(CACHE2).put(gridIdx, gridIdx);
        ignite.cache(CACHE1).get(gridIdx);
        ignite.cache(CACHE2).get(gridIdx);
    }
    assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            int cnt = G.allGrids().size();
            for (Ignite ignite : G.allGrids()) {
                CacheMetrics metrics1 = ignite.cache(CACHE1).metrics();
                CacheMetrics metrics2 = ignite.cache(CACHE2).metrics();
                if (metrics1.getCacheGets() < cnt || metrics2.getCacheGets() < cnt || metrics1.getCachePuts() < cnt || metrics2.getCachePuts() < cnt)
                    return false;
            }
            return true;
        }
    }, 10_000L));
    stopAllGrids();
    ig1 = startGrid(1);
    ig1.cluster().active(true);
    ig1.getOrCreateCache(cacheCfg2.setStatisticsEnabled(false));
    if (persistence)
        // Both caches restored from pds.
        assertCachesStatisticsMode(true, true);
    else
        assertCachesStatisticsMode(false, false);
    mxBeanCache1 = mxBean(1, CACHE1, CacheLocalMetricsMXBeanImpl.class);
    mxBeanCache2 = mxBean(1, CACHE2, CacheLocalMetricsMXBeanImpl.class);
    mxBeanCache1.enableStatistics();
    mxBeanCache2.disableStatistics();
    startGrid(2);
    assertCachesStatisticsMode(true, false);
}
Also used : CacheMetrics(org.apache.ignite.cache.CacheMetrics) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) CacheMetricsMXBean(org.apache.ignite.mxbean.CacheMetricsMXBean) Ignite(org.apache.ignite.Ignite) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 4 with CacheMetricsMXBean

use of org.apache.ignite.mxbean.CacheMetricsMXBean in project ignite by apache.

the class IndexMetricsTest method testIndexRebuildingMetric.

/**
 * @throws Exception If failed.
 */
@Test
public void testIndexRebuildingMetric() throws Exception {
    IgniteEx n = startGrid(0);
    n.cluster().active(true);
    String cacheName1 = "cache1";
    String cacheName2 = "cache2";
    IgniteCache<KeyClass, ValueClass> cache1 = n.getOrCreateCache(cacheConfiguration(cacheName1));
    IgniteCache<KeyClass, ValueClass> cache2 = n.getOrCreateCache(cacheConfiguration(cacheName2));
    int entryCnt1 = 100;
    int entryCnt2 = 200;
    for (int i = 0; i < entryCnt1; i++) cache1.put(new KeyClass(i), new ValueClass((long) i));
    for (int i = 0; i < entryCnt2; i++) cache2.put(new KeyClass(i), new ValueClass((long) i));
    List<Path> idxPaths = getIndexBinPaths(cacheName1);
    idxPaths.addAll(getIndexBinPaths(cacheName2));
    stopAllGrids();
    idxPaths.forEach(idxPath -> assertTrue(U.delete(idxPath)));
    IndexProcessor.idxRebuildCls = BlockingIndexesRebuildTask.class;
    n = startGrid(0);
    BooleanMetric idxRebuildInProgress1 = indexRebuildMetric(n, cacheName1, "IsIndexRebuildInProgress");
    BooleanMetric idxRebuildInProgress2 = indexRebuildMetric(n, cacheName2, "IsIndexRebuildInProgress");
    LongAdderMetric idxRebuildKeyProcessed1 = indexRebuildMetric(n, cacheName1, "IndexRebuildKeyProcessed");
    LongAdderMetric idxRebuildKeyProcessed2 = indexRebuildMetric(n, cacheName2, "IndexRebuildKeyProcessed");
    CacheMetrics cacheMetrics1 = cacheMetrics(n, cacheName1);
    CacheMetrics cacheMetrics2 = cacheMetrics(n, cacheName2);
    CacheMetricsMXBean cacheMetricsMXBean1 = cacheMetricsMXBean(n, cacheName1, CacheLocalMetricsMXBeanImpl.class);
    CacheMetricsMXBean cacheMetricsMXBean2 = cacheMetricsMXBean(n, cacheName2, CacheLocalMetricsMXBeanImpl.class);
    CacheMetricsMXBean cacheClusterMetricsMXBean1 = cacheMetricsMXBean(n, cacheName1, CacheClusterMetricsMXBeanImpl.class);
    CacheMetricsMXBean cacheClusterMetricsMXBean2 = cacheMetricsMXBean(n, cacheName2, CacheClusterMetricsMXBeanImpl.class);
    n.cluster().active(true);
    BooleanSupplier[] idxRebuildProgressCache1 = { idxRebuildInProgress1::value, cacheMetrics1::isIndexRebuildInProgress, cacheMetricsMXBean1::isIndexRebuildInProgress };
    BooleanSupplier[] idxRebuildProgressCache2 = { idxRebuildInProgress2::value, cacheMetrics2::isIndexRebuildInProgress, cacheMetricsMXBean2::isIndexRebuildInProgress };
    // It must always be false, because metric is only per node.
    BooleanSupplier[] idxRebuildProgressCluster = { cacheClusterMetricsMXBean1::isIndexRebuildInProgress, cacheClusterMetricsMXBean2::isIndexRebuildInProgress };
    LongSupplier[] idxRebuildKeyProcessedCache1 = { idxRebuildKeyProcessed1::value, cacheMetrics1::getIndexRebuildKeysProcessed, cacheMetricsMXBean1::getIndexRebuildKeysProcessed };
    LongSupplier[] idxRebuildKeyProcessedCache2 = { idxRebuildKeyProcessed2::value, cacheMetrics2::getIndexRebuildKeysProcessed, cacheMetricsMXBean2::getIndexRebuildKeysProcessed };
    // It must always be 0, because metric is only per node.
    LongSupplier[] idxRebuildKeyProcessedCluster = { cacheClusterMetricsMXBean1::getIndexRebuildKeysProcessed, cacheClusterMetricsMXBean2::getIndexRebuildKeysProcessed };
    assertEquals(true, idxRebuildProgressCache1);
    assertEquals(true, idxRebuildProgressCache2);
    assertEquals(false, idxRebuildProgressCluster);
    assertEquals(0, idxRebuildKeyProcessedCache1);
    assertEquals(0, idxRebuildKeyProcessedCache2);
    assertEquals(0, idxRebuildKeyProcessedCluster);
    ((BlockingIndexesRebuildTask) n.context().indexProcessor().idxRebuild()).stopBlock(cacheName1);
    n.cache(cacheName1).indexReadyFuture().get(30_000);
    assertEquals(false, idxRebuildProgressCache1);
    assertEquals(true, idxRebuildProgressCache2);
    assertEquals(false, idxRebuildProgressCluster);
    assertEquals(entryCnt1, idxRebuildKeyProcessedCache1);
    assertEquals(0, idxRebuildKeyProcessedCache2);
    assertEquals(0, idxRebuildKeyProcessedCluster);
    ((BlockingIndexesRebuildTask) n.context().indexProcessor().idxRebuild()).stopBlock(cacheName2);
    n.cache(cacheName2).indexReadyFuture().get(30_000);
    assertEquals(false, idxRebuildProgressCache1);
    assertEquals(false, idxRebuildProgressCache2);
    assertEquals(false, idxRebuildProgressCluster);
    assertEquals(entryCnt1, idxRebuildKeyProcessedCache1);
    assertEquals(entryCnt2, idxRebuildKeyProcessedCache2);
    assertEquals(0, idxRebuildKeyProcessedCluster);
}
Also used : BooleanMetric(org.apache.ignite.spi.metric.BooleanMetric) KeyClass(org.apache.ignite.internal.processors.cache.index.AbstractSchemaSelfTest.KeyClass) BooleanSupplier(java.util.function.BooleanSupplier) Path(java.nio.file.Path) CacheMetrics(org.apache.ignite.cache.CacheMetrics) CacheMetricsMXBean(org.apache.ignite.mxbean.CacheMetricsMXBean) ValueClass(org.apache.ignite.internal.processors.cache.index.AbstractSchemaSelfTest.ValueClass) IgniteEx(org.apache.ignite.internal.IgniteEx) LongAdderMetric(org.apache.ignite.internal.processors.metric.impl.LongAdderMetric) LongSupplier(java.util.function.LongSupplier) Test(org.junit.Test)

Example 5 with CacheMetricsMXBean

use of org.apache.ignite.mxbean.CacheMetricsMXBean in project ignite by apache.

the class CacheMetricsManageTest method testCacheSizeOnInactiveCluster.

/**
 * @throws Exception If failed.
 */
@Test
public void testCacheSizeOnInactiveCluster() throws Exception {
    persistence = true;
    IgniteEx grid = startGrid(0);
    assertFalse(grid.cluster().state().active());
    CacheMetricsMXBean mxBean = mxBean(0, CACHE1, CacheLocalMetricsMXBeanImpl.class);
    long size = mxBean.getCacheSize();
    assertEquals(-1, size);
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) CacheMetricsMXBean(org.apache.ignite.mxbean.CacheMetricsMXBean) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

CacheMetricsMXBean (org.apache.ignite.mxbean.CacheMetricsMXBean)6 Ignite (org.apache.ignite.Ignite)4 Test (org.junit.Test)4 CacheMetrics (org.apache.ignite.cache.CacheMetrics)3 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)3 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 IgniteTransactions (org.apache.ignite.IgniteTransactions)2 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 IgniteEx (org.apache.ignite.internal.IgniteEx)2 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)2 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)2 IgniteTxManager (org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager)2 GridCompoundFuture (org.apache.ignite.internal.util.future.GridCompoundFuture)2 Message (org.apache.ignite.plugin.extensions.communication.Message)2 Transaction (org.apache.ignite.transactions.Transaction)2 Path (java.nio.file.Path)1