migration_manager: notify before_drop_column_family when dropping indices

Fixes #17627

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
This commit is contained in:
Benny Halevy
2024-03-13 09:24:48 +02:00
parent 9cf6a2e510
commit 5bfca73b30
3 changed files with 36 additions and 1 deletions

View File

@@ -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

View File

@@ -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):