From 9788a8739c8768df9c4e1615df6579819567f692 Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Mon, 21 Jul 2025 13:03:15 +0300 Subject: [PATCH] antithesis: Add `DROP INDEX` parallel driver --- .../parallel_driver_drop_index.py | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100755 antithesis-tests/stress-composer/parallel_driver_drop_index.py diff --git a/antithesis-tests/stress-composer/parallel_driver_drop_index.py b/antithesis-tests/stress-composer/parallel_driver_drop_index.py new file mode 100755 index 000000000..f514dc7ad --- /dev/null +++ b/antithesis-tests/stress-composer/parallel_driver_drop_index.py @@ -0,0 +1,68 @@ +#!/usr/bin/env -S python3 -u + +import json + +import turso +from antithesis.random import get_random + +# Get initial state +try: + con_init = turso.connect("init_state.db") +except Exception as e: + print(f"Error connecting to database: {e}") + exit(0) + +cur_init = con_init.cursor() + +# Connect to the main database +try: + con = turso.connect("stress_composer.db", experimental_indexes=True) +except Exception as e: + print(f"Failed to open stress_composer.db. Exiting... {e}") + exit(0) + +cur = con.cursor() + +# Get all user-created indexes (excluding automatic indexes) +existing_indexes = cur.execute(""" + SELECT name, tbl_name FROM sqlite_master + WHERE type = 'index' + AND sql IS NOT NULL + AND name NOT LIKE 'sqlite_%' +""").fetchall() + +if not existing_indexes: + print("No indexes available to drop") + exit(0) + +# Select a random index to drop +selected_idx = get_random() % len(existing_indexes) +index_name, table_name = existing_indexes[selected_idx] + +print(f"Selected index: {index_name} on table {table_name}") +print(f"Total indexes available: {len(existing_indexes)}") + +try: + # Drop the index + drop_stmt = f"DROP INDEX {index_name}" + print(f"Dropping index: {drop_stmt}") + cur.execute(drop_stmt) + + # Remove index information from init_state.db + cur_init.execute(f""" + DELETE FROM indexes + WHERE idx_name = '{index_name}' + """) + con_init.commit() + + print(f"Successfully dropped index: {index_name}") +except turso.OperationalError as e: + print(f"Failed to drop index: {e}") + con.rollback() +except Exception as e: + # Handle case where index might not exist in indexes table + print(f"Warning: Could not remove index from metadata: {e}") + +con.commit() +con.close() +con_init.close() \ No newline at end of file