Skip to content

: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.

fix(data-imports): retry a concurrent delta-log purge in table size calc (#111238)

Tom Owers17f1bdf2f627
diff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/calculate_table_size.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/calculate_table_size.py
index 56eb1adc728e..69720775fd4b 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/calculate_table_size.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/calculate_table_size.py
@@ -115,20 +115,28 @@ def calculate_table_size_activity(inputs: CalculateTableSizeActivityInputs) -> N
total_mib = _live_delta_size_mib(_delta_table_uri(schema, table))
if total_mib is None:
total_mib = get_size_of_folder(s3_folder)
- except OSError as e:
+ except Exception as e:
+ import deltalake.exceptions # noqa: PLC0415 — keeps the heavy deltalake dep off this activity module's import path
+
+ if not isinstance(e, OSError | deltalake.exceptions.DeltaError):
+ raise
+
from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.delta.errors import ( # noqa: PLC0415 — keeps the heavy deltalake dep off this activity module's import path
TransientObjectStoreError,
+ is_transient_delta_maintenance_error,
is_transient_object_store_error,
)
- if not is_transient_object_store_error(e):
+ if not (is_transient_object_store_error(e) or is_transient_delta_maintenance_error(e)):
raise
# Covers this worker's own fd pressure (EMFILE/ENFILE, e.g. botocore loading a data file
- # while building the S3 client) and known-transient S3/object-store blips (IMDS/STS hiccups,
- # dropped connections) hit opening the Delta log (_live_delta_size_mib) or listing the query
- # folder (get_size_of_folder) — see is_transient_object_store_error. A retry recovers on its
- # own, so it shouldn't page anyone.
- logger.warning("Transient object-store error calculating table size in S3", exc_info=e)
+ # while building the S3 client), known-transient S3/object-store blips (IMDS/STS hiccups,
+ # dropped connections), and a concurrent reset/maintenance pass purging `_delta_log` out from
+ # under this read (is_transient_delta_maintenance_error, e.g. a full refresh racing this
+ # activity's own DeltaTable() open in _live_delta_size_mib) — all hit opening the Delta log
+ # or listing the query folder (get_size_of_folder). A retry recovers on its own, so it
+ # shouldn't page anyone.
+ logger.warning("Transient error calculating table size in S3", exc_info=e)
raise TransientObjectStoreError(str(e)) from e
logger.debug(f"Total size in MiB = {total_mib:.2f}")
diff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_calculate_table_size.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_calculate_table_size.py
index 7ad8af64efa5..36a35d03a50b 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_calculate_table_size.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_calculate_table_size.py
@@ -155,6 +155,48 @@ class TestCalculateTableSizeActivity:
CalculateTableSizeActivityInputs(team_id=team.id, schema_id=str(schema.id), job_id=str(job.id))
)
+ def test_reraises_a_concurrent_delta_log_purge_as_non_reportable(self, tmp_path: Path) -> None:
+ # A full refresh (or another maintenance pass) can purge a table's `_delta_log` out from
+ # under this activity's own DeltaTable() open in _live_delta_size_mib. delta-rs surfaces that
+ # race as a bare DeltaError ("Kernel error: File not found: .../_delta_log/<version>.json"),
+ # not the TableNotFoundError _live_delta_size_mib already handles.
+ team = _team()
+ schema, _table, job = _schema_table_job(
+ team, table_format="DeltaS3Wrapper", queryable_folder="stripe_charge__query_a"
+ )
+
+ with (
+ override_settings(BUCKET_URL=str(tmp_path)),
+ patch(f"{_DELTA_TABLE_MODULE}.delta_storage_options", return_value={}),
+ patch(
+ "deltalake.DeltaTable",
+ side_effect=deltalake.exceptions.DeltaError(
+ "Kernel error: File not found: dlt/team_1_postgres_test/properties/_delta_log/00000000000000000001.json"
+ ),
+ ),
+ ):
+ with pytest.raises(TransientObjectStoreError):
+ calculate_table_size_activity(
+ CalculateTableSizeActivityInputs(team_id=team.id, schema_id=str(schema.id), job_id=str(job.id))
+ )
+
+ def test_reraises_unrelated_delta_error(self, tmp_path: Path) -> None:
+ team = _team()
+ schema, _table, job = _schema_table_job(
+ team, table_format="DeltaS3Wrapper", queryable_folder="stripe_charge__query_a"
+ )
+
+ with (
+ override_settings(BUCKET_URL=str(tmp_path)),
+ patch(f"{_DELTA_TABLE_MODULE}.delta_storage_options", return_value={}),
+ patch("deltalake.DeltaTable", side_effect=deltalake.exceptions.DeltaError("Generic error: data corrupted")),
+ ):
+ with pytest.raises(deltalake.exceptions.DeltaError) as exc_info:
+ calculate_table_size_activity(
+ CalculateTableSizeActivityInputs(team_id=team.id, schema_id=str(schema.id), job_id=str(job.id))
+ )
+ assert not isinstance(exc_info.value, NonReportableError)
+
def test_reads_the_size_of_the_live_files_from_the_delta_log(self, tmp_path: Path) -> None:
# An S3 listing of the query folder pages through every object and takes minutes on a large
# table. The Delta log already carries the size of each live file, and the query folder holds