Search in sources :

Example 1 with CacheGroupMetricsImpl

use of org.apache.ignite.internal.processors.cache.CacheGroupMetricsImpl in project ignite by apache.

the class CacheDataPageScanQueryTest method testDataPageScanWithRestart.

/**
 * @throws Exception If failed.
 */
@SuppressWarnings("ConstantConditions")
@Test
@Ignore("https://issues.apache.org/jira/browse/IGNITE-11998")
public void testDataPageScanWithRestart() throws Exception {
    IgniteEx ignite = startGrid(0);
    ignite.cluster().active(true);
    IgniteInternalCache<Long, String> cache = ignite.cachex(CACHE);
    CacheGroupMetricsImpl metrics = cache.context().group().metrics();
    DataRegionMetricsImpl rmx = cache.context().dataRegion().metrics();
    long maxKey = 10_000;
    Map<Long, String> map = new ConcurrentHashMap<>();
    int threads = 16;
    AtomicInteger threadShift = new AtomicInteger();
    multithreaded((Callable<Void>) () -> {
        ThreadLocalRandom rnd = ThreadLocalRandom.current();
        int shift = threadShift.getAndIncrement();
        for (int i = shift; i < maxKey; i += threads) {
            Long k = (long) i;
            // Bigger than single page.
            String v = GridTestUtils.randomString(rnd, 6 * 1024);
            cache.put(k, v);
            map.put(k, v);
        }
        return null;
    }, threads);
    assertEquals(map.size(), cache.size());
    info("Page mem  : " + rmx.getPhysicalMemorySize());
    info("Alloc size: " + metrics.getTotalAllocatedSize());
    info("Store size: " + metrics.getStorageSize());
    HashMap<Long, String> map2 = new HashMap<>(map);
    IgniteCache<Long, String> c = ignite.cache(CACHE);
    for (Cache.Entry<Long, String> e : c.query(new ScanQuery<Long, String>()).getAll()) assertEquals(e.getValue(), map.remove(e.getKey()));
    assertTrue(map.isEmpty());
    assertTrue(CacheDataTree.isLastFindWithDataPageScan());
    stopAllGrids(true);
    ignite = startGrid(0);
    ignite.cluster().active(true);
    c = ignite.cache(CACHE);
    for (Cache.Entry<Long, String> e : c.query(new ScanQuery<Long, String>()).getAll()) assertEquals(e.getValue(), map2.remove(e.getKey()));
    assertTrue(map2.isEmpty());
    assertTrue(CacheDataTree.isLastFindWithDataPageScan());
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ScanQuery(org.apache.ignite.cache.query.ScanQuery) DataRegionMetricsImpl(org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl) CacheGroupMetricsImpl(org.apache.ignite.internal.processors.cache.CacheGroupMetricsImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteEx(org.apache.ignite.internal.IgniteEx) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Cache(javax.cache.Cache) IgniteInternalCache(org.apache.ignite.internal.processors.cache.IgniteInternalCache) IgniteCache(org.apache.ignite.IgniteCache) Ignore(org.junit.Ignore) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 2 with CacheGroupMetricsImpl

use of org.apache.ignite.internal.processors.cache.CacheGroupMetricsImpl in project ignite by apache.

the class IgnitePdsCacheWalDisabledOnRebalancingTest method testRebalancedPartitionsOwningWithConcurrentAffinityChange.

/**
 * Scenario: when rebalanced MOVING partitions are owning by checkpointer,
 * concurrent affinity change (caused by BLT change) may lead for additional partitions in MOVING state to appear.
 *
 * In such situation no partitions should be owned until new rebalancing process starts and finishes.
 *
 * @throws Exception If failed.
 */
@Test
public void testRebalancedPartitionsOwningWithConcurrentAffinityChange() throws Exception {
    Ignite ig0 = startGridsMultiThreaded(4);
    ig0.cluster().baselineAutoAdjustEnabled(false);
    fillCache(ig0.dataStreamer(CACHE3_NAME), CACHE_SIZE, GENERATING_FUNC);
    // Stop idx=2 to prepare for baseline topology change later.
    stopGrid(2);
    // Stop idx=1 and cleanup LFS to trigger full rebalancing after it restart.
    String ig1Name = grid(1).name();
    stopGrid(1);
    cleanPersistenceDir(ig1Name);
    // Blocking fileIO and blockMessagePredicate to block checkpointer and rebalancing for node idx=1.
    useBlockingFileIO = true;
    IgniteEx ig1;
    CacheGroupMetricsImpl metrics;
    int locMovingPartsNum;
    try {
        IgniteConfiguration cfg1 = getConfiguration(getTestIgniteInstanceName(1));
        TestRecordingCommunicationSpi spi1 = (TestRecordingCommunicationSpi) cfg1.getCommunicationSpi();
        spi1.blockMessages(blockDemandMessageForGroup(CU.cacheId(CACHE3_NAME)));
        IgniteInternalFuture<IgniteEx> startFut = GridTestUtils.runAsync(new Callable<IgniteEx>() {

            @Override
            public IgniteEx call() throws Exception {
                return startGrid(cfg1);
            }
        });
        spi1.waitForBlocked();
        ig1 = startFut.get();
        // Enable blocking checkpointer on node idx=1 (see BlockingCheckpointFileIOFactory).
        fileIoBlockingSemaphore.drainPermits();
        spi1.stopBlock(true, null, false, true);
        doSleep(500);
        metrics = ig1.cachex(CACHE3_NAME).context().group().metrics();
        locMovingPartsNum = metrics.getLocalNodeMovingPartitionsCount();
        // Partitions remain in MOVING state even after PME and rebalancing when checkpointer is blocked.
        assertTrue("Expected non-zero value for local moving partitions count on node idx = 1: " + locMovingPartsNum, 0 < locMovingPartsNum && locMovingPartsNum < CACHE3_PARTS_NUM);
        // Change baseline topology and release checkpointer to verify
        // that no partitions will be owned after affinity change.
        ig0.cluster().setBaselineTopology(ig1.context().discovery().topologyVersion());
        spi1.waitForBlocked();
    } finally {
        fileIoBlockingSemaphore.release(Integer.MAX_VALUE);
    }
    locMovingPartsNum = metrics.getLocalNodeMovingPartitionsCount();
    assertTrue("Expected moving partitions count on node idx = 1 equals to all partitions of the cache " + CACHE3_NAME + ": " + locMovingPartsNum, locMovingPartsNum == CACHE3_PARTS_NUM);
    TestRecordingCommunicationSpi commSpi = (TestRecordingCommunicationSpi) ig1.configuration().getCommunicationSpi();
    // When we stop blocking demand message rebalancing should complete and all partitions should be owned.
    commSpi.stopBlock();
    boolean res = GridTestUtils.waitForCondition(() -> metrics.getLocalNodeMovingPartitionsCount() == 0, 15_000);
    assertTrue("All partitions on node idx = 1 are expected to be owned", res);
    verifyCache(ig1.cache(CACHE3_NAME), GENERATING_FUNC);
}
Also used : CacheGroupMetricsImpl(org.apache.ignite.internal.processors.cache.CacheGroupMetricsImpl) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) IOException(java.io.IOException) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 3 with CacheGroupMetricsImpl

use of org.apache.ignite.internal.processors.cache.CacheGroupMetricsImpl in project ignite by apache.

the class IgnitePdsCacheWalDisabledOnRebalancingTest method testServerNodesFromBltLeavesAndJoinsDuringRebalancing.

/**
 * If server nodes from BLT leave topology and then join again after additional keys were put to caches,
 * rebalance starts.
 *
 * Test verifies that all moving partitions get owned after rebalance finishes.
 *
 * @throws Exception If failed.
 */
@Test
public void testServerNodesFromBltLeavesAndJoinsDuringRebalancing() throws Exception {
    Ignite ig0 = startGridsMultiThreaded(4);
    fillCache(ig0.dataStreamer(CACHE3_NAME), CACHE_SIZE, GENERATING_FUNC);
    List<Integer> nonAffinityKeys1 = nearKeys(grid(1).cache(CACHE3_NAME), 100, CACHE_SIZE / 2);
    List<Integer> nonAffinityKeys2 = nearKeys(grid(2).cache(CACHE3_NAME), 100, CACHE_SIZE / 2);
    stopGrid(1);
    stopGrid(2);
    Set<Integer> nonAffinityKeysSet = new HashSet<>();
    nonAffinityKeysSet.addAll(nonAffinityKeys1);
    nonAffinityKeysSet.addAll(nonAffinityKeys2);
    fillCache(ig0.dataStreamer(CACHE3_NAME), nonAffinityKeysSet, GENERATING_FUNC);
    int groupId = ((IgniteEx) ig0).cachex(CACHE3_NAME).context().groupId();
    blockMessagePredicate = (node, msg) -> {
        if (msg instanceof GridDhtPartitionDemandMessage)
            return ((GridDhtPartitionDemandMessage) msg).groupId() == groupId;
        return false;
    };
    IgniteEx ig1 = startGrid(1);
    CacheGroupMetricsImpl metrics = ig1.cachex(CACHE3_NAME).context().group().metrics();
    TestRecordingCommunicationSpi commSpi = (TestRecordingCommunicationSpi) ig1.configuration().getCommunicationSpi();
    startGrid(2);
    commSpi.stopBlock();
    boolean allOwned = GridTestUtils.waitForCondition(() -> metrics.getLocalNodeMovingPartitionsCount() == 0, 30_000);
    assertTrue("Partitions were not owned, there are " + metrics.getLocalNodeMovingPartitionsCount() + " partitions in MOVING state", allOwned);
}
Also used : CacheGroupMetricsImpl(org.apache.ignite.internal.processors.cache.CacheGroupMetricsImpl) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) GridDhtPartitionDemandMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemandMessage) HashSet(java.util.HashSet) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 4 with CacheGroupMetricsImpl

use of org.apache.ignite.internal.processors.cache.CacheGroupMetricsImpl in project ignite by apache.

the class IgnitePdsCacheWalDisabledOnRebalancingTest method testClientJoinsLeavesDuringRebalancing.

/**
 * If client joins topology during rebalancing process, rebalancing finishes successfully,
 * all partitions are owned as expected when rebalancing finishes.
 */
@Test
public void testClientJoinsLeavesDuringRebalancing() throws Exception {
    Ignite ig0 = startGrids(2);
    ig0.active(true);
    for (int i = 1; i < 4; i++) fillCache(ig0.dataStreamer("cache" + i), CACHE_SIZE, GENERATING_FUNC);
    String ig1Name = grid(1).name();
    stopGrid(1);
    cleanPersistenceDir(ig1Name);
    int groupId = ((IgniteEx) ig0).cachex(CACHE3_NAME).context().groupId();
    blockMessagePredicate = (node, msg) -> {
        if (msg instanceof GridDhtPartitionDemandMessage)
            return ((GridDhtPartitionDemandMessage) msg).groupId() == groupId;
        return false;
    };
    IgniteEx ig1 = startGrid(1);
    startClientGrid("client");
    stopGrid("client");
    CacheGroupMetricsImpl metrics = ig1.cachex(CACHE3_NAME).context().group().metrics();
    assertTrue("Unexpected moving partitions count: " + metrics.getLocalNodeMovingPartitionsCount(), metrics.getLocalNodeMovingPartitionsCount() == CACHE3_PARTS_NUM);
    TestRecordingCommunicationSpi commSpi = (TestRecordingCommunicationSpi) ig1.configuration().getCommunicationSpi();
    commSpi.stopBlock();
    boolean waitResult = GridTestUtils.waitForCondition(() -> metrics.getLocalNodeMovingPartitionsCount() == 0, 30_000);
    assertTrue("Failed to wait for owning all partitions, parts in moving state: " + metrics.getLocalNodeMovingPartitionsCount(), waitResult);
}
Also used : CacheGroupMetricsImpl(org.apache.ignite.internal.processors.cache.CacheGroupMetricsImpl) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) GridDhtPartitionDemandMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemandMessage) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

IgniteEx (org.apache.ignite.internal.IgniteEx)4 CacheGroupMetricsImpl (org.apache.ignite.internal.processors.cache.CacheGroupMetricsImpl)4 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)4 Test (org.junit.Test)4 Ignite (org.apache.ignite.Ignite)3 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)3 GridDhtPartitionDemandMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemandMessage)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Cache (javax.cache.Cache)1 IgniteCache (org.apache.ignite.IgniteCache)1 ScanQuery (org.apache.ignite.cache.query.ScanQuery)1 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)1 IgniteInternalCache (org.apache.ignite.internal.processors.cache.IgniteInternalCache)1 DataRegionMetricsImpl (org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl)1 Ignore (org.junit.Ignore)1