You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2019/03/28 14:08:14 UTC
[GitHub] [ignite] ilantukh commented on a change in pull request #6247:
IGNITE-9913 Prevent data updates blocking in case of backup BLT server node
leave
ilantukh commented on a change in pull request #6247: IGNITE-9913 Prevent data updates blocking in case of backup BLT server node leave
URL: https://github.com/apache/ignite/pull/6247#discussion_r270009283
##########
File path: modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/baseline/IgniteBaselineNodeLeaveExchangeTest.java
##########
@@ -0,0 +1,732 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.persistence.baseline;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLong;
+import javax.cache.Cache;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteDataStreamer;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.affinity.AffinityFunction;
+import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.cluster.ClusterTopologyException;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.TestDelayingCommunicationSpi;
+import org.apache.ignite.internal.TestDelayingTcpDiscoverySpi;
+import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
+import org.apache.ignite.internal.managers.communication.GridIoMessage;
+import org.apache.ignite.internal.processors.cache.GridCacheContext;
+import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
+import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage;
+import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage;
+import org.apache.ignite.internal.util.future.GridCompoundFuture;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.X;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgnitePredicate;
+import org.apache.ignite.plugin.extensions.communication.Message;
+import org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage;
+import org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryNodeFailedMessage;
+import org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryNodeLeftMessage;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.transactions.Transaction;
+import org.apache.ignite.transactions.TransactionConcurrency;
+import org.apache.ignite.transactions.TransactionIsolation;
+import org.apache.ignite.transactions.TransactionOptimisticException;
+import org.junit.Test;
+
+/**
+ * Tests the local affinity recalculation exchange in case of leaving a baseline node.
+ */
+public class IgniteBaselineNodeLeaveExchangeTest extends GridCommonAbstractTest {
+ /** Grids count. */
+ private static final int GRIDS_COUNT = 8;
+
+ /** Leaving grid index. */
+ private static final int LEAVING_GRID = GRIDS_COUNT / 2;
+
+ /** Tx cache name. */
+ private static final String TX_CACHE_NAME = "e"; // group ID = 101
+
+ /** Atomic cache name. */
+ private static final String ATOMIC_CACHE_NAME = "f"; // group ID = 102
+
+ /** Test attribute. */
+ private static final String TEST_ATTRIBUTE = "testAttribute";
+
+ /** Client grid name. */
+ private static final String CLIENT_GRID_NAME = "client";
+
+ /** Dummy grid name. */
+ private static final String DUMMY_GRID_NAME = "dummy";
+
+ /** Stop tx load flag. */
+ private static final AtomicBoolean txStop = new AtomicBoolean();
+
+ /** Stop atomic load flag. */
+ private static final AtomicBoolean atomicStop = new AtomicBoolean();
+
+ /** Keys count. */
+ private static final int KEYS_CNT = 100;
+
+ /** Account value bound. */
+ private static final long ACCOUNT_VAL_BOUND = 1000;
+
+ /** Account value origin. */
+ private static final long ACCOUNT_VAL_ORIGIN = 100;
+
+ /** Blocking discovery spi enabled. */
+ private static final AtomicBoolean delayMsg = new AtomicBoolean();
+
+ /** */
+ private volatile PickKeyOption pickKeyOption = PickKeyOption.NO_DATA_ON_LEAVING_NODE;
+
+ /** */
+ private volatile List<Integer> txKeys;
+
+ /** */
+ private volatile List<Integer> atomicKeys;
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+ cfg.setDataStorageConfiguration(
+ new DataStorageConfiguration()
+ .setDefaultDataRegionConfiguration(
+ new DataRegionConfiguration()
+ .setPersistenceEnabled(true)
+ .setInitialSize(300L * 1024 * 1024)
+ .setMaxSize(300L * 1024 * 1024)
+ )
+ .setWalSegmentSize(1024 * 1024)
+ );
+
+ if (igniteInstanceName.contains(DUMMY_GRID_NAME))
+ cfg.setUserAttributes(F.asMap(TEST_ATTRIBUTE, false));
+ else
+ cfg.setUserAttributes(F.asMap(TEST_ATTRIBUTE, true));
+
+ if (igniteInstanceName.contains(CLIENT_GRID_NAME))
+ cfg.setClientMode(true);
+
+ CacheConfiguration<Integer, Long> txCfg = new CacheConfiguration<Integer, Long>()
+ .setName(TX_CACHE_NAME)
+ .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL)
+ .setBackups(2)
+ .setNodeFilter(new TestNodeFilter())
+ .setAffinity(new RendezvousAffinityFunction(false, 32));
+
+ CacheConfiguration<Integer, Long> atomicCfg = new CacheConfiguration<Integer, Long>()
+ .setName(ATOMIC_CACHE_NAME)
+ .setAtomicityMode(CacheAtomicityMode.ATOMIC)
+ .setBackups(2)
+ .setNodeFilter(new TestNodeFilter())
+ .setAffinity(new RendezvousAffinityFunction(false, 32));
+
+ cfg.setCacheConfiguration(txCfg, atomicCfg);
+
+ cfg.setDiscoverySpi(new TestDelayingTcpDiscoverySpi() {
+ /** {@inheritDoc} */
+ @Override protected boolean delayMessage(TcpDiscoveryAbstractMessage msg) {
+ return delayMsg.get() &&
+ (msg instanceof TcpDiscoveryNodeFailedMessage || msg instanceof TcpDiscoveryNodeLeftMessage);
+ }
+ });
+
+ cfg.setCommunicationSpi(new TestDelayingCommunicationSpi() {
+ /** {@inheritDoc} */
+ @Override protected boolean delayMessage(Message msg, GridIoMessage ioMsg) {
+ return delayMsg.get() &&
+ (msg instanceof GridDhtPartitionsFullMessage || msg instanceof GridDhtPartitionsSingleMessage);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected int delayMillis() {
+ return 1000;
+ }
+ });
+
+ cfg.setConsistentId(igniteInstanceName);
+
+ cfg.setFailureDetectionTimeout(60_000);
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ cleanup();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ cleanup();
+ }
+
+ /**
+ * @param dummyCrd Dummy grid coordinator.
+ * @throws Exception if failed.
+ */
+ private void startAndActivateNodes(boolean dummyCrd) throws Exception {
+ if (dummyCrd) {
+ startGrid(DUMMY_GRID_NAME);
+
+ for (int i = 0; i < GRIDS_COUNT; i++)
+ startGrid(i);
+ }
+ else {
+ for (int i = 0; i < GRIDS_COUNT; i++)
+ startGrid(i);
+
+ startGrid(DUMMY_GRID_NAME);
+ }
+
+ startGrid(CLIENT_GRID_NAME);
+
+ grid(0).cluster().active(true);
+
+ awaitPartitionMapExchange();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ cleanup();
+ }
+
+ /**
+ *
+ */
+ private void cleanup() throws Exception {
+ delayMsg.set(false);
+
+ stopAllGrids();
+
+ cleanPersistenceDir();
+ }
+
+ /**
+ * @throws Exception if failed.
+ */
+ @Test
+ public void testServerLeaveOperationsFromClient() throws Exception {
+ testUpdatesNotBlockExchangeOnServerLeave(CLIENT_GRID_NAME, true);
+ }
+
+ /**
+ * @throws Exception if failed.
+ */
+ @Test
+ public void testServerLeaveOperationsFromDummyCrd() throws Exception {
+ testUpdatesNotBlockExchangeOnServerLeave(DUMMY_GRID_NAME, true);
+ }
+
+ /**
+ * @throws Exception if failed.
+ */
+ @Test
+ public void testServerLeaveOperationsFromRegularCrd() throws Exception {
+ testUpdatesNotBlockExchangeOnServerLeave(DUMMY_GRID_NAME, false);
+ }
+
+ /**
+ * @throws Exception if failed.
+ */
+ @Test
+ public void testServerLeaveOperationsFromServer() throws Exception {
+ testUpdatesNotBlockExchangeOnServerLeave(getTestIgniteInstanceName(0), true);
+ }
+
+ /**
+ * @param operationsGridName Grid name.
+ * @param dummyCrd Dummy grid coordinator.
+ * @throws Exception if failed.
+ */
+ private void testUpdatesNotBlockExchangeOnServerLeave(String operationsGridName,
+ boolean dummyCrd) throws Exception {
+ startAndActivateNodes(dummyCrd);
+
+ populateData(grid(operationsGridName), TX_CACHE_NAME);
+
+ putGetSelfCheck(operationsGridName);
+
+ IgniteInternalCache<Integer, Long> cachex = grid(LEAVING_GRID).cachex(TX_CACHE_NAME);
+
+ ArrayList<Integer> backupKeys = pickKey(cachex.context(), PickKeyOption.BACKUP_ON_LEAVING_NODE);
+
+ assertFalse(backupKeys.isEmpty());
+
+ CountDownLatch latch = new CountDownLatch(1);
+
+ IgniteInternalFuture fut = GridTestUtils.runAsync(() -> {
+ IgniteEx ignite = grid(operationsGridName);
+
+ IgniteInternalCache<Integer, Long> cache = ignite.cachex(TX_CACHE_NAME);
+
+ ThreadLocalRandom rnd = ThreadLocalRandom.current();
+
+ try (Transaction tx = ignite.transactions().txStart(TransactionConcurrency.PESSIMISTIC, TransactionIsolation.READ_COMMITTED)) {
+ cache.put(backupKeys.get(rnd.nextInt(backupKeys.size())), rnd.nextLong());
+
+ assertTrue("Exchange waited for partition released.", latch.await(30, TimeUnit.SECONDS));
+
+ tx.commit();
+ }
+
+ return true;
+ });
+
+ stopGrid(LEAVING_GRID);
+
+ awaitPartitionMapExchange();
+
+ latch.countDown();
+
+ fut.get();
+
+ putGetSelfCheck(operationsGridName);
+ }
+
+ /**
+ * @throws Exception if failed.
+ */
+ @Test
+ public void testServerLeaveUnderLoadFromClient() throws Exception {
+ testBltServerLeaveUnderLoad(CLIENT_GRID_NAME, true, pickKeyOption);
+ }
+
+ /**
+ * @throws Exception if failed.
+ */
+ @Test
+ public void testServerLeaveUnderLoadFromDummyCrd() throws Exception {
+ testBltServerLeaveUnderLoad(DUMMY_GRID_NAME, true, pickKeyOption);
+ }
+
+ /**
+ * @throws Exception if failed.
+ */
+ @Test
+ public void testServerLeaveUnderLoadFromRegularCrd() throws Exception {
+ testBltServerLeaveUnderLoad(DUMMY_GRID_NAME, false, pickKeyOption);
+ }
+
+ /**
+ * @throws Exception if failed.
+ */
+ @Test
+ public void testServerLeaveUnderLoadFromFirstServer() throws Exception {
+ testBltServerLeaveUnderLoad(getTestIgniteInstanceName(0), true, pickKeyOption);
+ }
+
+ /**
+ * @throws Exception if failed.
+ */
+ @Test
+ public void testServerLeaveUnderLoadFromLastServer() throws Exception {
+ testBltServerLeaveUnderLoad(getTestIgniteInstanceName(GRIDS_COUNT - 1), true, pickKeyOption);
+ }
+
+ /**
+ * @param operationsGridName Grid name.
+ * @param dummyCrd Dummy grid coordinator.
+ * @param pickKeyOption Pick key option.
+ * @throws Exception if failed.
+ */
+ private void testBltServerLeaveUnderLoad(
+ String operationsGridName,
+ boolean dummyCrd,
+ PickKeyOption pickKeyOption
+ ) throws Exception {
+ startAndActivateNodes(dummyCrd);
+
+ populateData(grid(operationsGridName), TX_CACHE_NAME);
+ populateData(grid(operationsGridName), ATOMIC_CACHE_NAME);
+
+ putGetSelfCheck(operationsGridName);
+
+ IgniteInternalCache<Integer, Long> txCache = grid(LEAVING_GRID).cachex(TX_CACHE_NAME);
+ IgniteInternalCache<Integer, Long> aCache = grid(LEAVING_GRID).cachex(ATOMIC_CACHE_NAME);
+
+ txKeys = pickKey(txCache.context(), pickKeyOption);
+ atomicKeys = pickKey(aCache.context(), pickKeyOption);
+
+ assertFalse(txKeys.isEmpty());
+ assertFalse(atomicKeys.isEmpty());
+
+ GridCompoundFuture<Long, Void> fut = new GridCompoundFuture<>();
+
+ fut.add(startTxLoad(1, operationsGridName, TransactionConcurrency.PESSIMISTIC, TransactionIsolation.REPEATABLE_READ, pickKeyOption));
+ fut.add(startTxLoad(1, operationsGridName, TransactionConcurrency.PESSIMISTIC, TransactionIsolation.READ_COMMITTED, pickKeyOption));
+ fut.add(startTxLoad(1, operationsGridName, TransactionConcurrency.OPTIMISTIC, TransactionIsolation.SERIALIZABLE, pickKeyOption));
+ fut.add(startAtomicLoad(1, operationsGridName, pickKeyOption));
+
+ fut.markInitialized();
+
+ U.sleep(1000);
Review comment:
Please avoid using sleeps. Is it possible to re-design this test to use latches instead?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services