mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Fabio Pistolesi
16.00.2015 1b91bc066c1e0ad77c05917c94d3fb28d6c729eb
opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/backends/persistit/PersistItStorage.java
@@ -784,9 +784,18 @@
  /** {@inheritDoc} */
  @Override
  public boolean isConfigurationChangeAcceptable(PersistitBackendCfg cfg, List<LocalizableMessage> unacceptableReasons)
  public boolean isConfigurationChangeAcceptable(PersistitBackendCfg newCfg,
      List<LocalizableMessage> unacceptableReasons)
  {
    return checkConfigurationDirectories(cfg, unacceptableReasons);
    long newSize = computeSize(newCfg);
    long oldSize = computeSize(config);
    return (newSize <= oldSize || memQuota.isMemoryAvailable(newSize - oldSize))
        && checkConfigurationDirectories(newCfg, unacceptableReasons);
  }
  private long computeSize(PersistitBackendCfg cfg)
  {
    return cfg.getDBCacheSize() > 0 ? cfg.getDBCacheSize() : memQuota.memPercentToBytes(cfg.getDBCachePercent());
  }
  /**
opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/core/BackendConfigManager.java
@@ -356,37 +356,36 @@
        }
      }
    }
    // See if the entry contains an attribute that specifies the class name
    // for the backend implementation.  If it does, then load it and make sure
    // that it's a valid backend implementation.  There is no such attribute,
    // the specified class cannot be loaded, or it does not contain a valid
    // backend implementation, then log an error and skip it.
    String className = configEntry.getJavaClass();
    try
    else if (configEntry.isEnabled())
    {
      Class<Backend<?>> backendClass = loadBackendClass(className);
      if (! Backend.class.isAssignableFrom(backendClass))
      /*
       * If the backend was not enabled, it has not been registered with directory server, so
       * no listeners will be registered at the lower layers. Verify as it was an add.
       */
      String className = configEntry.getJavaClass();
      try
      {
        unacceptableReason.add(ERR_CONFIG_BACKEND_CLASS_NOT_BACKEND.get(className, backendDN));
        return false;
      }
        Class<Backend<BackendCfg>> backendClass = loadBackendClass(className);
        if (! Backend.class.isAssignableFrom(backendClass))
        {
          unacceptableReason.add(ERR_CONFIG_BACKEND_CLASS_NOT_BACKEND.get(className, backendDN));
          return false;
        }
      Backend b = backendClass.newInstance();
      if (! b.isConfigurationAcceptable(configEntry, unacceptableReason, serverContext))
        Backend<BackendCfg> b = backendClass.newInstance();
        if (! b.isConfigurationAcceptable(configEntry, unacceptableReason, serverContext))
        {
          return false;
        }
      }
      catch (Exception e)
      {
        logger.traceException(e);
        unacceptableReason.add(
            ERR_CONFIG_BACKEND_CANNOT_INSTANTIATE.get(className, backendDN, stackTraceToSingleLineString(e)));
        return false;
      }
    }
    catch (Exception e)
    {
      logger.traceException(e);
      unacceptableReason.add(
          ERR_CONFIG_BACKEND_CANNOT_INSTANTIATE.get(className, backendDN, stackTraceToSingleLineString(e)));
      return false;
    }
    // If we've gotten to this point, then it is acceptable as far as we are
    // concerned.  If it is unacceptable according to the configuration for that
@@ -777,7 +776,7 @@
    // backend implementation, then log an error and skip it.
    String className = cfg.getJavaClass();
    Backend<?> backend;
    Backend<BackendCfg> backend;
    try
    {
      backend = loadBackendClass(className).newInstance();
@@ -900,9 +899,9 @@
  }
  @SuppressWarnings("unchecked")
  private Class<Backend<?>> loadBackendClass(String className) throws Exception
  private Class<Backend<BackendCfg>> loadBackendClass(String className) throws Exception
  {
    return (Class<Backend<?>>) DirectoryServer.loadClass(className);
    return (Class<Backend<BackendCfg>>) DirectoryServer.loadClass(className);
  }
  private WritabilityMode toWritabilityMode(BackendCfgDefn.WritabilityMode writabilityMode)
opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/core/MemoryQuota.java
@@ -41,8 +41,6 @@
 */
public final class MemoryQuota
{
  private static final double INIT_FUDGE_FACTOR = 0.9;
  private static final double FUDGE_FACTOR = 1.3;
  private static final long ONE_MEGABYTE = 1024 * 1024;
  private Semaphore reservedMemory;
@@ -55,7 +53,7 @@
  public MemoryQuota()
  {
    allowOvercommit = System.getProperty(ENABLE_MEMORY_OVERCOMMIT) != null;
    reservableMemory = (int)(INIT_FUDGE_FACTOR * (getOldGenInfo().getMax() / ONE_MEGABYTE));
    reservableMemory = (int)(Math.pow(Math.E / Math.PI, 2) * (getOldGenInfo().getMax() / ONE_MEGABYTE));
    reservedMemory = new Semaphore(reservableMemory, true);
  }
@@ -117,7 +115,7 @@
    {
      return true;
    }
    return reservedMemory.tryAcquire((int)(FUDGE_FACTOR * size / ONE_MEGABYTE));
    return reservedMemory.tryAcquire((int)(size / ONE_MEGABYTE));
  }
  /**
@@ -163,6 +161,6 @@
    {
      return;
    }
    reservedMemory.release((int)(FUDGE_FACTOR * size / ONE_MEGABYTE));
    reservedMemory.release((int)(size / ONE_MEGABYTE));
  }
}