Background
T426469 investigated revert detection windows and recommended a 90-day bounded approach as a pragmatic middle ground. That design was implemented in T425729 as a two-tier schema:
Bounded tier (4 columns, always TRUE/FALSE): revision_is_identity_reverted_within_90_days revision_first_identity_reverting_revision_id_within_90_days revision_seconds_to_identity_revert_within_90_days revision_is_identity_revert_within_90_days Authoritative tier (4 columns, TRUE/NULL): revision_is_identity_reverted revision_first_identity_reverting_revision_id revision_seconds_to_identity_revert revision_is_identity_revert
In the current daily writer (MWHistoryDeltaWriter), *both* tiers are in fact 90-day bounded: the revert_seed CTE pulls only the last 90 days from the Iceberg target, so any revision whose first revert landed more than 90 days later is invisible to the writer entirely.
Problem
After team review, the 90-day-window design is being reconsidered for three reasons:
- Semantic confusion. The "90 days" in these fields is measured from rev_dt of the incoming event backward into the Iceberg target — not from event_timestamp, not from the ingestion date, and not comparable to the 90-day windows used in other MediaWiki metrics. Consumers cannot safely interpret these fields against other 90-day signals.
- Implementation complexity. Correctly computing the bounded and authoritative tiers in SQL requires a multi-CTE chain (revert_seed → revert_candidates → sha1_ranked → first_revert → revert_annotations) plus a separate back-patch MERGE that updates already-committed rows when a late-arriving revert comes in. The chain has subtle correctness requirements. This complexity has already surfaced multiple reviewer comments in Gerrit 1284858.
- Correctness gap remains. Even with the 90-day window the authoritative tier is not truly authoritative: it returns NULL (not TRUE) for reverts detected at > 90 days. The monthly MWHistorySnapshotMerger overwrites these fields correctly via the full Spark-based algorithm, but the daily rows can be wrong for weeks.
Proposed spike
Determine whether computing revert fields via a full-table unbounded SHA1 self-join on the Iceberg target is fast enough to be used in MWHistoryDeltaWriter for every daily run.
This would:
- Drop the four _within_90_days columns from the schema entirely
- Drop all 90-day window bounds from the revert CTE chain (revert_seed becomes a full-table scan; the authoritative fields become truly authoritative)
- Drop the back-patch MERGE (MERGE 2): with full history available in MERGE 1, the reverted base row is always present and annotatable in the same pass
- Retain the four authoritative revert columns, now populated by the same SHA1-rank logic as the monthly Spark run
Current table dimensions (T425729, April 2026)
- ~8.1 billion rows, ~540 GB
- Partitioned by (months(event_timestamp)) → ~300 partitions after compaction
- Daily delta writer currently runs in 5–10 min/day
Prior performance data point (T426469)
Simulated CTE-only unbounded SHA1 scan on enwiki + frwiki: 89 s and 62 s, respectively, versus ~54 s / 50 s for the 90-day window. That test was a standalone SELECT, not the full writer pipeline against the complete Iceberg table.
What to build
- Branch off user-events (six-MERGE MWHistoryDeltaWriter chain including page and user events).
- Remove the four _within_90_days columns from DDL, INSERT, UPDATE, and MWHistorySnapshotMerger projection.
- Replace the revert_seed 90-day filter with a full-table scan (no lower bound on event_timestamp).
- Remove the 90-day bounds inside revert_annotations for the authoritative tier.
- Remove the back-patch MERGE (MERGE 2) and its CTE (buildBackPatchCteSQL).
- Run the modified writer against production data for a representative high-edit day (e.g. a Wednesday in April 2026).
Metrics to collect
- Wall time for the daily delta run
- Bytes scanned at the Iceberg table
- Spark shuffle bytes and number of files opened (from Spark History Server)
- Resulting revert field values: spot-check 1000 incoming revision_ids against wmf.mediawiki_history for accuracy
Acceptance threshold
- Daily run completes in ≤ 1 hour
- Revert field accuracy matches wmf.mediawiki_history on the sample (within expected compound-revert gap)
Out of scope
- The rev_dt 90-day filter on incoming events (line 173 in buildIncomingSQL): this guards against page imports and admin operations with artificially old rev_dt and is independently motivated; evaluate separately
- The tags MERGE 90-day lower bound on the target: similarly motivated by partition pruning, not by revert semantics; evaluate separately
- Fixing compound-revert detection (known gap regardless of approach; monthly merger covers it)
References