Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions deploy/helm/corvus/templates/compact.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ spec:
env:
{{- include "corvus.pgEnv" . | nindent 16 }}
{{- include "corvus.s3Env" . | nindent 16 }}
- name: CORVUS_LAKE_FORMAT
value: {{ .Values.lake.format | quote }}
{{- if eq .Values.lake.format "iceberg" }}
{{- include "corvus.lakeIcebergEnv" . | nindent 16 }}
{{- end }}
- name: CORVUS_COMPACT_BATCH_ROWS
value: {{ .Values.compact.batchRows | quote }}
- name: CORVUS_COMPACT_GRACE_S
Expand Down
9 changes: 9 additions & 0 deletions deploy/helm/corvus/templates/housekeeping.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ spec:
{{- include "corvus.pgEnv" . | nindent 16 }}
{{- include "corvus.s3Env" . | nindent 16 }}
{{- include "corvus.rawRetentionEnv" . | nindent 16 }}
- name: CORVUS_LAKE_FORMAT
value: {{ .Values.lake.format | quote }}
- name: CORVUS_LAKE_SNAPSHOT_RETENTION_DAYS
value: {{ .Values.lake.snapshotRetentionDays | quote }}
- name: CORVUS_LAKE_MAINTENANCE_ENABLED
value: {{ .Values.lake.maintenance.enabled | quote }}
{{- if eq .Values.lake.format "iceberg" }}
{{- include "corvus.lakeIcebergEnv" . | nindent 16 }}
{{- end }}
{{- include "corvus.extraEnv" .Values.housekeeping.env | nindent 16 }}
resources:
{{- toYaml .Values.housekeeping.resources | nindent 16 }}
Expand Down
13 changes: 13 additions & 0 deletions deploy/helm/corvus/tests/compact_refusal_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
suite: compaction refuses iceberg without its settings
templates:
- compact.yaml
tests:
- it: compaction refuses to render iceberg without a catalog uri
template: compact.yaml
set:
compact.enabled: true
lake.format: iceberg
asserts:
- failedTemplate:
errorMessage: lake.catalogUri is required when lake.format is iceberg

141 changes: 141 additions & 0 deletions deploy/helm/corvus/tests/lake_maintenance_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
suite: lake format of compaction and housekeeping
templates:
- compact.yaml
- housekeeping.yaml
tests:
- it: compaction keeps the parquet format by default and needs no catalog settings
template: compact.yaml
documentIndex: 0
asserts:
- contains:
path: spec.jobTemplate.spec.template.spec.containers[0].env
content:
name: CORVUS_LAKE_FORMAT
value: parquet
- notContains:
path: spec.jobTemplate.spec.template.spec.containers[0].env
content:
name: CORVUS_LAKE_CATALOG_URI
value: https://polaris.example.invalid/api/catalog

- it: compaction passes the iceberg settings and secrets when the format is iceberg
template: compact.yaml
documentIndex: 0
set:
lake.format: iceberg
lake.catalogUri: https://polaris.example.invalid/api/catalog
lake.oauth.tokenUrl: https://login.example.invalid/token
lake.oauth.scope: api://example/.default
lake.oauth.clientId: compact-client
lake.oauth.existingSecret: corvus-lake-oauth
lake.s3.endpointUrl: http://rook-ceph-rgw.example.invalid
lake.s3.existingSecret: corvus-lake-s3
asserts:
- contains:
path: spec.jobTemplate.spec.template.spec.containers[0].env
content:
name: CORVUS_LAKE_FORMAT
value: iceberg
- contains:
path: spec.jobTemplate.spec.template.spec.containers[0].env
content:
name: CORVUS_LAKE_CATALOG_URI
value: https://polaris.example.invalid/api/catalog
- contains:
path: spec.jobTemplate.spec.template.spec.containers[0].env
content:
name: CORVUS_LAKE_CLIENT_SECRET
valueFrom:
secretKeyRef:
name: corvus-lake-oauth
key: client-secret
- contains:
path: spec.jobTemplate.spec.template.spec.containers[0].env
content:
name: CORVUS_LAKE_S3_ACCESS_KEY
valueFrom:
secretKeyRef:
name: corvus-lake-s3
key: access-key

- it: housekeeping passes the snapshot retention and the format
template: housekeeping.yaml
documentIndex: 0
set:
lake.snapshotRetentionDays: 14
asserts:
- contains:
path: spec.jobTemplate.spec.template.spec.containers[0].env
content:
name: CORVUS_LAKE_SNAPSHOT_RETENTION_DAYS
value: "14"
- contains:
path: spec.jobTemplate.spec.template.spec.containers[0].env
content:
name: CORVUS_LAKE_FORMAT
value: parquet

- it: housekeeping passes the iceberg settings when the format is iceberg
template: housekeeping.yaml
documentIndex: 0
set:
lake.format: iceberg
lake.catalogUri: https://polaris.example.invalid/api/catalog
lake.oauth.tokenUrl: https://login.example.invalid/token
lake.oauth.scope: api://example/.default
lake.oauth.clientId: housekeeping-client
lake.oauth.existingSecret: corvus-lake-oauth
lake.s3.endpointUrl: http://rook-ceph-rgw.example.invalid
lake.s3.existingSecret: corvus-lake-s3
asserts:
- contains:
path: spec.jobTemplate.spec.template.spec.containers[0].env
content:
name: CORVUS_LAKE_CATALOG_URI
value: https://polaris.example.invalid/api/catalog
- contains:
path: spec.jobTemplate.spec.template.spec.containers[0].env
content:
name: CORVUS_LAKE_S3_SECRET_KEY
valueFrom:
secretKeyRef:
name: corvus-lake-s3
key: secret-key

- it: housekeeping refuses to render iceberg without a catalog uri
template: housekeeping.yaml
documentIndex: 0
set:
lake.format: iceberg
asserts:
- failedTemplate:
errorMessage: lake.catalogUri is required when lake.format is iceberg

- it: rejects a snapshot retention below one day in the schema
template: housekeeping.yaml
set:
lake.snapshotRetentionDays: 0
asserts:
- failedTemplate: {}

- it: housekeeping maintenance is off by default
template: housekeeping.yaml
documentIndex: 0
asserts:
- contains:
path: spec.jobTemplate.spec.template.spec.containers[0].env
content:
name: CORVUS_LAKE_MAINTENANCE_ENABLED
value: "false"

- it: housekeeping maintenance can be switched on
template: housekeeping.yaml
documentIndex: 0
set:
lake.maintenance.enabled: true
asserts:
- contains:
path: spec.jobTemplate.spec.template.spec.containers[0].env
content:
name: CORVUS_LAKE_MAINTENANCE_ENABLED
value: "true"
5 changes: 5 additions & 0 deletions deploy/helm/corvus/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@
"catalogUri": {"type": "string"},
"warehouse": {"type": "string", "minLength": 1},
"namespace": {"type": "string", "minLength": 1},
"snapshotRetentionDays": {"type": "integer", "minimum": 1},
"maintenance": {
"type": "object",
"properties": {"enabled": {"type": "boolean"}}
},
"oauth": {
"type": "object",
"properties": {
Expand Down
7 changes: 7 additions & 0 deletions deploy/helm/corvus/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ lake:
catalogUri: ""
warehouse: corvus
namespace: capture
# Iceberg snapshots older than this are expired by corvus-housekeeping (not while a branch or tag
# holds them). Expiry removes no rows. Read by housekeeping only.
snapshotRetentionDays: 7
# Routine Iceberg maintenance by housekeeping (snapshot expiry, orphan removal). Off: the platform's
# Airflow DAG iceberg_maintenance owns it. Only read with format iceberg.
maintenance:
enabled: false
oauth:
tokenUrl: ""
scope: ""
Expand Down
71 changes: 62 additions & 9 deletions docs/reference/data-lake.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ Settings: `CORVUS_LAKE_FORMAT` (`parquet` | `iceberg`); with `iceberg`, these ar
`CORVUS_LAKE_CLIENT_SECRET` (secret), `CORVUS_LAKE_S3_ENDPOINT_URL`, `CORVUS_LAKE_S3_ACCESS_KEY`,
`CORVUS_LAKE_S3_SECRET_KEY` (secret). Optional: `CORVUS_LAKE_WAREHOUSE` (`corvus`), `CORVUS_LAKE_NAMESPACE` (`capture`),
`CORVUS_LAKE_S3_REGION` (`us-east-1`). No further setting exists for the raw layout: it is the layout of this format.
`CORVUS_LAKE_SNAPSHOT_RETENTION_DAYS` (`7`, Helm `lake.snapshotRetentionDays`) is read by housekeeping only, and
`corvus-compact` and `corvus-housekeeping` read the same settings with `iceberg`.

### Privacy and retention

Expand All @@ -113,10 +115,12 @@ Settings: `CORVUS_LAKE_FORMAT` (`parquet` | `iceberg`); with `iceberg`, these ar
Ingest does not re-admit anything the plugin dropped.
* **Access** is only through the Polaris grants on the `capture` namespace. Data files live in the `polaris-corvus`
bucket and are reached through the catalog only; nothing copies `raw` out of the catalog.
* **Retention is permanent.** No housekeeping job expires Iceberg rows. The contents are reviewed once a year.
* **Erasure** of a player is planned as Iceberg row deletes (`player_key` below) in both tables, with immediate snapshot
expiry. That is a separate change. Until it lands, a completed erasure request (section 3) does not remove any Iceberg
row, because the Iceberg rows are not encrypted with the player's DEK.
* **Retention is permanent.** No housekeeping job deletes Iceberg rows (housekeeping expires snapshots only). The
contents are reviewed once a year.
* **Erasure** of a player removes the Iceberg rows by `player_key` (and by session for null-key orphans) in both
tables, then expires the older snapshots and removes their files; see *Erasure in Iceberg* in section 2a. A completed
erasure request in Iceberg mode means exactly that: the completion waits for the Iceberg step. The DEK deletion alone
does not count.
* **Player attribution** is the pseudonym (section 3's HMAC, 32 bytes, `player_key`), never the Mojang UUID or name.
Frames of orphan sessions (no `SessionStart` seen) have a null `player_key` and a null `protocol_version`. They cannot
be attributed to a player, so they cannot be erased by player either.
Expand Down Expand Up @@ -176,13 +180,55 @@ production and are not migrated: drop the table and let ingest recreate it.
The check uses the session cache (`CORVUS_SESSION_CACHE_TTL_S`, 60 s), so frames of a player erased less than that
time ago can still be written.

### Erasure in Iceberg

`corvus-compact` (section 7) handles the Iceberg tables when `CORVUS_LAKE_FORMAT=iceberg`, in the same run as the Parquet
files. Per erasure request, after the grace period:

1. delete the player's rows from `events` and from `raw`: first every row whose `player_key` is the pseudonym (one commit
per table), then the rows with a null `player_key` of the player's sessions (`corvus.sessions`, orphan frames), with
`IN` lists of 1000 session ids. pyiceberg 0.10 deletes copy-on-write (`Table.delete`): files with only erased rows are
dropped, mixed files are rewritten without them. Every delete commit is tagged in its snapshot summary with the
request id (`corvus.erasure-request`);
2. expire, per table, every snapshot older than the newest tagged snapshot (the cut). The cut and everything newer stay.
Expiry runs right after the delete, in the same run;
3. if a branch or tag points at one of the snapshots to expire, nothing is expired for that table. The request stays
pending with `lake_blocked_reason` set (the field of the erasure request in the API, `GET /api/v1/players/erasure/{id}`
and the list). The rows are gone from the current view already. The next run tries again, so the request
completes when the hold is released;
4. unless blocked, the files that only the expired snapshots named are deleted: manifest lists, manifests, data and
delete files of the expired snapshots (live and deleted entries) that no retained snapshot names. Nothing else is
touched. A file that no snapshot names (an in-flight write of another job, an orphan of a failed commit) is never
deleted by erasure, so this step needs no age margin. If this deletion fails, the request stays pending and the files
are left to the opt-in maintenance below.

Commit conflicts (an ingest append in between) retry the step with a fresh table load, at most 5 attempts with jittered
backoff, as in the sink. Other errors leave the request pending; the next run starts again (deletes are idempotent).

A request completes only when its Iceberg step finished without error and was not blocked. Dataset snapshots whose
manifest lists one of the sessions are marked `needs_rebuild` (`corvus.snapshot_state`, reason `erasure`), like the
snapshots with erased raw artefacts.

### Retention in Iceberg

* `raw` in Iceberg is kept, there is no time-based deletion of its rows: `CORVUS_RAW_RETENTION_DAYS` and pool retention
do not apply to it. Only an erasure removes Iceberg rows.
* **Routine maintenance is owned by the platform.** The Airflow DAG `iceberg_maintenance` (Spark: `rewrite_data_files`,
`expire_snapshots`, `remove_orphan_files`) runs nightly on `capture.events` and `capture.raw`. Corvus does not run a
second orphan remover by default. Helm `lake.maintenance.enabled` (`CORVUS_LAKE_MAINTENANCE_ENABLED`, default `false`)
switches on an opt-in variant in `corvus-housekeeping`: it expires snapshots older than
`CORVUS_LAKE_SNAPSHOT_RETENTION_DAYS` (7) and removes orphan files older than 24 h, so that a long rewrite of the DAG
is never cut. A snapshot is expired only when it is older than every branch and tag head. Expiry removes no rows.
Enable it only where the DAG does not run.
* Physical removal of erased files: erasure deletes them in the same run. If that step failed, the files stay until the
opt-in maintenance (24 h margin) or the DAG's orphan removal removes them.
* The Parquet `raw` files that exist from before the switch (`lake_files`) keep their retention until they are expired.

### Not covered yet

Each is a separate step: backfill of the existing Parquet files, erasure of Iceberg rows (row deletes by `player_key`,
then immediate snapshot expiry), snapshot pins by Iceberg snapshot id, and reading Iceberg `raw` in the ML jobs
(`corvus-ml` reads the Parquet `raw` layout only). Until those land, `corvus-compact` and `corvus-housekeeping` do not
see Iceberg data: erasure requests complete for the Parquet files only, and Iceberg `raw` is neither expired nor
rewritten.
Each is a separate step: backfill of the existing Parquet files into Iceberg, snapshot pins by Iceberg snapshot id,
reading Iceberg `raw` in the ML jobs (`corvus-ml` reads the Parquet `raw` layout only), and a re-check of an erasure
after its request completed (rows that land after the grace period are not seen again).

## 3. Keys and erasure

Expand Down Expand Up @@ -261,10 +307,17 @@ A file that lists an erased session without holding rows of it (typical for `raw
`lake_file_sessions` entry is removed. When every file of the requests is done, the requests get
`compaction_pending = false` and `compacted_at`. The job exits non-zero if any file failed.

Iceberg: with `CORVUS_LAKE_FORMAT=iceberg` the same run also erases the Iceberg rows and expires their snapshots; a
request completes only when that succeeded and is not blocked, see [Erasure in Iceberg](#erasure-in-iceberg).

Crash safety: until step 3 commits the old file stays the live one (an object copied but never registered is an orphan
that housekeeping removes after one hour); after it only `purge_pending` work remains, which every run retries first.
Repeating a run, or a repeated erasure of the same pseudonym, changes nothing.

Open points of the Iceberg step: the column statistics of the erased files stay in the manifest of the delete snapshot
(the cut) until the table's next commit (the rows do not). A new erasure request after the grace period is not verified
again once its request completed. Blocked requests are reported in the log and in the API only, there is no metric.

Snapshots are immutable and keep naming erased sessions and the file ids that compaction replaced. Jobs read a snapshot
through `GET /api/v1/snapshots/{id}/sessions?exclude_erased=true` (paged) and `GET /api/v1/snapshots/{id}/files`
(follows `replaced_by` to the live files; `raw` lists the live raw files, so a job does not scan partitions) instead of
Expand Down
4 changes: 4 additions & 0 deletions services/migrations/0008_iceberg_erasure.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Iceberg erasure (corvus-compact with CORVUS_LAKE_FORMAT=iceberg), see docs/reference/data-lake.md
-- section 2a. NULL: the request's rows are gone from the Iceberg tables. Set: the erasure is held
-- back (a branch or tag keeps a snapshot that still holds the rows); the request stays pending.
ALTER TABLE corvus.erasure_requests ADD COLUMN lake_blocked_reason text;
4 changes: 2 additions & 2 deletions services/src/corvus_services/api/pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,12 +614,12 @@ async def record_request(self, request: ErasureRequest) -> None:

_ERASURE_COLS = (
"id, pseudonym, requested_by, requested_at, status, player_known, key_deleted,"
" compaction_pending, compacted_at"
" compaction_pending, compacted_at, lake_blocked_reason"
)


def _erasure(r: tuple[Any, ...]) -> ErasureRequest:
return ErasureRequest(r[0], bytes(r[1]), r[2], r[3], r[4], r[5], r[6], r[7], r[8])
return ErasureRequest(r[0], bytes(r[1]), r[2], r[3], r[4], r[5], r[6], r[7], r[8], r[9])


class PgErasureStore:
Expand Down
3 changes: 3 additions & 0 deletions services/src/corvus_services/api/ports.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ class ErasureRequest:
key_deleted: bool
compaction_pending: bool
compacted_at: datetime | None = None
lake_blocked_reason: str | None = None
"""Set while the Iceberg rows of the request cannot be removed yet (a branch or tag holds a
snapshot that still contains them); the request stays pending until the hold is released."""


@dataclass(frozen=True)
Expand Down
10 changes: 8 additions & 2 deletions services/src/corvus_services/api/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ class SnapshotOut(BaseModel):
created_at: datetime
needs_rebuild: bool = Field(
default=False,
description="Erasure deleted the snapshot's raw-derived artefacts; rebuild the features",
description="Erasure removed rows of the snapshot's sessions or deleted its raw-derived "
"artefacts; rebuild the features",
)
manifest: dict[str, Any] | None = Field(
default=None, description="Present on the detail view only"
Expand Down Expand Up @@ -138,14 +139,19 @@ class ErasureOut(BaseModel):
key_deleted: bool
compaction_pending: bool
compacted_at: datetime | None = None
lake_blocked_reason: str | None = Field(
default=None,
description="Set while the Iceberg rows cannot be removed yet: a branch or tag keeps a "
"snapshot that still holds them. The request stays pending until the hold is released.",
)

@classmethod
def of(cls, r: ErasureRequest) -> ErasureOut:
return cls(
id=r.id, pseudonym=r.pseudonym.hex(), requested_by=r.requested_by,
requested_at=r.requested_at, status=r.status, player_known=r.player_known,
key_deleted=r.key_deleted, compaction_pending=r.compaction_pending,
compacted_at=r.compacted_at,
compacted_at=r.compacted_at, lake_blocked_reason=r.lake_blocked_reason,
) # fmt: skip


Expand Down
Loading
Loading