You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by dp...@apache.org on 2019/03/14 14:17:10 UTC

[ignite] branch ignite-11432 updated: IGNITE-11432: Add ability to specify auto-generated consistent ID in IgniteConfiguration

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

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


The following commit(s) were added to refs/heads/ignite-11432 by this push:
     new 199dd06  IGNITE-11432: Add ability to specify auto-generated consistent ID in IgniteConfiguration
199dd06 is described below

commit 199dd06d10bf5635d4d4ae519b5ca995acc771de
Author: Dmitriy Pavlov <dp...@apache.org>
AuthorDate: Thu Mar 14 17:16:45 2019 +0300

    IGNITE-11432: Add ability to specify auto-generated consistent ID in IgniteConfiguration
---
 .../filename/PdsConsistentIdProcessor.java         | 42 ++++++++++++++++++----
 .../IgniteUidAsConsistentIdMigrationTest.java      | 10 ++++--
 2 files changed, 42 insertions(+), 10 deletions(-)

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 ffef9af..a2942aa 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
@@ -116,21 +116,48 @@ public class PdsConsistentIdProcessor extends GridProcessorAdapter implements Pd
      * Prepares compatible PDS folder settings. No locking is performed, consistent ID is not overridden.
      *
      * @param pstStoreBasePath DB storage base path or null if persistence is not enabled.
-     * @param consistentId compatibility consistent ID
+     * @param consistentId compatibility consistent ID generated from IP/Port.
      * @return PDS folder settings compatible with previous versions.
      */
     private PdsFolderSettings compatibleResolve(
         @Nullable final File pstStoreBasePath,
-        @NotNull final Serializable consistentId) {
+        @NotNull final Serializable consistentId) throws IgniteCheckedException {
 
-        if (cfg.getConsistentId() != null) {
-            // compatible mode from configuration is used fot this case, no locking, no consitent id change
-            return new PdsFolderSettings(pstStoreBasePath, cfg.getConsistentId());
-        }
+        Serializable configuredConsistentId = cfg.getConsistentId();
+
+        if (configuredConsistentId != null)
+            return configuredConsIdResolve(pstStoreBasePath, configuredConsistentId);
 
         return new PdsFolderSettings(pstStoreBasePath, consistentId);
     }
 
+    /**
+     * Prepares compatible PDS folder settings based on Conistent ID from the configuration.
+     *
+     * @param pstStoreBasePath Persistent store base path.
+     * @param configuredConsistentId Configured consistent id.
+     */
+    @NotNull private PdsFolderSettings configuredConsIdResolve(@Nullable File pstStoreBasePath,
+        Serializable configuredConsistentId) throws IgniteCheckedException {
+        if (configuredConsistentId instanceof UUID) {
+            UUID uuid = (UUID)configuredConsistentId;
+
+            int nodeIdx = 0;
+            final String consIdBasedFolder = genNewStyleSubfolderName(nodeIdx, uuid);
+            final File existingUuidFolder = U.resolveWorkDirectory(pstStoreBasePath.getAbsolutePath(), consIdBasedFolder, false); //mkdir here
+            final GridCacheDatabaseSharedManager.FileLockHolder fileLockHolder = tryLock(existingUuidFolder);
+
+            return new PdsFolderSettings(pstStoreBasePath,
+                consIdBasedFolder,
+                configuredConsistentId,
+                fileLockHolder,
+                true);
+        }
+
+        // compatible mode from configuration is used fot this case, no locking, no consitent id change
+        return new PdsFolderSettings(pstStoreBasePath, configuredConsistentId);
+    }
+
     /** {@inheritDoc} */
     @Override public PdsFolderSettings resolveFolders() throws IgniteCheckedException {
         if (settings == null) {
@@ -170,8 +197,9 @@ public class PdsConsistentIdProcessor extends GridProcessorAdapter implements Pd
         // compatible mode from configuration is used fot this case
         if (cfg.getConsistentId() != null) {
             // compatible mode from configuration is used fot this case, no locking, no consistent id change
-            return new PdsFolderSettings(pstStoreBasePath, cfg.getConsistentId());
+            return configuredConsIdResolve(pstStoreBasePath, cfg.getConsistentId());
         }
+
         // The node scans the work directory and checks if there is a folder matching the consistent ID.
         // If such a folder exists, we start up with this ID (compatibility mode)
         final String subFolder = U.maskForFileName(consistentId.toString());
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/filename/IgniteUidAsConsistentIdMigrationTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/filename/IgniteUidAsConsistentIdMigrationTest.java
index a5c072b..0312058 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/filename/IgniteUidAsConsistentIdMigrationTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/filename/IgniteUidAsConsistentIdMigrationTest.java
@@ -225,9 +225,13 @@ public class IgniteUidAsConsistentIdMigrationTest extends GridCommonAbstractTest
         stopGrid(0);
 
         this.configuredConsistentId = generatedCid;
-        Ignite igniteRestarted = startActivateFillDataGrid(0);
 
-        assertPdsDirsDefaultExist(U.maskForFileName(configuredConsistentId.toString()));
+        Ignite igniteRestarted = startActivateGrid(0);
+
+        assertEquals("there!", igniteRestarted.getOrCreateCache(CACHE_NAME).get("hi"));
+
+        assertPdsDirsDefaultExist(sub);
+
         stopGrid(0);
     }
 
@@ -383,7 +387,7 @@ public class IgniteUidAsConsistentIdMigrationTest extends GridCommonAbstractTest
      * @return name of storage related subfolders
      */
     @NotNull private String genNewStyleSubfolderName(final int nodeIdx, final Ignite ignite) {
-        final Object consistentId = ignite.cluster().localNode().consistentId();
+        Object consistentId = ignite.cluster().localNode().consistentId();
 
         assertTrue("For new style folders consistent ID should be UUID," +
                 " but actual class is " + (consistentId == null ? null : consistentId.getClass()),