: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 re-trigger OOM repartition a rewrite already fixed (#71116)
Tom Owerse949c3f3458f
diff --git a/products/warehouse_sources/backend/models/oom_event.py b/products/warehouse_sources/backend/models/oom_event.pyindex ef1356190003..e4be544495f8 100644--- a/products/warehouse_sources/backend/models/oom_event.py+++ b/products/warehouse_sources/backend/models/oom_event.py@@ -4,6 +4,8 @@ from typing import TYPE_CHECKINGfrom django.db import modelsfrom django.utils import timezone+from dateutil import parser+from posthog.models.scoping.root_mixin import TeamScopedRootMixinfrom posthog.models.utils import UUIDModel, sane_repr@@ -51,6 +53,16 @@ class ExternalDataSchemaOOMEvent(TeamScopedRootMixin, UUIDModel):`days` is required (no default) so it stays sourced from `DATA_WAREHOUSE_REPARTITION_OOM_WINDOW_DAYS`at the call site rather than duplicating that window here where the two could silently diverge.++ The window is also floored at the schema's `last_repartition_at`: a completed repartition addresses+ the OOMs that preceded it, so counting them again would re-trigger a repartition on the same (now+ healthy) table every cooldown until they age out. Only OOMs a repartition did not fix count."""since = timezone.now() - timedelta(days=days)+ last_repartition_at = schema.last_repartition_at+ if last_repartition_at:+ try:+ since = max(since, parser.parse(last_repartition_at))+ except (ValueError, TypeError):+ passreturn cls.objects.for_team(schema.team_id).filter(schema_id=schema.pk, created_at__gte=since).count()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 b03cef3ecf25..07fc821a3de7 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@@ -208,9 +208,11 @@ async def maybe_flag_for_repartition(if schema.repartition_pending is not None:await logger.adebug(- f"repartition: over budget but already queued for the next run schema_id={schema.id} "- f"max_partition_bytes={max_bytes} budget_bytes={budget} repartition_pending={schema.repartition_pending}",+ f"repartition: needs repartition (trigger_reason={trigger_reason}) but already queued for the next "+ f"run schema_id={schema.id} max_partition_bytes={max_bytes} budget_bytes={budget} "+ f"repartition_pending={schema.repartition_pending}",schema_id=str(schema.id),+ trigger_reason=trigger_reason,max_partition_bytes=max_bytes,budget_bytes=budget,repartition_pending=schema.repartition_pending,@@ -220,10 +222,11 @@ async def maybe_flag_for_repartition(cooldown_remaining = _cooldown_seconds_remaining(schema)if cooldown_remaining > 0:await logger.adebug(- f"repartition: over budget but skipped, in post-repartition cooldown schema_id={schema.id} "- f"max_partition_bytes={max_bytes} budget_bytes={budget} last_repartition_at={schema.last_repartition_at} "- f"cooldown_seconds_remaining={int(cooldown_remaining)}",+ f"repartition: needs repartition (trigger_reason={trigger_reason}) but skipped, in post-repartition "+ f"cooldown schema_id={schema.id} max_partition_bytes={max_bytes} budget_bytes={budget} "+ f"last_repartition_at={schema.last_repartition_at} cooldown_seconds_remaining={int(cooldown_remaining)}",schema_id=str(schema.id),+ trigger_reason=trigger_reason,max_partition_bytes=max_bytes,budget_bytes=budget,last_repartition_at=schema.last_repartition_at,diff --git a/products/warehouse_sources/backend/tests/test_models.py b/products/warehouse_sources/backend/tests/test_models.pyindex 95c811e60087..927dd976e7f1 100644--- a/products/warehouse_sources/backend/tests/test_models.py+++ b/products/warehouse_sources/backend/tests/test_models.py@@ -234,6 +234,27 @@ class TestExternalDataSchemaOOMEvent(BaseTest):assert ExternalDataSchemaOOMEvent.recent_count(schema_a, days=30) == 3assert ExternalDataSchemaOOMEvent.recent_count(schema_b, days=7) == 1+ def test_recent_count_ignores_ooms_before_last_repartition(self) -> None:+ # A repartition fixes the OOMs that preceded it. Without this floor, those OOMs keep counting+ # and re-trigger a repartition on the same healthy table every cooldown until they age out.+ schema = self._schema("orders")+ self._oom(schema, age_days=2)+ self._oom(schema, age_days=2)+ self._oom(schema, age_days=2)+ schema.sync_type_config = {+ **(schema.sync_type_config or {}),+ "last_repartition_at": (timezone.now() - timedelta(days=1)).isoformat(),+ }+ schema.save()++ # All three OOMs predate the repartition, so none count toward re-triggering it.+ assert ExternalDataSchemaOOMEvent.recent_count(schema, days=7) == 0++ # An OOM recorded after the repartition still counts: the rewrite did not fix it, so this is a+ # real escalation the controller should act on.+ self._oom(schema)+ assert ExternalDataSchemaOOMEvent.recent_count(schema, days=7) == 1+class TestUpdateSyncTypeConfigKeys(BaseTest):"""The locked-merge helper that keeps the CDC extract activity and concurrent API PATCHes from