Repository navigation
Incremental RMV presist cursor in Iceberg snapshot - #114823
Conversation
|
Workflow [PR], commit [618c349] Summary: ❌
AI ReviewSummaryThis PR moves the incremental refreshable-MV cursor for transactional Iceberg targets into the Iceberg snapshot summary so restart recovery no longer depends on Keeper. The direct single-replica path is mostly wired up, but the current patch still has three correctness holes that can duplicate or replay data, plus one broad performance regression on every incremental view, so it is not ready to merge. Findings❌ Blockers
Tests
Final VerdictStatus: ❌ Block
LLVM Coverage ReportMeasured on commit 618c349.
Changed lines: Changed C/C++ lines covered: 110/118 (93.22%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes18 object files changed (+71.84 KiB total), 1 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units123 translation units recompiled, 1151 s compile time in total, 122 of them have a recent master baseline. |
| /// - a transactional target table (e.g. Iceberg on a REST/filesystem catalog): the write path commits | ||
| /// the cursor atomically with the data files in one catalog compare-and-swap -> exactly-once, and | ||
| /// the refresh keeps the cursor out of Keeper entirely and reads it back from the target here. | ||
| class RefreshCursorStore |
There was a problem hiding this comment.
Not sure about this interface, it looks like it is possible to support RMT since we commit parts there atomically into the keeper, but that's just an illusion, since this interface heavily relies on the fact that the storage sink will not submit partially consumed data, without this it is not possible to correctly understand the right border of the cursor since reading is being made in unordered mode.
There was a problem hiding this comment.
making max_insert_threads = 1. I think the right approach would be to wait for all inserts & write in Iceberg but it would be a big refactor (maybe in another pr).
Please let me know if you have any suggestions
There was a problem hiding this comment.
The smallest safe shape I see is to keep the interface Iceberg-only in this PR and make the optimization conditional on an actual metadata snapshot being committed. max_insert_threads = 1 removes the multi-sink case, but zero-output rounds still produce no Iceberg snapshot, so they need either an explicit empty-snapshot cursor commit or a fallback to the Keeper cursor for that round.
There was a problem hiding this comment.
As far as I know, Iceberg writes finalizes only at the end of the pipeline - that is why it is working right now even without max_insert_threads=1. My point was that let's not introduce a generic interface for that, since it may force someone to implement an invalid solution for another table.
There was a problem hiding this comment.
okay, got it. removed RefreshCursorStore
| refresh_context->setSetting("parallel_replicas_for_non_replicated_merge_tree", Field(UInt64{0})); | ||
| refresh_context->setSetting("allow_insert_into_iceberg", Field(UInt64{1})); | ||
| /// A transactional target commits the whole round in one snapshot with the cursor, so it must be a single writer. | ||
| refresh_context->setSetting("max_insert_threads", Field(UInt64{1})); |
There was a problem hiding this comment.
This only serializes sink creation inside one refresh on one replica. For APPEND INCREMENTAL SETTINGS all_replicas = 1 against a shared transactional Iceberg target (for example a REST catalog table, or a no-catalog table on shared object storage), multiple replicas can still start from the same table-level cursor, read the same source range, and race the metadata commit.
If replica A commits snapshot S1 with cursor C1 and replica B loses the compare-and-swap, B's retry loop does not rerun the SELECT from C1 or rebuild its data files. It just regenerates metadata around the rows it already read from C0, so the duplicate range is appended permanently once B succeeds on top of S1.
This needs a DDL-time rejection or real cross-replica coordination for shared transactional targets; max_insert_threads = 1 is not sufficient.
| refresh_context->setSetting("parallel_replicas_for_non_replicated_merge_tree", Field(UInt64{0})); | ||
| refresh_context->setSetting("allow_insert_into_iceberg", Field(UInt64{1})); | ||
| /// A transactional target commits the whole round in one snapshot with the cursor, so it must be a single writer. | ||
| refresh_context->setSetting("max_insert_threads", Field(UInt64{1})); |
There was a problem hiding this comment.
This forces max_insert_threads = 1 for every APPEND INCREMENTAL view, not just the transactional Iceberg targets that need a single writer to couple data and cursor in one snapshot. A regular incremental view writing to MergeTree still persists its cursor in Keeper only after the whole pipeline succeeds, so it can safely keep parallel insert threads.
As written, this silently serializes all existing incremental refreshes and can turn large INSERT SELECT rounds into single-threaded writes with no correctness benefit. Can we gate this on StorageObjectStorage::isTransactionalRefreshTarget() (or push it down into the Iceberg write path) instead of applying it unconditionally?
| /// truth on resume; otherwise resume from the cursor in the Keeper coordination znode. | ||
| stream_cursor = execution.znode.cursor; | ||
| StoragePtr target_table = view->getTargetTable(); | ||
| if (auto * object_storage = dynamic_cast<StorageObjectStorage *>(target_table.get()); |
There was a problem hiding this comment.
StorageMaterializedView::getTargetTable() can still return a wrapper such as StorageAlias, so this dynamic_cast<StorageObjectStorage *> misses TO alias_to_iceberg even though the nested insert eventually writes into the same transactional Iceberg table.
AliasSink::onStart() copies the outer context with Context::createCopy(getContext()), and ContextData copies streaming_cursor, so the inner Iceberg write still embeds clickhouse.refresh-cursor in the snapshot. But RefreshTask stays on the non-transactional path here, keeps resuming from/persisting only the local or Keeper cursor, and in the common Atomic case that cursor disappears on restart. The next refresh then rereads from the beginning and re-appends rows even though the Iceberg snapshot already has the correct cursor.
Please resolve wrappers before checking isTransactionalRefreshTarget() / loadRefreshCursor() (or make that capability virtual on IStorage) so alias targets participate in the same exact-once path as direct Iceberg tables.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Support exactly-once incremental refresh of refreshable materialized views into Iceberg targets by committing the refresh cursor atomically inside the Iceberg snapshot summary.
depends on #114152
cc @alesapin @Michicosun
Workflow [PR]
Sync PR [sync-upstream/pr/114823]
Version info
26.9.1.1509(included in26.9and later)