Repository navigation
Fix MergeTreeDeduplicationLog losing the active log and leaving phantom blobs - #121670
Merged
Merged
Conversation
…ntom blobs
- `dropOutdatedLogs` had an off-by-one: once the sum of entries reached the
deduplication window, it dropped "all older files, including current", so
the active log that the writer still appends to could be removed. Never drop
the current log, and count its entries towards the window.
- The appending writer for an unfinished log was opened eagerly in `load` and
`setDeduplicationWindowSize`. On object storage, finalizing an empty
`WriteMode::Append` buffer registers a blob in the file's metadata without
uploading any object, so every `DETACH`/`ATTACH` cycle without inserts in
between added one phantom blob, and the next load failed with `NoSuchKey`
("Error while loading MergeTree deduplication log"). Open the writer lazily
in `prepareToWrite` on the first written record.
- `sync` the writer after finalizing it in `shutdown`.
Split out of #96130
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Contributor
|
Workflow [PR], commit [d4c8257] Summary: ✅
AI ReviewSummaryThis PR fixes Tests
Final Verdict
LLVM Coverage ReportMeasured on commit d4c8257.
Changed lines: Changed C/C++ lines covered: 25/26 (96.15%) · Uncovered code |
alexey-milovidov
left a comment
Member
Author
There was a problem hiding this comment.
The changes LGTM.
This was referenced Sep 25, 2026
wickdChromosome
pushed a commit
to wickdChromosome/ClickHouse
that referenced
this pull request
Sep 26, 2026
… SETTING` ClickHouse#121670 stopped `MergeTreeDeduplicationLog::setDeduplicationWindowSize` from opening an appending writer for the unfinished log eagerly, but its test only covered the `load` path. Toggle `non_replicated_deduplication_window` on `s3_disk` without inserts between the toggles, with `DETACH`/`ATTACH` after each one. Verified locally against MinIO: a binary without the fix logs "Error while loading MergeTree deduplication log" (`NoSuchKey`) on both reattaches after the `ALTER`, a binary with the fix logs none. Related: ClickHouse#121670 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This was referenced Oct 28, 2026
alexey-milovidov
pushed a commit
to melvynator/ClickHouse
that referenced
this pull request
Nov 10, 2026
A file on an object-storage disk with local metadata can list an object of size 0 whose key was never uploaded: an empty append records one (StripeLog `INSERT ... SELECT ... LIMIT 0` on every release since 25.3, MergeTreeDeduplicationLog before ClickHouse#121670). `initialize` never selects such an object, but the sequential walk does: when the current object ends, `moveToNextBuffer` builds a reader for the next one whatever its size, and for a 0-byte object that is an open-ended GET of a missing key (S3_ERROR NoSuchKey), or, when the reader returns no bytes (filesystem cache, Azure), `nextImpl`'s single move + read ends the read early (ATTEMPT_TO_READ_AFTER_EOF, CANNOT_READ_ALL_DATA). The walk is reached by a sequential read across the object boundary (`max_threads = 1`, BACKUP), by the gather's own short forward seek (`remote_filesystem_read_method = 'read'`), and since ClickHouse#100763 by the default threadpool path, whose bounded `AsynchronousBoundedReadBuffer` turns the seek between StripeLog blocks into bytes to ignore. So a StripeLog table on S3 with an empty INSERT in the middle cannot be read on 26.4+ (including 26.8 LTS), and a table written on 26.3 becomes unreadable after the upgrade. Drop 0-byte objects from the object list in the constructor. They add no bytes to the file, so no file offset changes, and every walk of the list then agrees with `initialize`. The new integration test writes the table on 26.3.42.3 and reads it after upgrading to the current binary, on a plain s3 disk and on a cache over it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
lazerg
pushed a commit
to lazerg/ClickHouse
that referenced
this pull request
Nov 12, 2026
With local metadata, an empty `WriteMode::Append` uploads no object (`WriteBufferInlineOrBlob` cancels the upload when `create_blob_if_empty` is not set), but `AddBlobOperation` still listed the 0-byte object in the file's metadata. The metadata then referenced a key that does not exist. `StripeLogSink` opens `data.bin` for append even for an INSERT that writes no rows, so `INSERT ... SELECT ... LIMIT 0` followed by another INSERT made every later read of the table fail with `S3_ERROR` (NoSuchKey). `AddBlobOperation::execute` now skips a 0-byte object and still writes the metadata file, so a first empty append still creates the file. This is the contract the in-memory metadata backend of ClickHouse#100371 already has; ClickHouse#121670 fixed the same phantom at the caller for `MergeTreeDeduplicationLog`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Three fixes in
MergeTreeDeduplicationLog(used bynon_replicated_deduplication_window):dropOutdatedLogshad an off-by-one: once the sum of entries reached the deduplication window, it dropped all older logs including the current one, which the writer may still append to. The active log is now never dropped, and its entries count towards the window.loadand onsetDeduplicationWindowSize. On object storage, finalizing an emptyWriteMode::Appendbuffer registers a blob in the file's metadata without uploading any object. So everyDETACH/ATTACHcycle with no inserts in between added one phantom blob, and the next load failed withNoSuchKey("Error while loading MergeTree deduplication log"). The writer is now opened lazily inprepareToWrite, when the first record is written.syncthe writer after finalizing it inshutdown.New test
04640_deduplication_log_reattach_no_phantom_blobs(S3 disk, threeDETACH/ATTACHcycles).Split out of #96130, where the random
DETACH/ATTACHtesting hook found the bug.Related: #96130
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
MergeTreetables withnon_replicated_deduplication_windowon object storage failing to load their deduplication log (NoSuchKey) after being detached and attached back without inserts in between, and fix the deduplication log possibly dropping its active file.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/121670]
Version info
26.10.1.523-master(included in26.10and later)