Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(data-warehouse): Handle compaction errors #29462

Merged
merged 1 commit into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions posthog/temporal/data_imports/deltalake_compaction_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@
from django.db import close_old_connections
from temporalio import activity, workflow
from temporalio.common import RetryPolicy
from posthog.exceptions_capture import capture_exception
from posthog.settings import TEST, DEBUG
from posthog.temporal.common.base import PostHogWorkflow
from posthog.temporal.common.heartbeat_sync import HeartbeaterSync
from posthog.temporal.common.client import sync_connect
from posthog.temporal.common.logger import bind_temporal_worker_logger_sync
from posthog.temporal.common.logger import FilteringBoundLogger, bind_temporal_worker_logger_sync
from posthog.temporal.data_imports.pipelines.pipeline.delta_table_helper import DeltaTableHelper
from posthog.warehouse.models import ExternalDataJob, ExternalDataSchema
from posthog.constants import DATA_WAREHOUSE_COMPACTION_TASK_QUEUE
from temporalio.exceptions import WorkflowAlreadyStartedError


def trigger_compaction_job(job: ExternalDataJob, schema: ExternalDataSchema) -> str:
def trigger_compaction_job(job: ExternalDataJob, schema: ExternalDataSchema, logger: FilteringBoundLogger) -> str:
temporal = sync_connect()
workflow_id = f"{schema.id}-compaction"

Expand All @@ -39,7 +40,11 @@ def trigger_compaction_job(job: ExternalDataJob, schema: ExternalDataSchema) ->

if not DEBUG and not TEST:
# Wait for the compaction to complete before continuing
asyncio.run(handle.result())
try:
asyncio.run(handle.result())
except Exception as e:
capture_exception(e)
logger.exception(f"Compaction job failed with: {e}", exc_info=e)
Comment on lines +45 to +47
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want to re-raise here? Otherwise this will return a workflow-id of a Workflow that failed. But it looks like we are only logging that ID so maybe it's better not to re-raise.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, we want to carry on the external data job as normal - we want to avoid compaction job errors making the external data job fail

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thank you!

except WorkflowAlreadyStartedError:
pass

Expand Down Expand Up @@ -80,7 +85,7 @@ async def run(self, inputs: DeltalakeCompactionJobWorkflowInputs):
await workflow.execute_activity(
run_compaction,
inputs,
start_to_close_timeout=dt.timedelta(minutes=5),
start_to_close_timeout=dt.timedelta(minutes=60),
retry_policy=RetryPolicy(
maximum_attempts=1,
),
Expand Down
4 changes: 1 addition & 3 deletions posthog/temporal/data_imports/pipelines/pipeline/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,8 @@ def _post_run_operations(self, row_count: int):
self._logger.debug("No deltalake table, not continuing with post-run ops")
return

self._logger.debug("SKIPPING deltatable compact and vacuuming")

self._logger.debug("Triggering workflow to compact and vacuum")
compaction_job_id = trigger_compaction_job(self._job, self._schema)
compaction_job_id = trigger_compaction_job(self._job, self._schema, self._logger)
self._logger.debug(f"Compaction workflow id: {compaction_job_id}")

file_uris = delta_table.file_uris()
Expand Down
Loading