Fix: Invalidate tablets when table is dropped via schema event - #975
Fix: Invalidate tablets when table is dropped via schema event#975mykaul wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthrough
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Note
Quiet mode is enabled, so only the most important comments were posted inline. Other review comments are grouped below.
🟡 Other comments (1)
tests/integration/standard/test_tablets.py-221-234 (1)
221-234: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick winMake table restoration unconditional and reuse the class session.
If
run_tablets_invalidation_test(drop_table)raises, the recreation block is skipped. Later tests then run withouttest1.table1. Put restoration in afinallyblock or cleanup hook. Useself.sessioninstead of opening sessions that are not explicitly closed.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/integration/standard/test_tablets.py` around lines 221 - 234, Update test_tablets_invalidation_drop_table so table1 restoration always runs in a finally block, including when run_tablets_invalidation_test raises. Reuse self.session for both the DROP TABLE callback and the CREATE TABLE/data setup, removing the temporary cluster.connect() sessions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/unit/test_metadata.py`:
- Around line 445-465: Add concise docstrings to DropTableMetadataTest, its
setUp method, and both test_drop_table_invalidates_tablets methods in
tests/unit/test_metadata.py (lines 445-465). Also add a docstring to
test_tablets_invalidation_drop_table in
tests/integration/standard/test_tablets.py (lines 221-226), describing each
test’s purpose.
---
Other comments:
In `@tests/integration/standard/test_tablets.py`:
- Around line 221-234: Update test_tablets_invalidation_drop_table so table1
restoration always runs in a finally block, including when
run_tablets_invalidation_test raises. Reuse self.session for both the DROP TABLE
callback and the CREATE TABLE/data setup, removing the temporary
cluster.connect() sessions.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: QUIET
Plan: Pro Plus
Run ID: 48fe95f3-28e6-4a63-bdc3-0ffec5109391
📒 Files selected for processing (3)
cassandra/metadata.pytests/integration/standard/test_tablets.pytests/unit/test_metadata.py
600f53a to
c569402
Compare
There was a problem hiding this comment.
Note
Quiet mode is enabled, so only the most important comments were posted inline. Other review comments are grouped below.
🟡 Other comments (1)
tests/integration/standard/test_tablets.py-228-236 (1)
228-236: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winMake the restoration cleanup idempotent.
run_tablets_invalidation_testcan fail beforedrop_tableruns, such as when it cannot find a tablet record at Line 280. Thefinallyblock then createstest1.table1while it still exists, which can raiseAlreadyExistsand hide the original failure. UseCREATE TABLE IF NOT EXISTSor preserve the active test exception during cleanup.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/integration/standard/test_tablets.py` around lines 228 - 236, Make the restoration cleanup in the test method containing run_tablets_invalidation_test idempotent by changing its table recreation statement to use CREATE TABLE IF NOT EXISTS. Keep create_data(self.session) in the finally block so the shared table data is restored without masking the original test failure.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Other comments:
In `@tests/integration/standard/test_tablets.py`:
- Around line 228-236: Make the restoration cleanup in the test method
containing run_tablets_invalidation_test idempotent by changing its table
recreation statement to use CREATE TABLE IF NOT EXISTS. Keep
create_data(self.session) in the finally block so the shared table data is
restored without masking the original test failure.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: QUIET
Plan: Pro Plus
Run ID: fe4a0215-f2cb-49b4-9f72-7ef065d9b729
📒 Files selected for processing (2)
tests/integration/standard/test_tablets.pytests/unit/test_metadata.py
c569402 to
1a4645a
Compare
Signed-off-by: Yaniv Michael Kaul <yaniv.kaul@scylladb.com>
1a4645a to
e154dec
Compare
There was a problem hiding this comment.
Note
Quiet mode is enabled, so only the most important comments were posted inline. Other review comments are grouped below.
🟡 Other comments (1)
tests/integration/standard/test_tablets.py-279-284 (1)
279-284: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick winAssert cleanup for every tablet record.
run_tablets_invalidation_testchecks only the record forpk=2. The new test inserts 50 rows, so stale records for other tablets can remain undetected. Collect records for all inserted keys, or assert that the dropped table has no remaining tablet entries.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/integration/standard/test_tablets.py` around lines 279 - 284, Update run_tablets_invalidation_test to validate tablet metadata cleanup for every inserted key rather than only pk=2. Collect or query records across all 50 inserted keys, and assert that no tablet entries remain for the dropped table while preserving the existing invalidation flow.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Other comments:
In `@tests/integration/standard/test_tablets.py`:
- Around line 279-284: Update run_tablets_invalidation_test to validate tablet
metadata cleanup for every inserted key rather than only pk=2. Collect or query
records across all 50 inserted keys, and assert that no tablet entries remain
for the dropped table while preserving the existing invalidation flow.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: QUIET
Plan: Pro Plus
Run ID: 772fc231-b3f3-4a7c-a50d-0a78f6c5fc28
📒 Files selected for processing (1)
tests/integration/standard/test_tablets.py
Nope, I don't think it's needed at all, rabbit. |
Issue
The event-driven DROP TABLE path (Metadata._drop_table) never drops tablet metadata. Tablets are only invalidated on full schema rebuilds, keyspace events, and host removal. Stale tablet entries remain after a table is dropped, and a dropped-then-recreated table briefly routes on stale tablet data.
Fix
Call the existing _table_removed() helper from _drop_table(), outside the try block so invalidation also fires when the keyspace is unknown (race, or schema metadata disabled).
Test
Unit: Metadata._drop_table invalidates tablets for known and unknown keyspaces.
Integration: test_tablets_invalidation_drop_table drops a tablet table and waits for the tablet record to be purged.