Commit 2019f86
fix(clickhouse): add opt-out for staging cleanup after QRep flow (PeerDB-io#4466)
## Summary
Restores the ability to retain ClickHouse staging avro files after a
snapshot/QRep flow completes, addressing a silent behavior change
introduced in PeerDB-io#4200.
## Background — the regression
PeerDB-io#4200 (`StagingStore` abstraction) 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:
- **Before:** `CleanupQRepFlow` keyed off `config.StagingPath` (=
`SnapshotStagingPath`), guarded by `strings.HasPrefix(stagingPath,
"s3://")`. For ClickHouse mirrors, `SnapshotStagingPath` is typically
empty (the bucket comes from `PEERDB_CLICKHOUSE_AWS_S3_BUCKET_NAME`), so
the guard was false and **cleanup was a no-op** — staging avro files
were retained in the bucket.
- **After:** cleanup keys off the same real prefix that uploads use, so
it now always deletes `<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:
- New dynconf setting `PEERDB_CLICKHOUSE_SKIP_STAGING_CLEANUP` (bool,
default `false`).
- When enabled, `CleanupQRepFlow` logs and returns early without
deleting staging objects.
## Notes
- The staging bucket is PeerDB-internal scratch space; relying on
retained files is fragile. The recommended long-term path for consuming
avro artifacts is a dedicated PG→S3 QRep mirror. This flag is an escape
hatch for affected deployments.
- Separately, there is a latent mismatch when `PEERDB_S3_UUID_PREFIX` is
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
- [x] `go build ./connectors/clickhouse/... ./internal/...`
- [x] `go vet ./connectors/clickhouse/`
- [ ] Manual: run a CH snapshot with
`PEERDB_CLICKHOUSE_SKIP_STAGING_CLEANUP=true` and confirm staging avro
files remain after completion; with default, confirm they are deleted.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 8d99a2a commit 2019f86
2 files changed
Lines changed: 25 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
47 | 59 | | |
48 | 60 | | |
49 | 61 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
201 | 210 | | |
202 | 211 | | |
203 | 212 | | |
| |||
758 | 767 | | |
759 | 768 | | |
760 | 769 | | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
761 | 774 | | |
762 | 775 | | |
763 | 776 | | |
| |||
0 commit comments