You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by as...@apache.org on 2021/08/18 08:07:00 UTC

[ignite] branch master updated: IGNITE-15315 Always update partition clear version before preloading. - Fixes #9333.

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

ascherbakov 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 5501dd2  IGNITE-15315 Always update partition clear version before preloading. - Fixes #9333.
5501dd2 is described below

commit 5501dd264e7294adb1e1a5111b2878ce8569f30d
Author: Alexey Scherbakov <al...@gmail.com>
AuthorDate: Wed Aug 18 11:05:52 2021 +0300

    IGNITE-15315 Always update partition clear version before preloading. - Fixes #9333.
    
    Signed-off-by: Alexey Scherbakov <al...@gmail.com>
---
 .../dht/topology/GridDhtLocalPartition.java        | 10 +++-
 .../dht/topology/GridDhtPartitionTopologyImpl.java |  2 +
 ...ounterStateConsistencyHistoryRebalanceTest.java |  6 +++
 ...latilePartitionCounterStateConsistencyTest.java |  6 +++
 ...ounterStateConsistencyHistoryRebalanceTest.java |  6 +++
 .../TxPartitionCounterStateConsistencyTest.java    | 57 ++++++++++++++++++++++
 ...unterStateConsistencyVolatileRebalanceTest.java |  6 +++
 7 files changed, 92 insertions(+), 1 deletion(-)

diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/topology/GridDhtLocalPartition.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/topology/GridDhtLocalPartition.java
index da0383f..505f935 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/topology/GridDhtLocalPartition.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/topology/GridDhtLocalPartition.java
@@ -649,7 +649,7 @@ public class GridDhtLocalPartition extends GridCacheConcurrentMapImpl implements
 
             if (casState(state, MOVING)) {
                 // The state is switched under global topology lock, safe to record version here.
-                clearVer = ctx.versions().localOrder();
+                updateClearVersion();
 
                 return true;
             }
@@ -657,6 +657,14 @@ public class GridDhtLocalPartition extends GridCacheConcurrentMapImpl implements
     }
 
     /**
+     * Records a version for row clearing. Must be called when a partition is marked for full rebalancing.
+     * @see #clearAll(EvictionContext)
+     */
+    public void updateClearVersion() {
+        clearVer = ctx.versions().localOrder();
+    }
+
+    /**
      * @return {@code True} if partition state changed.
      */
     public boolean markLost() {
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/topology/GridDhtPartitionTopologyImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/topology/GridDhtPartitionTopologyImpl.java
index 7901d23..7d71982 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/topology/GridDhtPartitionTopologyImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/topology/GridDhtPartitionTopologyImpl.java
@@ -2524,6 +2524,8 @@ public class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
 
         if (part.state() != MOVING)
             part.moving();
+        else
+            part.updateClearVersion();
 
         if (clear)
             exchFut.addClearingPartition(grp, part.id());
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/AtomicPartitionCounterStateConsistencyHistoryRebalanceTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/AtomicPartitionCounterStateConsistencyHistoryRebalanceTest.java
index e808b91..3cb35c9 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/AtomicPartitionCounterStateConsistencyHistoryRebalanceTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/AtomicPartitionCounterStateConsistencyHistoryRebalanceTest.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.internal.processors.cache.transactions;
 
 import org.apache.ignite.testframework.junits.WithSystemProperty;
+import org.junit.Ignore;
 
 import static org.apache.ignite.IgniteSystemProperties.IGNITE_PREFER_WAL_REBALANCE;
 
@@ -26,4 +27,9 @@ import static org.apache.ignite.IgniteSystemProperties.IGNITE_PREFER_WAL_REBALAN
  */
 @WithSystemProperty(key = IGNITE_PREFER_WAL_REBALANCE, value = "true")
 public class AtomicPartitionCounterStateConsistencyHistoryRebalanceTest extends AtomicPartitionCounterStateConsistencyTest {
+    /** {@inheritDoc} */
+    @Ignore
+    @Override public void testClearVersion() throws Exception {
+        // Not applicable for historical preloading.
+    }
 }
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/AtomicVolatilePartitionCounterStateConsistencyTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/AtomicVolatilePartitionCounterStateConsistencyTest.java
index 7972182..5f3afb9 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/AtomicVolatilePartitionCounterStateConsistencyTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/AtomicVolatilePartitionCounterStateConsistencyTest.java
@@ -53,6 +53,12 @@ public class AtomicVolatilePartitionCounterStateConsistencyTest extends AtomicPa
     }
 
     /** {@inheritDoc} */
+    @Ignore
+    @Override public void testClearVersion() throws Exception {
+        // Not applicable for volatile mode.
+    }
+
+    /** {@inheritDoc} */
     @Override protected void forceCheckpoint(Collection<Ignite> nodes) throws IgniteCheckedException {
         // No-op.
     }
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxPartitionCounterStateConsistencyHistoryRebalanceTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxPartitionCounterStateConsistencyHistoryRebalanceTest.java
index 1e56992..f66bd2f 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxPartitionCounterStateConsistencyHistoryRebalanceTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxPartitionCounterStateConsistencyHistoryRebalanceTest.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.internal.processors.cache.transactions;
 
 import org.apache.ignite.testframework.junits.WithSystemProperty;
+import org.junit.Ignore;
 
 import static org.apache.ignite.IgniteSystemProperties.IGNITE_PREFER_WAL_REBALANCE;
 
@@ -26,4 +27,9 @@ import static org.apache.ignite.IgniteSystemProperties.IGNITE_PREFER_WAL_REBALAN
  */
 @WithSystemProperty(key = IGNITE_PREFER_WAL_REBALANCE, value = "true")
 public class TxPartitionCounterStateConsistencyHistoryRebalanceTest extends TxPartitionCounterStateConsistencyTest {
+    /** {@inheritDoc} */
+    @Ignore
+    @Override public void testClearVersion() throws Exception {
+        // Not applicable for historical preloading.
+    }
 }
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxPartitionCounterStateConsistencyTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxPartitionCounterStateConsistencyTest.java
index 5c78e3f..2a71918 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxPartitionCounterStateConsistencyTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxPartitionCounterStateConsistencyTest.java
@@ -42,6 +42,7 @@ import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteDataStreamer;
 import org.apache.ignite.cache.CacheAtomicityMode;
 import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.cluster.ClusterState;
 import org.apache.ignite.cluster.ClusterTopologyException;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.IgniteEx;
@@ -66,6 +67,7 @@ import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.Gri
 import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage;
 import org.apache.ignite.internal.processors.cache.distributed.near.GridNearLockRequest;
 import org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer;
+import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
 import org.apache.ignite.internal.util.typedef.G;
 import org.apache.ignite.internal.util.typedef.T2;
 import org.apache.ignite.internal.util.typedef.X;
@@ -77,11 +79,13 @@ import org.apache.ignite.plugin.extensions.communication.Message;
 import org.apache.ignite.spi.discovery.tcp.BlockTcpDiscoverySpi;
 import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
 import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.WithSystemProperty;
 import org.apache.ignite.transactions.Transaction;
 import org.apache.ignite.transactions.TransactionRollbackException;
 import org.junit.Test;
 
 import static java.util.stream.Collectors.toList;
+import static org.apache.ignite.IgniteSystemProperties.IGNITE_PREFER_WAL_REBALANCE;
 import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
 import static org.apache.ignite.internal.IgniteNodeAttributes.ATTR_IGNITE_INSTANCE_NAME;
 import static org.apache.ignite.internal.processors.cache.GridCacheOperation.CREATE;
@@ -1084,6 +1088,59 @@ public class TxPartitionCounterStateConsistencyTest extends TxPartitionCounterSt
     }
 
     /**
+     * Tests if a clear version comparison works properly during a partition clearing caused by full preloading.
+     */
+    @Test
+    @WithSystemProperty(key = IGNITE_PREFER_WAL_REBALANCE, value = "false")
+    public void testClearVersion() throws Exception {
+        backups = 1;
+
+        IgniteEx g0 = startGrid(0);
+        IgniteEx g1 = startGrid(1);
+
+        g0.cluster().state(ClusterState.ACTIVE);
+
+        IgniteCache<Integer, Integer> cache = g0.cache(DEFAULT_CACHE_NAME);
+
+        int[] parts = g0.affinity(DEFAULT_CACHE_NAME).primaryPartitions(g0.localNode());
+
+        int prim = parts[0];
+
+        List<Integer> keys = partitionKeys(cache, prim, 2_000, 0);
+
+        long topVer = g0.cachex(DEFAULT_CACHE_NAME).context().topology().readyTopologyVersion().topologyVersion();
+
+        // Move the version forward.
+        int c = 100_000;
+
+        // Simulating load by incrementing local version.
+        GridCacheVersion next = null;
+
+        while (c-- > 0)
+            next = g0.context().cache().context().versions().next(topVer);
+
+        assertTrue(next.order() - U.currentTimeMillis() > 60_000);
+
+        for (Integer key : keys)
+            cache.put(key, key);
+
+        assertPartitionsSame(idleVerify(g0, DEFAULT_CACHE_NAME));
+
+        g1.close();
+
+        for (Integer key : keys)
+            cache.remove(key);
+
+        g1 = startGrid(1);
+        g1.close();
+        g1 = startGrid(1);
+
+        awaitPartitionMapExchange();
+
+        assertPartitionsSame(idleVerify(g0, DEFAULT_CACHE_NAME));
+    }
+
+    /**
      * The scenario:
      * <p>
      * 1. Start updates only to primary partitions what will be switched when this node has left.
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxPartitionCounterStateConsistencyVolatileRebalanceTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxPartitionCounterStateConsistencyVolatileRebalanceTest.java
index bc32392..a0988b0 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxPartitionCounterStateConsistencyVolatileRebalanceTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxPartitionCounterStateConsistencyVolatileRebalanceTest.java
@@ -60,6 +60,12 @@ public class TxPartitionCounterStateConsistencyVolatileRebalanceTest extends TxP
     }
 
     /** {@inheritDoc} */
+    @Ignore
+    @Override public void testClearVersion() throws Exception {
+        // Not applicable for volatile mode.
+    }
+
+    /** {@inheritDoc} */
     @Override protected void forceCheckpoint(Collection<Ignite> nodes) throws IgniteCheckedException {
         // No-op.
     }