fix(clickhouse): add opt-out for staging cleanup after QRep flow#4466
Merged
Conversation
PR #4200 (StagingStore abstraction) unified the avro upload and staging cleanup paths onto the staging store's real bucket prefix. As a side effect, CleanupQRepFlow now always deletes staging avro files once a ClickHouse snapshot/QRep flow completes. Previously cleanup keyed off config.StagingPath, which is empty for ClickHouse mirrors that don't set SnapshotStagingPath (they get their bucket from PEERDB_CLICKHOUSE_AWS_S3_BUCKET_NAME), so the prefix guard `strings.HasPrefix(stagingPath, "s3://")` was false and cleanup was a no-op. Staging avro files were effectively retained. Some deployments have downstream pipelines that consume those files, and the upgrade silently broke them by deleting the files as soon as the mirror completed. Keep cleanup as the default (it's the correct behavior and avoids unbounded staging growth), but add PEERDB_CLICKHOUSE_SKIP_STAGING_CLEANUP to opt out and retain staging artifacts. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
masterashu
approved these changes
Jun 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Restores the ability to retain ClickHouse staging avro files after a snapshot/QRep flow completes, addressing a silent behavior change introduced in #4200.
Background — the regression
#4200 (
StagingStoreabstraction) refactored the ClickHouse connector so avro upload and staging cleanup both key off the staging store's real bucket prefix (staging.KeyPrefix()). The PR was described as "zero behavior change" for the S3 path, but the cleanup path actually changed behavior:CleanupQRepFlowkeyed offconfig.StagingPath(=SnapshotStagingPath), guarded bystrings.HasPrefix(stagingPath, "s3://"). For ClickHouse mirrors,SnapshotStagingPathis typically empty (the bucket comes fromPEERDB_CLICKHOUSE_AWS_S3_BUCKET_NAME), so the guard was false and cleanup was a no-op — staging avro files were retained in the bucket.<staging-prefix>/<flowJobName>once the flow completes.Deployments that upgraded from 0.36.18 → 0.36.24 and had downstream pipelines consuming those staging avro artifacts saw the files disappear as soon as the mirror's snapshot completed.
Change
Cleanup remains the default — it is the correct behavior and avoids unbounded staging growth. This PR adds an opt-out:
PEERDB_CLICKHOUSE_SKIP_STAGING_CLEANUP(bool, defaultfalse).CleanupQRepFlowlogs and returns early without deleting staging objects.Notes
PEERDB_S3_UUID_PREFIXis enabled: upload keys become<prefix>/<uuid>/<flowJobName>/...while cleanup deletes<prefix>/<flowJobName>, so cleanup misses those objects. Out of scope here but worth tracking.Test plan
go build ./connectors/clickhouse/... ./internal/...go vet ./connectors/clickhouse/PEERDB_CLICKHOUSE_SKIP_STAGING_CLEANUP=trueand confirm staging avro files remain after completion; with default, confirm they are deleted.🤖 Generated with Claude Code