From 77d5ccb84f03171221d91a35d0c55994bb1568a9 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 27 Nov 2024 17:15:42 +0800 Subject: [PATCH] test/topology_experimental_raft: Prevent keyspace creation conflicts with IF NOT EXISTS Background: - Python driver exhibits unexpected behavior causing duplicate keyspace creation attempts (scylladb/python-driver#317) - Existing test cases can fail with cassandra.AlreadyExists exception: ``` cassandra.AlreadyExists: Keyspace 'test_1732631552019_lxagp' already exists ``` Resolution: - Added `IF NOT EXISTS` clause to keyspace and table creation statements - Mitigates potential race conditions during test setup - Aligns with previous mitigation approach in commit 8876b9b0ef Specific Changes: - Ensures safe keyspace creation in concurrent test scenarios - Prevents test failures due to duplicate keyspace generation Fixes scylladb/scylladb#21701 Signed-off-by: Kefu Chai --- test/topology_experimental_raft/test_tablets.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/topology_experimental_raft/test_tablets.py b/test/topology_experimental_raft/test_tablets.py index acf2a0454fd0..b5cb08e30a24 100644 --- a/test/topology_experimental_raft/test_tablets.py +++ b/test/topology_experimental_raft/test_tablets.py @@ -1550,8 +1550,8 @@ async def create_and_populate_table(manager: ManagerClient, rf: int = 3, initial cql = manager.get_cql() try: - await cql.run_async(f"CREATE KEYSPACE {ks} WITH replication = {{'class': 'NetworkTopologyStrategy', 'replication_factor': {rf}}} AND tablets = {{'initial': {initial_tablets}}}") - await cql.run_async(f"CREATE TABLE {ks}.{table} (pk int PRIMARY KEY, c int)") + await cql.run_async(f"CREATE KEYSPACE IF NOT EXISTS {ks} WITH replication = {{'class': 'NetworkTopologyStrategy', 'replication_factor': {rf}}} AND tablets = {{'initial': {initial_tablets}}}") + await cql.run_async(f"CREATE TABLE IF NOT EXISTS {ks}.{table} (pk int PRIMARY KEY, c int)") await asyncio.gather(*[cql.run_async(f"INSERT INTO {ks}.{table} (pk, c) VALUES ({k}, 1);") for k in range(num_keys)]) yield TestContext(ks, table, rf, initial_tablets, num_keys) finally: