Object storage

Keep rendered snapshots and other blobs in S3 or Cloud Storage instead of Postgres, and move an install's blobs there without downtime.

Wardn keeps blobs in its object store: the rendered resources that snapshots are made of, and the screenshots agent jobs leave behind. A blob is named by the SHA-256 of its bytes and belongs to one organization. By default the object store is Postgres. On a large install the blobs become most of the database, so you can keep their bytes in a bucket instead:

WARDN_OBJECTSTORE_PROVIDERWhere the bytes areWhere the index and holds are
postgres (default)Rows in the core database, compressed with zstdThe same database
s3An S3 bucket, or any service that speaks the S3 API (MinIO, Ceph, Cloudflare R2)The core database
gcsA Google Cloud Storage bucketThe core database

The index stays in Postgres with every store. Which blobs exist, and which snapshots hold them, is decided in one database transaction, so a blob a snapshot holds is never deleted, however a cleanup races a new snapshot. The bucket holds bytes and nothing else. Wardn compresses blobs with zstd before writing them and checks every read against the blob's digest, so a damaged or swapped object is reported, never returned.

Set up a bucket

Make a bucket for Wardn, or a prefix in a bucket you already have. Turn off public access. Wardn needs these permissions on it:

s3:PutObject, s3:GetObject and s3:DeleteObject on the objects under the prefix, and s3:ListBucket on the bucket for the health check.

{
  "Version": "2012-10-17",
  "Statement": [
    { "Effect": "Allow", "Action": ["s3:PutObject", "s3:GetObject", "s3:DeleteObject"], "Resource": "arn:aws:s3:::wardn-blobs/prod/*" },
    { "Effect": "Allow", "Action": "s3:ListBucket", "Resource": "arn:aws:s3:::wardn-blobs" }
  ]
}

Credentials come from the AWS SDK's default chain: IRSA or EKS Pod Identity, the instance role, or the shared files. Set WARDN_OBJECTSTORE_S3_ACCESS_KEY_ID and WARDN_OBJECTSTORE_S3_SECRET_ACCESS_KEY only where none of those exists, such as with MinIO.

Then point Wardn at it. Every setting is in the configuration reference:

WARDN_OBJECTSTORE_S3_BUCKET=wardn-blobs
WARDN_OBJECTSTORE_S3_PREFIX=prod
WARDN_OBJECTSTORE_S3_REGION=eu-west-1

In the charts, set providers.objectstore and the objectStore block (every chart has it; see Helm chart values). A static key is named by the Secret that holds it, never written in the values file. Leave credentialsSecretRef out to use IRSA, Pod Identity or Workload Identity.

values.yaml
providers:
  objectstore: s3
objectStore:
  s3:
    bucket: wardn-blobs
    prefix: prod
    region: eu-west-1

The chart fails the render when providers.objectstore is s3 or gcs and its bucket is empty. objectStore.sweep.every and objectStore.sweep.grace set how often unheld blobs are swept and how old they must be (WARDN_OBJECTSTORE_SWEEP_EVERY, WARDN_OBJECTSTORE_SWEEP_GRACE).

On a new install, set WARDN_OBJECTSTORE_PROVIDER to s3 or gcs from the start, and you're done. On an install that already has blobs in Postgres, move them first, as below. A process on a bucket store refuses to start while a move to its bucket hasn't passed its checksum pass.

Move an install's blobs from Postgres

The move is online: Wardn keeps serving every read and write throughout, and nothing has to stop. It has three steps, each started from the wardn binary with the server's configuration plus the bucket settings above. Run them from a one-off pod or job that uses the server image and its Secret.

Copy and check

wardn objectstore move --to s3

This copies every blob that is still only in Postgres to the bucket. It then reads every copy back and checks it byte for byte against the stored blob and its digest. A copy that doesn't match is deleted and copied again. When every blob the copy found has passed, the move is verified:

s3://wardn-blobs/prod/: copied 5120 blobs (61440000 bytes), verified 5120, 0 failed their checksum and were copied again, dropped 0 inline; took 1m4s; move is verified

The servers keep running on the Postgres store meanwhile and keep writing new blobs there. Each run covers the blobs stored before it started, so it ends however busy the install is. Run move again whenever you like to catch up; finish takes the rest. If it stops partway (a crash, a lost connection, Ctrl-C), run it again: it resumes where it stopped, because each blob records its copy and its check.

Switch the servers

Set WARDN_OBJECTSTORE_PROVIDER=s3 (or gcs) with the bucket settings, and roll the servers out as usual. While the move is open, a server on the bucket store also writes each new blob to Postgres. Servers still on the Postgres store can then read what the new ones write, so the rollout can take as long as it needs.

Every server reads a blob's bytes from Postgres first, while they're still there, and from the bucket otherwise.

Finish

Once every server, worker and controller runs the bucket store:

wardn objectstore finish --to s3

This stops the extra writes to Postgres. It copies and checks what was written there since step 1, then drops the bytes from Postgres, but only for blobs whose copy passed the check. If any blob still has its bytes in Postgres at the end, finish stops with an error and the count, and you run it again. When nothing is left, the move is finished, and the space in Postgres is freed as autovacuum reclaims it.

Only one move or finish runs at a time; a second one is refused with objectstore.move_running until the first ends.

wardn objectstore status --to s3 shows the move's state and how many blobs still hold bytes in Postgres, how many of those aren't copied and how many aren't checked.

Run finish only after every process has switched. A process still on the Postgres store can't read a blob whose bytes are only in the bucket, and reports objectstore.moved instead. There is no move back from a bucket to Postgres.

Clean-up

A sweep removes blobs that nothing holds once they're older than a grace period. It deletes a blob's row and queues its object for deletion in the same transaction, then deletes the queued objects. A delete that fails stays queued for the next sweep. An upload that crashed before its row was written is queued too, and deleted once it's older than the sweep's grace period and at least an hour old, so a sweep never deletes an upload that is still finishing. So the bucket ends up holding only the objects the index names, and the objects of blobs swept during a move are cleaned up the same way.

Sweeps run by themselves, with every object store. Once an hour, one replica (the controller's leader) puts jobs on the work queue, one for each few dozen organizations and people, and the workers run them. A job removes blobs in batches of a thousand and stops after a bounded number of batches, so one place with a huge backlog is finished over several hours rather than holding a worker; running a sweep again, or two at once, only finds less to do. Blobs are removed when nothing holds them and they are older than WARDN_OBJECTSTORE_SWEEP_GRACE (24 hours, at least two hours). Storing bytes that an old, unheld blob already holds dates them afresh, so a blob that is needed again is never removed before whatever needs it records its hold. WARDN_OBJECTSTORE_SWEEP_EVERY sets the period, and 0 turns the schedule off.

The sweep counts what it does in wardn_blob_sweep_blobs_total, wardn_blob_sweep_bytes_total and wardn_blob_sweep_failures_total, and logs each place it removed something from.

Don't put a lifecycle rule on the prefix that expires objects: Wardn deletes what it no longer needs, and an object the index still names must stay.

Backups

With a bucket store, a backup is the database and the bucket. Restore them to the same point: an index row whose object is missing reads as damaged. Turn on versioning (S3) or object versioning or soft delete (Cloud Storage), so you can restore the bucket to the time of the database backup. See Backup and restore.

On this page