Skip to content

fix(k8s): prune superseded deces indices after a prod restore - #113

Merged
rhanka merged 1 commit into
mainfrom
fix/es-restore-prune
Oct 10, 2026
Merged

rhanka merged 1 commit into
mainfrom
fix/es-restore-prune

Conversation

@rhanka

@rhanka rhanka commented Oct 10, 2026

Copy link
Copy Markdown
Member

Why

Each prod restore creates deces-esdata_<dataprep>_<data> and moves the deces alias, but the superseded index was never deleted.

  • 2026-09-14: three full copies (45.5 GB) on the 59 GB volume. Together with the 6g heap, they left too little page cache for the live index (iowait 57-74 %, slow API). Pruned by hand.
  • 2026-10-10: the m09 restore left deces-esdata_44607e77_6c73c977 (15.2 GB) next to the live index.

What

prune_stale_indices() in overlays/prod/elasticsearch-restore.job.yaml deletes every deces-* index except the restore target and any index the deces alias still resolves to.

  • Runs after switch_alias, the live count check and write_marker; and on the "snapshot already live, skipping restore" path, so the next release clears copies left by restores that predate this change
  • Prunes nothing if the alias cannot be read
  • Best-effort: a failed DELETE is logged, the Job still succeeds
  • Each pruned index remains restorable from its S3 snapshot

Tests

  • deploy/k8s/tests/prod-restore-prune.sh (new, bash + awk, no Python/YAML parser): extracts the function from the rendered prod overlay and runs 7 scenarios against a stubbed Elasticsearch, plus checks both call sites
  • mutation-checked: dropping either call, deleting the target, ignoring the alias, dropping the empty-alias guard, or renaming the function each make it fail
  • deploy/k8s/tests/prod-manifest.sh asserts the function ships; passes

Every restore lands in a new deces-esdata_<dataprep>_<data> index and moves
the deces alias, but nothing removed the index it replaced. On 2026-09-14
three full copies (45.5 GB) sat on the 59 GB volume, cut the page cache left
for the live index and pushed iowait to 57-74 %; they were pruned by hand.
The 2026-10-10 restore left one more (deces-esdata_44607e77_6c73c977).

prune_stale_indices() deletes every deces-* index other than the target and
whatever the alias still resolves to:
- it runs right after the alias switch is verified and the marker written,
  and when the restore is skipped because the snapshot is already live, so a
  later release clears copies left by earlier restores
- it prunes nothing when the alias cannot be read
- it is best-effort: a failed delete is logged and does not fail the Job
- every pruned index stays recoverable from its S3 snapshot

prod-restore-prune.sh extracts the function from the rendered prod overlay
with awk (no YAML parser) and runs it against a stubbed Elasticsearch in 7
scenarios; it fails if either call site goes missing.
@coderabbitai

coderabbitai Bot commented Oct 10, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2f159688-98b0-4f1b-b967-ebc758e55740

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@rhanka
rhanka merged commit c2c146f into main Oct 10, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant