Package org.opencms.db.storage
Class CmsStorageManager
java.lang.Object
org.opencms.db.storage.CmsStorageManager
- All Implemented Interfaces:
AutoCloseable
Central coordinator of the OpenCms deduplicating media storage engine (DMSE).
The DMSE stores binary resource content in database, file system or S3-compatible backends, using SHA-512 content hashes for deduplication. Storage policies determine which contents remain in the regular VFS content columns and which are stored in a backend.
This manager evaluates policies, coordinates backend access and checks content references before deleting stored blobs.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classContainer for storage evaluation results, used by VFS drivers to determine which database columns to update. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCmsStorageManager(CmsSqlManager sqlManager, CmsParameterConfiguration configuration) Creates a new storage manager.CmsStorageManager(CmsSqlManager sqlManager, CmsParameterConfiguration configuration, CmsStoragePolicyConfiguration storagePolicyConfiguration) Creates a new storage manager. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes all configured storage backends.static CmsS3ClientConfigurationcreateS3ClientConfiguration(CmsParameterConfiguration configuration, String prefix) Creates an S3 client configuration from properties below the given prefix.static CmsS3ClientConfigurationcreateS3ClientConfiguration(CmsParameterConfiguration configuration, String backendId, String bucketOverride) Creates an S3 client configuration from a configured storage backend.voiddeleteContent(CmsDbContext dbc, String storage, String hash) Deletes content from external storage if it is no longer referenced in any content table.static StringgetActiveStorageId(CmsParameterConfiguration configuration) Returns the active storage backend id from the runtime property configuration.static StringgetActiveStorageType(CmsParameterConfiguration configuration) Returns the active storage backend type from the runtime property configuration.getDataStorageIds(CmsParameterConfiguration configuration) Returns the backend identifiers used for VFS data storage.getDeliveryStorage(String storage) Returns a delivery-capable storage backend by its stable storage identifier.static StringgetFileSystemStoragePath(CmsParameterConfiguration configuration, String storageId) Returns the configured file system repository path.getStorage(String storage) Returns a configured storage backend by its stable storage identifier.static StringgetStorageType(CmsParameterConfiguration configuration, String storageId) Returns the type for a configured storage backend.booleanisActiveStorage(String storage) Returns if the given stable storage identifier belongs to the active storage backend.byte[]loadContent(CmsDbContext dbc, byte[] contents, String storage, String hash) Loads the content either from the provided local bytes or from external storage.voidloadContentFrom(CmsDbContext dbc, byte[] contents, String storage, String hash, I_CmsFileContentStreamHandler handler) Loads content either from the provided local bytes or from external storage and passes it to an input stream handler.voidloadContentTo(CmsDbContext dbc, byte[] contents, String storage, String hash, OutputStream out) Loads content either from the provided local bytes or from external storage into an output stream.prepareContent(CmsDbContext dbc, CmsStoragePolicyContext context) Prepares content for storage by checking the policy and offloading to external storage if required.voidValidates all configured storage backends.
-
Field Details
-
PARAM_STORAGE_ACTIVE
Prefix for storage properties.- See Also:
-
PARAM_STORAGE_LEGACY
Prefix for the legacy storage list.- See Also:
-
PARAM_STORAGE_BACKEND_PREFIX
Prefix for backend-specific configuration.- See Also:
-
-
Constructor Details
-
CmsStorageManager
Creates a new storage manager.- Parameters:
sqlManager- the SQL managerconfiguration- the runtime property configuration
-
CmsStorageManager
public CmsStorageManager(CmsSqlManager sqlManager, CmsParameterConfiguration configuration, CmsStoragePolicyConfiguration storagePolicyConfiguration) Creates a new storage manager.- Parameters:
sqlManager- the SQL managerconfiguration- the runtime property configurationstoragePolicyConfiguration- the storage policy configuration
-
-
Method Details
-
createS3ClientConfiguration
public static CmsS3ClientConfiguration createS3ClientConfiguration(CmsParameterConfiguration configuration, String prefix) Creates an S3 client configuration from properties below the given prefix.- Parameters:
configuration- the runtime property configurationprefix- the property prefix, including its trailing dot- Returns:
- the S3 client configuration
-
createS3ClientConfiguration
public static CmsS3ClientConfiguration createS3ClientConfiguration(CmsParameterConfiguration configuration, String backendId, String bucketOverride) Creates an S3 client configuration from a configured storage backend.- Parameters:
configuration- the runtime property configurationbackendId- the configured storage backend id, ornullto use the active backendbucketOverride- the bucket override, ornullto use the backend bucket- Returns:
- the S3 client configuration
-
getActiveStorageId
Returns the active storage backend id from the runtime property configuration.- Parameters:
configuration- the runtime property configuration- Returns:
- the active storage backend id
-
getActiveStorageType
Returns the active storage backend type from the runtime property configuration.- Parameters:
configuration- the runtime property configuration- Returns:
- the active storage backend type
-
getDataStorageIds
Returns the backend identifiers used for VFS data storage.- Parameters:
configuration- the runtime property configuration- Returns:
- the active backend followed by all distinct legacy backends
-
getFileSystemStoragePath
public static String getFileSystemStoragePath(CmsParameterConfiguration configuration, String storageId) Returns the configured file system repository path.- Parameters:
configuration- the runtime property configurationstorageId- the storage backend id- Returns:
- the configured repository path
-
getStorageType
Returns the type for a configured storage backend.- Parameters:
configuration- the runtime property configurationstorageId- the storage backend id- Returns:
- the storage backend type
-
close
Closes all configured storage backends.- Specified by:
closein interfaceAutoCloseable- Throws:
Exception- if closing one or more storage backends fails
-
deleteContent
Deletes content from external storage if it is no longer referenced in any content table.- Parameters:
dbc- the database contextstorage- the stable storage identifier stored in the STORAGE columnhash- the hash of the content to delete
-
getDeliveryStorage
Returns a delivery-capable storage backend by its stable storage identifier.- Parameters:
storage- the stable storage identifier- Returns:
- the delivery-capable storage backend, or
nullif the backend does not support delivery - Throws:
CmsStorageException- if no backend is configured for the storage identifier
-
getStorage
Returns a configured storage backend by its stable storage identifier.- Parameters:
storage- the stable storage identifier- Returns:
- the configured storage backend, or null if no such backend is configured
-
isActiveStorage
Returns if the given stable storage identifier belongs to the active storage backend.- Parameters:
storage- the stable storage identifier- Returns:
trueif the storage identifier belongs to the active backend
-
loadContent
public byte[] loadContent(CmsDbContext dbc, byte[] contents, String storage, String hash) throws CmsStorageException Loads the content either from the provided local bytes or from external storage.- Parameters:
dbc- the database contextcontents- the local bytes (from FILE_CONTENT column)storage- the stable storage identifier stored in the STORAGE columnhash- the SHA-512 content hash stored in the HASH column- Returns:
- the raw bytes of the file
- Throws:
CmsStorageException- if external storage content can not be loaded
-
loadContentFrom
public void loadContentFrom(CmsDbContext dbc, byte[] contents, String storage, String hash, I_CmsFileContentStreamHandler handler) throws CmsStorageException Loads content either from the provided local bytes or from external storage and passes it to an input stream handler.- Parameters:
dbc- the database contextcontents- the local bytes (from FILE_CONTENT column)storage- the stable storage identifier stored in the STORAGE columnhash- the SHA-512 content hash stored in the HASH columnhandler- the stream handler- Throws:
CmsStorageException- if external storage content can not be loaded or handled
-
loadContentTo
public void loadContentTo(CmsDbContext dbc, byte[] contents, String storage, String hash, OutputStream out) throws CmsStorageException Loads content either from the provided local bytes or from external storage into an output stream.- Parameters:
dbc- the database contextcontents- the local bytes (from FILE_CONTENT column)storage- the stable storage identifier stored in the STORAGE columnhash- the SHA-512 content hash stored in the HASH columnout- the output stream to write to- Throws:
CmsStorageException- if external storage content can not be loaded or written
-
prepareContent
public CmsStorageManager.StorageResult prepareContent(CmsDbContext dbc, CmsStoragePolicyContext context) throws CmsDataAccessException Prepares content for storage by checking the policy and offloading to external storage if required.- Parameters:
dbc- the database contextcontext- the storage policy context- Returns:
- the storage result containing either the bytes or the hash
- Throws:
CmsDataAccessException- if storing required external content fails
-
validateStorages
Validates all configured storage backends.- Parameters:
dbc- the database context- Throws:
Exception- if a configured storage backend is not available
-