Search in sources :

Example 11 with PartitionsExchangeAware

use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.PartitionsExchangeAware in project ignite by apache.

the class EagerTtlTest method testOneNodeRestartWithTtlCache.

/**
 * Checks of restart node with TTL cache.
 *
 * @throws Exception If failed.
 */
@Test
public void testOneNodeRestartWithTtlCache() throws Exception {
    eagerTtl = true;
    IgniteEx ignite = startGrid(0);
    ignite.cluster().state(ClusterState.ACTIVE);
    IgniteCache<Integer, Integer> cache = ignite.cache(DEFAULT_CACHE_NAME);
    for (int i = 0; i < ENTRIES; i++) cache.put(i, i);
    ignite.close();
    LogListener assertListener = LogListener.matches(ASSERTION_ERR).build();
    listeningLog.registerListener(assertListener);
    ignite = startGrid(0);
    CountDownLatch exchangeHangLatch = new CountDownLatch(1);
    ignite.context().cache().context().exchange().registerExchangeAwareComponent(new PartitionsExchangeAware() {

        @Override
        public void onInitBeforeTopologyLock(GridDhtPartitionsExchangeFuture fut) {
            try {
                exchangeHangLatch.await();
            } catch (InterruptedException e) {
                log.error("Interrupted of waiting latch", e);
                fail(e.getMessage());
            }
        }
    });
    IgniteInternalFuture<?> activeFut = GridTestUtils.runAsync(() -> ignite(0).cluster().state(ClusterState.ACTIVE));
    assertFalse(activeFut.isDone());
    assertFalse(GridTestUtils.waitForCondition(assertListener::check, 2_000));
    exchangeHangLatch.countDown();
    activeFut.get();
    awaitPartitionMapExchange();
}
Also used : PartitionsExchangeAware(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.PartitionsExchangeAware) GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) LogListener(org.apache.ignite.testframework.LogListener) IgniteEx(org.apache.ignite.internal.IgniteEx) CountDownLatch(java.util.concurrent.CountDownLatch) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 12 with PartitionsExchangeAware

use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.PartitionsExchangeAware in project ignite by apache.

the class IgniteClusterSnapshotSelfTest method testConsistentClusterSnapshotLoadNewTopology.

/**
 * Take snapshot from the whole cluster and check snapshot consistency when the
 * cluster tx load starts on a new topology version.
 * Note: Client nodes and server nodes not in baseline topology must not be affected.
 *
 * @throws Exception If fails.
 */
@Test
public void testConsistentClusterSnapshotLoadNewTopology() throws Exception {
    int grids = 3;
    String snpName = "backup23012020";
    AtomicInteger atKey = new AtomicInteger(CACHE_KEYS_RANGE);
    AtomicInteger txKey = new AtomicInteger(CACHE_KEYS_RANGE);
    IgniteEx ignite = startGrids(grids);
    startClientGrid();
    ignite.cluster().baselineAutoAdjustEnabled(false);
    ignite.cluster().state(ACTIVE);
    ignite.events().localListen(e -> locEvts.add(e.type()), EVTS_CLUSTER_SNAPSHOT);
    // Start node not in baseline.
    IgniteEx notBltIgnite = startGrid(grids);
    File locSnpDir = snp(notBltIgnite).snapshotLocalDir(SNAPSHOT_NAME);
    String notBltDirName = folderName(notBltIgnite);
    IgniteCache<Integer, Integer> atCache = ignite.createCache(atomicCcfg);
    for (int idx = 0; idx < CACHE_KEYS_RANGE; idx++) {
        atCache.put(atKey.incrementAndGet(), -1);
        ignite.cache(DEFAULT_CACHE_NAME).put(txKey.incrementAndGet(), -1);
    }
    forceCheckpoint();
    CountDownLatch loadLatch = new CountDownLatch(1);
    ignite.context().cache().context().exchange().registerExchangeAwareComponent(new PartitionsExchangeAware() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void onInitBeforeTopologyLock(GridDhtPartitionsExchangeFuture fut) {
            if (fut.firstEvent().type() != EVT_DISCOVERY_CUSTOM_EVT)
                return;
            // First discovery custom event will be a snapshot operation.
            assertTrue(isSnapshotOperation(fut.firstEvent()));
            assertTrue("Snapshot must use pme-free exchange", fut.context().exchangeFreeSwitch());
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void onInitAfterTopologyLock(GridDhtPartitionsExchangeFuture fut) {
            if (fut.firstEvent().type() != EVT_DISCOVERY_CUSTOM_EVT)
                return;
            DiscoveryCustomMessage msg = ((DiscoveryCustomEvent) fut.firstEvent()).customMessage();
            assertNotNull(msg);
            if (msg instanceof SnapshotDiscoveryMessage)
                loadLatch.countDown();
        }
    });
    // Start cache load.
    IgniteInternalFuture<Long> loadFut = GridTestUtils.runMultiThreadedAsync(() -> {
        try {
            U.await(loadLatch);
            while (!Thread.currentThread().isInterrupted()) {
                ThreadLocalRandom rnd = ThreadLocalRandom.current();
                int atIdx = rnd.nextInt(grids);
                // Zero out the sign bit.
                grid(atIdx).cache(atomicCcfg.getName()).put(txKey.incrementAndGet(), rnd.nextInt() & Integer.MAX_VALUE);
                int txIdx = rnd.nextInt(grids);
                grid(txIdx).cache(DEFAULT_CACHE_NAME).put(atKey.incrementAndGet(), rnd.nextInt() & Integer.MAX_VALUE);
            }
        } catch (IgniteInterruptedCheckedException e) {
            throw new RuntimeException(e);
        }
    }, 3, "cache-put-");
    try {
        IgniteFuture<Void> fut = ignite.snapshot().createSnapshot(snpName);
        U.await(loadLatch, 10, TimeUnit.SECONDS);
        fut.get();
        waitForEvents(EVT_CLUSTER_SNAPSHOT_STARTED, EVT_CLUSTER_SNAPSHOT_FINISHED);
    } finally {
        loadFut.cancel();
    }
    // Cluster can be deactivated but we must test snapshot restore when binary recovery also occurred.
    stopAllGrids();
    assertTrue("Snapshot directory must be empty for node not in baseline topology: " + notBltDirName, !searchDirectoryRecursively(locSnpDir.toPath(), notBltDirName).isPresent());
    IgniteEx snpIg0 = startGridsFromSnapshot(grids, snpName);
    assertEquals("The number of all (primary + backup) cache keys mismatch for cache: " + DEFAULT_CACHE_NAME, CACHE_KEYS_RANGE, snpIg0.cache(DEFAULT_CACHE_NAME).size());
    assertEquals("The number of all (primary + backup) cache keys mismatch for cache: " + atomicCcfg.getName(), CACHE_KEYS_RANGE, snpIg0.cache(atomicCcfg.getName()).size());
    snpIg0.cache(DEFAULT_CACHE_NAME).query(new ScanQuery<>(null)).forEach(e -> assertTrue("Snapshot must contains only negative values " + "[cache=" + DEFAULT_CACHE_NAME + ", entry=" + e + ']', (Integer) e.getValue() < 0));
    snpIg0.cache(atomicCcfg.getName()).query(new ScanQuery<>(null)).forEach(e -> assertTrue("Snapshot must contains only negative values " + "[cache=" + atomicCcfg.getName() + ", entry=" + e + ']', (Integer) e.getValue() < 0));
}
Also used : GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) ScanQuery(org.apache.ignite.cache.query.ScanQuery) CountDownLatch(java.util.concurrent.CountDownLatch) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PartitionsExchangeAware(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.PartitionsExchangeAware) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteEx(org.apache.ignite.internal.IgniteEx) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) File(java.io.File) Test(org.junit.Test)

Example 13 with PartitionsExchangeAware

use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.PartitionsExchangeAware in project ignite by apache.

the class IgniteClusterSnapshotSelfTest method testClusterSnapshotCoordinatorStopped.

/**
 * @throws Exception If fails.
 */
@Test
public void testClusterSnapshotCoordinatorStopped() throws Exception {
    CountDownLatch block = new CountDownLatch(1);
    startGridsWithCache(3, dfltCacheCfg, CACHE_KEYS_RANGE);
    startClientGrid(3);
    awaitPartitionMapExchange();
    for (IgniteEx grid : Arrays.asList(grid(1), grid(2))) {
        grid.context().cache().context().exchange().registerExchangeAwareComponent(new PartitionsExchangeAware() {

            /**
             * {@inheritDoc}
             */
            @Override
            public void onInitBeforeTopologyLock(GridDhtPartitionsExchangeFuture fut) {
                try {
                    block.await(TIMEOUT, TimeUnit.MILLISECONDS);
                } catch (InterruptedException e) {
                    fail("Must not catch exception here: " + e.getMessage());
                }
            }
        });
    }
    for (Ignite grid : G.allGrids()) {
        TestRecordingCommunicationSpi.spi(grid).blockMessages((node, msg) -> {
            if (msg instanceof GridDhtPartitionsSingleMessage)
                return ((GridDhtPartitionsAbstractMessage) msg).exchangeId() != null;
            return false;
        });
    }
    IgniteFuture<Void> fut = grid(1).snapshot().createSnapshot(SNAPSHOT_NAME);
    stopGrid(0);
    block.countDown();
    // There are two exchanges happen: snapshot, node left (with pme-free).
    // Both of them are not require for sending messages.
    assertFalse("Pme-free switch doesn't expect messaging exchanging between nodes", GridTestUtils.waitForCondition(() -> {
        boolean hasMsgs = false;
        for (Ignite g : G.allGrids()) hasMsgs |= TestRecordingCommunicationSpi.spi(g).hasBlockedMessages();
        return hasMsgs;
    }, 5_000));
    assertThrowsWithCause((Callable<Object>) fut::get, IgniteException.class);
    List<GridDhtPartitionsExchangeFuture> exchFuts = grid(1).context().cache().context().exchange().exchangeFutures();
    assertFalse("Exchanges cannot be empty due to snapshot and node left happened", exchFuts.isEmpty());
    for (GridDhtPartitionsExchangeFuture exch : exchFuts) {
        assertTrue("Snapshot and node left events must keep `rebalanced` state" + exch, exch.rebalanced());
    }
}
Also used : GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) CountDownLatch(java.util.concurrent.CountDownLatch) GridDhtPartitionsAbstractMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsAbstractMessage) PartitionsExchangeAware(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.PartitionsExchangeAware) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) Test(org.junit.Test)

Example 14 with PartitionsExchangeAware

use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.PartitionsExchangeAware in project ignite by apache.

the class GridCacheVersionGenerationWithCacheStorageTest method checkGridCacheVersionsGenerationOrder.

/**
 * <or>
 *     <li>Start node.</li>
 *     <li>Start one more node asyncronously</li>
 *     <li>With the help of {@link PartitionsExchangeAware) slow down exchange in order to run some cache operations
 *      after discovery message processing but before exchange topology lock.</li>
 * </or>
 *
 * Ensure that topology version of entry and current topology version* are equals after exchange
 * and operation were finished.
 *
 * @param actions Actions to check: get, put etc.
 * @throws Exception
 */
private void checkGridCacheVersionsGenerationOrder(Consumer<IgniteEx> actions, Set<Integer> keySetToCheck) throws Exception {
    IgniteEx ign = startGrid(0);
    ign.context().cache().context().exchange().registerExchangeAwareComponent(new PartitionsExchangeAware() {

        @Override
        public void onInitBeforeTopologyLock(GridDhtPartitionsExchangeFuture fut) {
            try {
                latch.await();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    });
    IgniteInternalFuture<?> newNodeJoinFut = GridTestUtils.runAsync(() -> startGrid(1));
    waitForCondition(() -> (ignite(0).context().discovery().topologyVersion() == 2), 10_000);
    assertEquals(2, ignite(0).context().discovery().topologyVersion());
    assertEquals(1, ignite(0).cachex(DEFAULT_CACHE_NAME).context().topology().readyTopologyVersion().topologyVersion());
    actions.accept(ign);
    latch.countDown();
    newNodeJoinFut.get();
    long expTop = (ign.context().cache().cache(DEFAULT_CACHE_NAME).context().kernalContext().discovery().gridStartTime() - TOP_VER_BASE_TIME) / 1000 + 1;
    ign.cache(DEFAULT_CACHE_NAME).getEntries(keySetToCheck).stream().map(CacheEntry::version).forEach(v -> assertEquals(expTop, ((GridCacheVersion) v).topologyVersion()));
}
Also used : PartitionsExchangeAware(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.PartitionsExchangeAware) GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) IgniteEx(org.apache.ignite.internal.IgniteEx)

Example 15 with PartitionsExchangeAware

use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.PartitionsExchangeAware in project ignite by apache.

the class FullHistRebalanceOnClientStopTest method testFullRebalanceNotTriggeredWhenClientNodeStopsDuringPme.

/**
 * @throws Exception if failed.
 */
@Test
@WithSystemProperty(key = IGNITE_PDS_WAL_REBALANCE_THRESHOLD, value = "0")
public void testFullRebalanceNotTriggeredWhenClientNodeStopsDuringPme() throws Exception {
    startGrids(2);
    IgniteEx ig0 = grid(0);
    ig0.cluster().active(true);
    IgniteCache<Object, Object> cache = ig0.cache(CACHE_NAME);
    startClientGrid(5);
    final int entryCnt = PARTS_CNT * 1000;
    final int preloadEntryCnt = PARTS_CNT * 1001;
    for (int i = 0; i < preloadEntryCnt; i++) cache.put(i, i);
    forceCheckpoint();
    stopGrid(1);
    for (int i = 0; i < entryCnt; i++) cache.put(i, i + 100);
    forceCheckpoint();
    final CountDownLatch exchangeLatch = new CountDownLatch(1);
    final CountDownLatch hangingPmeStartedLatch = new CountDownLatch(1);
    ig0.context().cache().context().exchange().registerExchangeAwareComponent(new PartitionsExchangeAware() {

        @Override
        public void onInitAfterTopologyLock(GridDhtPartitionsExchangeFuture fut) {
            try {
                hangingPmeStartedLatch.countDown();
                exchangeLatch.await();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    });
    IgniteInternalFuture fut = GridTestUtils.runAsync(() -> {
        try {
            startGrid(1);
            awaitPartitionMapExchange();
        } catch (Exception e) {
            e.printStackTrace();
        }
    });
    IgniteInternalFuture clientStopFut = GridTestUtils.runAsync(() -> {
        try {
            hangingPmeStartedLatch.await();
            stopGrid(5);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }, "client-starter");
    assertFalse(fut.isDone());
    exchangeLatch.countDown();
    clientStopFut.get();
    fut.get();
    awaitPartitionMapExchange();
    boolean histRebalanceInvoked = RebalanceCheckingCommunicationSpi.histRebalances();
    boolean fullRebalanceInvoked = RebalanceCheckingCommunicationSpi.fullRebalances();
    RebalanceCheckingCommunicationSpi.cleanup();
    assertTrue("Historical rebalance hasn't been invoked.", histRebalanceInvoked);
    assertFalse("Full rebalance has been invoked.", fullRebalanceInvoked);
}
Also used : PartitionsExchangeAware(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.PartitionsExchangeAware) GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) IgniteEx(org.apache.ignite.internal.IgniteEx) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) IgniteException(org.apache.ignite.IgniteException) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Aggregations

IgniteEx (org.apache.ignite.internal.IgniteEx)15 GridDhtPartitionsExchangeFuture (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture)15 PartitionsExchangeAware (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.PartitionsExchangeAware)15 Test (org.junit.Test)12 CountDownLatch (java.util.concurrent.CountDownLatch)11 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)7 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)7 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 IgniteException (org.apache.ignite.IgniteException)4 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Ignite (org.apache.ignite.Ignite)3 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)3 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)3 CheckpointListener (org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointListener)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 GridDhtPartitionDemandMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemandMessage)2 GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)2 File (java.io.File)1