ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agoncha...@apache.org
Subject ignite git commit: IGNITE-6746 Adding persistent system cache
Date Tue, 24 Oct 2017 15:16:08 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-6746 [created] 4865cf5b2


IGNITE-6746 Adding persistent system cache


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/4865cf5b
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/4865cf5b
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/4865cf5b

Branch: refs/heads/ignite-6746
Commit: 4865cf5b24c153057e211c65a12257d95778b793
Parents: b51df62
Author: Alexey Goncharuk <alexey.goncharuk@gmail.com>
Authored: Tue Oct 24 18:15:54 2017 +0300
Committer: Alexey Goncharuk <alexey.goncharuk@gmail.com>
Committed: Tue Oct 24 18:15:54 2017 +0300

----------------------------------------------------------------------
 .../org/apache/ignite/internal/IgniteEx.java    |  7 +++
 .../apache/ignite/internal/IgniteKernal.java    | 14 +++++
 .../org/apache/ignite/internal/IgnitionEx.java  | 20 ++++---
 .../processors/cache/GridCacheProcessor.java    | 11 +++-
 .../processors/cache/GridCacheUtils.java        | 18 ++++--
 .../IgniteCacheDatabaseSharedManager.java       | 59 +++++++++++++++-----
 .../processors/igfs/IgfsIgniteMock.java         |  7 +++
 .../junits/multijvm/IgniteProcessProxy.java     |  5 ++
 8 files changed, 113 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/4865cf5b/modules/core/src/main/java/org/apache/ignite/internal/IgniteEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteEx.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteEx.java
index 53b3e4f..a698cae 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteEx.java
@@ -44,6 +44,13 @@ public interface IgniteEx extends Ignite {
     public <K extends GridCacheUtilityKey, V> IgniteInternalCache<K, V> utilityCache();
 
     /**
+     * Gets utility cache with enabled persistence.
+     *
+     * @return Utility cache.
+     */
+    public <K extends GridCacheUtilityKey, V> IgniteInternalCache<K, V> persistentUtilityCache();
+
+    /**
      * Gets the cache instance for the given name if one is configured or
      * <tt>null</tt> otherwise returning even non-public caches.
      *

http://git-wip-us.apache.org/repos/asf/ignite/blob/4865cf5b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
index ba42a95..313a8e1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
@@ -3317,6 +3317,20 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable
{
     }
 
     /** {@inheritDoc} */
+    @Override public <K extends GridCacheUtilityKey, V> IgniteInternalCache<K, V>
persistentUtilityCache() {
+        guard();
+
+        try {
+            checkClusterState();
+
+            return ctx.cache().persistentUtilityCache();
+        }
+        finally {
+            unguard();
+        }
+    }
+
+    /** {@inheritDoc} */
     @Override public <K, V> IgniteInternalCache<K, V> cachex(String name) {
         CU.validateCacheName(name);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/4865cf5b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
index 36257e2..80e49cf 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
@@ -69,6 +69,7 @@ import org.apache.ignite.configuration.PersistentStoreConfiguration;
 import org.apache.ignite.configuration.TransactionConfiguration;
 import org.apache.ignite.internal.binary.BinaryMarshaller;
 import org.apache.ignite.internal.managers.communication.GridIoPolicy;
+import org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager;
 import org.apache.ignite.internal.processors.datastructures.DataStructuresProcessor;
 import org.apache.ignite.internal.processors.igfs.IgfsThreadFactory;
 import org.apache.ignite.internal.processors.igfs.IgfsUtils;
@@ -2222,7 +2223,11 @@ public class IgnitionEx {
         public void initializeDefaultCacheConfiguration(IgniteConfiguration cfg) throws IgniteCheckedException
{
             List<CacheConfiguration> cacheCfgs = new ArrayList<>();
 
-            cacheCfgs.add(utilitySystemCache());
+            cacheCfgs.add(systemCache(CU.UTILITY_CACHE_NAME, GridCacheDatabaseSharedManager.systemDataRegionName()));
+
+            if (CU.isPersistenceEnabled(cfg))
+                cacheCfgs.add(systemCache(CU.PERSISTENT_UTILITY_CACHE_NAME,
+                    GridCacheDatabaseSharedManager.systemPersistentDataRegionName()));
 
             if (IgniteComponentType.HADOOP.inClassPath())
                 cacheCfgs.add(CU.hadoopSystemCache());
@@ -2409,15 +2414,13 @@ public class IgnitionEx {
             }
         }
 
-        /**
-         * Creates utility system cache configuration.
-         *
-         * @return Utility system cache configuration.
-         */
-        private static CacheConfiguration utilitySystemCache() {
+        private static CacheConfiguration systemCache(
+            String name,
+            String dataRegionName
+        ) {
             CacheConfiguration cache = new CacheConfiguration();
 
-            cache.setName(CU.UTILITY_CACHE_NAME);
+            cache.setName(name);
             cache.setCacheMode(REPLICATED);
             cache.setAtomicityMode(TRANSACTIONAL);
             cache.setRebalanceMode(SYNC);
@@ -2426,6 +2429,7 @@ public class IgnitionEx {
             cache.setNodeFilter(CacheConfiguration.ALL_NODES);
             cache.setRebalanceOrder(-2); //Prior to user caches.
             cache.setCopyOnRead(false);
+            cache.setDataRegionName(dataRegionName);
 
             return cache;
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/4865cf5b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
----------------------------------------------------------------------
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 021807a..b7660aa 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
@@ -682,7 +682,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
             CacheType cacheType = cacheType(cacheName);
 
             if (cacheType != CacheType.USER && cfg.getDataRegionName() == null)
-                cfg.setDataRegionName(sharedCtx.database().systemDateRegionName());
+                cfg.setDataRegionName(GridCacheDatabaseSharedManager.systemDataRegionName());
 
             if (!cacheType.userCache())
                 stopSeq.addLast(cacheName);
@@ -3259,6 +3259,15 @@ public class GridCacheProcessor extends GridProcessorAdapter {
     }
 
     /**
+     * Gets utility cache.
+     *
+     * @return Utility cache.
+     */
+    public <K, V> IgniteInternalCache<K, V> persistentUtilityCache() {
+        return internalCacheEx(CU.PERSISTENT_UTILITY_CACHE_NAME);
+    }
+
+    /**
      * @param name Cache name.
      * @return Cache.
      */

http://git-wip-us.apache.org/repos/asf/ignite/blob/4865cf5b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
index 26e2254..887ffc5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
@@ -164,6 +164,9 @@ public class GridCacheUtils {
     /** System cache name. */
     public static final String UTILITY_CACHE_NAME = "ignite-sys-cache";
 
+    /** Persistent system cache name. */
+    public static final String PERSISTENT_UTILITY_CACHE_NAME = "ignite-persistent-sys-cache";
+
     /** */
     public static final String CONTINUOUS_QRY_LOG_CATEGORY = "org.apache.ignite.continuous.query";
 
@@ -1060,7 +1063,7 @@ public class GridCacheUtils {
      * @return {@code True} if this is utility system cache.
      */
     public static boolean isUtilityCache(String cacheName) {
-        return UTILITY_CACHE_NAME.equals(cacheName);
+        return UTILITY_CACHE_NAME.equals(cacheName) || PERSISTENT_UTILITY_CACHE_NAME.equals(cacheName);
     }
 
     /**
@@ -1705,10 +1708,17 @@ public class GridCacheUtils {
      * @return {@code true} if persistence is enabled for at least one data region, {@code
false} if not.
      */
     public static boolean isPersistenceEnabled(IgniteConfiguration cfg) {
-        if (cfg.getDataStorageConfiguration() == null)
+        return isPersistenceEnabled(cfg.getDataStorageConfiguration());
+    }
+
+    /**
+     * @return {@code true} if persistence is enabled for at least one data region, {@code
false} if not.
+     */
+    public static boolean isPersistenceEnabled(@Nullable DataStorageConfiguration dsCfg)
{
+        if (dsCfg == null)
             return false;
 
-        DataRegionConfiguration dfltReg = cfg.getDataStorageConfiguration().getDefaultDataRegionConfiguration();
+        DataRegionConfiguration dfltReg = dsCfg.getDefaultDataRegionConfiguration();
 
         if (dfltReg == null)
             return false;
@@ -1716,7 +1726,7 @@ public class GridCacheUtils {
         if (dfltReg.isPersistenceEnabled())
             return true;
 
-        DataRegionConfiguration[] regCfgs = cfg.getDataStorageConfiguration().getDataRegionConfigurations();
+        DataRegionConfiguration[] regCfgs = dsCfg.getDataRegionConfigurations();
 
         if (regCfgs == null)
             return false;

http://git-wip-us.apache.org/repos/asf/ignite/blob/4865cf5b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/IgniteCacheDatabaseSharedManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/IgniteCacheDatabaseSharedManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/IgniteCacheDatabaseSharedManager.java
index 933c195..dda2f79 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/IgniteCacheDatabaseSharedManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/IgniteCacheDatabaseSharedManager.java
@@ -57,6 +57,7 @@ import org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseL
 import org.apache.ignite.internal.processors.cluster.IgniteChangeGlobalStateSupport;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.T2;
+import org.apache.ignite.internal.util.typedef.internal.CU;
 import org.apache.ignite.internal.util.typedef.internal.LT;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteBiTuple;
@@ -75,6 +76,9 @@ public class IgniteCacheDatabaseSharedManager extends GridCacheSharedManagerAdap
     /** DataRegionConfiguration name reserved for internal caches. */
     static final String SYSTEM_DATA_REGION_NAME = "sysMemPlc";
 
+    /** DataRegionConfiguration name reserved for internal persisted caches. */
+    static final String SYSTEM_PERSISTENT_DATA_REGION_NAME = "sysPersistedMemPlc";
+
     /** Minimum size of memory chunk */
     private static final long MIN_PAGE_MEMORY_SIZE = 10 * 1024 * 1024;
 
@@ -218,36 +222,47 @@ public class IgniteCacheDatabaseSharedManager extends GridCacheSharedManagerAdap
 
         if (dataRegionCfgs != null) {
             for (DataRegionConfiguration dataRegionCfg : dataRegionCfgs)
-                addDataRegion(memCfg, dataRegionCfg, dataRegionCfg.getName());
+                addDataRegion(memCfg, dataRegionCfg);
         }
 
         addDataRegion(
             memCfg,
-            memCfg.getDefaultDataRegionConfiguration(),
-            memCfg.getDefaultDataRegionConfiguration().getName()
+            memCfg.getDefaultDataRegionConfiguration()
         );
 
         addDataRegion(
             memCfg,
             createSystemDataRegion(
+                SYSTEM_DATA_REGION_NAME,
                 memCfg.getSystemRegionInitialSize(),
-                memCfg.getSystemRegionMaxSize()
-            ),
-            SYSTEM_DATA_REGION_NAME
+                memCfg.getSystemRegionMaxSize(),
+                false
+            )
         );
+
+        if (CU.isPersistenceEnabled(memCfg)) {
+            addDataRegion(
+                memCfg,
+                createSystemDataRegion(
+                    SYSTEM_PERSISTENT_DATA_REGION_NAME,
+                    memCfg.getSystemRegionInitialSize(),
+                    memCfg.getSystemRegionMaxSize(),
+                    true
+                )
+            );
+        }
     }
 
     /**
      * @param dataStorageCfg Database config.
      * @param dataRegionCfg Data region config.
-     * @param dataRegionName Data region name.
      * @throws IgniteCheckedException If failed to initialize swap path.
      */
     private void addDataRegion(
         DataStorageConfiguration dataStorageCfg,
-        DataRegionConfiguration dataRegionCfg,
-        String dataRegionName
+        DataRegionConfiguration dataRegionCfg
     ) throws IgniteCheckedException {
+        String dataRegionName = dataRegionCfg.getName();
         String dfltMemPlcName = dataStorageCfg.getDefaultDataRegionConfiguration().getName();
 
         if (dfltMemPlcName == null)
@@ -315,15 +330,22 @@ public class IgniteCacheDatabaseSharedManager extends GridCacheSharedManagerAdap
     /**
      * @param sysCacheInitSize Initial size of PageMemory to be created for system cache.
      * @param sysCacheMaxSize Maximum size of PageMemory to be created for system cache.
+     * @param persistenceEnabled {@code true} if persistence should be enabled for this cache.
      *
      * @return {@link DataRegionConfiguration configuration} of DataRegion for system cache.
      */
-    private DataRegionConfiguration createSystemDataRegion(long sysCacheInitSize, long sysCacheMaxSize)
{
+    private DataRegionConfiguration createSystemDataRegion(
+        String regionName,
+        long sysCacheInitSize,
+        long sysCacheMaxSize,
+        boolean persistenceEnabled
+    ) {
         DataRegionConfiguration res = new DataRegionConfiguration();
 
-        res.setName(SYSTEM_DATA_REGION_NAME);
+        res.setName(regionName);
         res.setInitialSize(sysCacheInitSize);
         res.setMaxSize(sysCacheMaxSize);
+        res.setPersistenceEnabled(persistenceEnabled);
 
         return res;
     }
@@ -507,10 +529,10 @@ public class IgniteCacheDatabaseSharedManager extends GridCacheSharedManagerAdap
                 "non-empty name.");
 
         if (observedNames.contains(regName))
-            throw new IgniteCheckedException("Two MemoryPolicies have the same name: " +
regName);
+            throw new IgniteCheckedException("Two DataRegionConfiguration have the same name:
" + regName);
 
-        if (SYSTEM_DATA_REGION_NAME.equals(regName))
-            throw new IgniteCheckedException("'" + SYSTEM_DATA_REGION_NAME + "' policy name
is reserved for internal use.");
+        if (SYSTEM_DATA_REGION_NAME.equals(regName) || SYSTEM_PERSISTENT_DATA_REGION_NAME.equals(regName))
+            throw new IgniteCheckedException("'" + regName + "' data region name is reserved
for internal use.");
 
         observedNames.add(regName);
     }
@@ -959,11 +981,18 @@ public class IgniteCacheDatabaseSharedManager extends GridCacheSharedManagerAdap
     /**
      * @return Name of DataRegionConfiguration for internal caches.
      */
-    public String systemDateRegionName() {
+    public static String systemDataRegionName() {
         return SYSTEM_DATA_REGION_NAME;
     }
 
     /**
+     * @return Name of DataRegionConfiguration for internal caches.
+     */
+    public static String systemPersistentDataRegionName() {
+        return SYSTEM_PERSISTENT_DATA_REGION_NAME;
+    }
+
+    /**
      * Method for fake (standalone) context initialization. Not to be called in production
code
      * @param pageSize configured page size
      */

http://git-wip-us.apache.org/repos/asf/ignite/blob/4865cf5b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsIgniteMock.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsIgniteMock.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsIgniteMock.java
index a0ce285..7bc1401 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsIgniteMock.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsIgniteMock.java
@@ -99,6 +99,13 @@ public class IgfsIgniteMock implements IgniteEx {
     }
 
     /** {@inheritDoc} */
+    @Override public <K extends GridCacheUtilityKey, V> IgniteInternalCache<K, V>
persistentUtilityCache() {
+        throwUnsupported();
+
+        return null;
+    }
+
+    /** {@inheritDoc} */
     @Nullable @Override public <K, V> IgniteInternalCache<K, V> cachex(@Nullable
String name) {
         throwUnsupported();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/4865cf5b/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java
b/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java
index 86a374a..35b123d 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java
@@ -408,6 +408,11 @@ public class IgniteProcessProxy implements IgniteEx {
     }
 
     /** {@inheritDoc} */
+    @Override public <K extends GridCacheUtilityKey, V> IgniteInternalCache<K, V>
persistentUtilityCache() {
+        throw new UnsupportedOperationException("Operation isn't supported yet.");
+    }
+
+    /** {@inheritDoc} */
     @Nullable @Override public <K, V> IgniteInternalCache<K, V> cachex(@Nullable
String name) {
         throw new UnsupportedOperationException("Operation isn't supported yet.");
     }


Mime
View raw message