You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sk...@apache.org on 2021/06/04 17:07:35 UTC

[ignite] branch master updated: IGNITE-14821 Fixed AssertionError when historical iterator tries to iterate WAL out of reservation. Fixes #9146

This is an automated email from the ASF dual-hosted git repository.

sk0x50 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new 8db5b13  IGNITE-14821 Fixed AssertionError when historical iterator tries to iterate WAL out of reservation. Fixes #9146
8db5b13 is described below

commit 8db5b13481549124756c49040acbdd44e61d9086
Author: Vladislav Pyatkov <vl...@gmail.com>
AuthorDate: Fri Jun 4 20:06:29 2021 +0300

    IGNITE-14821 Fixed AssertionError when historical iterator tries to iterate WAL out of reservation. Fixes #9146
    
    Signed-off-by: Slava Koptilin <sl...@gmail.com>
---
 .../GridCacheDatabaseSharedManager.java            |   3 +-
 ...ebalanceTwoPartsInDifferentCheckpointsTest.java | 158 +++++++++++++++++++++
 .../ignite/testsuites/IgnitePdsTestSuite2.java     |   3 +
 3 files changed, 162 insertions(+), 2 deletions(-)

diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheDatabaseSharedManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheDatabaseSharedManager.java
index 96b2708..a518c92 100755
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheDatabaseSharedManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheDatabaseSharedManager.java
@@ -1785,8 +1785,7 @@ public class GridCacheDatabaseSharedManager extends IgniteCacheDatabaseSharedMan
             if (ptr == null)
                 return false;
 
-            if (oldestWALPointerToReserve == null ||
-                ptr.index() < oldestWALPointerToReserve.index())
+            if (oldestWALPointerToReserve == null || ptr.compareTo(oldestWALPointerToReserve) < 0)
                 oldestWALPointerToReserve = ptr;
         }
 
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/HistoricalRebalanceTwoPartsInDifferentCheckpointsTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/HistoricalRebalanceTwoPartsInDifferentCheckpointsTest.java
new file mode 100644
index 0000000..d31ec30
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/HistoricalRebalanceTwoPartsInDifferentCheckpointsTest.java
@@ -0,0 +1,158 @@
+/*
+ * 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.distributed.dht.preloader;
+
+import java.util.LinkedHashSet;
+import java.util.concurrent.atomic.AtomicBoolean;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteSystemProperties;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cluster.ClusterState;
+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.TestRecordingCommunicationSpi;
+import org.apache.ignite.testframework.junits.WithSystemProperty;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+/**
+ * There are two partition have updates in the different checkpoints. This test checks how historical rebalance works in
+ * these circumstances.
+ */
+@WithSystemProperty(key = IgniteSystemProperties.IGNITE_PREFER_WAL_REBALANCE, value = "true")
+public class HistoricalRebalanceTwoPartsInDifferentCheckpointsTest extends GridCommonAbstractTest {
+    /** {@inheritDoc} */
+    @Override public IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        return super.getConfiguration(igniteInstanceName)
+            .setCommunicationSpi(new TestRecordingCommunicationSpi())
+            .setDataStorageConfiguration(new DataStorageConfiguration()
+                .setDefaultDataRegionConfiguration(new DataRegionConfiguration()
+                    .setPersistenceEnabled(true)))
+            .setCacheConfiguration(new CacheConfiguration().setName(DEFAULT_CACHE_NAME)
+                .setAtomicityMode(CacheAtomicityMode.ATOMIC)
+                .setCacheMode(CacheMode.PARTITIONED)
+                .setBackups(1));
+    }
+
+    /** {@inheritDoc} */
+    @Override public void beforeTest() throws Exception {
+        super.beforeTest();
+
+        cleanPersistenceDir();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void afterTest() throws Exception {
+        super.afterTest();
+
+        stopAllGrids();
+    }
+
+    /**
+     * Checks when updates for 0 partition precedes updates for 2 partition in WAL.
+     *
+     * @throws Exception If failed.
+     */
+    @Test
+    public void testYoungerPartitionUpdateFirst() throws Exception {
+        rebalanceTwoPartitions(true);
+    }
+
+    /**
+     * Checks when updates for 2 partition precedes updates for 0 partition in WAL.
+     *
+     * @throws Exception If failed.
+     */
+    @Test
+    public void testOlderPartitionUpdateFirst() throws Exception {
+        rebalanceTwoPartitions(false);
+    }
+
+    /**
+     * Checks a historical rebalance for partitions 0 and 2.
+     *
+     * @param descending When true first updates is for younger partition, false is older one.
+     * @throws Exception If failed.
+     */
+    public void rebalanceTwoPartitions(boolean descending) throws Exception {
+        IgniteEx ignite0 = startGrids(2);
+
+        ignite0.cluster().state(ClusterState.ACTIVE);
+
+        awaitPartitionMapExchange();
+
+        LinkedHashSet<Integer> partKeys = new LinkedHashSet<>();
+
+        if (descending) {
+            partKeys.addAll(partitionKeys(ignite0.cache(DEFAULT_CACHE_NAME), 0, 10, 0));
+            partKeys.addAll(partitionKeys(ignite0.cache(DEFAULT_CACHE_NAME), 2, 10, 0));
+        }
+        else {
+            partKeys.addAll(partitionKeys(ignite0.cache(DEFAULT_CACHE_NAME), 2, 10, 0));
+            partKeys.addAll(partitionKeys(ignite0.cache(DEFAULT_CACHE_NAME), 0, 10, 0));
+        }
+
+        IgniteCache cache = ignite0.cache(DEFAULT_CACHE_NAME);
+
+        partKeys.forEach(key -> cache.put(key, key));
+
+        info("Data preload completed.");
+
+        stopGrid(1);
+
+        awaitPartitionMapExchange();
+
+        info("Node stopped.");
+
+        for (Integer key : partKeys) {
+            cache.put(key, key + 1);
+
+            forceCheckpoint();
+        }
+
+        IgniteConfiguration cfg = getConfiguration(getTestIgniteInstanceName(1));
+
+        AtomicBoolean hasFullRebalance = new AtomicBoolean();
+        AtomicBoolean hasHistoricalRebalance = new AtomicBoolean();
+
+        ((TestRecordingCommunicationSpi)cfg.getCommunicationSpi()).record((node, msg) -> {
+            if (msg instanceof GridDhtPartitionDemandMessage) {
+                GridDhtPartitionDemandMessage demandMsg = (GridDhtPartitionDemandMessage)msg;
+
+                hasFullRebalance.set(demandMsg.partitions().hasFull());
+                hasHistoricalRebalance.set(demandMsg.partitions().hasHistorical());
+            }
+
+            return false;
+        });
+
+        startGrid(cfg);
+
+        awaitPartitionMapExchange();
+
+        info("Node started and rebalance completed.");
+
+        assertFalse(hasFullRebalance.get());
+
+        assertTrue(hasHistoricalRebalance.get());
+    }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java
index d9e6d83..e7ac51f 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java
@@ -21,6 +21,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.HistoricalRebalanceHeuristicsTest;
+import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.HistoricalRebalanceTwoPartsInDifferentCheckpointsTest;
 import org.apache.ignite.internal.processors.cache.persistence.IgniteDataStorageMetricsSelfTest;
 import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsCacheStartStopWithFreqCheckpointTest;
 import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsCorruptedStoreTest;
@@ -246,5 +247,7 @@ public class IgnitePdsTestSuite2 {
         GridTestUtils.addTestIfNeeded(suite, IgniteLocalWalSizeTest.class, ignoredTests);
 
         GridTestUtils.addTestIfNeeded(suite, WriteAheadLogManagerSelfTest.class, ignoredTests);
+
+        GridTestUtils.addTestIfNeeded(suite, HistoricalRebalanceTwoPartsInDifferentCheckpointsTest.class, ignoredTests);
     }
 }