You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by jo...@apache.org on 2019/04/18 15:49:50 UTC
[ignite] branch master updated: IGNITE-11743 Keep cache descriptor
available until cache is stopped - Fixes #6470.
This is an automated email from the ASF dual-hosted git repository.
jokser 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 ee7f56f IGNITE-11743 Keep cache descriptor available until cache is stopped - Fixes #6470.
ee7f56f is described below
commit ee7f56f042a1cd62752075b7573ab9ae32c2644c
Author: Pavel Kovalenko <jo...@gmail.com>
AuthorDate: Thu Apr 18 18:49:30 2019 +0300
IGNITE-11743 Keep cache descriptor available until cache is stopped - Fixes #6470.
Signed-off-by: Pavel Kovalenko <jo...@gmail.com>
---
.../processors/cache/ClusterCachesInfo.java | 52 +++++++++++-
.../processors/cache/GridCacheProcessor.java | 20 +++++
.../persistence/file/FilePageStoreManager.java | 2 +-
.../IgnitePdsNodeJoinWithCachesStopping.java | 93 ++++++++++++++++++++++
.../ignite/testsuites/IgnitePdsTestSuite3.java | 2 +
5 files changed, 165 insertions(+), 4 deletions(-)
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java
index fbd650d..72ac6be 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java
@@ -90,6 +90,18 @@ class ClusterCachesInfo {
/** */
private final GridKernalContext ctx;
+ /**
+ * Map contains cache descriptors that were removed from {@link #registeredCaches} due to cache stop request.
+ * Such descriptors will be removed from the map only after whole cache stop process is finished.
+ */
+ private final ConcurrentMap<String, DynamicCacheDescriptor> markedForDeletionCaches = new ConcurrentHashMap<>();
+
+ /**
+ * Map contains cache group descriptors that were removed from {@link #registeredCacheGrps} due to cache stop request.
+ * Such descriptors will be removed from the map only after whole cache stop process is finished.
+ */
+ private final ConcurrentMap<Integer, CacheGroupDescriptor> markedForDeletionCacheGrps = new ConcurrentHashMap<>();
+
/** Dynamic caches. */
private final ConcurrentMap<String, DynamicCacheDescriptor> registeredCaches = new ConcurrentHashMap<>();
@@ -740,7 +752,13 @@ class ClusterCachesInfo {
String cacheName,
DynamicCacheDescriptor desc
) {
- DynamicCacheDescriptor old = registeredCaches.remove(cacheName);
+ DynamicCacheDescriptor old = registeredCaches.get(cacheName);
+
+ assert old != null && old == desc : "Dynamic cache map was concurrently modified [req=" + req + ']';
+
+ markedForDeletionCaches.put(cacheName, old);
+
+ registeredCaches.remove(cacheName);
if (req.restart()) {
IgniteUuid restartId = req.restartId();
@@ -748,8 +766,6 @@ class ClusterCachesInfo {
restartingCaches.put(cacheName, restartId == null ? NULL_OBJECT : restartId);
}
- assert old != null && old == desc : "Dynamic cache map was concurrently modified [req=" + req + ']';
-
ctx.discovery().removeCacheFilter(cacheName);
exchangeActions.addCacheToStop(req, desc);
@@ -761,6 +777,8 @@ class ClusterCachesInfo {
grpDesc.onCacheStopped(desc.cacheName(), desc.cacheId());
if (!grpDesc.hasCaches()) {
+ markedForDeletionCacheGrps.put(grpDesc.groupId(), grpDesc);
+
registeredCacheGrps.remove(grpDesc.groupId());
ctx.discovery().removeCacheGroup(grpDesc);
@@ -1495,6 +1513,34 @@ class ClusterCachesInfo {
}
/**
+ * @param cacheName Cache name.
+ */
+ public void cleanupRemovedCache(String cacheName) {
+ markedForDeletionCaches.remove(cacheName);
+ }
+
+ /**
+ * @param grpId Group ID.
+ */
+ public void cleanupRemovedGroup(int grpId) {
+ markedForDeletionCacheGrps.remove(grpId);
+ }
+
+ /**
+ * @param cacheName Cache name.
+ */
+ public @Nullable DynamicCacheDescriptor markedForDeletionCacheDesc(String cacheName) {
+ return markedForDeletionCaches.get(cacheName);
+ }
+
+ /**
+ * @param grpId Group id.
+ */
+ public @Nullable CacheGroupDescriptor markedForDeletionCacheGroupDesc(int grpId) {
+ return markedForDeletionCacheGrps.get(grpId);
+ }
+
+ /**
* Save dynamic cache descriptor on disk.
*
* @param desc Cache to save.
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
index a91ef54..bd1a3e9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
@@ -758,6 +758,8 @@ public class GridCacheProcessor extends GridProcessorAdapter {
}
cctx.cleanup();
+
+ cachesInfo.cleanupRemovedCache(cctx.name());
}
/**
@@ -778,6 +780,8 @@ public class GridCacheProcessor extends GridProcessorAdapter {
U.error(log, "Failed to unregister MBean for cache group: " + grp.name(), e);
}
}
+
+ cachesInfo.cleanupRemovedGroup(grp.groupId());
}
/**
@@ -5092,6 +5096,22 @@ public class GridCacheProcessor extends GridProcessorAdapter {
}
/**
+ * Tries to find cache group descriptor either in registered cache groups
+ * or in marked for deletion collection if cache group is considered to be stopped.
+ *
+ * @param grpId Group id.
+ */
+ public CacheGroupDescriptor cacheGroupDescriptor(int grpId) {
+ CacheGroupDescriptor desc = cacheGroupDescriptors().get(grpId);
+
+ // Try to find descriptor if it was marked for deletion.
+ if (desc == null)
+ return cachesInfo.markedForDeletionCacheGroupDesc(grpId);
+
+ return desc;
+ }
+
+ /**
* @param cacheId Cache ID.
* @return Cache descriptor.
*/
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FilePageStoreManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FilePageStoreManager.java
index 84fb321..3bf4db8 100755
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FilePageStoreManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FilePageStoreManager.java
@@ -1120,7 +1120,7 @@ public class FilePageStoreManager extends GridCacheSharedManagerAdapter implemen
private CacheStoreHolder getHolder(int grpId) throws IgniteCheckedException {
try {
return idxCacheStores.computeIfAbsent(grpId, (key) -> {
- CacheGroupDescriptor gDesc = cctx.cache().cacheGroupDescriptors().get(grpId);
+ CacheGroupDescriptor gDesc = cctx.cache().cacheGroupDescriptor(grpId);
CacheStoreHolder holder0 = null;
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsNodeJoinWithCachesStopping.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsNodeJoinWithCachesStopping.java
new file mode 100644
index 0000000..a2f557a
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsNodeJoinWithCachesStopping.java
@@ -0,0 +1,93 @@
+/*
+ * 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;
+
+import org.apache.ignite.Ignite;
+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.IgniteInternalFuture;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+/**
+ * Test checks correctness of simultaneous node join and massive caches stopping.
+ */
+public class IgnitePdsNodeJoinWithCachesStopping extends GridCommonAbstractTest {
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+ return cfg.setDataStorageConfiguration(new DataStorageConfiguration()
+ .setDefaultDataRegionConfiguration(new DataRegionConfiguration()
+ .setMaxSize(200 * 1024 * 1024)
+ .setPersistenceEnabled(true)));
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ super.beforeTest();
+
+ cleanPersistenceDir();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ stopAllGrids();
+
+ cleanPersistenceDir();
+
+ super.afterTest();
+ }
+
+ /**
+ *
+ */
+ @Test
+ public void test() throws Exception {
+ final Ignite ig = startGridsMultiThreaded(2);
+
+ for (int i = 0; i < 100; i++)
+ ig.createCache(new CacheConfiguration<>("test0" + i).setBackups(0));
+
+ IgniteInternalFuture<Boolean> gridStartFut = GridTestUtils.runAsync(() ->
+ {
+ try {
+ startGrid(2);
+ }
+ catch (Exception e) {
+ return false;
+ }
+
+ return true;
+ }, "new-server-start-thread");
+
+ for (int k = 0; k < 5; k++) {
+ final int l = k;
+ GridTestUtils.runAsync(() -> {
+ for (int m = l * 20; m < (l + 1) * 20; m++)
+ ig.destroyCache("test0" + m);
+
+ }, "cache-destroy-thread");
+ }
+
+ assertTrue(gridStartFut.get());
+ }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite3.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite3.java
index d99cb82..acda43b 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite3.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite3.java
@@ -22,6 +22,7 @@ import java.util.Collection;
import java.util.List;
import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsContinuousRestartTest;
import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsContinuousRestartTestWithExpiryPolicy;
+import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsNodeJoinWithCachesStopping;
import org.apache.ignite.testframework.GridTestUtils;
import org.apache.ignite.testframework.junits.DynamicSuite;
import org.junit.runner.RunWith;
@@ -58,5 +59,6 @@ public class IgnitePdsTestSuite3 {
// Rebalancing test
GridTestUtils.addTestIfNeeded(suite, IgnitePdsContinuousRestartTest.class, ignoredTests);
GridTestUtils.addTestIfNeeded(suite, IgnitePdsContinuousRestartTestWithExpiryPolicy.class, ignoredTests);
+ GridTestUtils.addTestIfNeeded(suite, IgnitePdsNodeJoinWithCachesStopping.class, ignoredTests);
}
}