Skip to content

Commit

Permalink
cql-pytest: Verify RF is changes by at most 1 when tablets on
Browse files Browse the repository at this point in the history
This commit adds a test verifying that we can only
change the RF of a keyspace for any DC by at most 1
when using tablets.

Fixes scylladb#18029
  • Loading branch information
dawmd authored and ptrsmrn committed May 14, 2024
1 parent e7f35dd commit 3eaea7f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
8 changes: 7 additions & 1 deletion test/cql-pytest/test_keyspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,13 @@ def test_drop_keyspace_nonexistent(cql):
# Test trying to ALTER a keyspace.
def test_alter_keyspace(cql, this_dc):
with new_test_keyspace(cql, "WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', '" + this_dc + "' : 1 }") as keyspace:
cql.execute(f"ALTER KEYSPACE {keyspace} WITH REPLICATION = {{ 'class' : 'NetworkTopologyStrategy', '{this_dc}' : 3 }} AND DURABLE_WRITES = false")
cql.execute(f"ALTER KEYSPACE {keyspace} WITH REPLICATION = {{ 'class' : 'NetworkTopologyStrategy', '{this_dc}' : 2 }} AND DURABLE_WRITES = false")

# Test trying to ALTER a keyspace's RF by more than 1 at a time
def test_alter_keyspace(cql, this_dc):
with new_test_keyspace(cql, "WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', '" + this_dc + "' : 1 }") as keyspace:
with pytest.raises(InvalidRequest):
cql.execute(f"ALTER KEYSPACE {keyspace} WITH REPLICATION = {{ 'class' : 'NetworkTopologyStrategy', '{this_dc}' : 3 }} AND DURABLE_WRITES = false")

# Test trying to ALTER a keyspace with invalid options.
def test_alter_keyspace_invalid(cql, this_dc):
Expand Down
32 changes: 32 additions & 0 deletions test/cql-pytest/test_tablets.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,35 @@ def test_lwt_support_with_tablets(cql, test_keyspace, skip_without_tablets):
cql.execute(f"DELETE FROM {table} WHERE key = 1 IF EXISTS")
res = cql.execute(f"SELECT val FROM {table} WHERE key = 1").one()
assert res.val == 0


# We want to ensure that we can only change the RF of any DC by at most 1 at a time
# if we use tablets. That provides us with the guarantee that the old and the new QUORUM
# overlap by at least one node.
def test_alter_tablet_keyspace(cql, this_dc):
with new_test_keyspace(cql, f"WITH REPLICATION = {{ 'class' : 'NetworkTopologyStrategy', '{this_dc}' : 1 }} "
f"AND TABLETS = {{ 'enabled': true, 'initial': 128 }}") as keyspace:
def change_opt_rf(rf_opt, new_rf):
cql.execute(f"ALTER KEYSPACE {keyspace} WITH REPLICATION = {{ 'class' : 'NetworkTopologyStrategy', '{rf_opt}' : {new_rf} }}")
def change_dc_rf(new_rf):
change_opt_rf(this_dc, new_rf)
def change_default_rf(new_rf):
change_opt_rf("replication_factor", new_rf)

change_dc_rf(2)
change_dc_rf(3)

with pytest.raises(InvalidRequest):
change_dc_rf(5)
with pytest.raises(InvalidRequest):
change_dc_rf(1)
with pytest.raises(InvalidRequest):
change_dc_rf(10)

# Changing the default replication factor doesn't affect any of the existing DCs,
# so we can change it arbitrarily.
change_default_rf(4)
change_default_rf(2)
change_default_rf(8)
change_default_rf(1)
change_default_rf(10)

0 comments on commit 3eaea7f

Please sign in to comment.