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

[ignite] branch ignite-2.11 updated: IGNITE-15274: Use workDir instead of storagePath for client nodes (#9319)

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

nizhikov pushed a commit to branch ignite-2.11
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/ignite-2.11 by this push:
     new 76efe50  IGNITE-15274: Use workDir instead of storagePath for client nodes (#9319)
76efe50 is described below

commit 76efe5099502477e46c1c12d5e27a3820a152665
Author: Nikolay <ni...@apache.org>
AuthorDate: Thu Aug 12 16:59:06 2021 +0300

    IGNITE-15274: Use workDir instead of storagePath for client nodes (#9319)
    
    (cherry picked from commit f8a1cc8a642ca8a6a8e3b4f601bd4b335f1528a4)
---
 .../internal/maintenance/MaintenanceFileStore.java | 20 +++---
 .../internal/maintenance/MaintenanceProcessor.java | 24 +++----
 .../persistence/file/FilePageStoreManager.java     |  2 +-
 .../filename/PdsConsistentIdProcessor.java         | 11 ++--
 .../persistence/filename/PdsFolderSettings.java    |  9 +++
 .../cache/persistence/IgnitePdsOnClientTest.java   | 76 ++++++++++++++++++++++
 .../testsuites/IgniteClientNodesTestSuite.java     |  4 +-
 7 files changed, 117 insertions(+), 29 deletions(-)

diff --git a/modules/core/src/main/java/org/apache/ignite/internal/maintenance/MaintenanceFileStore.java b/modules/core/src/main/java/org/apache/ignite/internal/maintenance/MaintenanceFileStore.java
index 4695cbf..b88be2a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/maintenance/MaintenanceFileStore.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/maintenance/MaintenanceFileStore.java
@@ -27,7 +27,6 @@ import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.internal.processors.cache.persistence.file.FileIO;
 import org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory;
-import org.apache.ignite.internal.processors.cache.persistence.filename.PdsFolderSettings;
 import org.apache.ignite.internal.processors.cache.persistence.filename.PdsFoldersResolver;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.maintenance.MaintenanceTask;
@@ -64,7 +63,7 @@ public class MaintenanceFileStore {
     private static final int MAX_MNTC_TASK_PARTS_COUNT = 3;
 
     /** */
-    private final boolean inMemoryMode;
+    private final boolean disabled;
 
     /** */
     private final PdsFoldersResolver pdsFoldersResolver;
@@ -85,11 +84,11 @@ public class MaintenanceFileStore {
     private final IgniteLogger log;
 
     /** */
-    public MaintenanceFileStore(boolean inMemoryMode,
+    public MaintenanceFileStore(boolean disabled,
                                 PdsFoldersResolver pdsFoldersResolver,
                                 FileIOFactory ioFactory,
                                 IgniteLogger log) {
-        this.inMemoryMode = inMemoryMode;
+        this.disabled = disabled;
         this.pdsFoldersResolver = pdsFoldersResolver;
         this.ioFactory = ioFactory;
         this.log = log;
@@ -97,11 +96,10 @@ public class MaintenanceFileStore {
 
     /** */
     public void init() throws IgniteCheckedException, IOException {
-        if (inMemoryMode)
+        if (disabled)
             return;
 
-        PdsFolderSettings folderSettings = pdsFoldersResolver.resolveFolders();
-        File storeDir = new File(folderSettings.persistentStoreRootPath(), folderSettings.folderName());
+        File storeDir = pdsFoldersResolver.resolveFolders().persistentStoreNodePath();
         U.ensureDirectory(storeDir, "store directory for node persistent data", log);
 
         mntcTasksFile = new File(storeDir, MAINTENANCE_FILE_NAME);
@@ -126,7 +124,7 @@ public class MaintenanceFileStore {
      * Stops
      */
     public void stop() throws IOException {
-        if (inMemoryMode)
+        if (disabled)
             return;
 
         if (mntcTasksFileIO != null)
@@ -200,7 +198,7 @@ public class MaintenanceFileStore {
 
     /** */
     public Map<String, MaintenanceTask> getAllTasks() {
-        if (inMemoryMode)
+        if (disabled)
             return null;
 
         return Collections.unmodifiableMap(tasksInSync);
@@ -208,7 +206,7 @@ public class MaintenanceFileStore {
 
     /** */
     public void writeMaintenanceTask(MaintenanceTask task) throws IOException {
-        if (inMemoryMode)
+        if (disabled)
             return;
 
         tasksInSync.put(task.name(), task);
@@ -218,7 +216,7 @@ public class MaintenanceFileStore {
 
     /** */
     public void deleteMaintenanceTask(String taskName) throws IOException {
-        if (inMemoryMode)
+        if (disabled)
             return;
 
         tasksInSync.remove(taskName);
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/maintenance/MaintenanceProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/maintenance/MaintenanceProcessor.java
index 5328d13..88f32e9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/maintenance/MaintenanceProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/maintenance/MaintenanceProcessor.java
@@ -39,7 +39,7 @@ import org.jetbrains.annotations.Nullable;
 /** */
 public class MaintenanceProcessor extends GridProcessorAdapter implements MaintenanceRegistry {
     /** */
-    private static final String IN_MEMORY_MODE_ERR_MSG = "Maintenance Mode is not supported for in-memory clusters";
+    private static final String DISABLED_ERR_MSG = "Maintenance Mode is not supported for in-memory and client nodes";
 
     /**
      * Active {@link MaintenanceTask}s are the ones that were read from disk when node entered Maintenance Mode.
@@ -59,7 +59,7 @@ public class MaintenanceProcessor extends GridProcessorAdapter implements Mainte
     private final MaintenanceFileStore fileStorage;
 
     /** */
-    private final boolean inMemoryMode;
+    private final boolean disabled;
 
     /** */
     private volatile boolean maintenanceMode;
@@ -70,9 +70,9 @@ public class MaintenanceProcessor extends GridProcessorAdapter implements Mainte
     public MaintenanceProcessor(GridKernalContext ctx) {
         super(ctx);
 
-        inMemoryMode = !CU.isPersistenceEnabled(ctx.config());
+        disabled = !CU.isPersistenceEnabled(ctx.config()) || ctx.clientNode();
 
-        if (inMemoryMode) {
+        if (disabled) {
             fileStorage = new MaintenanceFileStore(true,
                 null,
                 null,
@@ -89,8 +89,8 @@ public class MaintenanceProcessor extends GridProcessorAdapter implements Mainte
 
     /** {@inheritDoc} */
     @Override public @Nullable MaintenanceTask registerMaintenanceTask(MaintenanceTask task) throws IgniteCheckedException {
-        if (inMemoryMode)
-            throw new IgniteCheckedException(IN_MEMORY_MODE_ERR_MSG);
+        if (disabled)
+            throw new IgniteCheckedException(DISABLED_ERR_MSG);
 
         if (isMaintenanceMode())
             throw new IgniteCheckedException("Node is already in Maintenance Mode, " +
@@ -130,7 +130,7 @@ public class MaintenanceProcessor extends GridProcessorAdapter implements Mainte
 
     /** {@inheritDoc} */
     @Override public void start() throws IgniteCheckedException {
-        if (inMemoryMode)
+        if (disabled)
             return;
 
         try {
@@ -223,7 +223,7 @@ public class MaintenanceProcessor extends GridProcessorAdapter implements Mainte
 
     /** {@inheritDoc} */
     @Override public boolean unregisterMaintenanceTask(String maintenanceTaskName) {
-        if (inMemoryMode)
+        if (disabled)
             return false;
 
         boolean deleted;
@@ -250,8 +250,8 @@ public class MaintenanceProcessor extends GridProcessorAdapter implements Mainte
 
     /** {@inheritDoc} */
     @Override public void registerWorkflowCallback(@NotNull String maintenanceTaskName, @NotNull MaintenanceWorkflowCallback cb) {
-        if (inMemoryMode)
-            throw new IgniteException(IN_MEMORY_MODE_ERR_MSG);
+        if (disabled)
+            throw new IgniteException(DISABLED_ERR_MSG);
 
         List<MaintenanceAction<?>> actions = cb.allActions();
 
@@ -281,8 +281,8 @@ public class MaintenanceProcessor extends GridProcessorAdapter implements Mainte
 
     /** {@inheritDoc} */
     @Override public List<MaintenanceAction<?>> actionsForMaintenanceTask(String maintenanceTaskName) {
-        if (inMemoryMode)
-            throw new IgniteException(IN_MEMORY_MODE_ERR_MSG);
+        if (disabled)
+            throw new IgniteException(DISABLED_ERR_MSG);
 
         if (!activeTasks.containsKey(maintenanceTaskName))
             throw new IgniteException("Maintenance workflow callback for given task name not found, " +
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 dd87d35..05376b5 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
@@ -231,7 +231,7 @@ public class FilePageStoreManager extends GridCacheSharedManagerAdapter implemen
 
         final PdsFolderSettings folderSettings = ctx.pdsFolderResolver().resolveFolders();
 
-        storeWorkDir = new File(folderSettings.persistentStoreRootPath(), folderSettings.folderName());
+        storeWorkDir = folderSettings.persistentStoreNodePath();
 
         U.ensureDirectory(storeWorkDir, "page store work directory", log);
 
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/filename/PdsConsistentIdProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/filename/PdsConsistentIdProcessor.java
index 951a2e1..f74c761 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/filename/PdsConsistentIdProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/filename/PdsConsistentIdProcessor.java
@@ -157,14 +157,16 @@ public class PdsConsistentIdProcessor extends GridProcessorAdapter implements Pd
      * @throws IgniteCheckedException if IO failed.
      */
     private PdsFolderSettings prepareNewSettings() throws IgniteCheckedException {
-        final File pstStoreBasePath = resolvePersistentStoreBasePath();
+        boolean clientMode = ctx.clientNode();
+
+        final File pstStoreBasePath = resolvePersistentStoreBasePath(clientMode);
         //here deprecated method is used to get compatible version of consistentId
         final Serializable consistentId = ctx.discovery().consistentId();
 
         if (!CU.isPersistenceEnabled(cfg))
             return compatibleResolve(pstStoreBasePath, consistentId);
 
-        if (ctx.clientNode())
+        if (clientMode)
             return new PdsFolderSettings(pstStoreBasePath, UUID.randomUUID());
 
         if (getBoolean(IGNITE_DATA_STORAGE_FOLDER_BY_CONSISTENT_ID, false))
@@ -440,15 +442,16 @@ public class PdsConsistentIdProcessor extends GridProcessorAdapter implements Pd
     /**
      * @return DB storage absolute root path resolved as 'db' folder in Ignite work dir (by default) or using persistent
      * store configuration. Null if persistence is not enabled. Returned folder is created automatically.
+     * @param clientMode {@code True} if client node.
      * @throws IgniteCheckedException if I/O failed.
      */
-    @Nullable private File resolvePersistentStoreBasePath() throws IgniteCheckedException {
+    @Nullable private File resolvePersistentStoreBasePath(boolean clientMode) throws IgniteCheckedException {
         final DataStorageConfiguration dsCfg = cfg.getDataStorageConfiguration();
 
         if (dsCfg == null)
             return null;
 
-        final String pstPath = dsCfg.getStoragePath();
+        final String pstPath = clientMode ? null : dsCfg.getStoragePath();
 
         return U.resolveWorkDirectory(
             cfg.getWorkDirectory(),
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/filename/PdsFolderSettings.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/filename/PdsFolderSettings.java
index c47cbc9..ce80463 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/filename/PdsFolderSettings.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/filename/PdsFolderSettings.java
@@ -137,6 +137,15 @@ public class PdsFolderSettings {
         return persistentStoreRootPath;
     }
 
+    /**
+     * @return Storage directory for node.
+     */
+    public File persistentStoreNodePath() {
+        assert persistentStoreRootPath != null;
+
+        return new File(persistentStoreRootPath, folderName);
+    }
+
     /** {@inheritDoc} */
     @Override public String toString() {
         return S.toString(PdsFolderSettings.class, this);
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsOnClientTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsOnClientTest.java
new file mode 100644
index 0000000..0777498
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsOnClientTest.java
@@ -0,0 +1,76 @@
+/*
+ * 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.IgniteCache;
+import org.apache.ignite.cluster.ClusterState;
+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.IgnitionEx;
+import org.apache.ignite.internal.processors.cache.persistence.filename.PdsFolderSettings;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+/** */
+public class IgnitePdsOnClientTest extends GridCommonAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+        cfg.setDataStorageConfiguration(new DataStorageConfiguration()
+            .setDefaultDataRegionConfiguration(new DataRegionConfiguration().setPersistenceEnabled(true)));
+
+        if (IgnitionEx.isClientMode())
+            cfg.getDataStorageConfiguration().setStoragePath("/unexisting/storage/path");
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        super.beforeTest();
+
+        cleanPersistenceDir();
+    }
+
+    /**
+     * Tests client node can start with {@link DataStorageConfiguration#getStoragePath()} configuration.
+     * Client node doesn't store data so {@link DataStorageConfiguration#getStoragePath()} should be ignored.
+     */
+    @Test
+    public void testStartClientWithPersistenceConfiguration() throws Exception {
+        try (Ignite ignite = startGrid(0)) {
+            IgniteEx client = startClientGrid(1);
+
+            client.cluster().state(ClusterState.ACTIVE);
+
+            IgniteCache<Integer, Integer> cache = client.createCache("my-cache");
+
+            cache.put(1, 1);
+            assertEquals((Integer)1, cache.get(1));
+
+            PdsFolderSettings settings = client.context().pdsFolderResolver().resolveFolders();
+
+            // Checking there are no files created on client node start.
+            assertFalse(settings.persistentStoreNodePath().exists());
+        }
+    }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteClientNodesTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteClientNodesTestSuite.java
index 6eef3f5..7b746e8 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteClientNodesTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteClientNodesTestSuite.java
@@ -20,6 +20,7 @@ package org.apache.ignite.testsuites;
 import org.apache.ignite.internal.processors.cache.distributed.IgniteCacheClientNodeConcurrentStart;
 import org.apache.ignite.internal.processors.cache.distributed.IgniteCacheClientReconnectTest;
 import org.apache.ignite.internal.processors.cache.distributed.IgniteCacheManyClientsTest;
+import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsOnClientTest;
 import org.junit.runner.RunWith;
 import org.junit.runners.Suite;
 
@@ -28,7 +29,8 @@ import org.junit.runners.Suite;
 @Suite.SuiteClasses({
     IgniteCacheManyClientsTest.class,
     IgniteCacheClientNodeConcurrentStart.class,
-    IgniteCacheClientReconnectTest.class
+    IgniteCacheClientReconnectTest.class,
+    IgnitePdsOnClientTest.class
 })
 public class IgniteClientNodesTestSuite {
 }