Repository navigation
Fix new materialized view on idle RabbitMQ table missing messages published right after CREATE - #133955
Fix new materialized view on idle RabbitMQ table missing messages published right after CREATE#133955aarvnd wants to merge 1 commit into
RabbitMQ table missing messages published right after CREATE#133955Conversation
|
Workflow [PR], commit [860c5a1] Summary: ❌
AI ReviewSummaryThe PR snapshots the dependent materialized views of a Findings❌ Blockers
Tests
Final VerdictStatus: ❌ Block Prevent consumption with an empty/unready view snapshot, or link a dedicated issue for that pre-existing race, and strengthen the regression test so it proves the stale-pipeline behavior. |
|
|
||
| /// Taken before the insert pipeline is built, so a view created after this point (and possibly missing from | ||
| /// the pipeline) is always detected by the sources, which then end the cycle before consuming a message. | ||
| auto streaming_views = DatabaseCatalog::instance().getDependentViews(table_id); |
There was a problem hiding this comment.
[Blocker] Refuse an empty view snapshot before consuming messages
The last view can disappear after threadFunc passes hasDependencies but before this snapshot is taken. Then streaming_views is empty, InterpreterInsertQuery builds a NullSinkToStorage, and dependentViewsChanged compares two empty sets and allows consumption. The cycle discards the rows and calls sendAck before reaching the later hasDependencies check at line 1612. Messages published while a view is detached or being recreated can therefore still be permanently lost.
Revalidate dependency readiness after building the pipeline and before executing the sources, as StorageNATS::streamToViews already does, or otherwise reject an empty/unready snapshot. This race predates the PR but remains reachable through the dependency-change handling being fixed here; if it is deferred, please link a dedicated tracking issue.
|
|
||
| # Create mv2 right after a streaming cycle that knows only mv1 has started, then publish. The server log is | ||
| # tailed on the host, as the cycle waits for a message only for stream_poll_timeout_ms (500 ms). | ||
| started = f"StorageRabbitMQ ({db}.rabbit): Started streaming to 1 attached views" |
There was a problem hiding this comment.
[Major] Establish that the test actually exercises a stale pipeline
Started streaming to 1 attached views is logged in threadFunc before streamToViews takes the snapshot or builds the insert pipeline. After this wait, mv2 can finish creation before the pipeline reads its dependencies, so both tables receive 100 rows even with the fix removed. The same false pass occurs if scheduling the query/publisher takes longer than the 500 ms idle wait and a fresh cycle starts first.
Please make the test establish that an already-built pipeline is invalidated before it consumes the first message, and verify that the test fails with the new guard removed. The current row-count assertions alone do not distinguish exercising this fix from avoiding the original race.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units8 translation units recompiled, 16 s compile time in total, 8 of them have a recent master baseline. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a materialized view created on an idle
RabbitMQtable silently missing (and acking) messages published right after itsCREATEreturned.Details
Each background streaming cycle builds its
InterpreterInsertQuerypipeline from the views that exist when the cycle starts. An idle cycle can wait up tostream_poll_timeout_msfor its first message. If a materialized view was created during that wait, the first messages went only to the old views and were acked, so the new view never received them.Changes:
StorageRabbitMQ::streamToViewsrecords the dependent views before building the pipeline and passes them to eachRabbitMQSource.RabbitMQSource::generateImplcompares the current dependent views with the recorded ones before consuming a message. If they differ, the cycle ends without consuming (nothing is acked), and the next cycle, built for the new set of views, delivers the message. This is usually one catalog lookup per cycle and does not apply to directSELECT.StorageRabbitMQ::threadFunclogs the current number of views inStarted streaming to N attached viewsinstead of the count taken at the start of the run.Not covered: a view created after a cycle has already consumed its first message still receives rows from the next cycle (as before, like Kafka).
ALTER TABLE ... MODIFY QUERYkeeps the view ID, so it is not detected.Testing
Added the integration test
test_rabbitmq_view_added_to_idle_table_gets_new_messagestotests/integration/test_storage_rabbitmq/test.py, based on the reproduction in the issue: it createsmv2right after a streaming cycle starts, publishes 100 messages and expects both target tables to get 100 rows. Not run locally: there was no build directory or Docker integration environment. The test file was only checked to parse.Testing
python3 -c ast.parse on tests/integration/test_storage_rabbitmq/test.py: ok. C++ not compiled and the integration test not run (no build directory or Docker integration environment in this worktree).
Closes #133901
Workflow [PR]
Sync PR [sync-upstream/pr/133955]