You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by av...@apache.org on 2016/12/26 15:36:07 UTC
[2/2] ignite git commit: IGNITE-4424 REPLICATED cache isn't synced
across nodes
IGNITE-4424 REPLICATED cache isn't synced across nodes
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/7035e5ee
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/7035e5ee
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/7035e5ee
Branch: refs/heads/ignite-4424-1.6.12
Commit: 7035e5ee55d48d2c53296453f9e649dc8d9c98cc
Parents: 1859857
Author: Anton Vinogradov <av...@apache.org>
Authored: Mon Dec 26 18:33:52 2016 +0300
Committer: Anton Vinogradov <av...@apache.org>
Committed: Mon Dec 26 18:33:52 2016 +0300
----------------------------------------------------------------------
.../GridNearAtomicAbstractUpdateFuture.java | 34 ++-
.../GridNearAtomicSingleUpdateFuture.java | 44 ++--
.../dht/atomic/GridNearAtomicUpdateFuture.java | 57 ++---
.../AtomicPutAllChangingTopologyTest.java | 212 +++++++++++++++++++
.../IgniteCacheFailoverTestSuite.java | 3 +
5 files changed, 284 insertions(+), 66 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/7035e5ee/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicAbstractUpdateFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicAbstractUpdateFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicAbstractUpdateFuture.java
index 85751bb..a212f7b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicAbstractUpdateFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicAbstractUpdateFuture.java
@@ -213,14 +213,18 @@ public abstract class GridNearAtomicAbstractUpdateFuture extends GridFutureAdapt
// Cannot remap.
remapCnt = 1;
- map(topVer);
+ GridCacheVersion futVer = addAtomicFuture(topVer);
+
+ if (futVer != null)
+ map(topVer, futVer);
}
}
/**
* @param topVer Topology version.
+ * @param futVer Future version
*/
- protected abstract void map(AffinityTopologyVersion topVer);
+ protected abstract void map(AffinityTopologyVersion topVer, GridCacheVersion futVer);
/**
* Maps future on ready topology.
@@ -303,7 +307,7 @@ public abstract class GridNearAtomicAbstractUpdateFuture extends GridFutureAdapt
* @param req Request.
* @param e Error.
*/
- protected void onSendError(GridNearAtomicUpdateRequest req, IgniteCheckedException e) {
+ protected final void onSendError(GridNearAtomicUpdateRequest req, IgniteCheckedException e) {
synchronized (mux) {
GridNearAtomicUpdateResponse res = new GridNearAtomicUpdateResponse(cctx.cacheId(),
req.nodeId(),
@@ -315,4 +319,28 @@ public abstract class GridNearAtomicAbstractUpdateFuture extends GridFutureAdapt
onResult(req.nodeId(), res, true);
}
}
+
+ /**
+ * Adds future prevents topology change before operation complete.
+ * Should be invoked before topology lock released.
+ *
+ * @param topVer Topology version.
+ * @return Future version in case future added.
+ */
+ protected final GridCacheVersion addAtomicFuture(AffinityTopologyVersion topVer) {
+ GridCacheVersion futVer = cctx.versions().next(topVer);
+
+ synchronized (mux) {
+ assert this.futVer == null : this;
+ assert this.topVer == AffinityTopologyVersion.ZERO : this;
+
+ this.topVer = topVer;
+ this.futVer = futVer;
+ }
+
+ if (storeFuture() && !cctx.mvcc().addAtomicFuture(futVer, this))
+ return null;
+
+ return futVer;
+ }
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/7035e5ee/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateFuture.java
index 256c7ac..b996ce4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateFuture.java
@@ -344,14 +344,7 @@ public class GridNearAtomicSingleUpdateFuture extends GridNearAtomicAbstractUpda
@Override public void apply(final IgniteInternalFuture<AffinityTopologyVersion> fut) {
cctx.kernalContext().closure().runLocalSafe(new Runnable() {
@Override public void run() {
- try {
- AffinityTopologyVersion topVer = fut.get();
-
- map(topVer);
- }
- catch (IgniteCheckedException e) {
- onDone(e);
- }
+ mapOnTopology();
}
});
}
@@ -384,7 +377,9 @@ public class GridNearAtomicSingleUpdateFuture extends GridNearAtomicAbstractUpda
@Override protected void mapOnTopology() {
cache.topology().readLock();
- AffinityTopologyVersion topVer = null;
+ AffinityTopologyVersion topVer;
+
+ GridCacheVersion futVer;
try {
if (cache.topology().stopping()) {
@@ -406,6 +401,8 @@ public class GridNearAtomicSingleUpdateFuture extends GridNearAtomicAbstractUpda
}
topVer = fut.topologyVersion();
+
+ futVer = addAtomicFuture(topVer);
}
else {
if (waitTopFut) {
@@ -431,11 +428,12 @@ public class GridNearAtomicSingleUpdateFuture extends GridNearAtomicAbstractUpda
cache.topology().readUnlock();
}
- map(topVer);
+ if (futVer != null)
+ map(topVer, futVer);
}
/** {@inheritDoc} */
- protected void map(AffinityTopologyVersion topVer) {
+ @Override protected void map(AffinityTopologyVersion topVer, GridCacheVersion futVer) {
Collection<ClusterNode> topNodes = CU.affinityNodes(cctx, topVer);
if (F.isEmpty(topNodes)) {
@@ -445,11 +443,6 @@ public class GridNearAtomicSingleUpdateFuture extends GridNearAtomicAbstractUpda
return;
}
- Exception err = null;
- GridNearAtomicUpdateRequest singleReq0 = null;
-
- GridCacheVersion futVer = cctx.versions().next(topVer);
-
GridCacheVersion updVer;
// Assign version on near node in CLOCK ordering mode even if fastMap is false.
@@ -466,16 +459,17 @@ public class GridNearAtomicSingleUpdateFuture extends GridNearAtomicAbstractUpda
else
updVer = null;
+ Exception err = null;
+ GridNearAtomicUpdateRequest singleReq0 = null;
+
try {
singleReq0 = mapSingleUpdate(topVer, futVer, updVer);
synchronized (mux) {
- assert this.futVer == null : this;
- assert this.topVer == AffinityTopologyVersion.ZERO : this;
+ assert this.futVer == futVer || (this.isDone() && this.error() != null);
+ assert this.topVer == topVer;
- this.topVer = topVer;
this.updVer = updVer;
- this.futVer = futVer;
resCnt = 0;
@@ -492,14 +486,6 @@ public class GridNearAtomicSingleUpdateFuture extends GridNearAtomicAbstractUpda
return;
}
- if (storeFuture()) {
- if (!cctx.mvcc().addAtomicFuture(futVer, this)) {
- assert isDone() : this;
-
- return;
- }
- }
-
// Optimize mapping for single key.
mapSingle(singleReq0.nodeId(), singleReq0);
}
@@ -507,7 +493,7 @@ public class GridNearAtomicSingleUpdateFuture extends GridNearAtomicAbstractUpda
/**
* @return Future version.
*/
- GridCacheVersion onFutureDone() {
+ private GridCacheVersion onFutureDone() {
GridCacheVersion ver0;
GridFutureAdapter<Void> fut0;
http://git-wip-us.apache.org/repos/asf/ignite/blob/7035e5ee/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
index 30a0c3d..21abd6d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
@@ -456,14 +456,7 @@ public class GridNearAtomicUpdateFuture extends GridNearAtomicAbstractUpdateFutu
@Override public void apply(final IgniteInternalFuture<AffinityTopologyVersion> fut) {
cctx.kernalContext().closure().runLocalSafe(new Runnable() {
@Override public void run() {
- try {
- AffinityTopologyVersion topVer = fut.get();
-
- map(topVer, remapKeys);
- }
- catch (IgniteCheckedException e) {
- onDone(e);
- }
+ mapOnTopology();
}
});
}
@@ -497,7 +490,9 @@ public class GridNearAtomicUpdateFuture extends GridNearAtomicAbstractUpdateFutu
@Override protected void mapOnTopology() {
cache.topology().readLock();
- AffinityTopologyVersion topVer = null;
+ AffinityTopologyVersion topVer;
+
+ GridCacheVersion futVer;
try {
if (cache.topology().stopping()) {
@@ -519,6 +514,8 @@ public class GridNearAtomicUpdateFuture extends GridNearAtomicAbstractUpdateFutu
}
topVer = fut.topologyVersion();
+
+ futVer = addAtomicFuture(topVer);
}
else {
if (waitTopFut) {
@@ -544,7 +541,8 @@ public class GridNearAtomicUpdateFuture extends GridNearAtomicAbstractUpdateFutu
cache.topology().readUnlock();
}
- map(topVer, null);
+ if (futVer != null)
+ map(topVer, futVer, remapKeys);
}
/**
@@ -602,15 +600,18 @@ public class GridNearAtomicUpdateFuture extends GridNearAtomicAbstractUpdateFutu
}
/** {@inheritDoc} */
- protected void map(AffinityTopologyVersion topVer) {
- map(topVer, null);
+ @Override protected void map(AffinityTopologyVersion topVer, GridCacheVersion futVer) {
+ map(topVer, futVer, null);
}
/**
* @param topVer Topology version.
+ * @param futVer Future ID.
* @param remapKeys Keys to remap.
*/
- void map(AffinityTopologyVersion topVer, @Nullable Collection<KeyCacheObject> remapKeys) {
+ void map(AffinityTopologyVersion topVer,
+ GridCacheVersion futVer,
+ @Nullable Collection<KeyCacheObject> remapKeys) {
Collection<ClusterNode> topNodes = CU.affinityNodes(cctx, topVer);
if (F.isEmpty(topNodes)) {
@@ -620,14 +621,6 @@ public class GridNearAtomicUpdateFuture extends GridNearAtomicAbstractUpdateFutu
return;
}
- Exception err = null;
- GridNearAtomicUpdateRequest singleReq0 = null;
- Map<UUID, GridNearAtomicUpdateRequest> mappings0 = null;
-
- int size = keys.size();
-
- GridCacheVersion futVer = cctx.versions().next(topVer);
-
GridCacheVersion updVer;
// Assign version on near node in CLOCK ordering mode even if fastMap is false.
@@ -644,6 +637,12 @@ public class GridNearAtomicUpdateFuture extends GridNearAtomicAbstractUpdateFutu
else
updVer = null;
+ Exception err = null;
+ GridNearAtomicUpdateRequest singleReq0 = null;
+ Map<UUID, GridNearAtomicUpdateRequest> mappings0 = null;
+
+ int size = keys.size();
+
try {
if (size == 1 && !fastMap) {
assert remapKeys == null || remapKeys.size() == 1;
@@ -676,12 +675,10 @@ public class GridNearAtomicUpdateFuture extends GridNearAtomicAbstractUpdateFutu
}
synchronized (mux) {
- assert this.futVer == null : this;
- assert this.topVer == AffinityTopologyVersion.ZERO : this;
+ assert this.futVer == futVer || (this.isDone() && this.error() != null);
+ assert this.topVer == topVer;
- this.topVer = topVer;
this.updVer = updVer;
- this.futVer = futVer;
resCnt = 0;
@@ -701,14 +698,6 @@ public class GridNearAtomicUpdateFuture extends GridNearAtomicAbstractUpdateFutu
return;
}
- if (storeFuture()) {
- if (!cctx.mvcc().addAtomicFuture(futVer, this)) {
- assert isDone() : this;
-
- return;
- }
- }
-
// Optimize mapping for single key.
if (singleReq0 != null)
mapSingle(singleReq0.nodeId(), singleReq0);
@@ -725,7 +714,7 @@ public class GridNearAtomicUpdateFuture extends GridNearAtomicAbstractUpdateFutu
/**
* @return Future version.
*/
- GridCacheVersion onFutureDone() {
+ private GridCacheVersion onFutureDone() {
GridCacheVersion ver0;
GridFutureAdapter<Void> fut0;
http://git-wip-us.apache.org/repos/asf/ignite/blob/7035e5ee/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/AtomicPutAllChangingTopologyTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/AtomicPutAllChangingTopologyTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/AtomicPutAllChangingTopologyTest.java
new file mode 100644
index 0000000..878cb17
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/AtomicPutAllChangingTopologyTest.java
@@ -0,0 +1,212 @@
+/*
+ * 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.atomic;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.CountDownLatch;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.cache.affinity.fair.FairAffinityFunction;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheMode.REPLICATED;
+import static org.apache.ignite.cache.CachePeekMode.BACKUP;
+import static org.apache.ignite.cache.CachePeekMode.PRIMARY;
+import static org.apache.ignite.cache.CacheRebalanceMode.SYNC;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+
+/** */
+public class AtomicPutAllChangingTopologyTest extends GridCommonAbstractTest {
+ /** */
+ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+ /** */
+ private static final int NODES_CNT = 3;
+
+ /** */
+ public static final String CACHE_NAME = "test-cache";
+
+ /** */
+ private static final int CACHE_SIZE = 20_000;
+
+ /** */
+ private static volatile CountDownLatch FILLED_LATCH;
+
+ /**
+ * @return Cache configuration.
+ */
+ private CacheConfiguration<Integer, Integer> cacheConfig() {
+ return new CacheConfiguration<Integer, Integer>()
+ .setAtomicityMode(ATOMIC)
+ .setCacheMode(REPLICATED)
+ .setAffinity(new FairAffinityFunction(false, 1))
+ .setWriteSynchronizationMode(FULL_SYNC)
+ .setRebalanceMode(SYNC)
+ .setName(CACHE_NAME);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(IP_FINDER);
+
+ return cfg;
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testPutAllOnChangingTopology() throws Exception {
+ List<IgniteInternalFuture> futs = new LinkedList<>();
+
+ for (int i = 1; i < NODES_CNT; i++)
+ futs.add(startNodeAsync(i));
+
+ futs.add(startSeedNodeAsync());
+
+ boolean failed = false;
+
+ for (IgniteInternalFuture fut : futs) {
+ try {
+ fut.get();
+ }
+ catch (Throwable th) {
+ log.error("Check failed.", th);
+
+ failed = true;
+ }
+ }
+
+ if (failed)
+ throw new RuntimeException("Test Failed.");
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ FILLED_LATCH = new CountDownLatch(1);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ super.afterTest();
+
+ stopAllGrids();
+ }
+
+ /**
+ * @return Future.
+ * @throws IgniteCheckedException If failed.
+ */
+ private IgniteInternalFuture startSeedNodeAsync() throws IgniteCheckedException {
+ return GridTestUtils.runAsync(new Callable<Object>() {
+ @Override public Boolean call() throws Exception {
+ Ignite node = startGrid(0);
+
+ log.info("Creating cache.");
+
+ IgniteCache<Integer, Integer> cache = node.getOrCreateCache(cacheConfig());
+
+ log.info("Created cache.");
+
+ Map<Integer, Integer> data = new HashMap<>(CACHE_SIZE);
+
+ for (int i = 0; i < CACHE_SIZE; i++)
+ data.put(i, i);
+
+ log.info("Filling.");
+
+ cache.putAll(data);
+
+ log.info("Filled.");
+
+ FILLED_LATCH.countDown();
+
+ checkCacheState(node, cache);
+
+ return true;
+ }
+ });
+ }
+
+ /**
+ * @param nodeId Node index.
+ * @return Future.
+ * @throws IgniteCheckedException If failed.
+ */
+ private IgniteInternalFuture startNodeAsync(final int nodeId) throws IgniteCheckedException {
+ return GridTestUtils.runAsync(new Callable<Object>() {
+ @Override public Boolean call() throws Exception {
+ Ignite node = startGrid(nodeId);
+
+ log.info("Getting cache.");
+
+ IgniteCache<Integer, Integer> cache = node.getOrCreateCache(cacheConfig());
+
+ log.info("Got cache.");
+
+ FILLED_LATCH.await();
+
+ log.info("Got Filled.");
+
+ cache.put(1, nodeId);
+
+ checkCacheState(node, cache);
+
+ return true;
+ }
+ });
+ }
+
+ /**
+ * @param node Node.
+ * @param cache Cache.
+ * @throws Exception If failed.
+ */
+ private void checkCacheState(Ignite node, IgniteCache<Integer, Integer> cache) throws Exception {
+ int locSize = cache.localSize(PRIMARY, BACKUP);
+ int locSize2 = -1;
+
+ if (locSize != CACHE_SIZE) {
+ U.sleep(5000);
+
+ // Rechecking.
+ locSize2 = cache.localSize(PRIMARY, BACKUP);
+ }
+
+ assertEquals("Wrong cache size on node [node=" + node.configuration().getGridName() +
+ ", expected= " + CACHE_SIZE +
+ ", actual=" + locSize +
+ ", actual2=" + locSize2 + "]",
+ locSize, CACHE_SIZE);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/7035e5ee/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheFailoverTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheFailoverTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheFailoverTestSuite.java
index c9e507d..5bc6729 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheFailoverTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheFailoverTestSuite.java
@@ -33,6 +33,7 @@ import org.apache.ignite.internal.processors.cache.distributed.dht.GridCacheDhtR
import org.apache.ignite.internal.processors.cache.distributed.dht.GridCacheTxNodeFailureSelfTest;
import org.apache.ignite.internal.processors.cache.distributed.dht.GridNearCacheTxNodeFailureSelfTest;
import org.apache.ignite.internal.processors.cache.distributed.dht.IgniteAtomicLongChangingTopologySelfTest;
+import org.apache.ignite.internal.processors.cache.distributed.dht.atomic.AtomicPutAllChangingTopologyTest;
import org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridCacheAtomicClientInvalidPartitionHandlingSelfTest;
import org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridCacheAtomicClientRemoveFailureTest;
import org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridCacheAtomicInvalidPartitionHandlingSelfTest;
@@ -95,6 +96,8 @@ public class IgniteCacheFailoverTestSuite extends TestSuite {
suite.addTestSuite(GridCacheTxNodeFailureSelfTest.class);
suite.addTestSuite(GridNearCacheTxNodeFailureSelfTest.class);
+ suite.addTestSuite(AtomicPutAllChangingTopologyTest.class);
+
return suite;
}
}