:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(data-warehouse): don't repartition a table pending a corruption revive (#71265)
Tom Owers3788060ea226
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/repartition_controller.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/repartition_controller.pyindex fe84ad508388..d011c2be697c 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/repartition_controller.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/repartition_controller.py@@ -147,6 +147,16 @@ async def maybe_flag_for_repartition(omitted it is evaluated lazily, only once the table is confirmed over budget."""try:+ # A table pending a corruption revive must heal before it's rewritten — flagging it here would+ # re-arm the revive loop after the heal clears the marker. Skip; the healed table is evaluated+ # normally on a later run.+ if schema.delta_revive_required is not None:+ await logger.adebug(+ f"repartition: skipped detection, table pending corruption revive schema_id={schema.id}",+ schema_id=str(schema.id),+ )+ return+partition_bytes = await asyncio.to_thread(measure_partition_bytes, delta_table)if not partition_bytes:await logger.adebug(diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/test_repartition_controller.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/test_repartition_controller.pyindex 62e25d4c9fb3..3e4611a29fa4 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/test_repartition_controller.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/test_repartition_controller.py@@ -238,6 +238,38 @@ class TestRepartitionOOMHistoryTrigger:else:assert schema.repartition_pending is None+ def test_pending_revive_skips_detection(self, team):+ # A table pending a corruption revive must not be flagged for repartition — the extract activity+ # heals it, and flagging here would re-arm the revive the moment the heal clears the marker.+ schema = _make_schema(+ team,+ {+ "partitioning_enabled": True,+ "partition_mode": "md5",+ "partition_count": 2,+ "partitioning_keys": ["id"],+ "delta_revive_required": {+ "reason": "repartition_scan_missing_data_file",+ "missing_path": "x/p.parquet",+ },+ },+ )+ for _ in range(3): # enough OOMs to flag a within-budget table if the revive guard weren't there+ ExternalDataSchemaOOMEvent.objects.for_team(schema.team_id).create(team_id=schema.team_id, schema=schema)++ with tempfile.TemporaryDirectory() as d:+ delta = _write_partitioned_delta(f"{d}/t", ["0", "1"])+ with (+ patch.object(ctrl, "target_partition_bytes", return_value=10**12),+ patch.object(ctrl, "repartition_oom_threshold", return_value=3),+ patch.object(ctrl, "is_auto_repartition_enabled", return_value=True),+ patch.object(ctrl, "capture_repartition_event"),+ ):+ self._detect(team, schema, delta)++ schema.refresh_from_db()+ assert schema.repartition_pending is None+# An Exception-derived cancellation, named exactly `CancelledError`: models how `async_to_sync` can# surface a worker-shutdown cancel so it slips past a plain BaseException catch. `_is_cancellation`@@ -282,6 +314,36 @@ class TestRepartitionActivity:mocked.assert_not_called()flag.assert_not_called()+ def test_noop_when_revive_pending(self, team):+ # A table pending a corruption revive skips the whole activity — no detection, no rewrite — even+ # with a repartition already queued, so it can't interleave with the extract's heal and re-arm+ # the non-billable revive loop.+ schema = _make_schema(+ team,+ {+ "repartition_pending": {+ "partition_mode": "md5",+ "partition_keys": ["id"],+ "trigger_reason": "oom_history",+ },+ "delta_revive_required": {+ "reason": "repartition_scan_missing_data_file",+ "missing_path": "x/p.parquet",+ },+ },+ )+ mocked = AsyncMock()+ with (+ patch.object(repartition_table, "HeartbeaterSync"),+ patch.object(repartition_table, "repartition_table_in_place", new=mocked),+ patch.object(repartition_table, "capture_repartition_event"),+ patch.object(repartition_table, "is_auto_repartition_enabled", return_value=True),+ patch.object(repartition_table, "maybe_flag_for_repartition") as flag,+ ):+ ActivityEnvironment().run(maybe_repartition_table_activity, self._inputs(team, schema))+ mocked.assert_not_called()+ flag.assert_not_called()+@pytest.mark.parametrize("recorded_max_partition_bytes", [None, 5])def test_pre_extraction_flags_over_budget_live_table(self, team, recorded_max_partition_bytes):# Nothing queued, flag on: the activity reads the LIVE on-disk size and repartitions when it'sdiff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/repartition_table.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/repartition_table.pyindex f65ce78291fe..de09b976cdea 100644--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/repartition_table.py+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/repartition_table.py@@ -196,6 +196,17 @@ def _maybe_repartition_table(inputs: RepartitionActivityInputs, logger: Filterin)return+ # A table with a pending corruption revive must heal first — the extract activity resets it and+ # rebuilds from source. Repartitioning it here would interleave with that heal and re-hollow the+ # table, re-arming the revive marker every run (a non-billable revive loop). Skip until the revive+ # clears the marker; the healed table is repartitioned normally on a later run.+ if schema.delta_revive_required is not None:+ logger.info(+ f"repartition: skipped, table pending corruption revive schema_id={schema.id}",+ schema_id=str(schema.id),+ )+ return+# Log the rollout-flag verdict (and the recorded/budget sizes) so it's clear from the Syncs UI why a# table does or doesn't repartition — a disabled flag is the most common reason for a no-op. Note# `max_partition_bytes` here is the last *recorded* value (can be stale); the gate no longer trusts