Files
floci/docs/configuration/storage.md
T
Niels Kootstra a0cb86cc13 fix(cloudwatchlogs): journal log events instead of rewriting the store under persistent mode (#4187)
* perf(storage): append WAL batches once and skip compaction of an unchanged store

A putAll batch was N locked appends and N flushes; it is now one contiguous run of records and one flush. Compaction rewrote the snapshot on every tick even when nothing had changed since the last one, so an idle store kept rewriting its file; the store now tracks whether it changed and compaction returns early otherwise. Entries replayed from the log at load mark the store changed so the next compaction folds them in.

* fix(storage): recover from a corrupt WAL tail instead of failing boot

The replay reader trusted the signed length headers it read: a negative length threw IllegalArgumentException out of load() and failed the owning service at boot, and a length past the end of the file read to EOF. After any stop, the writer reopened behind the unreadable bytes, so every entry appended after a torn tail was lost on the next load until a compaction happened. Lengths are now bounded by the bytes left in the file, every framing or decode failure stops replay with a warning, and the unreadable tail is cut off before the writer reopens. An unreadable snapshot is quarantined to a .corrupt sibling like the other file-backed stores do, instead of being overwritten by the next compaction.

* fix(storage): journal append-heavy stores under persistent mode

PersistentStorage rewrites the whole store file on every mutation, so the cost of a write grows with the store. A store can now declare an APPEND_HEAVY write profile on StorageFactory.create; under persistent mode such a store is backed by WalStorage with the store's own JSON file as the snapshot and a .wal file next to it. The snapshot layout means an existing store file is picked up as the first snapshot and the file is current again after a clean shutdown, so no migration is needed in either direction. The other modes ignore the profile.

* fix(cloudwatchlogs): journal log events under persistent storage

Every PutLogEvents batch rewrote the whole cwlogs-events.json file under persistent mode, so the cost of one batch grew with the number of stored events. The events store now declares the APPEND_HEAVY write profile: a batch is appended to cwlogs-events.wal and the JSON file is rewritten on the WAL compaction interval and at shutdown. Groups, streams, filters and policies keep the file that is rewritten on every call.

Closes #2500

* docs(storage): describe journaled stores under persistent mode

Explain that CloudWatch Logs events are journaled to cwlogs-events.wal under persistent mode, that the compaction interval now governs that store too, and that the JSON file is current after a clean shutdown and up to one interval behind while running. Also corrects the documented CloudWatch Logs flush interval default from 5000 to 15000, which is what EmulatorConfig ships.

* docs(storage): describe journaled stores as append-heavy

The pages said the CloudWatch Logs event store only ever grows, but the 20,000-event cap, retention pruning and DeleteLogStream all remove events. What qualifies a store for journaling is its write pattern, which is what WriteProfile.APPEND_HEAVY says, so the pages now say that.
2026-09-23 00:08:45 -04:00

189 lines
7.8 KiB
Markdown

# Storage Modes
Floci supports four storage backends. You can set a global default and override it per service.
## Modes
| Mode | Data survives restart | Write performance | Use case |
|---|---|---|---|
| `memory` | No | Fastest | Unit tests, CI pipelines |
| `persistent` | Yes | Synchronous disk write on every change; append-heavy stores are journaled (see below) | Development with durable state |
| `hybrid` | Yes | In-memory reads, async flush to disk | General local development |
| `wal` | Yes | Append-only write-ahead log with compaction | High-write workloads |
## Global Configuration
| Variable | Default | Description |
|---|---|---|
| `FLOCI_STORAGE_MODE` | `memory` | Storage backend (`memory`, `persistent`, `hybrid`, `wal`) |
| `FLOCI_STORAGE_PERSISTENT_PATH` | `./data` | Base directory for all persistent data |
| `FLOCI_STORAGE_WAL_COMPACTION_INTERVAL_MS` | `30000` | WAL compaction interval (milliseconds) |
!!! note "Code default vs shipped default"
The Java `@WithDefault` for `storage.mode` is `hybrid`, but the published Docker image ships with `memory` set in `application.yml`. Running the stock image gives you `memory` unless you set `FLOCI_STORAGE_MODE`.
### Journaled stores under `persistent` mode
Most stores under `persistent` mode are rewritten in full on every change, which keeps the file
current after every call but makes the cost of one write grow with the size of the store.
Append-heavy stores are journaled instead: a change is appended to a `.wal` file next to the
store, and the store's JSON file is rewritten from memory on the `FLOCI_STORAGE_WAL_COMPACTION_INTERVAL_MS`
cadence and at shutdown, and only when something changed. Today this applies to CloudWatch Logs
events (`cwlogs-events.json` with `cwlogs-events.wal`). After a clean shutdown the JSON file holds
every event; while Floci runs it can be up to one compaction interval behind, and the journal is
replayed on the next start. An existing `cwlogs-events.json` from an older version is picked up as
the first snapshot without any migration.
## Per-Service Override
When not set for a service, it inherits `FLOCI_STORAGE_MODE`. Only override when you need different behavior for a specific service.
| Variable | Default | Description |
|---|---|---|
| `FLOCI_STORAGE_SERVICES_SSM_MODE` | global default | SSM storage mode |
| `FLOCI_STORAGE_SERVICES_SSM_FLUSH_INTERVAL_MS` | `5000` | SSM flush interval (ms) |
| `FLOCI_STORAGE_SERVICES_SQS_MODE` | global default | SQS storage mode |
| `FLOCI_STORAGE_SERVICES_S3_MODE` | global default | S3 storage mode |
| `FLOCI_STORAGE_SERVICES_DYNAMODB_MODE` | global default | DynamoDB storage mode |
| `FLOCI_STORAGE_SERVICES_DYNAMODB_FLUSH_INTERVAL_MS` | `5000` | DynamoDB flush interval (ms) |
| `FLOCI_STORAGE_SERVICES_SNS_MODE` | global default | SNS storage mode |
| `FLOCI_STORAGE_SERVICES_SNS_FLUSH_INTERVAL_MS` | `5000` | SNS flush interval (ms) |
| `FLOCI_STORAGE_SERVICES_LAMBDA_MODE` | global default | Lambda storage mode |
| `FLOCI_STORAGE_SERVICES_LAMBDA_FLUSH_INTERVAL_MS` | `5000` | Lambda flush interval (ms) |
| `FLOCI_STORAGE_SERVICES_CLOUDWATCHLOGS_MODE` | global default | CloudWatch Logs storage mode |
| `FLOCI_STORAGE_SERVICES_CLOUDWATCHLOGS_FLUSH_INTERVAL_MS` | `15000` | CloudWatch Logs flush interval (ms) |
| `FLOCI_STORAGE_SERVICES_CLOUDWATCHMETRICS_MODE` | global default | CloudWatch Metrics storage mode |
| `FLOCI_STORAGE_SERVICES_CLOUDWATCHMETRICS_FLUSH_INTERVAL_MS` | `5000` | CloudWatch Metrics flush interval (ms) |
| `FLOCI_STORAGE_SERVICES_SECRETSMANAGER_MODE` | global default | Secrets Manager storage mode |
| `FLOCI_STORAGE_SERVICES_SECRETSMANAGER_FLUSH_INTERVAL_MS` | `5000` | Secrets Manager flush interval (ms) |
| `FLOCI_STORAGE_SERVICES_ACM_MODE` | global default | ACM storage mode |
| `FLOCI_STORAGE_SERVICES_ACM_FLUSH_INTERVAL_MS` | `5000` | ACM flush interval (ms) |
| `FLOCI_STORAGE_SERVICES_APPSYNC_MODE` | global default | AppSync storage mode |
| `FLOCI_STORAGE_SERVICES_APPSYNC_FLUSH_INTERVAL_MS` | `5000` | AppSync flush interval (ms) |
| `FLOCI_STORAGE_SERVICES_OPENSEARCH_MODE` | global default | OpenSearch storage mode |
| `FLOCI_STORAGE_SERVICES_OPENSEARCH_FLUSH_INTERVAL_MS` | `5000` | OpenSearch flush interval (ms) |
| `FLOCI_STORAGE_SERVICES_RDS_MODE` | global default | RDS metadata storage mode (see note below) |
!!! note "RDS storage mode"
`FLOCI_STORAGE_SERVICES_RDS_MODE` controls Floci's own metadata persistence for RDS, not the
DB container volumes. In all modes, each DB instance or cluster gets a named Docker volume
(`floci-rds-{volumeId}`). In `memory` mode the volume is automatically removed when the
instance is deleted. In other modes the volume is retained unless
`FLOCI_STORAGE_PRUNE_VOLUMES_ON_DELETE=true`.
## Recommended Profiles
=== "Fast CI"
All in memory — fastest possible startup and test execution:
```bash
FLOCI_STORAGE_MODE=memory
```
=== "Local development"
Hybrid — survive restarts without slowing down writes:
```bash
FLOCI_STORAGE_MODE=hybrid
FLOCI_STORAGE_PERSISTENT_PATH=/app/data
```
Docker Compose:
```yaml
volumes:
- floci-data:/app/data
environment:
FLOCI_STORAGE_MODE: hybrid
FLOCI_STORAGE_PERSISTENT_PATH: /app/data
```
=== "Durable development"
Persistent — every write is immediately on disk:
```bash
FLOCI_STORAGE_MODE=persistent
FLOCI_STORAGE_PERSISTENT_PATH=/app/data
```
Docker Compose:
```yaml
volumes:
- floci-data:/app/data
environment:
FLOCI_STORAGE_MODE: persistent
FLOCI_STORAGE_PERSISTENT_PATH: /app/data
```
=== "Mixed"
Keep most services in memory, persist only DynamoDB and S3:
```bash
FLOCI_STORAGE_MODE=memory
FLOCI_STORAGE_SERVICES_DYNAMODB_MODE=persistent
FLOCI_STORAGE_SERVICES_S3_MODE=hybrid
FLOCI_STORAGE_PERSISTENT_PATH=/app/data
```
## Container Storage (RDS, OpenSearch, MSK, ECR)
Services that spawn Docker containers (RDS, OpenSearch, MSK, ECR registry) need a volume for their
data. Floci manages this automatically using **named Docker volumes** — no extra configuration
required.
### How it works
Each resource gets a `volumeId` (a 6-character hex string, e.g. `a1b2c3`) generated at creation
time and stored in the resource model. The container name and volume name both use this suffix:
```
floci-rds-a1b2c3 # RDS instance container and volume
floci-opensearch-b4c5d6 # OpenSearch domain container and volume
floci-msk-e7f8a9 # MSK cluster container and volume
floci-ecr-registry-data # ECR shared registry volume (singleton)
```
Volumes are labelled `floci=true` so you can manage them with standard Docker commands:
```bash
# List all Floci-managed volumes
docker volume ls --filter label=floci=true
# Remove all Floci-managed volumes (destructive)
docker volume prune --filter label=floci=true
```
### Volume lifecycle
By default volumes survive resource deletion, matching real AWS behavior.
| `FLOCI_STORAGE_MODE` | Volume on resource delete |
|---|---|
| `memory` | **Always removed** — memory mode implies no persistence across restarts |
| `persistent` / `hybrid` / `wal` | Retained (default) — remove with `FLOCI_STORAGE_PRUNE_VOLUMES_ON_DELETE=true` |
```bash
# Remove named volumes immediately when a resource is deleted (useful in CI with persistent mode)
FLOCI_STORAGE_PRUNE_VOLUMES_ON_DELETE=true
```
### Host-path mode (advanced)
Set `FLOCI_STORAGE_HOST_PERSISTENT_PATH` to an **absolute host path** to use bind mounts instead
of named volumes. This is only needed when you must access the container data directly from the
host filesystem.
```bash
FLOCI_STORAGE_HOST_PERSISTENT_PATH=/absolute/host/path/data
```
!!! warning
`FLOCI_STORAGE_HOST_PERSISTENT_PATH` must be an absolute path (starting with `/`). Volume
names and relative paths are not supported and will be silently ignored, falling back to
named-volume mode.