From 5bfca73b303f3bee7fa421a29caebadd34d71a41 Mon Sep 17 00:00:00 2001 From: Benny Halevy Date: Wed, 13 Mar 2024 09:24:48 +0200 Subject: [PATCH] migration_manager: notify before_drop_column_family when dropping indices Fixes #17627 Signed-off-by: Benny Halevy --- db/schema_tables.cc | 1 + test/cql-pytest/test_tablets.py | 33 ++++++++++++++++++++++++++++++++- test/cql-pytest/util.py | 3 +++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/db/schema_tables.cc b/db/schema_tables.cc index 5549d44a77..0a60f4a6be 100644 --- a/db/schema_tables.cc +++ b/db/schema_tables.cc @@ -2759,6 +2759,7 @@ static void make_update_indices_mutations( schema_ptr view; try { view = db.find_schema(old_table->ks_name(), secondary_index::index_table_name(name)); + db.get_notifier().before_drop_column_family(*view, mutations, timestamp); } catch (const replica::no_such_column_family&) { on_internal_error(slogger, format("Could not find schema for dropped index {}.{}", old_table->ks_name(), secondary_index::index_table_name(name))); diff --git a/test/cql-pytest/test_tablets.py b/test/cql-pytest/test_tablets.py index 14d44516b3..88a6aa2bae 100644 --- a/test/cql-pytest/test_tablets.py +++ b/test/cql-pytest/test_tablets.py @@ -13,7 +13,7 @@ ############################################################################# import pytest -from util import new_test_keyspace, new_test_table, unique_name +from util import new_test_keyspace, new_test_table, unique_name, index_table_name from cassandra.protocol import ConfigurationException, InvalidRequest # A fixture similar to "test_keyspace", just creates a keyspace that enables @@ -170,3 +170,34 @@ def test_tablets_are_dropped_when_dropping_table_with_view(cql, test_keyspace): except: pass raise e + + +# Test the following cases: +# 1. When an index of a tablets-enabled table is dropped, all of its tablets are dropped with it. +# 2. When a tablets-enabled table that has an index is dropped, the tablets associated with the table and index are dropped with it. +# +# Reproduces https://github.com/scylladb/scylladb/issues/17627 +@pytest.mark.parametrize("drop_index", [True, False]) +def test_tablets_are_dropped_when_dropping_index(cql, test_keyspace, drop_index): + table_name = unique_name() + schema = "pk int PRIMARY KEY, c int" + cql.execute(f"CREATE TABLE {test_keyspace}.{table_name} ({schema})") + try: + index_name = unique_name() + cql.execute(f"CREATE INDEX {index_name} ON {test_keyspace}.{table_name} (c)") + verify_tablets_presence(cql, test_keyspace, table_name) + verify_tablets_presence(cql, test_keyspace, index_table_name(index_name)) + + if drop_index: + cql.execute(f"DROP INDEX {test_keyspace}.{index_name}") + verify_tablets_presence(cql, test_keyspace, index_table_name(index_name), expected=False) + + cql.execute(f"DROP TABLE {test_keyspace}.{table_name}") + verify_tablets_presence(cql, test_keyspace, table_name, expected=False) + verify_tablets_presence(cql, test_keyspace, index_table_name(index_name), expected=False) + except Exception as e: + try: + cql.execute(f"DROP TABLE {test_keyspace}.{table_name}") + except: + pass + raise e diff --git a/test/cql-pytest/util.py b/test/cql-pytest/util.py index b35883ad66..5bd3af90c4 100644 --- a/test/cql-pytest/util.py +++ b/test/cql-pytest/util.py @@ -190,6 +190,9 @@ def new_secondary_index(cql, table, column, name='', extra=''): finally: cql.execute(f"DROP INDEX {keyspace}.{name}") +def index_table_name(index_name : str): + return f"{index_name}_index" + # Helper function for establishing a connection with given username and password @contextmanager def cql_session(host, port, is_ssl, username, password, request_timeout=120):