Skip to content

Commit

Permalink
fix(ToggleTableIcsMonkey): check if selected CF is a view
Browse files Browse the repository at this point in the history
	In order to avoid complicated filtering and lists of tables,
	explicitely check if CF is a view or not.
  • Loading branch information
yarongilor authored and fruch committed Apr 17, 2023
1 parent 2a69ace commit b163715
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
7 changes: 3 additions & 4 deletions sdcm/nemesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
from sdcm.utils.loader_utils import DEFAULT_USER, DEFAULT_USER_PASSWORD, SERVICE_LEVEL_NAME_TEMPLATE
from sdcm.utils.nemesis_utils.indexes import get_random_column_name, create_index, \
wait_for_index_to_be_built, verify_query_by_index_works, drop_index, get_partition_key_name, \
wait_for_view_to_be_built, drop_materialized_view
wait_for_view_to_be_built, drop_materialized_view, is_cf_a_view
from sdcm.utils.replication_strategy_utils import temporary_replication_strategy_setter, \
NetworkTopologyReplicationStrategy, ReplicationStrategy, SimpleReplicationStrategy
from sdcm.utils.sstable.load_utils import SstableLoadUtils
Expand Down Expand Up @@ -2335,13 +2335,11 @@ def toggle_table_ics(self): # pylint: disable=too-many-locals
"""
list_additional_params = get_compaction_random_additional_params()
all_ks_cfs = self.cluster.get_non_system_ks_cf_list(db_node=self.target_node)
non_mview_ks_cfs = self.cluster.get_non_system_ks_cf_list(db_node=self.target_node, filter_out_mv=True)

if not all_ks_cfs:
raise UnsupportedNemesis(
'Non-system keyspace and table are not found. toggle_tables_ics nemesis can\'t run')

mview_ks_cfs = list(set(all_ks_cfs) - set(non_mview_ks_cfs))
keyspace_table = random.choice(all_ks_cfs)
keyspace, table = keyspace_table.split('.')
cur_compaction_strategy = get_compaction_strategy(node=self.target_node, keyspace=keyspace,
Expand All @@ -2356,7 +2354,8 @@ def toggle_table_ics(self): # pylint: disable=too-many-locals
if new_compaction_strategy in [CompactionStrategy.INCREMENTAL, CompactionStrategy.SIZE_TIERED]:
for param in list_additional_params:
new_compaction_strategy_as_dict.update(param)
alter_command_prefix = 'ALTER TABLE ' if keyspace_table not in mview_ks_cfs else 'ALTER MATERIALIZED VIEW '
alter_command_prefix = 'ALTER TABLE ' if not is_cf_a_view(
node=self.target_node, ks=keyspace, cf=table) else 'ALTER MATERIALIZED VIEW '
cmd = alter_command_prefix + \
" {keyspace_table} WITH compaction = {new_compaction_strategy_as_dict};".format(**locals())
self.log.debug("Toggle table ICS query to execute: {}".format(cmd))
Expand Down
15 changes: 15 additions & 0 deletions sdcm/utils/nemesis_utils/indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@
LOGGER = logging.getLogger(__name__)


def is_cf_a_view(node: BaseNode, ks, cf) -> bool:
"""
Check if a CF is a materialized-view or not (a normal table)
"""
with node.parent_cluster.cql_connection_patient(node) as session:
try:
result = session.execute(f"SELECT view_name FROM system_schema.views"
f" WHERE keyspace_name = '{ks}'"
f" AND view_name = '{cf}'")
return result and bool(len(result.one()))
except Exception as exc: # pylint: disable=broad-except
LOGGER.debug('Got no result from system_schema.views for %s.%s table. Error: %s', ks, cf, exc)
return False


def get_column_names(session, ks, cf, is_partition_key: bool = False) -> list:
filter_kind = " kind in ('static', 'regular')" if not is_partition_key else "kind = 'partition_key'"
res = session.execute(f"SELECT column_name FROM system_schema.columns"
Expand Down

0 comments on commit b163715

Please sign in to comment.