| File was renamed from opendj-server-legacy/src/main/java/org/opends/server/backends/persistit/PersistItStorage.java |
| | |
| | | * |
| | | * Copyright 2014-2015 ForgeRock AS |
| | | */ |
| | | package org.opends.server.backends.persistit; |
| | | package org.opends.server.backends.pdb; |
| | | |
| | | import static com.persistit.Transaction.CommitPolicy.*; |
| | | import static java.util.Arrays.*; |
| | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.util.Reject; |
| | | import org.opends.server.admin.server.ConfigurationChangeListener; |
| | | import org.opends.server.admin.std.server.PersistitBackendCfg; |
| | | import org.opends.server.admin.std.server.PDBBackendCfg; |
| | | import org.opends.server.api.Backupable; |
| | | import org.opends.server.api.DiskSpaceMonitorHandler; |
| | | import org.opends.server.backends.pluggable.spi.Cursor; |
| | |
| | | |
| | | /** PersistIt database implementation of the {@link Storage} engine. */ |
| | | @SuppressWarnings("javadoc") |
| | | public final class PersistItStorage implements Storage, Backupable, ConfigurationChangeListener<PersistitBackendCfg>, |
| | | public final class PDBStorage implements Storage, Backupable, ConfigurationChangeListener<PDBBackendCfg>, |
| | | DiskSpaceMonitorHandler |
| | | { |
| | | private static final String VOLUME_NAME = "dj"; |
| | |
| | | } |
| | | map.clear(); |
| | | } |
| | | PersistItStorage.this.close(); |
| | | PDBStorage.this.close(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | private final File backendDirectory; |
| | | private Persistit db; |
| | | private Volume volume; |
| | | private PersistitBackendCfg config; |
| | | private PDBBackendCfg config; |
| | | private DiskSpaceMonitor diskMonitor; |
| | | private MemoryQuota memQuota; |
| | | private StorageStatus storageStatus = StorageStatus.working(); |
| | |
| | | * @throws ConfigException if memory cannot be reserved |
| | | */ |
| | | // FIXME: should be package private once importer is decoupled. |
| | | public PersistItStorage(final PersistitBackendCfg cfg, ServerContext serverContext) throws ConfigException |
| | | public PDBStorage(final PDBBackendCfg cfg, ServerContext serverContext) throws ConfigException |
| | | { |
| | | this.serverContext = serverContext; |
| | | backendDirectory = new File(getFileForPath(cfg.getDBDirectory()), cfg.getBackendId()); |
| | | config = cfg; |
| | | cfg.addPersistitChangeListener(this); |
| | | cfg.addPDBChangeListener(this); |
| | | } |
| | | |
| | | private Configuration buildConfiguration(AccessMode accessMode) |
| | |
| | | { |
| | | memQuota.releaseMemory(memQuota.memPercentToBytes(config.getDBCachePercent())); |
| | | } |
| | | config.removePersistitChangeListener(this); |
| | | config.removePDBChangeListener(this); |
| | | diskMonitor.deregisterMonitoredDirectory(getDirectory(), this); |
| | | } |
| | | |
| | |
| | | |
| | | final long bufferCount = getBufferPoolCfg(dbCfg).computeBufferCount(db.getAvailableHeap()); |
| | | final long totalSize = bufferCount * BUFFER_SIZE / 1024; |
| | | logger.info(NOTE_PERSISTIT_MEMORY_CFG, config.getBackendId(), bufferCount, BUFFER_SIZE, totalSize); |
| | | logger.info(NOTE_PDB_MEMORY_CFG, config.getBackendId(), bufferCount, BUFFER_SIZE, totalSize); |
| | | |
| | | db.initialize(); |
| | | volume = db.loadVolume(VOLUME_NAME); |
| | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isConfigurationChangeAcceptable(PersistitBackendCfg newCfg, |
| | | public boolean isConfigurationChangeAcceptable(PDBBackendCfg newCfg, |
| | | List<LocalizableMessage> unacceptableReasons) |
| | | { |
| | | long newSize = computeSize(newCfg); |
| | |
| | | && checkConfigurationDirectories(newCfg, unacceptableReasons); |
| | | } |
| | | |
| | | private long computeSize(PersistitBackendCfg cfg) |
| | | private long computeSize(PDBBackendCfg cfg) |
| | | { |
| | | return cfg.getDBCacheSize() > 0 ? cfg.getDBCacheSize() : memQuota.memPercentToBytes(cfg.getDBCachePercent()); |
| | | } |
| | |
| | | * @param context TODO |
| | | * @return true if newly created backend has a valid configuration |
| | | */ |
| | | static boolean isConfigurationAcceptable(PersistitBackendCfg cfg, List<LocalizableMessage> unacceptableReasons, |
| | | static boolean isConfigurationAcceptable(PDBBackendCfg cfg, List<LocalizableMessage> unacceptableReasons, |
| | | ServerContext context) |
| | | { |
| | | if (context != null) |
| | |
| | | return checkConfigurationDirectories(cfg, unacceptableReasons); |
| | | } |
| | | |
| | | private static boolean checkConfigurationDirectories(PersistitBackendCfg cfg, |
| | | private static boolean checkConfigurationDirectories(PDBBackendCfg cfg, |
| | | List<LocalizableMessage> unacceptableReasons) |
| | | { |
| | | final ConfigChangeResult ccr = new ConfigChangeResult(); |
| | |
| | | * @param ccr the current list of change results |
| | | * @throws forwards a file exception |
| | | */ |
| | | private static void checkDBDirPermissions(PersistitBackendCfg cfg, ConfigChangeResult ccr) |
| | | private static void checkDBDirPermissions(PDBBackendCfg cfg, ConfigChangeResult ccr) |
| | | { |
| | | try |
| | | { |
| | |
| | | * @param backendDir the directory to setup |
| | | * @param curCfg a backend configuration |
| | | */ |
| | | private void setDBDirPermissions(PersistitBackendCfg curCfg, File backendDir) throws ConfigException |
| | | private void setDBDirPermissions(PDBBackendCfg curCfg, File backendDir) throws ConfigException |
| | | { |
| | | FilePermission backendPermission = decodeDBDirPermissions(curCfg); |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | private static FilePermission decodeDBDirPermissions(PersistitBackendCfg curCfg) throws ConfigException |
| | | private static FilePermission decodeDBDirPermissions(PDBBackendCfg curCfg) throws ConfigException |
| | | { |
| | | try |
| | | { |
| | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public ConfigChangeResult applyConfigurationChange(PersistitBackendCfg cfg) |
| | | public ConfigChangeResult applyConfigurationChange(PDBBackendCfg cfg) |
| | | { |
| | | final ConfigChangeResult ccr = new ConfigChangeResult(); |
| | | |