/* * The contents of this file are subject to the terms of the Common Development and * Distribution License (the License). You may not use this file except in compliance with the * License. * * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the * specific language governing permission and limitations under the License. * * When distributing Covered Software, include this CDDL Header Notice in each file and include * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL * Header, with the fields enclosed by brackets [] replaced by your own identifying * information: "Portions Copyright [year] [name of copyright owner]". * * Copyright 2014-2015 ForgeRock AS. * Portions Copyright 2026 3A Systems, LLC. */ package org.opends.server.backends.pluggable.spi; import java.io.Closeable; import java.util.Set; import org.forgerock.opendj.config.server.ConfigException; import org.opends.server.types.BackupConfig; import org.opends.server.types.BackupDirectory; import org.opends.server.types.DirectoryException; import org.opends.server.types.RestoreConfig; /** * This interface abstracts the underlying storage engine, * isolating the pluggable backend generic code from a particular storage engine implementation. */ public interface Storage extends Closeable { /** * Starts the import operation. * @return a new Importer object which must be closed to release all resources * @throws ConfigException * if there is a problem with the configuration * @throws StorageRuntimeException * if a problem occurs with the underlying storage engine * @see #close() to release all resources once import is finished */ Importer startImport() throws ConfigException, StorageRuntimeException; /** * Opens the storage engine to allow executing operations on it. * * @param accessMode * Specify the access mode to this storage. * @throws NullPointerException * if accessMode is null. * @throws Exception * if a problem occurs with the underlying storage engine * @see #close() to release all resources once import is finished */ void open(AccessMode accessMode) throws Exception; /** * Executes a read operation. In case of a read operation rollback, implementations must propagate the failure * to the caller rather than replay the operation: unlike {@link WriteOperation}, a {@link ReadOperation} is 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. * * @param * type of the value returned * @param readOperation * the read operation to execute * @return the value read by the read operation * @throws Exception * if a problem occurs with the underlying storage engine */ T read(ReadOperation readOperation) throws Exception; /** * Executes a write operation. In case of a write operation rollback, implementations may replay the write * operation rather than propagate the failure: a {@link WriteOperation} is required to be idempotent for * exactly that reason. A replay must 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 instead of being retried forever. 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. * * @param writeOperation * the write operation to execute * @throws Exception * if a problem occurs with the underlying storage engine, including a conflict that outlasted the * replays the implementation makes */ void write(WriteOperation writeOperation) throws Exception; /** * Remove all files for a backend of this storage. * * @throws StorageRuntimeException if removal fails */ void removeStorageFiles() throws StorageRuntimeException; /** * Returns the current status of the storage. * * @return the current status of the storage */ StorageStatus getStorageStatus(); /** * Returns {@code true} if this storage supports backup and restore. * * @return {@code true} if this storage supports backup and restore. */ boolean supportsBackupAndRestore(); /** * Creates a backup for this storage. * * @param backupConfig * The configuration to use when performing the backup. * @throws DirectoryException * If a Directory Server error occurs. */ void createBackup(BackupConfig backupConfig) throws DirectoryException; /** * Removes a backup for this storage. * * @param backupDirectory * The backup directory structure with which the specified backup is * associated. * @param backupID * The backup ID for the backup to be removed. * @throws DirectoryException * If it is not possible to remove the specified backup. */ void removeBackup(BackupDirectory backupDirectory, String backupID) throws DirectoryException; /** * Restores a backup for this storage. * * @param restoreConfig * The configuration to use when performing the restore. * @throws DirectoryException * If a Directory Server error occurs. */ void restoreBackup(RestoreConfig restoreConfig) throws DirectoryException; /** * Lists the trees that exist in this storage. * * @return a set of {@link TreeName}s representing the trees that exist in this storage */ Set listTrees(); @Override void close(); }