IGNITE-5215: Allow user to configure memory policy with maxSize lesser than 
default initialSize

(cherry picked from commit 6319266)


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

Branch: refs/heads/ignite-5075-pds
Commit: 91b6b13e16788fd528766b0954f0d843b27e3a23
Parents: 44f276a
Author: Ivan Rakov <[email protected]>
Authored: Mon May 15 15:27:00 2017 +0300
Committer: Ivan Rakov <[email protected]>
Committed: Thu May 18 14:03:00 2017 +0300

----------------------------------------------------------------------
 .../IgniteCacheDatabaseSharedManager.java       | 24 +++++++++++++++-----
 1 file changed, 18 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/91b6b13e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java
index 540b9ea..0624966 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java
@@ -55,11 +55,13 @@ import 
org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseList
 import 
org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture;
 import 
org.apache.ignite.internal.processors.cluster.IgniteChangeGlobalStateSupport;
 import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.LT;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteBiTuple;
 import org.apache.ignite.mxbean.MemoryMetricsMXBean;
 import org.jetbrains.annotations.Nullable;
 
+import static 
org.apache.ignite.configuration.MemoryConfiguration.DFLT_MEMORY_POLICY_INITIAL_SIZE;
 import static 
org.apache.ignite.configuration.MemoryConfiguration.DFLT_MEM_PLC_DEFAULT_NAME;
 
 /**
@@ -405,18 +407,28 @@ public class IgniteCacheDatabaseSharedManager extends 
GridCacheSharedManagerAdap
      * @param plcCfg MemoryPolicyConfiguration to validate.
      * @throws IgniteCheckedException If config is invalid.
      */
-    private static void checkPolicySize(MemoryPolicyConfiguration plcCfg) 
throws IgniteCheckedException {
+    private void checkPolicySize(MemoryPolicyConfiguration plcCfg) throws 
IgniteCheckedException {
         if (plcCfg.getInitialSize() < MIN_PAGE_MEMORY_SIZE)
             throw new IgniteCheckedException("MemoryPolicy must have size more 
than 10MB (use " +
                 "MemoryPolicyConfiguration.initialSize property to set correct 
size in bytes) " +
                 "[name=" + plcCfg.getName() + ", size=" + 
U.readableSize(plcCfg.getInitialSize(), true) + "]"
             );
 
-        if (plcCfg.getMaxSize() < plcCfg.getInitialSize())
-            throw new IgniteCheckedException("MemoryPolicy maxSize must not be 
smaller than " +
-                "initialSize [name=" + plcCfg.getName() +
-                ", initSize=" + U.readableSize(plcCfg.getInitialSize(), true) +
-                ", maxSize=" + U.readableSize(plcCfg.getMaxSize(), true) + 
']');
+        if (plcCfg.getMaxSize() < plcCfg.getInitialSize()) {
+            if (plcCfg.getInitialSize() == DFLT_MEMORY_POLICY_INITIAL_SIZE) {
+                plcCfg.setInitialSize(plcCfg.getMaxSize());
+
+                LT.warn(log, "MemoryPolicy maxSize=" + 
U.readableSize(plcCfg.getMaxSize(), true) +
+                    " is smaller than defaultInitialSize=" +
+                    
U.readableSize(MemoryConfiguration.DFLT_MEMORY_POLICY_INITIAL_SIZE, true) +
+                    ", setting initialSize to " + 
U.readableSize(plcCfg.getMaxSize(), true));
+            } else {
+                throw new IgniteCheckedException("MemoryPolicy maxSize must 
not be smaller than " +
+                    "initialSize [name=" + plcCfg.getName() +
+                    ", initSize=" + U.readableSize(plcCfg.getInitialSize(), 
true) +
+                    ", maxSize=" + U.readableSize(plcCfg.getMaxSize(), true) + 
']');
+            }
+        }
     }
 
     /**

Reply via email to