Search in sources :

Example 1 with CacheGroupMetricsMXBean

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

the class CacheGroupMetricsMBeanTest method testCacheGroupMetrics.

/**
 * @throws Exception If failed.
 */
public void testCacheGroupMetrics() throws Exception {
    startGrid(0);
    startGrid(1);
    startGrid(2);
    awaitPartitionMapExchange(true, false, null);
    CacheGroupMetricsMXBean mxBean0Grp1 = mxBean(0, "group1");
    CacheGroupMetricsMXBean mxBean0Grp2 = mxBean(0, "group2");
    CacheGroupMetricsMXBean mxBean0Grp3 = mxBean(0, "cache4");
    CacheGroupMetricsMXBean mxBean1Grp1 = mxBean(1, "group1");
    CacheGroupMetricsMXBean mxBean2Grp1 = mxBean(2, "group1");
    assertEquals("group1", mxBean0Grp1.getGroupName());
    assertEquals(null, mxBean0Grp3.getGroupName());
    assertEquals(3, mxBean0Grp1.getBackups());
    assertEquals(10, mxBean0Grp1.getPartitions());
    assertEquals(1, mxBean0Grp1.getMinimumNumberOfPartitionCopies());
    assertEquals(3, mxBean0Grp1.getMaximumNumberOfPartitionCopies());
    assertEquals(0, mxBean0Grp1.getClusterMovingPartitionsCount());
    assertEquals(19, mxBean0Grp1.getClusterOwningPartitionsCount());
    assertEquals(7, mxBean0Grp1.getLocalNodeOwningPartitionsCount());
    assertEquals(6, mxBean1Grp1.getLocalNodeOwningPartitionsCount());
    assertEquals(6, mxBean2Grp1.getLocalNodeOwningPartitionsCount());
    assertEquals(F.asList("cache1"), mxBean0Grp1.getCaches());
    assertEquals(F.asList("cache2", "cache3"), mxBean0Grp2.getCaches());
    assertEquals(F.asList("cache4"), mxBean0Grp3.getCaches());
    assertEquals(arrayToAssignmentMap(assignmentMapArr), mxBean0Grp1.getAffinityPartitionsAssignmentMap());
    assertEquals(arrayToAllocationMap(assignmentMapArr), mxBean0Grp1.getOwningPartitionsAllocationMap());
    assertEquals(arrayToAllocationMap(new int[10][]), mxBean0Grp1.getMovingPartitionsAllocationMap());
    try (IgniteDataStreamer<Integer, Integer> st = grid(0).dataStreamer("cache1")) {
        for (int i = 0; i < 50_000; i++) st.addData(i, i);
    }
    stopGrid(2);
    // Check moving partitions while rebalancing.
    assertFalse(arrayToAllocationMap(new int[10][]).equals(mxBean0Grp1.getMovingPartitionsAllocationMap()));
    assertTrue(mxBean0Grp1.getLocalNodeMovingPartitionsCount() > 0);
    assertTrue(mxBean0Grp1.getClusterMovingPartitionsCount() > 0);
}
Also used : CacheGroupMetricsMXBean(org.apache.ignite.mxbean.CacheGroupMetricsMXBean)

Example 2 with CacheGroupMetricsMXBean

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

the class CacheGroupMetricsTest method testCacheGroupMetrics.

/**
 * @throws Exception If failed.
 */
@Test
public void testCacheGroupMetrics() throws Exception {
    pds = false;
    startGrid(0);
    startGrid(1);
    startGrid(2);
    awaitPartitionMapExchange(true, false, null);
    T2<CacheGroupMetricsMXBean, MetricRegistry> mxBean0Grp1 = cacheGroupMetrics(0, "group1");
    T2<CacheGroupMetricsMXBean, MetricRegistry> mxBean0Grp2 = cacheGroupMetrics(0, "group2");
    T2<CacheGroupMetricsMXBean, MetricRegistry> mxBean0Grp3 = cacheGroupMetrics(0, "cache4");
    T2<CacheGroupMetricsMXBean, MetricRegistry> mxBean1Grp1 = cacheGroupMetrics(1, "group1");
    T2<CacheGroupMetricsMXBean, MetricRegistry> mxBean2Grp1 = cacheGroupMetrics(2, "group1");
    assertEquals("group1", mxBean0Grp1.get1().getGroupName());
    assertEquals(null, mxBean0Grp3.get1().getGroupName());
    assertEquals(3, mxBean0Grp1.get1().getBackups());
    assertEquals(10, mxBean0Grp1.get1().getPartitions());
    assertEquals(1, mxBean0Grp1.get2().<IntMetric>findMetric("MinimumNumberOfPartitionCopies").value());
    assertEquals(3, mxBean0Grp1.get2().<IntMetric>findMetric("MaximumNumberOfPartitionCopies").value());
    assertEquals(0, mxBean0Grp1.get1().getClusterMovingPartitionsCount());
    assertEquals(19, mxBean0Grp1.get1().getClusterOwningPartitionsCount());
    assertEquals(7, mxBean0Grp1.get2().<IntMetric>findMetric("LocalNodeOwningPartitionsCount").value());
    assertEquals(6, mxBean1Grp1.get2().<IntMetric>findMetric("LocalNodeOwningPartitionsCount").value());
    assertEquals(6, mxBean2Grp1.get2().<IntMetric>findMetric("LocalNodeOwningPartitionsCount").value());
    assertEquals(F.asList("cache1"), mxBean0Grp1.get2().<ObjectMetric<List<String>>>findMetric("Caches").value());
    assertEquals(F.asList("cache2", "cache3"), mxBean0Grp2.get2().<ObjectMetric<List<String>>>findMetric("Caches").value());
    assertEquals(F.asList("cache4"), mxBean0Grp3.get2().<ObjectMetric<List<String>>>findMetric("Caches").value());
    assertEquals(arrayToAssignmentMap(assignmentMapArr), mxBean0Grp1.get2().<ObjectMetric<Map<Integer, List<String>>>>findMetric("AffinityPartitionsAssignmentMap").value());
    assertEquals(arrayToAllocationMap(assignmentMapArr), mxBean0Grp1.get2().<ObjectMetric<Map<Integer, List<String>>>>findMetric("OwningPartitionsAllocationMap").value());
    ObjectMetric<Map<Integer, List<String>>> movingPartitionsAllocationMap = mxBean0Grp1.get2().findMetric("MovingPartitionsAllocationMap");
    assertEquals(arrayToAllocationMap(new int[10][]), movingPartitionsAllocationMap.value());
    try (IgniteDataStreamer<Integer, Integer> st = grid(0).dataStreamer("cache1")) {
        for (int i = 0; i < 50_000; i++) st.addData(i, i);
    }
    // Pause rebalance to check instant partitions states.
    grid(0).rebalanceEnabled(false);
    grid(1).rebalanceEnabled(false);
    stopGrid(2);
    // Check moving partitions while rebalancing.
    assertFalse(arrayToAllocationMap(new int[10][]).equals(movingPartitionsAllocationMap.value()));
    int movingCnt = mxBean0Grp1.get2().<IntMetric>findMetric("LocalNodeMovingPartitionsCount").value();
    assertTrue(movingCnt > 0);
    assertTrue(mxBean0Grp1.get1().getClusterMovingPartitionsCount() > 0);
    final CountDownLatch evictLatch = new CountDownLatch(1);
    // Block all evicting threads to count total renting partitions.
    grid(0).events().localListen(new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            try {
                evictLatch.await();
            } catch (InterruptedException e) {
                log.error("Interrupted", e);
            }
            return true;
        }
    }, EventType.EVT_CACHE_REBALANCE_OBJECT_UNLOADED);
    grid(0).rebalanceEnabled(true);
    grid(1).rebalanceEnabled(true);
    startGrid(2);
    try {
        assertTrue("Renting partitions count when node returns not equals to moved partitions when node left", GridTestUtils.waitForCondition(new GridAbsPredicate() {

            @Override
            public boolean apply() {
                IntMetric localNodeRentingPartitionsCount = mxBean0Grp1.get2().findMetric("LocalNodeRentingPartitionsCount");
                log.info("Renting partitions count: " + localNodeRentingPartitionsCount.value());
                log.info("Renting entries count: " + mxBean0Grp1.get2().findMetric("LocalNodeRentingEntriesCount").getAsString());
                return localNodeRentingPartitionsCount.value() == movingCnt;
            }
        }, 10_000L));
        assertTrue("Renting entries count is 0", mxBean0Grp1.get2().<IntMetric>findMetric("LocalNodeRentingPartitionsCount").value() > 0);
    } finally {
        evictLatch.countDown();
    }
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) CountDownLatch(java.util.concurrent.CountDownLatch) CacheGroupMetricsMXBean(org.apache.ignite.mxbean.CacheGroupMetricsMXBean) ObjectMetric(org.apache.ignite.spi.metric.ObjectMetric) Event(org.apache.ignite.events.Event) ArrayList(java.util.ArrayList) List(java.util.List) IntMetric(org.apache.ignite.spi.metric.IntMetric) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 3 with CacheGroupMetricsMXBean

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

the class CacheGroupMetricsTest method checkClientNode.

/**
 * @throws Exception if failed.
 */
public void checkClientNode(boolean pds) throws Exception {
    this.pds = pds;
    startGrid(0);
    IgniteEx client = startClientGrid(1);
    if (pds)
        client.cluster().state(ClusterState.ACTIVE);
    AtomicReference<Exception> err = new AtomicReference<>();
    Consumer<String> lsnr = new Consumer<String>() {

        @Override
        public void accept(String s) {
            if (s.contains("Exception"))
                err.set(new IgniteException("Error was logged: " + s));
        }
    };
    testLog.registerListener(lsnr);
    String[] names = new String[] { "group1", "group2", "cache4" };
    for (String name : names) {
        T2<CacheGroupMetricsMXBean, MetricRegistry> grp1 = cacheGroupMetrics(1, name);
        for (Metric metric : grp1.get2()) metric.getAsString();
    }
    testLog.unregisterListener(lsnr);
    if (err.get() != null)
        throw err.get();
}
Also used : MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) AtomicReference(java.util.concurrent.atomic.AtomicReference) IgniteException(org.apache.ignite.IgniteException) CacheGroupMetricsMXBean(org.apache.ignite.mxbean.CacheGroupMetricsMXBean) Consumer(java.util.function.Consumer) IgniteException(org.apache.ignite.IgniteException) IgniteEx(org.apache.ignite.internal.IgniteEx) Metric(org.apache.ignite.spi.metric.Metric) ObjectMetric(org.apache.ignite.spi.metric.ObjectMetric) AtomicLongMetric(org.apache.ignite.internal.processors.metric.impl.AtomicLongMetric) IntMetric(org.apache.ignite.spi.metric.IntMetric) LongMetric(org.apache.ignite.spi.metric.LongMetric)

Example 4 with CacheGroupMetricsMXBean

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

the class CacheGroupMetricsTest method testAllocatedPages.

/**
 * Test allocated pages counts for cache groups.
 */
@Test
public void testAllocatedPages() throws Exception {
    pds = true;
    cleanPersistenceDir();
    IgniteEx ignite = startGrid(0);
    ignite.cluster().active(true);
    T2<CacheGroupMetricsMXBean, MetricRegistry> mxBean0Grp1 = cacheGroupMetrics(0, "group1");
    T2<CacheGroupMetricsMXBean, MetricRegistry> mxBean0Grp2 = cacheGroupMetrics(0, "group2");
    T2<CacheGroupMetricsMXBean, MetricRegistry> mxBean0Grp3 = cacheGroupMetrics(0, "cache4");
    GridMetricManager mmgr = ignite.context().metric();
    LongMetric totalPages = mmgr.registry(metricName(DATAREGION_METRICS_PREFIX, "default")).findMetric("TotalAllocatedPages");
    assertEquals(totalPages.value(), mxBean0Grp1.get2().<LongMetric>findMetric("TotalAllocatedPages").value() + mxBean0Grp2.get2().<LongMetric>findMetric("TotalAllocatedPages").value() + mxBean0Grp3.get2().<LongMetric>findMetric("TotalAllocatedPages").value());
    for (int cacheIdx = 1; cacheIdx <= 4; cacheIdx++) {
        IgniteCache cache = ignite.cache("cache" + cacheIdx);
        for (int i = 0; i < 10 * cacheIdx; i++) cache.put(i, new byte[100]);
    }
    assertEquals(totalPages.value(), mxBean0Grp1.get2().<LongMetric>findMetric("TotalAllocatedPages").value() + mxBean0Grp2.get2().<LongMetric>findMetric("TotalAllocatedPages").value() + mxBean0Grp3.get2().<LongMetric>findMetric("TotalAllocatedPages").value());
}
Also used : CacheGroupMetricsMXBean(org.apache.ignite.mxbean.CacheGroupMetricsMXBean) IgniteEx(org.apache.ignite.internal.IgniteEx) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) IgniteCache(org.apache.ignite.IgniteCache) GridMetricManager(org.apache.ignite.internal.processors.metric.GridMetricManager) AtomicLongMetric(org.apache.ignite.internal.processors.metric.impl.AtomicLongMetric) LongMetric(org.apache.ignite.spi.metric.LongMetric) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

CacheGroupMetricsMXBean (org.apache.ignite.mxbean.CacheGroupMetricsMXBean)4 MetricRegistry (org.apache.ignite.internal.processors.metric.MetricRegistry)3 IgniteEx (org.apache.ignite.internal.IgniteEx)2 AtomicLongMetric (org.apache.ignite.internal.processors.metric.impl.AtomicLongMetric)2 IntMetric (org.apache.ignite.spi.metric.IntMetric)2 LongMetric (org.apache.ignite.spi.metric.LongMetric)2 ObjectMetric (org.apache.ignite.spi.metric.ObjectMetric)2 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Consumer (java.util.function.Consumer)1 IgniteCache (org.apache.ignite.IgniteCache)1 IgniteException (org.apache.ignite.IgniteException)1 Event (org.apache.ignite.events.Event)1 GridMetricManager (org.apache.ignite.internal.processors.metric.GridMetricManager)1