From 1a74022252cf186105fcc53863ca2d1bc46ae189 Mon Sep 17 00:00:00 2001
From: boli <boli@localhost>
Date: Wed, 08 Apr 2009 15:46:12 +0000
Subject: [PATCH] Fix for issue 2070: Added validation of DB cache size before applying it to JE.

---
 opends/src/server/org/opends/server/backends/jeb/ConfigurableEnvironment.java |   25 ++++++++++++++++++-------
 opends/src/messages/messages/jeb.properties                                   |    6 ++++++
 2 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/opends/src/messages/messages/jeb.properties b/opends/src/messages/messages/jeb.properties
index 8f658d9..c128494 100644
--- a/opends/src/messages/messages/jeb.properties
+++ b/opends/src/messages/messages/jeb.properties
@@ -358,3 +358,9 @@
  backup in '%s'.  A full backup will be executed
 SEVERE_ERR_CONFIG_INDEX_TYPE_NEEDS_VALID_MATCHING_RULE_192=The attribute '%s' \
 cannot have extensible index type for invalid matching rule name '%s'
+SEVERE_ERR_CONFIG_JEB_CACHE_SIZE_GREATER_THAN_JVM_HEAP_193=Configuration \
+  attribute ds-cfg-db-cache-size has a value of %d but the JVM is only \
+  configured for %d. Consider using ds-cfg-db-cache-percent
+SEVERE_ERR_CONFIG_JEB_CACHE_SIZE_TOO_SMALL_194=Configuration \
+  attribute ds-cfg-db-cache-size has a value of %d which is less than \
+  the minimum: %d
diff --git a/opends/src/server/org/opends/server/backends/jeb/ConfigurableEnvironment.java b/opends/src/server/org/opends/server/backends/jeb/ConfigurableEnvironment.java
index 9987ab2..1af255b 100644
--- a/opends/src/server/org/opends/server/backends/jeb/ConfigurableEnvironment.java
+++ b/opends/src/server/org/opends/server/backends/jeb/ConfigurableEnvironment.java
@@ -27,6 +27,7 @@
 package org.opends.server.backends.jeb;
 
 import com.sleepycat.je.EnvironmentConfig;
+import com.sleepycat.je.dbi.MemoryBudget;
 
 import org.opends.server.config.ConfigConstants;
 import org.opends.server.config.ConfigException;
@@ -43,6 +44,7 @@
 import java.util.Arrays;
 
 import org.opends.messages.Message;
+import static org.opends.messages.JebMessages.*;
 
 import org.opends.server.loggers.debug.DebugTracer;
 import org.opends.server.admin.std.server.LocalDBBackendCfg;
@@ -426,6 +428,21 @@
   public static EnvironmentConfig parseConfigEntry(LocalDBBackendCfg cfg)
        throws ConfigException
   {
+    // See if the db cache size setting is valid.
+    if(cfg.getDBCacheSize() != 0)
+    {
+      if (MemoryBudget.getRuntimeMaxMemory() < cfg.getDBCacheSize()) {
+        throw new ConfigException(
+            ERR_CONFIG_JEB_CACHE_SIZE_GREATER_THAN_JVM_HEAP.get(
+                cfg.getDBCacheSize(), MemoryBudget.getRuntimeMaxMemory()));
+      }
+      if (cfg.getDBCacheSize() < MemoryBudget.MIN_MAX_MEMORY_SIZE) {
+        throw new ConfigException(
+            ERR_CONFIG_JEB_CACHE_SIZE_TOO_SMALL.get(
+                cfg.getDBCacheSize(), MemoryBudget.MIN_MAX_MEMORY_SIZE));
+      }
+    }
+
     EnvironmentConfig envConfig = defaultConfig();
 
     // Handle the attributes that do not have a JE property.
@@ -445,13 +462,7 @@
     // See if there are any native JE properties specified in the config
     // and if so try to parse, evaluate and set them.
     SortedSet<String> jeProperties = cfg.getJEProperty();
-    try {
-      envConfig = setJEProperties(envConfig, jeProperties, attrMap);
-    } catch (ConfigException e) {
-      throw e;
-    }
-
-    return envConfig;
+    return setJEProperties(envConfig, jeProperties, attrMap);
   }
 
 

--
Gitblit v1.10.0