Search in sources :

Example 1 with KeyClass

use of org.apache.ignite.internal.processors.cache.index.AbstractSchemaSelfTest.KeyClass 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 2 with KeyClass

use of org.apache.ignite.internal.processors.cache.index.AbstractSchemaSelfTest.KeyClass in project ignite by apache.

the class IndexMetricsTest method cacheConfiguration.

/**
 * @return Default cache configuration.
 */
private CacheConfiguration<KeyClass, ValueClass> cacheConfiguration(String cacheName) {
    CacheConfiguration<KeyClass, ValueClass> ccfg = new CacheConfiguration<>(cacheName);
    QueryEntity entity = new QueryEntity();
    entity.setKeyType(KeyClass.class.getName());
    entity.setValueType(ValueClass.class.getName());
    entity.setKeyFieldName("key");
    entity.addQueryField("key", entity.getKeyType(), null);
    entity.setIndexes(Collections.singletonList(new QueryIndex("key", true, cacheName + "_index")));
    ccfg.setQueryEntities(Collections.singletonList(entity));
    return ccfg;
}
Also used : KeyClass(org.apache.ignite.internal.processors.cache.index.AbstractSchemaSelfTest.KeyClass) ValueClass(org.apache.ignite.internal.processors.cache.index.AbstractSchemaSelfTest.ValueClass) QueryIndex(org.apache.ignite.cache.QueryIndex) QueryEntity(org.apache.ignite.cache.QueryEntity) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Aggregations

KeyClass (org.apache.ignite.internal.processors.cache.index.AbstractSchemaSelfTest.KeyClass)2 ValueClass (org.apache.ignite.internal.processors.cache.index.AbstractSchemaSelfTest.ValueClass)2 Path (java.nio.file.Path)1 BooleanSupplier (java.util.function.BooleanSupplier)1 LongSupplier (java.util.function.LongSupplier)1 CacheMetrics (org.apache.ignite.cache.CacheMetrics)1 QueryEntity (org.apache.ignite.cache.QueryEntity)1 QueryIndex (org.apache.ignite.cache.QueryIndex)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 LongAdderMetric (org.apache.ignite.internal.processors.metric.impl.LongAdderMetric)1 CacheMetricsMXBean (org.apache.ignite.mxbean.CacheMetricsMXBean)1 BooleanMetric (org.apache.ignite.spi.metric.BooleanMetric)1 Test (org.junit.Test)1