You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sd...@apache.org on 2022/05/18 07:42:32 UTC
[ignite] branch master updated: IGNITE-16986 Fix incorrect params of GridCacheManager stop method (#10025)
This is an automated email from the ASF dual-hosted git repository.
sdanilov 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 be45101ea7e IGNITE-16986 Fix incorrect params of GridCacheManager stop method (#10025)
be45101ea7e is described below
commit be45101ea7e59b0538eaa468e93a734a13e8cbb9
Author: Semyon Danilov <sa...@yandex.ru>
AuthorDate: Wed May 18 11:42:24 2022 +0400
IGNITE-16986 Fix incorrect params of GridCacheManager stop method (#10025)
---
.../processors/cache/ClusterCachesInfo.java | 9 ---
.../processors/cache/GridCacheProcessor.java | 74 +++++++++++++---------
.../processors/query/GridQueryIndexing.java | 3 +-
.../processors/query/GridQueryProcessor.java | 14 ++--
.../processors/query/DummyQueryIndexing.java | 2 +-
.../processors/query/h2/IgniteH2Indexing.java | 4 +-
.../processors/query/h2/SchemaManager.java | 5 +-
.../query/stat/StatisticsConfigurationTest.java | 4 --
8 files changed, 60 insertions(+), 55 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 616ad6a0242..29f268478d3 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
@@ -965,15 +965,6 @@ public class ClusterCachesInfo {
exchangeActions.addCacheGroupToStop(grpDesc, req.destroy());
assert exchangeActions.checkStopRequestConsistency(grpDesc.groupId());
-
- // If all caches in group will be destroyed it is not necessary to destroy single cache
- // because group will be stopped anyway.
- if (req.destroy()) {
- for (ExchangeActions.CacheActionData action : exchangeActions.cacheStopRequests()) {
- if (action.descriptor().groupId() == grpDesc.groupId())
- action.request().destroy(false);
- }
- }
}
return true;
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 2930a06594c..25728dcd104 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
@@ -793,12 +793,12 @@ public class GridCacheProcessor extends GridProcessorAdapter {
GridCacheAdapter<?, ?> cache = stoppedCaches.remove(cacheName);
if (cache != null)
- stopCache(cache, cancel, false);
+ stopCache(cache, cancel, false, false);
}
for (GridCacheAdapter<?, ?> cache : stoppedCaches.values()) {
if (cache == stoppedCaches.remove(cache.name()))
- stopCache(cache, cancel, false);
+ stopCache(cache, cancel, false, false);
}
for (CacheGroupContext grp : cacheGrps.values())
@@ -1001,7 +1001,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
// Re-create cache structures inside indexing in order to apply recent schema changes.
GridCacheContextInfo cacheInfo = new GridCacheContextInfo(cache.context(), false);
- ctx.query().onCacheStop0(cacheInfo, rmvIdx);
+ ctx.query().onCacheStop0(cacheInfo, rmvIdx, rmvIdx);
ctx.query().onCacheStart0(cacheInfo, desc.schema(), desc.sql());
}
}
@@ -1030,20 +1030,22 @@ public class GridCacheProcessor extends GridProcessorAdapter {
/**
* @param cache Cache to stop.
* @param cancel Cancel flag.
- * @param destroy Destroy data flag. Setting to <code>true</code> will remove all cache data.
+ * @param callDestroy Cache destroy flag. This flag is passed to the {@link GridCacheManager#stop} method.
+ * @param clearCache Cache data clear flag. Setting to {@code true} will remove all cache data.
*/
- private void stopCache(GridCacheAdapter<?, ?> cache, boolean cancel, boolean destroy) {
- stopCache(cache, cancel, destroy, true);
+ private void stopCache(GridCacheAdapter<?, ?> cache, boolean cancel, boolean callDestroy, boolean clearCache) {
+ stopCache(cache, cancel, callDestroy, clearCache, true);
}
/**
* @param cache Cache to stop.
* @param cancel Cancel flag.
- * @param destroy Destroy data flag. Setting to <code>true</code> will remove all cache data.
+ * @param callDestroy Cache destroy flag. This flag is passed to the {@link GridCacheManager#stop} method.
+ * @param clearCache Cache data clear flag. Setting to {@code true} will remove all cache data.
* @param clearDbObjects If {@code false} DB objects don't removed (used for cache.close() on client node).
*/
@SuppressWarnings({"unchecked"})
- private void stopCache(GridCacheAdapter<?, ?> cache, boolean cancel, boolean destroy, boolean clearDbObjects) {
+ private void stopCache(GridCacheAdapter<?, ?> cache, boolean cancel, boolean callDestroy, boolean clearCache, boolean clearDbObjects) {
GridCacheContext ctx = cache.context();
try {
@@ -1061,14 +1063,17 @@ public class GridCacheProcessor extends GridProcessorAdapter {
cache.stop();
- cache.removeMetrics(destroy);
+ cache.removeMetrics(callDestroy);
GridCacheContextInfo cacheInfo = new GridCacheContextInfo(ctx, false);
- if (!clearDbObjects)
- ctx.kernalContext().query().getIndexing().closeCacheOnClient(ctx.name());
+ if (clearDbObjects) {
+ boolean rmvIdx = !cache.context().group().persistenceEnabled() || callDestroy;
+ boolean clearIdx = !cache.context().group().persistenceEnabled() || clearCache;
+ ctx.kernalContext().query().onCacheStop(cacheInfo, rmvIdx, clearIdx);
+ }
else
- ctx.kernalContext().query().onCacheStop(cacheInfo, !cache.context().group().persistenceEnabled() || destroy);
+ ctx.kernalContext().query().getIndexing().closeCacheOnClient(ctx.name());
if (isNearEnabled(ctx)) {
GridDhtCacheAdapter dht = ctx.near().dht();
@@ -1077,7 +1082,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
if (dht != null) {
dht.stop();
- dht.removeMetrics(destroy);
+ dht.removeMetrics(callDestroy);
GridCacheContext<?, ?> dhtCtx = dht.context();
@@ -1086,7 +1091,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
for (ListIterator<GridCacheManager> it = dhtMgrs.listIterator(dhtMgrs.size()); it.hasPrevious(); ) {
GridCacheManager mgr = it.previous();
- mgr.stop(cancel, destroy);
+ mgr.stop(cancel, callDestroy);
}
}
}
@@ -1100,22 +1105,22 @@ public class GridCacheProcessor extends GridProcessorAdapter {
GridCacheManager mgr = it.previous();
if (!excludes.contains(mgr))
- mgr.stop(cancel, destroy);
+ mgr.stop(cancel, callDestroy);
}
ctx.kernalContext().continuous().onCacheStop(ctx);
- ctx.kernalContext().cache().context().snapshot().onCacheStop(ctx, destroy);
+ ctx.kernalContext().cache().context().snapshot().onCacheStop(ctx, callDestroy);
ctx.kernalContext().coordinators().onCacheStop(ctx);
- ctx.group().stopCache(ctx, destroy);
+ ctx.group().stopCache(ctx, clearCache);
U.stopLifecycleAware(log, lifecycleAwares(ctx.group(), cache.configuration(), ctx.store().configuredStore()));
IgnitePageStoreManager pageStore;
- if (destroy && (pageStore = sharedCtx.pageStore()) != null) {
+ if (callDestroy && (pageStore = sharedCtx.pageStore()) != null) {
try {
locCfgMgr.removeCacheData(new StoredCacheData(ctx.config()));
}
@@ -2096,7 +2101,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
sharedCtx.database().checkpointReadLock();
try {
- prepareCacheStop(cctx.name(), false, clearDbObjects);
+ prepareCacheStop(cctx.name(), false, false, clearDbObjects);
if (!cctx.group().hasCaches())
stopCacheGroup(cctx.group().groupId(), false);
@@ -2651,18 +2656,20 @@ public class GridCacheProcessor extends GridProcessorAdapter {
/**
* @param cacheName Cache name.
- * @param destroy Cache data destroy flag. Setting to <code>true</code> will remove all cache data.
+ * @param callDestroy Cache destroy flag. This flag is passed to the {@link GridCacheManager#stop} method.
+ * @param clearCache Cache data clear flag. Setting to {@code true} will remove all cache data.
*/
- public void prepareCacheStop(String cacheName, boolean destroy) {
- prepareCacheStop(cacheName, destroy, true);
+ public void prepareCacheStop(String cacheName, boolean callDestroy, boolean clearCache) {
+ prepareCacheStop(cacheName, callDestroy, clearCache, true);
}
/**
* @param cacheName Cache name.
- * @param destroy Cache data destroy flag. Setting to <code>true</code> will remove all cache data.
+ * @param callDestroy Cache destroy flag. This flag is passed to the {@link GridCacheManager#stop} method.
+ * @param clearCache Cache data clear flag. Setting to {@code true} will remove all cache data.
* @param clearDbObjects If {@code false} DB objects don't removed (used for cache.close() on client node).
*/
- public void prepareCacheStop(String cacheName, boolean destroy, boolean clearDbObjects) {
+ public void prepareCacheStop(String cacheName, boolean callDestroy, boolean clearCache, boolean clearDbObjects) {
assert sharedCtx.database().checkpointLockIsHeldByThread();
GridCacheAdapter<?, ?> cache = caches.remove(cacheName);
@@ -2674,7 +2681,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
onKernalStop(cache, true);
- stopCache(cache, true, destroy, clearDbObjects);
+ stopCache(cache, true, callDestroy, clearCache, clearDbObjects);
}
else
// Try to unregister query structures for not started caches.
@@ -2825,7 +2832,9 @@ public class GridCacheProcessor extends GridProcessorAdapter {
sharedCtx.kernalContext().pools().getSystemExecutorService(),
cachesToStop.entrySet(),
cachesToStopByGrp -> {
- CacheGroupContext gctx = cacheGrps.get(cachesToStopByGrp.getKey());
+ Integer groupId = cachesToStopByGrp.getKey();
+
+ CacheGroupContext gctx = cacheGrps.get(groupId);
if (gctx != null)
gctx.preloader().pause();
@@ -2856,11 +2865,16 @@ public class GridCacheProcessor extends GridProcessorAdapter {
sharedCtx.database().checkpointReadLock();
try {
- boolean destroyCache = action.request().destroy();
+ boolean callDestroy = action.request().destroy();
+
+ // If all caches in group will be destroyed it is not necessary to clear a single cache
+ // because group will be stopped anyway.
+ // Stop will still be called with destroy {@code true}, but cache will not be cleared.
+ boolean clearCache = callDestroy && !grpIdToDestroy.contains(groupId);
- prepareCacheStop(cacheName, destroyCache);
+ prepareCacheStop(cacheName, callDestroy, clearCache);
- if (destroyCache || grpIdToDestroy.contains(cachesToStopByGrp.getKey()))
+ if (callDestroy || grpIdToDestroy.contains(groupId))
ctx.query().completeRebuildIndexes(cacheName);
}
finally {
@@ -3315,7 +3329,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
CacheGroupContext grp = cache.context().group();
onKernalStop(cache, true);
- stopCache(cache, true, false);
+ stopCache(cache, true, false, false);
sharedCtx.affinity().stopCacheOnReconnect(cache.context());
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
index 64f09934139..d1ed5611fb1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
@@ -208,9 +208,10 @@ public interface GridQueryIndexing {
*
* @param cacheInfo Cache context info.
* @param rmvIdx If {@code true}, will remove index.
+ * @param clearIdx If {@code true}, will clear the index.
* @throws IgniteCheckedException If failed to drop cache schema.
*/
- public void unregisterCache(GridCacheContextInfo cacheInfo, boolean rmvIdx) throws IgniteCheckedException;
+ public void unregisterCache(GridCacheContextInfo cacheInfo, boolean rmvIdx, boolean clearIdx) throws IgniteCheckedException;
/**
*
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
index a4a2431b319..708815451e3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
@@ -1222,14 +1222,15 @@ public class GridQueryProcessor extends GridProcessorAdapter {
GridCacheContextInfo cacheInfo = idx.registeredCacheInfo(cacheName);
if (cacheInfo != null)
- onCacheStop(cacheInfo, true);
+ onCacheStop(cacheInfo, true, true);
}
/**
* @param cacheInfo Cache context info.
* @param removeIdx If {@code true}, will remove index.
+ * @param clearIdx If {@code true}, will clear the index.
*/
- public void onCacheStop(GridCacheContextInfo cacheInfo, boolean removeIdx) {
+ public void onCacheStop(GridCacheContextInfo cacheInfo, boolean removeIdx, boolean clearIdx) {
if (idx == null)
return;
@@ -1237,7 +1238,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
return;
try {
- onCacheStop0(cacheInfo, removeIdx);
+ onCacheStop0(cacheInfo, removeIdx, clearIdx);
}
finally {
busyLock.leaveBusy();
@@ -2294,7 +2295,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
cacheNames.add(CU.mask(cacheName));
}
catch (IgniteCheckedException | RuntimeException e) {
- onCacheStop0(cacheInfo, true);
+ onCacheStop0(cacheInfo, true, true);
throw e;
}
@@ -2307,8 +2308,9 @@ public class GridQueryProcessor extends GridProcessorAdapter {
*
* @param cacheInfo Cache context info.
* @param destroy Destroy flag.
+ * @param clearIdx Clear flag.
*/
- public void onCacheStop0(GridCacheContextInfo cacheInfo, boolean destroy) {
+ public void onCacheStop0(GridCacheContextInfo cacheInfo, boolean destroy, boolean clearIdx) {
if (idx == null || !cacheNames.contains(cacheInfo.name()))
return;
@@ -2348,7 +2350,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
// Notify indexing.
try {
- idx.unregisterCache(cacheInfo, destroy);
+ idx.unregisterCache(cacheInfo, destroy, clearIdx);
}
catch (Exception e) {
U.error(log, "Failed to clear indexing on cache unregister (will ignore): " + cacheName, e);
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/query/DummyQueryIndexing.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/query/DummyQueryIndexing.java
index 08e7ff25111..a65dc135de7 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/query/DummyQueryIndexing.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/query/DummyQueryIndexing.java
@@ -165,7 +165,7 @@ public class DummyQueryIndexing implements GridQueryIndexing {
}
/** {@inheritDoc} */
- @Override public void unregisterCache(GridCacheContextInfo cacheInfo, boolean rmvIdx) throws IgniteCheckedException {
+ @Override public void unregisterCache(GridCacheContextInfo cacheInfo, boolean rmvIdx, boolean clearIdx) throws IgniteCheckedException {
}
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
index f3679f277d5..d32beccbf80 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
@@ -2429,7 +2429,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
}
/** {@inheritDoc} */
- @Override public void unregisterCache(GridCacheContextInfo cacheInfo, boolean rmvIdx) {
+ @Override public void unregisterCache(GridCacheContextInfo cacheInfo, boolean rmvIdx, boolean clearIdx) {
ctx.indexProcessor().unregisterCache(cacheInfo);
String cacheName = cacheInfo.name();
@@ -2437,7 +2437,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
partReservationMgr.onCacheStop(cacheName);
// Drop schema (needs to be called after callback to DML processor because the latter depends on schema).
- schemaMgr.onCacheDestroyed(cacheName, rmvIdx);
+ schemaMgr.onCacheDestroyed(cacheName, rmvIdx, clearIdx);
// Unregister connection.
connMgr.onCacheDestroyed();
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/SchemaManager.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/SchemaManager.java
index 55eb31b1a5f..77f2a28b953 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/SchemaManager.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/SchemaManager.java
@@ -346,8 +346,9 @@ public class SchemaManager implements GridQuerySchemaManager {
*
* @param cacheName Cache name.
* @param rmvIdx Whether to remove indexes.
+ * @param clearIdx Whether to clear the index.
*/
- public void onCacheDestroyed(String cacheName, boolean rmvIdx) {
+ public void onCacheDestroyed(String cacheName, boolean rmvIdx, boolean clearIdx) {
String schemaName = schemaName(cacheName);
H2Schema schema = schemas.get(schemaName);
@@ -361,7 +362,7 @@ public class SchemaManager implements GridQuerySchemaManager {
for (H2TableDescriptor tbl : schema.tables()) {
if (F.eq(tbl.cacheName(), cacheName)) {
try {
- tbl.table().setRemoveIndexOnDestroy(rmvIdx);
+ tbl.table().setRemoveIndexOnDestroy(clearIdx);
dropTable(tbl, rmvIdx);
lsnr.onSqlTypeDropped(schemaName, tbl.type());
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/stat/StatisticsConfigurationTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/stat/StatisticsConfigurationTest.java
index e3979297167..b032482fd72 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/stat/StatisticsConfigurationTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/stat/StatisticsConfigurationTest.java
@@ -417,10 +417,6 @@ public class StatisticsConfigurationTest extends StatisticsAbstractTest {
dropSmallTable(null);
- // TODO: remove after fix IGNITE-14814
- if (persist)
- statisticsMgr(0).dropStatistics(SMALL_TARGET);
-
waitForStats(SCHEMA, "SMALL", TIMEOUT, (stats) -> stats.forEach(s -> assertNull(s)));
waitForStats(SCHEMA, "SMALL_A", TIMEOUT, checkTotalRows, checkColumStats);