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/03/10 09:21:32 UTC
[ignite] branch master updated: IGNITE-16662 Fix NPE in PersistenceTask
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 95ad019 IGNITE-16662 Fix NPE in PersistenceTask
95ad019 is described below
commit 95ad019446f4de6021b23c2ca00c843d1c94eaee
Author: Semyon Danilov <sa...@yandex.ru>
AuthorDate: Tue Feb 15 12:23:45 2022 +0300
IGNITE-16662 Fix NPE in PersistenceTask
---
.../processors/cache/CacheGroupContext.java | 2 +-
.../visor/persistence/PersistenceTask.java | 9 +-
.../MaintenancePersistenceTaskTest.java | 178 +++++++++++++++++++++
.../ignite/testsuites/IgnitePdsTestSuite8.java | 2 +
4 files changed, 188 insertions(+), 3 deletions(-)
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupContext.java
index 9cbd8b0..ddb7931 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupContext.java
@@ -1267,7 +1267,7 @@ public class CacheGroupContext {
}
/**
- * @param enabled Enabled flag..
+ * @param enabled Enabled flag.
*/
private void persistGlobalWalState(boolean enabled) {
shared().database().walEnabled(grpId, enabled, false);
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/persistence/PersistenceTask.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/persistence/PersistenceTask.java
index 3ae84ba..8e3b941 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/persistence/PersistenceTask.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/persistence/PersistenceTask.java
@@ -330,8 +330,13 @@ public class PersistenceTask extends VisorOneNodeTask<PersistenceTaskArg, Persis
GridCacheProcessor cacheProc = ignite.context().cache();
DataStorageConfiguration dsCfg = ignite.context().config().getDataStorageConfiguration();
- List<String> corruptedCacheNames = corruptedCacheDirectories(ignite.context().maintenanceRegistry()
- .activeMaintenanceTask(CORRUPTED_DATA_FILES_MNTC_TASK_NAME));
+ MaintenanceTask task = ignite.context().maintenanceRegistry()
+ .activeMaintenanceTask(CORRUPTED_DATA_FILES_MNTC_TASK_NAME);
+
+ if (task == null)
+ return res;
+
+ List<String> corruptedCacheNames = corruptedCacheDirectories(task);
Map<String, IgniteBiTuple<Boolean, Boolean>> cachesInfo = new HashMap<>();
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/MaintenancePersistenceTaskTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/MaintenancePersistenceTaskTest.java
new file mode 100644
index 0000000..d1b962a
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/MaintenancePersistenceTaskTest.java
@@ -0,0 +1,178 @@
+/*
+ * 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.Ignition;
+import org.apache.ignite.client.Config;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.ClientConfiguration;
+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.visor.VisorTaskArgument;
+import org.apache.ignite.internal.visor.persistence.PersistenceCleanAndBackupSettings;
+import org.apache.ignite.internal.visor.persistence.PersistenceCleanAndBackupType;
+import org.apache.ignite.internal.visor.persistence.PersistenceOperation;
+import org.apache.ignite.internal.visor.persistence.PersistenceTask;
+import org.apache.ignite.internal.visor.persistence.PersistenceTaskArg;
+import org.apache.ignite.internal.visor.persistence.PersistenceTaskResult;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+import static java.util.Collections.singletonList;
+
+/**
+ * Tests for maintenance persistence task.
+ */
+public class MaintenancePersistenceTaskTest extends GridCommonAbstractTest {
+ /** Test cache name. */
+ private static final String CACHE_NAME = "test-cache";
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+ cfg.setDataStorageConfiguration(
+ new DataStorageConfiguration()
+ .setDefaultDataRegionConfiguration(
+ new DataRegionConfiguration()
+ .setMaxSize(10 * 1024 * 1024)
+ .setPersistenceEnabled(true)
+ )
+
+ );
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ super.beforeTest();
+
+ stopAllGrids();
+
+ cleanPersistenceDir();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ super.afterTest();
+
+ stopAllGrids();
+
+ cleanPersistenceDir();
+ }
+
+ /**
+ * Tests that executing "persistence --info" after "persistence --clean" works.
+ *
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testInfoAfterClean() throws Exception {
+ IgniteEx server1 = startGrid("test1");
+
+ server1.cluster().state(ClusterState.ACTIVE);
+
+ server1.getOrCreateCache(CACHE_NAME);
+
+ // Disable WAL for the cache
+ try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER))) {
+ assertTrue(client.cluster().isWalEnabled(CACHE_NAME));
+
+ client.cluster().disableWal(CACHE_NAME);
+
+ assertFalse(client.cluster().isWalEnabled(CACHE_NAME));
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ server1.close();
+
+ try {
+ server1 = startGrid("test1");
+ fail();
+ }
+ catch (Exception ignored) {
+ // It's ok, we should not be able to start with WAL disabled for a system cache.
+ // We will start in the maintenance mode.
+ }
+
+ server1.close();
+
+ // Starts in maintenance
+ server1 = startGrid("test1");
+
+ assertTrue(server1.context().maintenanceRegistry().isMaintenanceMode());
+
+ PersistenceTaskResult infoResultBeforeClean = executeInfo(server1);
+ assertNotNull(infoResultBeforeClean);
+
+ PersistenceTaskResult cleanResult = executeClean(server1);
+ assertNotNull(cleanResult);
+
+ PersistenceTaskResult infoResultAfterClean = executeInfo(server1);
+ assertNotNull(infoResultAfterClean);
+
+ server1.close();
+
+ // Restart node again, it should start normally
+ server1 = startGrid("test1");
+
+ assertFalse(server1.context().maintenanceRegistry().isMaintenanceMode());
+ }
+
+ /**
+ * Executes "--persistence info".
+ *
+ * @param node Ignite node.
+ * @return Execution's result.
+ */
+ private PersistenceTaskResult executeInfo(IgniteEx node) {
+ VisorTaskArgument<PersistenceTaskArg> infoArgument = new VisorTaskArgument<>(
+ node.localNode().id(),
+ new PersistenceTaskArg(PersistenceOperation.INFO, null),
+ false
+ );
+
+ return node.compute().execute(new PersistenceTask(), infoArgument);
+ }
+
+ /**
+ * Executes "--persistence clean".
+ *
+ * @param node Ignite node.
+ * @return Execution's result.
+ */
+ private PersistenceTaskResult executeClean(IgniteEx node) {
+ PersistenceCleanAndBackupSettings settings = new PersistenceCleanAndBackupSettings(
+ PersistenceCleanAndBackupType.CORRUPTED,
+ singletonList(CACHE_NAME)
+ );
+
+ VisorTaskArgument<PersistenceTaskArg> cleanArgument = new VisorTaskArgument<>(
+ node.localNode().id(),
+ new PersistenceTaskArg(PersistenceOperation.CLEAN, settings),
+ false
+ );
+
+ return node.compute().execute(new PersistenceTask(), cleanArgument);
+ }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite8.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite8.java
index 20b0216..b9438d1 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite8.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite8.java
@@ -28,6 +28,7 @@ import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsDefragme
import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsDefragmentationRandomLruEvictionTest;
import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsDefragmentationTest;
import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsRecoveryAfterFileCorruptionTest;
+import org.apache.ignite.internal.processors.cache.persistence.MaintenancePersistenceTaskTest;
import org.apache.ignite.internal.processors.cache.persistence.NoUnnecessaryRebalanceTest;
import org.apache.ignite.internal.processors.cache.persistence.PagesPossibleCorruptionDiagnosticTest;
import org.apache.ignite.internal.processors.cache.persistence.PendingTreeCorruptionTest;
@@ -100,6 +101,7 @@ public class IgnitePdsTestSuite8 {
GridTestUtils.addTestIfNeeded(suite, PendingTreeCorruptionTest.class, ignoredTests);
GridTestUtils.addTestIfNeeded(suite, PagesPossibleCorruptionDiagnosticTest.class, ignoredTests);
+ GridTestUtils.addTestIfNeeded(suite, MaintenancePersistenceTaskTest.class, ignoredTests);
return suite;
}