Keep only a few failure samples in the encryption backfill

Merged
GF
20d ago
+38-11

Stacked on #3833 (which is stacked on #3190). The base branch stack/debug-log-entry-encryption is a copy of #3833's head. Please merge #3190 and #3833 first, then retarget this PR to main.

Follow-up to #4936, covering three review points that landed after it was merged.

Problem

  • security:backfill_encryption kept every failing row in memory, although the report shows only three per table. A dry run against a large table whose rows use other keys (the check the docs ask for before switching to your own keys) grew with the table and could run out of memory before printing its report.
  • The tests checked the JSON report but not the exit status, which the Docker guide relies on.
  • The previews in the Docker guide ran the task without a dry-run argument, so it read DRY_RUN from the container environment. With DRY_RUN=false set there, the preview wrote. If rows then failed and the operator removed the new keys as the guide says, rows the preview had already converted became unreadable.

Changes

  • The task counts every failure but keeps at most three samples per table.
  • run_backfill in the test keeps the exit status. The tests assert status 1 for a dry run and a real run with refused rows, and status 0 for a clean run.
  • A new test refuses five rows and checks failed_count 5 with three samples.
  • Both previews in docs/hosting/docker.md pass 1 as the dry-run argument, which takes precedence over the environment, and the steps ask to check for "dry_run":true in the report.

Tests

test/lib/tasks/security_backfill_test.rb and the encryption tests pass with keys; Rubocop is clean.

šŸ¤– Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Backfill results now count every failed row while showing up to three failure examples.
    • Backfill tasks now return a failure status when rows are refused, including during dry runs. Clean runs return a success status.