ConfigurableEnvironment.java revision 29b1cca745810ca5f054aace99379ba6af427e6b
0N/A/*
2362N/A * CDDL HEADER START
0N/A *
0N/A * The contents of this file are subject to the terms of the
0N/A * Common Development and Distribution License, Version 1.0 only
0N/A * (the "License"). You may not use this file except in compliance
0N/A * with the License.
0N/A *
0N/A * You can obtain a copy of the license at
0N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE
0N/A * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
0N/A * See the License for the specific language governing permissions
0N/A * and limitations under the License.
0N/A *
0N/A * When distributing Covered Code, include this CDDL HEADER in each
0N/A * file and include the License file at
0N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
0N/A * add the following below this CDDL HEADER, with the fields enclosed
2362N/A * by brackets "[]" replaced with your own identifying information:
2362N/A * Portions Copyright [yyyy] [name of copyright owner]
2362N/A *
0N/A * CDDL HEADER END
0N/A *
0N/A *
0N/A * Portions Copyright 2006-2007 Sun Microsystems, Inc.
0N/A */
0N/Apackage org.opends.server.backends.jeb;
0N/A
0N/Aimport com.sleepycat.je.EnvironmentConfig;
0N/A
0N/Aimport org.opends.server.config.ConfigConstants;
0N/Aimport org.opends.server.config.ConfigException;
0N/Aimport org.opends.server.types.DebugLogLevel;
0N/A
0N/Aimport java.util.HashMap;
0N/Aimport java.util.Map;
0N/Aimport java.lang.reflect.Method;
0N/A
0N/Aimport static org.opends.server.loggers.debug.DebugLogger.debugCaught;
0N/Aimport static org.opends.server.loggers.debug.DebugLogger.debugEnabled;
0N/Aimport org.opends.server.admin.std.server.JEBackendCfg;
0N/Aimport org.opends.server.admin.std.meta.JEBackendCfgDefn;
0N/Aimport org.opends.server.admin.DurationPropertyDefinition;
0N/Aimport org.opends.server.admin.BooleanPropertyDefinition;
0N/Aimport org.opends.server.admin.PropertyDefinition;
0N/A
0N/A/**
0N/A * This class maps JE properties to configuration attributes.
0N/A */
0N/Apublic class ConfigurableEnvironment
0N/A{
0N/A /**
0N/A * The name of the attribute which configures the database cache size as a
0N/A * percentage of Java VM heap size.
0N/A */
0N/A public static final String ATTR_DATABASE_CACHE_PERCENT =
0N/A ConfigConstants.NAME_PREFIX_CFG + "database-cache-percent";
0N/A
0N/A /**
0N/A * The name of the attribute which configures the database cache size as an
0N/A * approximate number of bytes.
0N/A */
0N/A public static final String ATTR_DATABASE_CACHE_SIZE =
0N/A ConfigConstants.NAME_PREFIX_CFG + "database-cache-size";
0N/A
0N/A /**
0N/A * The name of the attribute which configures whether data updated by a
0N/A * database transaction is forced to disk.
0N/A */
0N/A public static final String ATTR_DATABASE_TXN_NO_SYNC =
0N/A ConfigConstants.NAME_PREFIX_CFG + "database-txn-no-sync";
0N/A
0N/A /**
0N/A * The name of the attribute which configures whether data updated by a
0N/A * database transaction is written from the Java VM to the O/S.
0N/A */
0N/A public static final String ATTR_DATABASE_TXN_WRITE_NO_SYNC =
0N/A ConfigConstants.NAME_PREFIX_CFG + "database-txn-write-no-sync";
0N/A
0N/A /**
0N/A * The name of the attribute which configures whether the database background
0N/A * cleaner thread runs.
0N/A */
0N/A public static final String ATTR_DATABASE_RUN_CLEANER =
0N/A ConfigConstants.NAME_PREFIX_CFG + "database-run-cleaner";
0N/A
0N/A /**
0N/A * The name of the attribute which configures the minimum percentage of log
0N/A * space that must be used in log files.
0N/A */
0N/A public static final String ATTR_CLEANER_MIN_UTILIZATION =
0N/A ConfigConstants.NAME_PREFIX_CFG + "database-cleaner-min-utilization";
0N/A
0N/A /**
0N/A * The name of the attribute which configures the maximum size of each
0N/A * individual JE log file, in bytes.
0N/A */
0N/A public static final String ATTR_DATABASE_LOG_FILE_MAX =
0N/A ConfigConstants.NAME_PREFIX_CFG + "database-log-file-max";
0N/A
0N/A /**
0N/A * The name of the attribute which configures the database cache eviction
0N/A * algorithm.
0N/A */
0N/A public static final String ATTR_EVICTOR_LRU_ONLY =
0N/A ConfigConstants.NAME_PREFIX_CFG + "database-evictor-lru-only";
0N/A
0N/A /**
0N/A * The name of the attribute which configures the number of nodes in one scan
0N/A * of the database cache evictor.
0N/A */
0N/A public static final String ATTR_EVICTOR_NODES_PER_SCAN =
0N/A ConfigConstants.NAME_PREFIX_CFG + "database-evictor-nodes-per-scan";
0N/A
0N/A
0N/A /**
0N/A * The name of the attribute which configures whether the logging file
0N/A * handler will be on or off.
0N/A */
0N/A public static final String ATTR_LOGGING_FILE_HANDLER_ON =
0N/A ConfigConstants.NAME_PREFIX_CFG + "database-logging-file-handler-on";
0N/A
0N/A
0N/A /**
0N/A * The name of the attribute which configures the trace logging message level.
0N/A */
0N/A public static final String ATTR_LOGGING_LEVEL =
0N/A ConfigConstants.NAME_PREFIX_CFG + "database-logging-level";
0N/A
0N/A
0N/A /**
0N/A * The name of the attribute which configures how many bytes are written to
0N/A * the log before the checkpointer runs.
0N/A */
0N/A public static final String ATTR_CHECKPOINTER_BYTES_INTERVAL =
0N/A ConfigConstants.NAME_PREFIX_CFG + "database-checkpointer-bytes-interval";
0N/A
0N/A
0N/A /**
0N/A * The name of the attribute which configures the amount of time between
0N/A * runs of the checkpointer.
0N/A */
public static final String ATTR_CHECKPOINTER_WAKEUP_INTERVAL =
ConfigConstants.NAME_PREFIX_CFG +
"database-checkpointer-wakeup-interval";
/**
* The name of the attribute which configures the number of lock tables.
*/
public static final String ATTR_NUM_LOCK_TABLES =
ConfigConstants.NAME_PREFIX_CFG + "database-lock-num-lock-tables";
/**
* The name of the attribute which configures the number threads
* allocated by the cleaner for log file processing.
*/
public static final String ATTR_NUM_CLEANER_THREADS =
ConfigConstants.NAME_PREFIX_CFG + "database-cleaner-num-threads";
/**
* A map of JE property names to the corresponding configuration attribute.
*/
private static HashMap<String, String> attrMap =
new HashMap<String, String>();
/**
* A map of configuration attribute names to the corresponding configuration
* object getter method.
*/
private static HashMap<String,Method> methodMap =
new HashMap<String, Method>();
/**
* A map of configuration attribute names to the corresponding configuration
* PropertyDefinition.
*/
private static HashMap<String,PropertyDefinition> defnMap =
new HashMap<String, PropertyDefinition>();
/**
* Register a JE property and its corresponding configuration attribute.
*
* @param propertyName The name of the JE property to be registered.
* @param attrName The name of the configuration attribute associated
* with the property.
* @throws Exception If there is an error in the attribute name.
*/
private static void registerProp(String propertyName, String attrName)
throws Exception
{
// Strip off NAME_PREFIX_CFG.
String baseName = attrName.substring(7);
// Convert hyphenated to camel case.
StringBuilder builder = new StringBuilder();
boolean capitalize = true;
for (int i = 0; i < baseName.length(); i++)
{
char c = baseName.charAt(i);
if (c == '-')
{
capitalize = true;
}
else
{
if (capitalize)
{
builder.append(Character.toUpperCase(c));
}
else
{
builder.append(c);
}
capitalize = false;
}
}
String methodBaseName = builder.toString();
Class configClass = JEBackendCfg.class;
JEBackendCfgDefn defn = JEBackendCfgDefn.getInstance();
Class defClass = defn.getClass();
PropertyDefinition propDefn =
(PropertyDefinition)defClass.getMethod("get" + methodBaseName +
"PropertyDefinition").invoke(defn);
String methodName;
if (propDefn instanceof BooleanPropertyDefinition)
{
methodName = "is" + methodBaseName;
}
else
{
methodName = "get" + methodBaseName;
}
defnMap.put(attrName, propDefn);
methodMap.put(attrName, configClass.getMethod(methodName));
attrMap.put(propertyName, attrName);
}
/**
* Get the name of the configuration attribute associated with a JE property.
* @param jeProperty The name of the JE property.
* @return The name of the associated configuration attribute.
*/
public static String getAttributeForProperty(String jeProperty)
{
return attrMap.get(jeProperty);
}
/**
* Get the value of a JE property that is mapped to a configuration attribute.
* @param cfg The configuration containing the property values.
* @param attrName The conriguration attribute type name.
* @return The string value of the JE property.
*/
private static String getPropertyValue(JEBackendCfg cfg, String attrName)
{
try
{
PropertyDefinition propDefn = defnMap.get(attrName);
Method method = methodMap.get(attrName);
if (propDefn instanceof DurationPropertyDefinition)
{
Long value = (Long)method.invoke(cfg);
// JE durations are in microseconds so we must convert.
DurationPropertyDefinition durationPropDefn =
(DurationPropertyDefinition)propDefn;
value = 1000*durationPropDefn.getBaseUnit().getDuration(value);
return String.valueOf(value);
}
else
{
Object value = method.invoke(cfg);
return String.valueOf(value);
}
}
catch (Exception e)
{
if (debugEnabled())
{
debugCaught(DebugLogLevel.ERROR, e);
}
return "";
}
}
static
{
// Register the parameters that have JE property names.
try
{
registerProp("je.maxMemoryPercent", ATTR_DATABASE_CACHE_PERCENT);
registerProp("je.maxMemory", ATTR_DATABASE_CACHE_SIZE);
registerProp("je.cleaner.minUtilization", ATTR_CLEANER_MIN_UTILIZATION);
registerProp("je.env.runCleaner", ATTR_DATABASE_RUN_CLEANER);
registerProp("je.evictor.lruOnly", ATTR_EVICTOR_LRU_ONLY);
registerProp("je.evictor.nodesPerScan", ATTR_EVICTOR_NODES_PER_SCAN);
registerProp("je.log.fileMax", ATTR_DATABASE_LOG_FILE_MAX);
registerProp("java.util.logging.FileHandler.on",
ATTR_LOGGING_FILE_HANDLER_ON);
registerProp("java.util.logging.level", ATTR_LOGGING_LEVEL);
registerProp("je.checkpointer.bytesInterval",
ATTR_CHECKPOINTER_BYTES_INTERVAL);
registerProp("je.checkpointer.wakeupInterval",
ATTR_CHECKPOINTER_WAKEUP_INTERVAL);
registerProp("je.lock.nLockTables", ATTR_NUM_LOCK_TABLES);
registerProp("je.cleaner.threads", ATTR_NUM_CLEANER_THREADS);
}
catch (Exception e)
{
if (debugEnabled())
{
debugCaught(DebugLogLevel.ERROR, e);
}
}
}
/**
* Create a JE environment configuration with default values.
*
* @return A JE environment config containing default values.
*/
public static EnvironmentConfig defaultConfig()
{
EnvironmentConfig envConfig = new EnvironmentConfig();
envConfig.setTransactional(true);
envConfig.setAllowCreate(true);
// This property was introduced in JE 3.0. Shared latches are now used on
// all internal nodes of the b-tree, which increases concurrency for many
// operations.
envConfig.setConfigParam("je.env.sharedLatches", "true");
// This parameter was set to false while diagnosing a Sleepycat bug.
// Normally cleansed log files are deleted, but if this is set false
// they are instead renamed from .jdb to .del.
envConfig.setConfigParam("je.cleaner.expunge", "true");
return envConfig;
}
/**
* Parse a configuration associated with a JE environment and create an
* environment config from it.
*
* @param cfg The configuration to be parsed.
* @return An environment config instance corresponding to the config entry.
* @throws ConfigException If there is an error in the provided configuration
* entry.
*/
public static EnvironmentConfig parseConfigEntry(JEBackendCfg cfg)
throws ConfigException
{
EnvironmentConfig envConfig = defaultConfig();
// Handle the attributes that do not have a JE property.
envConfig.setTxnNoSync(cfg.isDatabaseTxnNoSync());
envConfig.setTxnWriteNoSync(cfg.isDatabaseTxnWriteNoSync());
// Iterate through the config attributes associated with a JE property.
for (Map.Entry<String, String> mapEntry : attrMap.entrySet())
{
String jeProperty = mapEntry.getKey();
String attrName = mapEntry.getValue();
String value = getPropertyValue(cfg, attrName);
envConfig.setConfigParam(jeProperty, value);
}
return envConfig;
}
}