Class PDBStorage
- java.lang.Object
-
- org.opends.server.backends.pdb.PDBStorage
-
- All Implemented Interfaces:
Closeable,AutoCloseable,ConfigurationChangeListener<PDBBackendCfg>,Backupable,DiskSpaceMonitorHandler,Storage
public final class PDBStorage extends Object implements Storage, Backupable, ConfigurationChangeListener<PDBBackendCfg>, DiskSpaceMonitorHandler
PersistIt database implementation of theStorageengine.
-
-
Constructor Summary
Constructors Constructor Description PDBStorage(PDBBackendCfg cfg, ServerContext serverContext)Creates a new persistit storage with the provided configuration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterRestore(Path restoreDirectory, Path saveDirectory)Called after the restore operation has finished successfully.ConfigChangeResultapplyConfigurationChange(PDBBackendCfg cfg)Applies the configuration changes to this change listener.PathbeforeRestore()Called before the restore operation begins.voidclose()voidcreateBackup(BackupConfig backupConfig)Creates a backup for this storage.voiddiskFullThresholdReached(File directory, long thresholdInBytes)Notifies that the registered "full" threshold have been reached.voiddiskLowThresholdReached(File directory, long thresholdInBytes)Notifies that the registered "low" threshold have been reached.voiddiskSpaceRestored(File directory, long lowThresholdInBytes, long fullThresholdInBytes)Notifies that the free disk space is now above both "low" and "full" thresholds.FilegetDirectory()Returns the directory which acts as the root of all files to backup and restore.ListIterator<Path>getFilesToBackup()Returns the files to backup.StorageStatusgetStorageStatus()Returns the current status of the storage.booleanisConfigurationChangeAcceptable(PDBBackendCfg newCfg, List<org.forgerock.i18n.LocalizableMessage> unacceptableReasons)Indicates whether the proposed change to the configuration is acceptable to this change listener.booleanisDirectRestore()Indicates if restore is done directly in the restore directory.Set<TreeName>listTrees()Lists the trees that exist in this storage.voidopen(AccessMode accessMode)Opens the storage engine to allow executing operations on it.<T> Tread(ReadOperation<T> operation)Executes a read operation.voidremoveBackup(BackupDirectory backupDirectory, String backupID)Removes a backup for this storage.voidremoveStorageFiles()Remove all files for a backend of this storage.voidrestoreBackup(RestoreConfig restoreConfig)Restores a backup for this storage.ImporterstartImport()Starts the import operation.booleansupportsBackupAndRestore()Returnstrueif this storage supports backup and restore.voidwrite(WriteOperation operation)Executes a write operation.
-
-
-
Constructor Detail
-
PDBStorage
public PDBStorage(PDBBackendCfg cfg, ServerContext serverContext) throws ConfigException
Creates a new persistit storage with the provided configuration.- Parameters:
cfg- The configuration.serverContext- This server instance context- Throws:
ConfigException- if memory cannot be reserved
-
-
Method Detail
-
close
public void close()
-
open
public void open(AccessMode accessMode) throws ConfigException, StorageRuntimeException
Description copied from interface:StorageOpens the storage engine to allow executing operations on it.- Specified by:
openin interfaceStorage- Parameters:
accessMode- Specify the access mode to this storage.- Throws:
ConfigExceptionStorageRuntimeException- See Also:
to release all resources once import is finished
-
read
public <T> T read(ReadOperation<T> operation) throws Exception
Description copied from interface:StorageExecutes a read operation. In case of a read operation rollback, implementations must propagate the failure to the caller rather than replay the operation: unlikeWriteOperation, aReadOperationis not required to be idempotent, and several of them are not - they write to a stream, print, or accumulate state that a second attempt would double.
-
startImport
public Importer startImport() throws ConfigException, StorageRuntimeException
Description copied from interface:StorageStarts the import operation.- Specified by:
startImportin interfaceStorage- Returns:
- a new Importer object which must be closed to release all resources
- Throws:
ConfigException- if there is a problem with the configurationStorageRuntimeException- if a problem occurs with the underlying storage engine- See Also:
to release all resources once import is finished
-
write
public void write(WriteOperation operation) throws Exception
Executes a write operation. In case of a write operation rollback, implementations may replay the write operation rather than propagate the failure: aWriteOperationis required to be idempotent for exactly that reason. A replay may be bounded - by a number of attempts, by a window of time, or by both - so that a conflict which does not clear reaches the caller, or may go on for as long as the conflict lasts, the way a writer of a lock based engine waits for a lock; an engine which resolves every conflict by a rollback should bound it by time only, since a healthy write under concurrent load loses several in a row. The pluggable backend holds locks across this method, up to the exclusive lock of an entry container, and every thread waiting on one of those locks waits for as long as this method does.A caller that mutates state around this method must handle that bound being spent. Removing an entry from an in-memory map before the write so that a replay still finds the work to do, or reading configuration back out of the operation once it returns, both assume the write is applied; when it is not, this method throws with that state already changed and the transaction not applied, and the caller is the only place that can reconcile the two.
A transaction the engine rolled back is replayed for as long as the
db-txn-retry-time-limitof the backend allows - without limit when it is 0, its default - except that the limit never ends the replays before one has been made. A rollback is how persistit resolves two transactions writing the same key, so a healthy write under concurrent load can lose several of them in a row: a count of attempts failed such writes (#1149), and the replays are bounded by time alone. Without a limit a write waits for its conflict to clear the way a JE writer waits for a lock. A limit is for the configuration change paths of the pluggable backend, which hold an entry container's exclusive lock across this method: every reader of that suffix then waits - untimed and uninterruptibly - until it returns.Once the limit is spent the conflict is reported as a
StorageRuntimeExceptionnaming the backend, the attempts spent, the time they took and the property whose value ran out. It carries the conflict as a suppressed exception rather than as its cause: a cause is unwrapped below and thrown in its place, andEntryContainer.throwAllowedExceptionTypeslikewise passes aStorageRuntimeExceptionthrough untouched only while it has no cause. Given a cause, both hand the caller a bare RollbackException instead, and the message of aStorageRuntimeExceptionwrapping one is just its class name - which is allERR_OPEN_ENV_FAILwould report when this happens as a backend starts.
-
supportsBackupAndRestore
public boolean supportsBackupAndRestore()
Description copied from interface:StorageReturnstrueif this storage supports backup and restore.- Specified by:
supportsBackupAndRestorein interfaceStorage- Returns:
trueif this storage supports backup and restore.
-
getDirectory
public File getDirectory()
Description copied from interface:BackupableReturns the directory which acts as the root of all files to backup and restore.- Specified by:
getDirectoryin interfaceBackupable- Returns:
- the root directory
-
getFilesToBackup
public ListIterator<Path> getFilesToBackup() throws DirectoryException
Description copied from interface:BackupableReturns the files to backup.- Specified by:
getFilesToBackupin interfaceBackupable- Returns:
- an iterator of files to backup, which may be empty but never
null - Throws:
DirectoryException- If an error occurs.
-
beforeRestore
public Path beforeRestore() throws DirectoryException
Description copied from interface:BackupableCalled before the restore operation begins.In case of direct restore, the backupable entity should take any action to save a copy of existing data before restore operation. Saving includes removing the existing data and copying it in a save directory.
- Specified by:
beforeRestorein interfaceBackupable- Returns:
- the directory where current files are saved. It may be
nullif not applicable. - Throws:
DirectoryException- If an error occurs.
-
isDirectRestore
public boolean isDirectRestore()
Description copied from interface:BackupableIndicates if restore is done directly in the restore directory.- Specified by:
isDirectRestorein interfaceBackupable- Returns:
trueif restore is done directly in the restore directory provided bygetDirectory()method, orfalseif restore is done in a temporary directory.
-
afterRestore
public void afterRestore(Path restoreDirectory, Path saveDirectory) throws DirectoryException
Description copied from interface:BackupableCalled after the restore operation has finished successfully.For direct restore, the backupable entity can safely discard the saved copy. For indirect restore, the backupable entity should switch the restored directory to the final restore directory.
- Specified by:
afterRestorein interfaceBackupable- Parameters:
restoreDirectory- The directory in which files have actually been restored. It is nevernull.saveDirectory- The directory in which current files have been saved. It may benullifbeforeRestore()returnednull.- Throws:
DirectoryException- If an error occurs.
-
createBackup
public void createBackup(BackupConfig backupConfig) throws DirectoryException
Description copied from interface:StorageCreates a backup for this storage.- Specified by:
createBackupin interfaceStorage- Parameters:
backupConfig- The configuration to use when performing the backup.- Throws:
DirectoryException- If a Directory Server error occurs.
-
removeBackup
public void removeBackup(BackupDirectory backupDirectory, String backupID) throws DirectoryException
Description copied from interface:StorageRemoves a backup for this storage.- Specified by:
removeBackupin interfaceStorage- Parameters:
backupDirectory- The backup directory structure with which the specified backup is associated.backupID- The backup ID for the backup to be removed.- Throws:
DirectoryException- If it is not possible to remove the specified backup.
-
restoreBackup
public void restoreBackup(RestoreConfig restoreConfig) throws DirectoryException
Description copied from interface:StorageRestores a backup for this storage.- Specified by:
restoreBackupin interfaceStorage- Parameters:
restoreConfig- The configuration to use when performing the restore.- Throws:
DirectoryException- If a Directory Server error occurs.
-
listTrees
public Set<TreeName> listTrees()
Description copied from interface:StorageLists the trees that exist in this storage.
-
isConfigurationChangeAcceptable
public boolean isConfigurationChangeAcceptable(PDBBackendCfg newCfg, List<org.forgerock.i18n.LocalizableMessage> unacceptableReasons)
Description copied from interface:ConfigurationChangeListenerIndicates whether the proposed change to the configuration is acceptable to this change listener.- Specified by:
isConfigurationChangeAcceptablein interfaceConfigurationChangeListener<PDBBackendCfg>- Parameters:
newCfg- The new configuration containing the changes.unacceptableReasons- A list that can be used to hold messages about why the provided configuration is not acceptable.- Returns:
- Returns
trueif the proposed change is acceptable, orfalseif it is not.
-
applyConfigurationChange
public ConfigChangeResult applyConfigurationChange(PDBBackendCfg cfg)
Description copied from interface:ConfigurationChangeListenerApplies the configuration changes to this change listener.- Specified by:
applyConfigurationChangein interfaceConfigurationChangeListener<PDBBackendCfg>- Parameters:
cfg- The new configuration containing the changes.- Returns:
- Returns information about the result of changing the configuration.
-
removeStorageFiles
public void removeStorageFiles() throws StorageRuntimeExceptionDescription copied from interface:StorageRemove all files for a backend of this storage.- Specified by:
removeStorageFilesin interfaceStorage- Throws:
StorageRuntimeException- if removal fails
-
getStorageStatus
public StorageStatus getStorageStatus()
Description copied from interface:StorageReturns the current status of the storage.- Specified by:
getStorageStatusin interfaceStorage- Returns:
- the current status of the storage
-
diskFullThresholdReached
public void diskFullThresholdReached(File directory, long thresholdInBytes)
Description copied from interface:DiskSpaceMonitorHandlerNotifies that the registered "full" threshold have been reached.- Specified by:
diskFullThresholdReachedin interfaceDiskSpaceMonitorHandler- Parameters:
directory- the directory for which the threshold has been triggeredthresholdInBytes- the threshold value in bytes
-
diskLowThresholdReached
public void diskLowThresholdReached(File directory, long thresholdInBytes)
Description copied from interface:DiskSpaceMonitorHandlerNotifies that the registered "low" threshold have been reached.- Specified by:
diskLowThresholdReachedin interfaceDiskSpaceMonitorHandler- Parameters:
directory- the directory for which the threshold has been triggeredthresholdInBytes- the threshold value in bytes
-
diskSpaceRestored
public void diskSpaceRestored(File directory, long lowThresholdInBytes, long fullThresholdInBytes)
Description copied from interface:DiskSpaceMonitorHandlerNotifies that the free disk space is now above both "low" and "full" thresholds.- Specified by:
diskSpaceRestoredin interfaceDiskSpaceMonitorHandler- Parameters:
directory- the directory for which the threshold has been triggeredTODOlowThresholdInBytes- the low threshold value in bytesfullThresholdInBytes- the full threshold value in bytes
-
-