CodamAIDocs
Topicdone

Storage backends

Where the file contents live: local file system or volume, and applications without any file storage.

Variants
FILESYSTEM: local file system / volumeNONE: no file storagestartup check of the base directoryhealth checkrunning in a container

What this is about

CDMS does not store the content of files in the database, but in a file storage. Which one that is, is called the storage backend. You choose it in the hub on the system, field Storage:

  • FILESYSTEM: the contents live in a directory of the server, in a container on a mounted volume.
  • NONE: the application has no file storage.

A separate module brings the file storage into the application: cdms-localfs-storage. With NONE this module is missing.

The variants

Storage of the system

When: The application has file models.

  1. 1
    Build
    adds the module cdms-localfs-storage to the application
  2. 2
    Build
    the project scaffold writes codamai.cdms.persistence.file.basePath into the configuration, default /files/
  3. 3
    CDMS
    checks the base directory at startup
  4. 4
    CDMS→File storage
    stores contents under <basePath>/…/<fileId>

Result: See Storage layout and tenant isolation in storage.

When: The application needs no files.

  1. 1
    Build
    no file storage module, no base directory
  2. 2
    CDMS
    a request wants to write or read content
  3. 3
    CDMS→Client
    rejected, file-storage-not-configured

Result: File models make no sense here. They need the system to have a file storage.

See also The project scaffold.

Configuring the base directory

application.yaml
Request
codamai:
  cdms:
    persistence:
      file:
        basePath: ${CODAMAI_CDMS_PERSISTENCE_FILE_BASE_PATH:/files/}
In a container
env:
  - name: CODAMAI_CDMS_PERSISTENCE_FILE_BASE_PATH
    value: /data/files/
volumeMounts:
  - name: cdms-files
    mountPath: /data/files

You set the operating mode (SINGLE or MULTI) for the whole installation. It applies to database and file storage alike and decides whether tenants get directories of their own. See SINGLE and MULTI across both modules.

The check at startup

Startup of an application with FILESYSTEM
  1. CDMS
    Configured
    Is basePath set?
    ↳ no the application does not start
  2. CDMS
    Present
    Does the directory exist, and is it a directory?
    ↳ no the application does not start, the log names the path
  3. CDMS
    Writable
    May the application write there?
    ↳ no the application does not start, the log names the path
  4. Storage ready

CDMS deliberately does not create the base directory itself. If the volume were not mounted, the application would otherwise write into the container’s own file system and lose all files at the next restart, while the records stay in the database.

During operation

If the Actuator is included, the health check reports an entry storageRoot: writable as long as the base directory is writable, otherwise DOWN with the reason. That way a lost volume is noticed before users notice it.

Pitfalls

What comes next

Sources in the code and the knowledge base
  • CDMS/cdms-localfs-storage – FileProperties, FileStorageStartupCheck, FileStorageRoot, FileStorageHealthIndicator, LocalFSFileController; docs/05-configuration.md; docs/adr/ADR-001, ADR-008, ADR-020
  • CDMS/cdms-system-layer – AbstractLayer.fileStorage (file-storage-not-configured)
  • CDMS/cdms-scaffold – CdmsScaffoldService (storage FILESYSTEM/NONE, basePath, CODAMAI_CDMS_PERSISTENCE_FILE_BASE_PATH)
  • CDMS/cdms-commons – FileStorageControllerInterface (contract of the file storage)
Search