Search in sources :

Example 81 with MetricRegistry

use of org.apache.ignite.internal.processors.metric.MetricRegistry in project ignite by apache.

the class CacheGroupMetricsWithIndexBuildFailTest method testIndexRebuildCountPartitionsLeft.

/**
 */
@Test
public void testIndexRebuildCountPartitionsLeft() throws Exception {
    IgniteEx ignite0 = startGrid(0);
    ignite0.cluster().active(true);
    String cacheName1 = "cache1";
    String cacheName2 = "cache2";
    IgniteCache<Integer, Integer> cache1 = ignite0.getOrCreateCache(cacheConfiguration(cacheName1));
    IgniteCache<Integer, Integer> cache2 = ignite0.getOrCreateCache(cacheConfiguration(cacheName2));
    cache1.put(1, 1);
    cache2.put(1, 1);
    int parts1 = ignite0.cachex(cacheName1).configuration().getAffinity().partitions();
    int parts2 = ignite0.cachex(cacheName2).configuration().getAffinity().partitions();
    List<Path> idxPaths = getIndexBinPaths(cacheName1);
    stopAllGrids();
    idxPaths.forEach(idxPath -> assertTrue(U.delete(idxPath)));
    IndexProcessor.idxRebuildCls = BlockingIndexesRebuildTask.class;
    IgniteEx ignite = startGrid(0);
    ignite.cluster().active(true);
    MetricRegistry grpMreg = ignite.context().metric().registry(metricName(CACHE_GROUP_METRICS_PREFIX, GROUP_NAME));
    LongMetric indexBuildCountPartitionsLeft = grpMreg.findMetric("IndexBuildCountPartitionsLeft");
    assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return parts1 + parts2 == indexBuildCountPartitionsLeft.value();
        }
    }, 5000));
    failIndexRebuild.set(true);
    ((AbstractIndexingCommonTest.BlockingIndexesRebuildTask) ignite.context().indexProcessor().idxRebuild()).stopBlock(cacheName1);
    GridTestUtils.assertThrows(log, () -> ignite.cache(cacheName1).indexReadyFuture().get(30_000), IgniteSpiException.class, "Test exception.");
    assertEquals(parts2, indexBuildCountPartitionsLeft.value());
    failIndexRebuild.set(false);
    ((AbstractIndexingCommonTest.BlockingIndexesRebuildTask) ignite.context().indexProcessor().idxRebuild()).stopBlock(cacheName2);
    ignite.cache(cacheName2).indexReadyFuture().get(30_000);
    assertEquals(0, indexBuildCountPartitionsLeft.value());
}
Also used : Path(java.nio.file.Path) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteEx(org.apache.ignite.internal.IgniteEx) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) LongMetric(org.apache.ignite.spi.metric.LongMetric) AbstractIndexingCommonTest(org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest) Test(org.junit.Test)

Example 82 with MetricRegistry

use of org.apache.ignite.internal.processors.metric.MetricRegistry in project ignite by apache.

the class ZookeeperDiscoverySpi method onContextInitialized0.

/**
 * {@inheritDoc}
 */
@Override
protected void onContextInitialized0(IgniteSpiContext spiCtx) throws IgniteSpiException {
    super.onContextInitialized0(spiCtx);
    MetricRegistry discoReg = (MetricRegistry) getSpiContext().getOrCreateMetricRegistry(DISCO_METRICS);
    stats.registerMetrics(discoReg);
    discoReg.register("Coordinator", () -> impl.getCoordinator(), UUID.class, "Coordinator ID");
}
Also used : MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry)

Example 83 with MetricRegistry

use of org.apache.ignite.internal.processors.metric.MetricRegistry in project ignite by apache.

the class ZookeeperDiscoveryMiscTest method testMbean.

/**
 * @throws Exception if failed.
 */
@Test
public void testMbean() throws Exception {
    int cnt = 3;
    startGrids(cnt);
    UUID crdNodeId = grid(0).localNode().id();
    try {
        for (int i = 0; i < cnt; i++) {
            IgniteEx grid = grid(i);
            ZookeeperDiscoverySpiMBean bean = getMxBean(grid.context().igniteInstanceName(), "SPIs", ZookeeperDiscoverySpi.class, ZookeeperDiscoverySpiMBean.class);
            MetricRegistry discoReg = grid.context().metric().registry(DISCO_METRICS);
            assertNotNull(bean);
            assertEquals(String.valueOf(grid.cluster().node(crdNodeId)), bean.getCoordinatorNodeFormatted());
            assertEquals(String.valueOf(grid.cluster().localNode()), bean.getLocalNodeFormatted());
            assertEquals(zkCluster.getConnectString(), bean.getZkConnectionString());
            assertEquals((long) grid.configuration().getFailureDetectionTimeout(), bean.getZkSessionTimeout());
            assertEquals(grid.cluster().topologyVersion(), discoReg.<LongMetric>findMetric("CurrentTopologyVersion").value());
            assertEquals(grid.cluster().node(crdNodeId).id(), discoReg.<ObjectMetric<UUID>>findMetric("Coordinator").value());
            assertEquals(cnt - i - 1, bean.getNodesJoined());
            assertEquals(cnt - i - 1, discoReg.<LongMetric>findMetric("JoinedNodes").value());
            Arrays.asList("LeftNodes", "FailedNodes", "CommunicationErrors").forEach(name -> {
                assertEquals(0, discoReg.<LongMetric>findMetric(name).value());
            });
            assertEquals(0, bean.getNodesLeft());
            assertEquals(0, bean.getNodesFailed());
            assertEquals(0, bean.getCommErrorProcNum());
        }
    } finally {
        stopAllGrids();
    }
}
Also used : ZookeeperDiscoverySpiMBean(org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpiMBean) ObjectMetric(org.apache.ignite.spi.metric.ObjectMetric) IgniteEx(org.apache.ignite.internal.IgniteEx) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) LongMetric(org.apache.ignite.spi.metric.LongMetric) UUID(java.util.UUID) Test(org.junit.Test)

Example 84 with MetricRegistry

use of org.apache.ignite.internal.processors.metric.MetricRegistry in project ignite by apache.

the class CacheGroupMetricsWithIndexTest method testIndexCreateCountPartitionsLeftInCluster.

/**
 * Test number of partitions need to finished create indexes.
 * <p>Case:
 * <ul>
 *     <li>Start cluster, load data with indexes</li>
 *     <li>Kill single node, create new index, start node.</li>
 *     <li>Make sure that index rebuild count is in range of total new index size and 0 and decreasing</li>
 *     <li>Wait until rebuild finished, assert that no index errors</li>
 * </ul>
 * </p>
 */
@Test
public void testIndexCreateCountPartitionsLeftInCluster() throws Exception {
    pds = true;
    Ignite ignite = startGrid(0);
    startGrid(1);
    ignite.cluster().active(true);
    IgniteCache<Object, Object> cache1 = ignite.cache(CACHE_NAME);
    String addColSql = "ALTER TABLE " + TABLE + " ADD COLUMN " + COLUMN3_NAME + " BIGINT";
    cache1.query(new SqlFieldsQuery(addColSql)).getAll();
    for (int i = 0; i < 100_000; i++) {
        Long id = (long) i;
        BinaryObjectBuilder o = ignite.binary().builder(OBJECT_NAME).setField(KEY_NAME, id).setField(COLUMN1_NAME, i / 2).setField(COLUMN2_NAME, "str" + Integer.toHexString(i)).setField(COLUMN3_NAME, id * 10);
        cache1.put(id, o.build());
    }
    stopGrid(1);
    MetricRegistry metrics = cacheGroupMetrics(0, GROUP_NAME).get2();
    GridTestUtils.runAsync(() -> {
        String createIdxSql = "CREATE INDEX " + INDEX_NAME + " ON " + TABLE + "(" + COLUMN3_NAME + ")";
        cache1.query(new SqlFieldsQuery(createIdxSql)).getAll();
        String selectIdxSql = "select * from information_schema.indexes where index_name='" + INDEX_NAME + "'";
        List<List<?>> all = cache1.query(new SqlFieldsQuery(selectIdxSql)).getAll();
        assertEquals("Index not found", 1, all.size());
    });
    final LongMetric idxBuildCntPartitionsLeft0 = metrics.findMetric("IndexBuildCountPartitionsLeft");
    assertTrue("Timeout wait start build index", waitForCondition(() -> idxBuildCntPartitionsLeft0.value() > 0, 30_000));
    assertTrue("Timeout wait finished build index", waitForCondition(() -> idxBuildCntPartitionsLeft0.value() == 0, 30_000));
    startGrid(1);
    metrics = cacheGroupMetrics(1, GROUP_NAME).get2();
    final LongMetric idxBuildCntPartitionsLeft1 = metrics.findMetric("IndexBuildCountPartitionsLeft");
    assertTrue("Timeout wait start build index", waitForCondition(() -> idxBuildCntPartitionsLeft1.value() > 0, 30_000));
    assertTrue("Timeout wait finished build index", waitForCondition(() -> idxBuildCntPartitionsLeft1.value() == 0, 30_000));
}
Also used : MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) Ignite(org.apache.ignite.Ignite) ArrayList(java.util.ArrayList) List(java.util.List) LongMetric(org.apache.ignite.spi.metric.LongMetric) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) Test(org.junit.Test)

Example 85 with MetricRegistry

use of org.apache.ignite.internal.processors.metric.MetricRegistry in project ignite by apache.

the class CacheGroupMetricsWithIndexTest method testIndexRebuildCountPartitionsLeftInCluster.

/**
 * Test number of partitions need to finished indexes rebuilding.
 * <p>Case:
 * <ul>
 *     <li>Start cluster, load data with indexes</li>
 *     <li>Kill single node, delete index.bin, start node.</li>
 *     <li>Make sure that index rebuild count is in range of total new index size and 0 and decreasing</li>
 *     <li>Wait until rebuild finished, assert that no index errors</li>
 * </ul>
 * </p>
 */
@Test
public void testIndexRebuildCountPartitionsLeftInCluster() throws Exception {
    pds = true;
    Ignite ignite = startGrid(0);
    startGrid(1);
    ignite.cluster().active(true);
    IgniteCache<Object, Object> cache1 = ignite.cache(CACHE_NAME);
    for (int i = 0; i < 100_000; i++) {
        Long id = (long) i;
        BinaryObjectBuilder o = ignite.binary().builder(OBJECT_NAME).setField(KEY_NAME, id).setField(COLUMN1_NAME, i / 2).setField(COLUMN2_NAME, "str" + Integer.toHexString(i));
        cache1.put(id, o.build());
    }
    String consistentId = ignite.cluster().localNode().consistentId().toString();
    stopGrid(0);
    File dir = U.resolveWorkDirectory(U.defaultWorkDirectory(), DFLT_STORE_DIR, false);
    IOFileFilter filter = FileFilterUtils.nameFileFilter("index.bin");
    Collection<File> idxBinFiles = FileUtils.listFiles(dir, filter, TrueFileFilter.TRUE);
    for (File indexBin : idxBinFiles) if (indexBin.getAbsolutePath().contains(consistentId))
        U.delete(indexBin);
    startGrid(0);
    MetricRegistry metrics = cacheGroupMetrics(0, GROUP_NAME).get2();
    LongMetric idxBuildCntPartitionsLeft = metrics.findMetric("IndexBuildCountPartitionsLeft");
    assertTrue("Timeout wait start rebuild index", waitForCondition(() -> idxBuildCntPartitionsLeft.value() > 0, 30_000));
    assertTrue("Timeout wait finished rebuild index", GridTestUtils.waitForCondition(() -> idxBuildCntPartitionsLeft.value() == 0, 30_000));
}
Also used : MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) IOFileFilter(org.apache.commons.io.filefilter.IOFileFilter) Ignite(org.apache.ignite.Ignite) LongMetric(org.apache.ignite.spi.metric.LongMetric) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder) File(java.io.File) Test(org.junit.Test)

Aggregations

MetricRegistry (org.apache.ignite.internal.processors.metric.MetricRegistry)86 Test (org.junit.Test)52 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)29 IgniteEx (org.apache.ignite.internal.IgniteEx)26 LongMetric (org.apache.ignite.spi.metric.LongMetric)26 List (java.util.List)11 CountDownLatch (java.util.concurrent.CountDownLatch)11 UUID (java.util.UUID)10 Map (java.util.Map)8 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)8 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)8 ArrayList (java.util.ArrayList)7 IgniteException (org.apache.ignite.IgniteException)7 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)7 IntMetric (org.apache.ignite.spi.metric.IntMetric)7 IgniteCache (org.apache.ignite.IgniteCache)6 ClusterNode (org.apache.ignite.cluster.ClusterNode)6 Arrays (java.util.Arrays)5 HashSet (java.util.HashSet)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5