Skip to content
Permalink
Browse files
Rename truncate_drop guardrail to drop_truncate_table
Patch by Josh McKenzie; reviewed by Andres de la Pena for CASSANDRA-17592
  • Loading branch information
josh-mckenzie committed May 6, 2022
1 parent c9ed13c commit 030831c5f5457c37ba78f0539898bb6cbd676823
Showing 11 changed files with 29 additions and 27 deletions.
@@ -1,4 +1,5 @@
4.1
* Rename truncate_drop guardrail to drop_truncate_table (CASSANDRA-17592)
* nodetool enablefullquerylog can NPE when directory has no files (CASSANDRA-17595)
* Add auto_snapshot_ttl configuration (CASSANDRA-16790)
* List snapshots of dropped tables (CASSANDRA-16843)
@@ -88,6 +88,7 @@ New features
- Whether the creation of secondary indexes is allowed.
- Whether the creation of uncompressed tables is allowed.
- Whether querying with ALLOW FILTERING is allowed.
- Whether DROP or TRUNCATE TABLE commands are allowed.
- Add support for the use of pure monotonic functions on the last attribute of the GROUP BY clause.
- Add floor functions that can be use to group by time range.
- Support for native transport rate limiting via native_transport_rate_limiting_enabled and
@@ -1629,8 +1629,8 @@ drop_compact_storage_enabled: false
# user_timestamps_enabled: true
# Guardrail to allow/disallow GROUP BY functionality.
# group_by_enabled: true
# Guardrail to allow/disallow TRUNCATE and DROP statements
# truncate_drop_enabled: true
# Guardrail to allow/disallow TRUNCATE and DROP TABLE statements
# drop_truncate_table_enabled: true
# Guardrail to warn or fail when using a page size greater than threshold.
# The two thresholds default to -1 to disable.
# page_size_warn_threshold: -1
@@ -826,7 +826,7 @@ public static void setClientMode(boolean clientMode)
public volatile Set<ConsistencyLevel> write_consistency_levels_disallowed = Collections.emptySet();
public volatile boolean user_timestamps_enabled = true;
public volatile boolean group_by_enabled = true;
public volatile boolean truncate_drop_enabled = true;
public volatile boolean drop_truncate_table_enabled = true;
public volatile boolean secondary_indexes_enabled = true;
public volatile boolean uncompressed_tables_enabled = true;
public volatile boolean compact_tables_enabled = true;
@@ -330,17 +330,17 @@ public void setGroupByEnabled(boolean enabled)
}

@Override
public boolean getTruncateDropEnabled()
public boolean getDropTruncateTableEnabled()
{
return config.truncate_drop_enabled;
return config.drop_truncate_table_enabled;
}

public void setTruncateDropEnabled(boolean enabled)
public void setDropTruncateTableEnabled(boolean enabled)
{
updatePropertyWithLogging("truncate_drop_enabled",
updatePropertyWithLogging("drop_truncate_table_enabled",
enabled,
() -> config.truncate_drop_enabled,
x -> config.truncate_drop_enabled = x);
() -> config.drop_truncate_table_enabled,
x -> config.drop_truncate_table_enabled = x);
}

@Override
@@ -58,7 +58,7 @@ public void authorize(ClientState state) throws InvalidRequestException, Unautho
public void validate(ClientState state) throws InvalidRequestException
{
Schema.instance.validateTable(keyspace(), name());
Guardrails.truncateDropEnabled.ensureEnabled(state);
Guardrails.dropTruncateTableEnabled.ensureEnabled(state);
}

public ResultMessage execute(QueryState state, QueryOptions options, long queryStartNanoTime) throws InvalidRequestException, TruncateException
@@ -49,7 +49,7 @@ public DropTableStatement(String keyspaceName, String tableName, boolean ifExist

public Keyspaces apply(Keyspaces schema)
{
Guardrails.truncateDropEnabled.ensureEnabled(state);
Guardrails.dropTruncateTableEnabled.ensureEnabled(state);

KeyspaceMetadata keyspace = schema.getNullable(keyspaceName);

@@ -145,10 +145,10 @@ public final class Guardrails implements GuardrailsMBean
state -> !CONFIG_PROVIDER.getOrCreate(state).getGroupByEnabled(),
"GROUP BY functionality");

public static final DisableFlag truncateDropEnabled =
new DisableFlag("truncate_drop",
state -> !CONFIG_PROVIDER.getOrCreate(state).getTruncateDropEnabled(),
"TRUNCATE and DROP TABLE functionality");
public static final DisableFlag dropTruncateTableEnabled =
new DisableFlag("drop_truncate_table_enabled",
state -> !CONFIG_PROVIDER.getOrCreate(state).getDropTruncateTableEnabled(),
"DROP and TRUNCATE TABLE functionality");

/**
* Guardrail disabling user's ability to turn off compression
@@ -588,15 +588,15 @@ public void setGroupByEnabled(boolean enabled)
}

@Override
public boolean getTruncateDropEnabled()
public boolean getDropTruncateTableEnabled()
{
return DEFAULT_CONFIG.getTruncateDropEnabled();
return DEFAULT_CONFIG.getDropTruncateTableEnabled();
}

@Override
public void setTruncateDropEnabled(boolean enabled)
public void setDropTruncateTableEnabled(boolean enabled)
{
DEFAULT_CONFIG.setTruncateDropEnabled(enabled);
DEFAULT_CONFIG.setDropTruncateTableEnabled(enabled);
}

@Override
@@ -158,7 +158,7 @@
*
* @return {@code true} if allowed, {@code false} otherwise.
*/
boolean getTruncateDropEnabled();
boolean getDropTruncateTableEnabled();

/**
* @return The threshold to warn when page size exceeds given size.
@@ -269,12 +269,12 @@
*
* @return {@code true} if allowed, {@code false} otherwise.
*/
boolean getTruncateDropEnabled();
boolean getDropTruncateTableEnabled();

/**
* Sets whether users can TRUNCATE or DROP TABLE
*/
void setTruncateDropEnabled(boolean enabled);
void setDropTruncateTableEnabled(boolean enabled);

/**
* @return The threshold to warn when requested page size greater than threshold.
@@ -23,13 +23,13 @@

import static java.lang.String.format;

public class GuardrailTruncateDropTest extends GuardrailTester
public class GuardrailDropTruncateTableTest extends GuardrailTester
{
private String tableQuery = "CREATE TABLE %s(pk int, ck int, v int, PRIMARY KEY(pk, ck))";

private void setGuardrail(boolean enabled)
{
Guardrails.instance.setTruncateDropEnabled(enabled);
Guardrails.instance.setDropTruncateTableEnabled(enabled);
}

@After
@@ -51,15 +51,15 @@ public void testCannotDropWhileFeatureDisabled() throws Throwable
{
setGuardrail(false);
createTable(tableQuery);
assertFails("DROP TABLE %s", "TRUNCATE and DROP TABLE functionality is not allowed");
assertFails("DROP TABLE %s", "DROP and TRUNCATE TABLE functionality is not allowed");
}

@Test
public void testIfExistsDoesNotBreakGuardrail() throws Throwable
{
setGuardrail(false);
createTable(tableQuery);
assertFails("DROP TABLE IF EXISTS %s", "TRUNCATE and DROP TABLE functionality is not allowed");
assertFails("DROP TABLE IF EXISTS %s", "DROP and TRUNCATE TABLE functionality is not allowed");
}

@Test
@@ -75,7 +75,7 @@ public void testCannotTruncateWhileFeatureDisabled() throws Throwable
{
setGuardrail(false);
createTable(tableQuery);
assertFails("TRUNCATE TABLE %s", "TRUNCATE and DROP TABLE functionality is not allowed");
assertFails("TRUNCATE TABLE %s", "DROP and TRUNCATE TABLE functionality is not allowed");
}

@Test

0 comments on commit 030831c

Please sign in to comment.