You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "aparnanaik0522 (via GitHub)" <gi...@apache.org> on 2025/09/24 17:12:20 UTC

[PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

aparnanaik0522 opened a new pull request, #4393:
URL: https://github.com/apache/cassandra/pull/4393

   Add DDL Guardrail enabling administrators to disallow creation/modification of key spaces with durable_writes = false
   
   This change implements a guardrail to disallow creation or alteration of key spaces to set the property durable_writes = false; durable_writes = true or unset should be the only allowable options for this property when enabled.
   
   patch by Aparna Naik; 
   
   reviewed by <Reviewers> for CASSANDRA-20913
   Co-authored-by: Name1 <email1>
   Co-authored-by: Name2 <email2>
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4393:
URL: https://github.com/apache/cassandra/pull/4393#discussion_r2377791224


##########
src/java/org/apache/cassandra/config/GuardrailsOptions.java:
##########
@@ -1430,6 +1473,26 @@ private static Set<String> validateTableProperties(Set<String> properties, Strin
         return lowerCaseProperties;
     }
 
+    private static Set<String> validateKeyspaceProperties(Set<String> properties, String name)
+    {
+        if(properties == null)

Review Comment:
   `if (properties == null)` (insert one space please)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4393:
URL: https://github.com/apache/cassandra/pull/4393#discussion_r2377895360


##########
test/unit/org/apache/cassandra/db/guardrails/GuardrailKeyspacePropertiesTest.java:
##########
@@ -0,0 +1,224 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.db.guardrails;
+
+import static java.lang.String.format;
+import static org.apache.cassandra.db.guardrails.GuardrailTester.guardrails;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.apache.cassandra.db.guardrails.GuardrailTester;
+import org.apache.cassandra.db.guardrails.Guardrails;
+import org.apache.cassandra.schema.KeyspaceParams;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * Tests the guardrail for keyspace properties, {@link Guardrails#keyspaceProperties}.
+ */
+public class GuardrailKeyspacePropertiesTest extends GuardrailTester
+{
+    private static final String CREATE_KEYSPACE = "CREATE KEYSPACE %s %s";
+    private static final String ALTER_KEYSPACE = "ALTER KEYSPACE %s WITH %s";
+
+    private static final String WARNED_PROPERTY_NAME = "keyspace_properties_warned";
+    private static final String IGNORED_PROPERTY_NAME = "keyspace_properties_ignored";
+    private static final String DISALLOWED_PROPERTY_NAME = "keyspace_properties_disallowed";
+
+    public GuardrailKeyspacePropertiesTest()
+    {
+        super(Guardrails.keyspaceProperties);
+    }
+
+    @Before
+    public void before()
+    {
+        // Set up basic test configuration - only allow "replication" by default
+        Set<String> allowed = new HashSet<>(Arrays.asList("replication"));
+        Set<String> allKeyspaceProperties = Arrays.stream(KeyspaceParams.Option.values())
+                                                  .map(KeyspaceParams.Option::toString)
+                                                  .collect(Collectors.toSet());
+        guardrails().setKeyspacePropertiesDisallowed(allKeyspaceProperties
+                                                     .stream()
+                                                     .filter(p -> !allowed.contains(p))
+                                                     .map(String::toUpperCase)
+                                                     .collect(Collectors.toSet()));
+        // Configure "durable_writes" to be warned about (tests will override as needed)
+        guardrails().setKeyspacePropertiesWarned("durable_writes");
+        guardrails().setKeyspacePropertiesIgnored(Collections.emptySet());
+    }
+
+    @Test
+    public void testConfigValidation()
+    {
+        String message = "Invalid value for %s: null is not allowed";
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesWarned, (Set<String>) null, message, WARNED_PROPERTY_NAME);
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesIgnored, (Set<String>) null, message, IGNORED_PROPERTY_NAME);
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesDisallowed, (Set<String>) null, message, DISALLOWED_PROPERTY_NAME);
+
+        assertValidProperty(Collections.emptySet());
+        assertValidProperty(getValidKeyspaceProperties());
+
+        assertValidPropertyCSV("");
+        assertValidPropertyCSV(String.join(",", getValidKeyspaceProperties()));
+
+        assertInvalidProperty(Collections.singleton("invalid"), Collections.singleton("invalid"));
+        assertInvalidProperty(ImmutableSet.of("replication", "invalid1", "invalid2"), ImmutableSet.of("invalid1", "invalid2"));
+        assertInvalidProperty(ImmutableSet.of("invalid1", "invalid2", "replication"), ImmutableSet.of("invalid1", "invalid2"));
+        assertInvalidProperty(ImmutableSet.of("invalid1", "replication", "invalid2"), ImmutableSet.of("invalid1", "invalid2"));
+
+        assertInvalidPropertyCSV("invalid", "[invalid]");
+        assertInvalidPropertyCSV("replication,invalid1,invalid2", "[invalid1, invalid2]");
+        assertInvalidPropertyCSV("invalid1,invalid2,replication", "[invalid1, invalid2]");
+        assertInvalidPropertyCSV("invalid1,replication,invalid2", "[invalid1, invalid2]");
+    }
+
+    private void assertValidProperty(Set<String> properties)
+    {
+        assertValidProperty(Guardrails::setKeyspacePropertiesWarned, Guardrails::getKeyspacePropertiesWarned, properties);
+        assertValidProperty(Guardrails::setKeyspacePropertiesIgnored, Guardrails::getKeyspacePropertiesIgnored, properties);
+        assertValidProperty(Guardrails::setKeyspacePropertiesDisallowed, Guardrails::getKeyspacePropertiesDisallowed, properties);
+    }
+
+    private void assertValidPropertyCSV(String csv)
+    {
+        csv = sortCSV(csv);
+        assertValidProperty(Guardrails::setKeyspacePropertiesWarnedCSV, g -> sortCSV(g.getKeyspacePropertiesWarnedCSV()), csv);
+        assertValidProperty(Guardrails::setKeyspacePropertiesIgnoredCSV, g -> sortCSV(g.getKeyspacePropertiesIgnoredCSV()), csv);
+        assertValidProperty(Guardrails::setKeyspacePropertiesDisallowedCSV, g -> sortCSV(g.getKeyspacePropertiesDisallowedCSV()), csv);
+    }
+
+    private void assertInvalidProperty(Set<String> properties, Set<String> invalidProperties)
+    {
+        String message = format("Invalid value for %s: '%s' do not parse as valid keyspace properties",
+                                WARNED_PROPERTY_NAME, invalidProperties);
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesWarned, properties, message, WARNED_PROPERTY_NAME);
+
+        message = format("Invalid value for %s: '%s' do not parse as valid keyspace properties",
+                         IGNORED_PROPERTY_NAME, invalidProperties);
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesIgnored, properties, message, IGNORED_PROPERTY_NAME);
+
+        message = format("Invalid value for %s: '%s' do not parse as valid keyspace properties",
+                         DISALLOWED_PROPERTY_NAME, invalidProperties);
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesDisallowed, properties, message, DISALLOWED_PROPERTY_NAME);
+    }
+
+    private void assertInvalidPropertyCSV(String properties, String rejected)
+    {
+        String message = "Invalid value for %s: '%s' do not parse as valid keyspace properties";
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesWarnedCSV, properties, message, WARNED_PROPERTY_NAME, rejected);
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesIgnoredCSV, properties, message, IGNORED_PROPERTY_NAME, rejected);
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesDisallowedCSV, properties, message, DISALLOWED_PROPERTY_NAME, rejected);
+    }
+
+    @Test
+    public void testCreateKeyspaceWithWarned() throws Throwable
+    {
+        String ks = createKeyspaceName();
+        String statement = format(CREATE_KEYSPACE, ks,
+                                 "WITH replication = {'class': 'NetworkTopologyStrategy', 'replication_factor': 1} AND durable_writes = false");
+        assertWarns(statement, "Keyspace Properties durable_writes is not recommended");
+    }
+
+    @Test
+    public void testCreateKeyspaceWithIgnored() throws Throwable
+    {
+        guardrails().setKeyspacePropertiesIgnored("durable_writes");
+        guardrails().setKeyspacePropertiesWarned(Collections.emptySet());
+        String ks = createKeyspaceName();
+        String statement = format(CREATE_KEYSPACE, ks,
+                                 "WITH replication = {'class': 'NetworkTopologyStrategy', 'replication_factor': 1} AND durable_writes = false");
+        assertValid(statement);
+    }
+
+    @Test
+    public void testCreateKeyspaceWithDisallowed() throws Throwable
+    {
+        guardrails().setKeyspacePropertiesDisallowed("durable_writes");
+        String ks = createKeyspaceName();
+        String statement = format(CREATE_KEYSPACE, ks,
+                                 "WITH replication = {'class': 'NetworkTopologyStrategy', 'replication_factor': 1} AND durable_writes = false");
+        assertFails(statement, "Keyspace Properties durable_writes is forbidden");

Review Comment:
   `Keyspace properties`? Why capitalized `P` in `Properties`? This is an opportunity to change it for table properties guardrail is it is same `P` there. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4393:
URL: https://github.com/apache/cassandra/pull/4393#discussion_r2377803984


##########
src/java/org/apache/cassandra/config/GuardrailsOptions.java:
##########
@@ -1430,6 +1473,26 @@ private static Set<String> validateTableProperties(Set<String> properties, Strin
         return lowerCaseProperties;
     }
 
+    private static Set<String> validateKeyspaceProperties(Set<String> properties, String name)
+    {
+        if(properties == null)
+            throw new IllegalArgumentException(format("Invalid value for %s: null is not allowed", name));
+        
+        Set<String> lowerCaseProperties = properties.stream().map(String::toLowerCase).collect(toSet());
+
+        Set<String> validKeyspaceProperties = Set.of(

Review Comment:
   Can you specify all options? In table case, we do `TableAttributes.allKeywords()`. Add 
   
       public static Set<String> allKeywords()
       {
           return Sets.union(validKeywords, obsoleteKeywords);
       }
   
   to `KeyspaceAttributes` class and reuse it here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

Posted by "aparnanaik0522 (via GitHub)" <gi...@apache.org>.
aparnanaik0522 commented on code in PR #4393:
URL: https://github.com/apache/cassandra/pull/4393#discussion_r2380056499


##########
test/unit/org/apache/cassandra/db/guardrails/GuardrailKeyspacePropertiesTest.java:
##########
@@ -0,0 +1,224 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.db.guardrails;
+
+import static java.lang.String.format;
+import static org.apache.cassandra.db.guardrails.GuardrailTester.guardrails;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.apache.cassandra.db.guardrails.GuardrailTester;
+import org.apache.cassandra.db.guardrails.Guardrails;
+import org.apache.cassandra.schema.KeyspaceParams;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * Tests the guardrail for keyspace properties, {@link Guardrails#keyspaceProperties}.
+ */
+public class GuardrailKeyspacePropertiesTest extends GuardrailTester
+{
+    private static final String CREATE_KEYSPACE = "CREATE KEYSPACE %s %s";
+    private static final String ALTER_KEYSPACE = "ALTER KEYSPACE %s WITH %s";
+
+    private static final String WARNED_PROPERTY_NAME = "keyspace_properties_warned";
+    private static final String IGNORED_PROPERTY_NAME = "keyspace_properties_ignored";
+    private static final String DISALLOWED_PROPERTY_NAME = "keyspace_properties_disallowed";
+
+    public GuardrailKeyspacePropertiesTest()
+    {
+        super(Guardrails.keyspaceProperties);
+    }
+
+    @Before
+    public void before()
+    {
+        // Set up basic test configuration - only allow "replication" by default
+        Set<String> allowed = new HashSet<>(Arrays.asList("replication"));
+        Set<String> allKeyspaceProperties = Arrays.stream(KeyspaceParams.Option.values())
+                                                  .map(KeyspaceParams.Option::toString)
+                                                  .collect(Collectors.toSet());
+        guardrails().setKeyspacePropertiesDisallowed(allKeyspaceProperties
+                                                     .stream()
+                                                     .filter(p -> !allowed.contains(p))
+                                                     .map(String::toUpperCase)
+                                                     .collect(Collectors.toSet()));
+        // Configure "durable_writes" to be warned about (tests will override as needed)
+        guardrails().setKeyspacePropertiesWarned("durable_writes");
+        guardrails().setKeyspacePropertiesIgnored(Collections.emptySet());
+    }
+
+    @Test
+    public void testConfigValidation()
+    {
+        String message = "Invalid value for %s: null is not allowed";
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesWarned, (Set<String>) null, message, WARNED_PROPERTY_NAME);
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesIgnored, (Set<String>) null, message, IGNORED_PROPERTY_NAME);
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesDisallowed, (Set<String>) null, message, DISALLOWED_PROPERTY_NAME);
+
+        assertValidProperty(Collections.emptySet());
+        assertValidProperty(getValidKeyspaceProperties());
+
+        assertValidPropertyCSV("");
+        assertValidPropertyCSV(String.join(",", getValidKeyspaceProperties()));
+
+        assertInvalidProperty(Collections.singleton("invalid"), Collections.singleton("invalid"));
+        assertInvalidProperty(ImmutableSet.of("replication", "invalid1", "invalid2"), ImmutableSet.of("invalid1", "invalid2"));
+        assertInvalidProperty(ImmutableSet.of("invalid1", "invalid2", "replication"), ImmutableSet.of("invalid1", "invalid2"));
+        assertInvalidProperty(ImmutableSet.of("invalid1", "replication", "invalid2"), ImmutableSet.of("invalid1", "invalid2"));
+
+        assertInvalidPropertyCSV("invalid", "[invalid]");
+        assertInvalidPropertyCSV("replication,invalid1,invalid2", "[invalid1, invalid2]");
+        assertInvalidPropertyCSV("invalid1,invalid2,replication", "[invalid1, invalid2]");
+        assertInvalidPropertyCSV("invalid1,replication,invalid2", "[invalid1, invalid2]");
+    }
+
+    private void assertValidProperty(Set<String> properties)
+    {
+        assertValidProperty(Guardrails::setKeyspacePropertiesWarned, Guardrails::getKeyspacePropertiesWarned, properties);
+        assertValidProperty(Guardrails::setKeyspacePropertiesIgnored, Guardrails::getKeyspacePropertiesIgnored, properties);
+        assertValidProperty(Guardrails::setKeyspacePropertiesDisallowed, Guardrails::getKeyspacePropertiesDisallowed, properties);
+    }
+
+    private void assertValidPropertyCSV(String csv)
+    {
+        csv = sortCSV(csv);
+        assertValidProperty(Guardrails::setKeyspacePropertiesWarnedCSV, g -> sortCSV(g.getKeyspacePropertiesWarnedCSV()), csv);
+        assertValidProperty(Guardrails::setKeyspacePropertiesIgnoredCSV, g -> sortCSV(g.getKeyspacePropertiesIgnoredCSV()), csv);
+        assertValidProperty(Guardrails::setKeyspacePropertiesDisallowedCSV, g -> sortCSV(g.getKeyspacePropertiesDisallowedCSV()), csv);
+    }
+
+    private void assertInvalidProperty(Set<String> properties, Set<String> invalidProperties)
+    {
+        String message = format("Invalid value for %s: '%s' do not parse as valid keyspace properties",
+                                WARNED_PROPERTY_NAME, invalidProperties);
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesWarned, properties, message, WARNED_PROPERTY_NAME);
+
+        message = format("Invalid value for %s: '%s' do not parse as valid keyspace properties",
+                         IGNORED_PROPERTY_NAME, invalidProperties);
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesIgnored, properties, message, IGNORED_PROPERTY_NAME);
+
+        message = format("Invalid value for %s: '%s' do not parse as valid keyspace properties",
+                         DISALLOWED_PROPERTY_NAME, invalidProperties);
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesDisallowed, properties, message, DISALLOWED_PROPERTY_NAME);
+    }
+
+    private void assertInvalidPropertyCSV(String properties, String rejected)
+    {
+        String message = "Invalid value for %s: '%s' do not parse as valid keyspace properties";
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesWarnedCSV, properties, message, WARNED_PROPERTY_NAME, rejected);
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesIgnoredCSV, properties, message, IGNORED_PROPERTY_NAME, rejected);
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesDisallowedCSV, properties, message, DISALLOWED_PROPERTY_NAME, rejected);
+    }
+
+    @Test
+    public void testCreateKeyspaceWithWarned() throws Throwable
+    {
+        String ks = createKeyspaceName();
+        String statement = format(CREATE_KEYSPACE, ks,
+                                 "WITH replication = {'class': 'NetworkTopologyStrategy', 'replication_factor': 1} AND durable_writes = false");
+        assertWarns(statement, "Keyspace Properties durable_writes is not recommended");
+    }
+
+    @Test
+    public void testCreateKeyspaceWithIgnored() throws Throwable
+    {
+        guardrails().setKeyspacePropertiesIgnored("durable_writes");
+        guardrails().setKeyspacePropertiesWarned(Collections.emptySet());
+        String ks = createKeyspaceName();
+        String statement = format(CREATE_KEYSPACE, ks,
+                                 "WITH replication = {'class': 'NetworkTopologyStrategy', 'replication_factor': 1} AND durable_writes = false");
+        assertValid(statement);
+    }
+
+    @Test
+    public void testCreateKeyspaceWithDisallowed() throws Throwable
+    {
+        guardrails().setKeyspacePropertiesDisallowed("durable_writes");
+        String ks = createKeyspaceName();
+        String statement = format(CREATE_KEYSPACE, ks,
+                                 "WITH replication = {'class': 'NetworkTopologyStrategy', 'replication_factor': 1} AND durable_writes = false");
+        assertFails(statement, "Keyspace Properties durable_writes is forbidden");

Review Comment:
   GuardrailTablePropertiesTest.java does not have similar assertion messages. It only passes property names like "[comment]" to its assertions, not full formatted messages.
   
   I have made required changes for this in GuardrailKeyspacePropertiesTest.java file. Thanks! 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4393:
URL: https://github.com/apache/cassandra/pull/4393#discussion_r2377803984


##########
src/java/org/apache/cassandra/config/GuardrailsOptions.java:
##########
@@ -1430,6 +1473,26 @@ private static Set<String> validateTableProperties(Set<String> properties, Strin
         return lowerCaseProperties;
     }
 
+    private static Set<String> validateKeyspaceProperties(Set<String> properties, String name)
+    {
+        if(properties == null)
+            throw new IllegalArgumentException(format("Invalid value for %s: null is not allowed", name));
+        
+        Set<String> lowerCaseProperties = properties.stream().map(String::toLowerCase).collect(toSet());
+
+        Set<String> validKeyspaceProperties = Set.of(

Review Comment:
   Can you specify all options? In table case, we do `TableAttributes.allKeywords()`. Add 
   
       public static Set<String> allKeywords()
       {
           return Sets.union(validKeywords, obsoleteKeywords);
       }
   
   to `KeyspaceAttributes` class and reuse it here so it is future-proof.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #4393:
URL: https://github.com/apache/cassandra/pull/4393#discussion_r2380304737


##########
src/java/org/apache/cassandra/config/GuardrailsOptions.java:
##########
@@ -25,9 +25,10 @@
 import javax.annotation.Nullable;
 
 import com.google.common.collect.Sets;
+import org.apache.cassandra.utils.LocalizeString;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-

Review Comment:
   nit: preserve this space between import groups



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4393:
URL: https://github.com/apache/cassandra/pull/4393#discussion_r2377814139


##########
test/unit/org/apache/cassandra/db/guardrails/GuardrailKeyspacePropertiesTest.java:
##########
@@ -0,0 +1,224 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.db.guardrails;
+
+import static java.lang.String.format;
+import static org.apache.cassandra.db.guardrails.GuardrailTester.guardrails;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.apache.cassandra.db.guardrails.GuardrailTester;
+import org.apache.cassandra.db.guardrails.Guardrails;
+import org.apache.cassandra.schema.KeyspaceParams;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * Tests the guardrail for keyspace properties, {@link Guardrails#keyspaceProperties}.
+ */
+public class GuardrailKeyspacePropertiesTest extends GuardrailTester

Review Comment:
   please update `GuardrailsConfigCommandsTest` test as well by adding newly added guardrail name among others. As of now I believe that test would fail. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4393:
URL: https://github.com/apache/cassandra/pull/4393#discussion_r2377895360


##########
test/unit/org/apache/cassandra/db/guardrails/GuardrailKeyspacePropertiesTest.java:
##########
@@ -0,0 +1,224 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.db.guardrails;
+
+import static java.lang.String.format;
+import static org.apache.cassandra.db.guardrails.GuardrailTester.guardrails;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.apache.cassandra.db.guardrails.GuardrailTester;
+import org.apache.cassandra.db.guardrails.Guardrails;
+import org.apache.cassandra.schema.KeyspaceParams;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * Tests the guardrail for keyspace properties, {@link Guardrails#keyspaceProperties}.
+ */
+public class GuardrailKeyspacePropertiesTest extends GuardrailTester
+{
+    private static final String CREATE_KEYSPACE = "CREATE KEYSPACE %s %s";
+    private static final String ALTER_KEYSPACE = "ALTER KEYSPACE %s WITH %s";
+
+    private static final String WARNED_PROPERTY_NAME = "keyspace_properties_warned";
+    private static final String IGNORED_PROPERTY_NAME = "keyspace_properties_ignored";
+    private static final String DISALLOWED_PROPERTY_NAME = "keyspace_properties_disallowed";
+
+    public GuardrailKeyspacePropertiesTest()
+    {
+        super(Guardrails.keyspaceProperties);
+    }
+
+    @Before
+    public void before()
+    {
+        // Set up basic test configuration - only allow "replication" by default
+        Set<String> allowed = new HashSet<>(Arrays.asList("replication"));
+        Set<String> allKeyspaceProperties = Arrays.stream(KeyspaceParams.Option.values())
+                                                  .map(KeyspaceParams.Option::toString)
+                                                  .collect(Collectors.toSet());
+        guardrails().setKeyspacePropertiesDisallowed(allKeyspaceProperties
+                                                     .stream()
+                                                     .filter(p -> !allowed.contains(p))
+                                                     .map(String::toUpperCase)
+                                                     .collect(Collectors.toSet()));
+        // Configure "durable_writes" to be warned about (tests will override as needed)
+        guardrails().setKeyspacePropertiesWarned("durable_writes");
+        guardrails().setKeyspacePropertiesIgnored(Collections.emptySet());
+    }
+
+    @Test
+    public void testConfigValidation()
+    {
+        String message = "Invalid value for %s: null is not allowed";
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesWarned, (Set<String>) null, message, WARNED_PROPERTY_NAME);
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesIgnored, (Set<String>) null, message, IGNORED_PROPERTY_NAME);
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesDisallowed, (Set<String>) null, message, DISALLOWED_PROPERTY_NAME);
+
+        assertValidProperty(Collections.emptySet());
+        assertValidProperty(getValidKeyspaceProperties());
+
+        assertValidPropertyCSV("");
+        assertValidPropertyCSV(String.join(",", getValidKeyspaceProperties()));
+
+        assertInvalidProperty(Collections.singleton("invalid"), Collections.singleton("invalid"));
+        assertInvalidProperty(ImmutableSet.of("replication", "invalid1", "invalid2"), ImmutableSet.of("invalid1", "invalid2"));
+        assertInvalidProperty(ImmutableSet.of("invalid1", "invalid2", "replication"), ImmutableSet.of("invalid1", "invalid2"));
+        assertInvalidProperty(ImmutableSet.of("invalid1", "replication", "invalid2"), ImmutableSet.of("invalid1", "invalid2"));
+
+        assertInvalidPropertyCSV("invalid", "[invalid]");
+        assertInvalidPropertyCSV("replication,invalid1,invalid2", "[invalid1, invalid2]");
+        assertInvalidPropertyCSV("invalid1,invalid2,replication", "[invalid1, invalid2]");
+        assertInvalidPropertyCSV("invalid1,replication,invalid2", "[invalid1, invalid2]");
+    }
+
+    private void assertValidProperty(Set<String> properties)
+    {
+        assertValidProperty(Guardrails::setKeyspacePropertiesWarned, Guardrails::getKeyspacePropertiesWarned, properties);
+        assertValidProperty(Guardrails::setKeyspacePropertiesIgnored, Guardrails::getKeyspacePropertiesIgnored, properties);
+        assertValidProperty(Guardrails::setKeyspacePropertiesDisallowed, Guardrails::getKeyspacePropertiesDisallowed, properties);
+    }
+
+    private void assertValidPropertyCSV(String csv)
+    {
+        csv = sortCSV(csv);
+        assertValidProperty(Guardrails::setKeyspacePropertiesWarnedCSV, g -> sortCSV(g.getKeyspacePropertiesWarnedCSV()), csv);
+        assertValidProperty(Guardrails::setKeyspacePropertiesIgnoredCSV, g -> sortCSV(g.getKeyspacePropertiesIgnoredCSV()), csv);
+        assertValidProperty(Guardrails::setKeyspacePropertiesDisallowedCSV, g -> sortCSV(g.getKeyspacePropertiesDisallowedCSV()), csv);
+    }
+
+    private void assertInvalidProperty(Set<String> properties, Set<String> invalidProperties)
+    {
+        String message = format("Invalid value for %s: '%s' do not parse as valid keyspace properties",
+                                WARNED_PROPERTY_NAME, invalidProperties);
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesWarned, properties, message, WARNED_PROPERTY_NAME);
+
+        message = format("Invalid value for %s: '%s' do not parse as valid keyspace properties",
+                         IGNORED_PROPERTY_NAME, invalidProperties);
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesIgnored, properties, message, IGNORED_PROPERTY_NAME);
+
+        message = format("Invalid value for %s: '%s' do not parse as valid keyspace properties",
+                         DISALLOWED_PROPERTY_NAME, invalidProperties);
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesDisallowed, properties, message, DISALLOWED_PROPERTY_NAME);
+    }
+
+    private void assertInvalidPropertyCSV(String properties, String rejected)
+    {
+        String message = "Invalid value for %s: '%s' do not parse as valid keyspace properties";
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesWarnedCSV, properties, message, WARNED_PROPERTY_NAME, rejected);
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesIgnoredCSV, properties, message, IGNORED_PROPERTY_NAME, rejected);
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesDisallowedCSV, properties, message, DISALLOWED_PROPERTY_NAME, rejected);
+    }
+
+    @Test
+    public void testCreateKeyspaceWithWarned() throws Throwable
+    {
+        String ks = createKeyspaceName();
+        String statement = format(CREATE_KEYSPACE, ks,
+                                 "WITH replication = {'class': 'NetworkTopologyStrategy', 'replication_factor': 1} AND durable_writes = false");
+        assertWarns(statement, "Keyspace Properties durable_writes is not recommended");
+    }
+
+    @Test
+    public void testCreateKeyspaceWithIgnored() throws Throwable
+    {
+        guardrails().setKeyspacePropertiesIgnored("durable_writes");
+        guardrails().setKeyspacePropertiesWarned(Collections.emptySet());
+        String ks = createKeyspaceName();
+        String statement = format(CREATE_KEYSPACE, ks,
+                                 "WITH replication = {'class': 'NetworkTopologyStrategy', 'replication_factor': 1} AND durable_writes = false");
+        assertValid(statement);
+    }
+
+    @Test
+    public void testCreateKeyspaceWithDisallowed() throws Throwable
+    {
+        guardrails().setKeyspacePropertiesDisallowed("durable_writes");
+        String ks = createKeyspaceName();
+        String statement = format(CREATE_KEYSPACE, ks,
+                                 "WITH replication = {'class': 'NetworkTopologyStrategy', 'replication_factor': 1} AND durable_writes = false");
+        assertFails(statement, "Keyspace Properties durable_writes is forbidden");

Review Comment:
   `Keyspace properties`? Why capitalized `P` in `Properties`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #4393:
URL: https://github.com/apache/cassandra/pull/4393#discussion_r2380328773


##########
src/java/org/apache/cassandra/config/GuardrailsOptions.java:
##########
@@ -1424,12 +1467,28 @@ private static Set<String> validateTableProperties(Set<String> properties, Strin
         Set<String> diff = Sets.difference(lowerCaseProperties, TableAttributes.allKeywords());
 
         if (!diff.isEmpty())
-            throw new IllegalArgumentException(format("Invalid value for %s: '%s' do not parse as valid table properties",
+            throw new IllegalArgumentException(format("Invalid values for %s: '%s' do not parse as valid table properties",
                                                       name, diff));
 
         return lowerCaseProperties;
     }
 
+    private static Set<String> validateKeyspaceProperties(Set<String> properties, String name)
+    {
+        if (properties == null)
+            throw new IllegalArgumentException(format("Invalid values for %s: null is not allowed", name));

Review Comment:
   nit: In this case, though, I might just go with `Invalid value for...` since `null` is...singular?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4393:
URL: https://github.com/apache/cassandra/pull/4393#discussion_r2383986615


##########
src/java/org/apache/cassandra/config/GuardrailsOptions.java:
##########
@@ -1424,7 +1471,23 @@ private static Set<String> validateTableProperties(Set<String> properties, Strin
         Set<String> diff = Sets.difference(lowerCaseProperties, TableAttributes.allKeywords());
 
         if (!diff.isEmpty())
-            throw new IllegalArgumentException(format("Invalid value for %s: '%s' do not parse as valid table properties",
+            throw new IllegalArgumentException(format("Invalid values for %s: '%s' do not parse as valid table properties",

Review Comment:
   @aparnanaik0522  you have changed it here but you have not reflected this change into table tests



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4393:
URL: https://github.com/apache/cassandra/pull/4393#discussion_r2377805774


##########
src/java/org/apache/cassandra/config/GuardrailsOptions.java:
##########
@@ -1430,6 +1473,26 @@ private static Set<String> validateTableProperties(Set<String> properties, Strin
         return lowerCaseProperties;
     }
 
+    private static Set<String> validateKeyspaceProperties(Set<String> properties, String name)
+    {
+        if(properties == null)
+            throw new IllegalArgumentException(format("Invalid value for %s: null is not allowed", name));
+        
+        Set<String> lowerCaseProperties = properties.stream().map(String::toLowerCase).collect(toSet());
+
+        Set<String> validKeyspaceProperties = Set.of(
+                                                KeyspaceParams.Option.DURABLE_WRITES.toString(),
+                                                KeyspaceParams.Option.REPLICATION.toString(),
+                                                KeyspaceParams.Option.FAST_PATH.toString()
+                                            );
+        Set<String> diff = Sets.difference(lowerCaseProperties, validKeyspaceProperties);
+
+        if(!diff.isEmpty())

Review Comment:
   `if (!...`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #4393:
URL: https://github.com/apache/cassandra/pull/4393#discussion_r2380305448


##########
src/java/org/apache/cassandra/config/GuardrailsOptions.java:
##########
@@ -25,9 +25,10 @@
 import javax.annotation.Nullable;
 
 import com.google.common.collect.Sets;
+import org.apache.cassandra.utils.LocalizeString;

Review Comment:
   nit: move this down into the `cassandra` import group and alphabetize



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #4393:
URL: https://github.com/apache/cassandra/pull/4393#discussion_r2380365967


##########
src/java/org/apache/cassandra/config/GuardrailsOptions.java:
##########
@@ -1424,12 +1467,28 @@ private static Set<String> validateTableProperties(Set<String> properties, Strin
         Set<String> diff = Sets.difference(lowerCaseProperties, TableAttributes.allKeywords());
 
         if (!diff.isEmpty())
-            throw new IllegalArgumentException(format("Invalid value for %s: '%s' do not parse as valid table properties",
+            throw new IllegalArgumentException(format("Invalid values for %s: '%s' do not parse as valid table properties",
                                                       name, diff));
 
         return lowerCaseProperties;
     }
 
+    private static Set<String> validateKeyspaceProperties(Set<String> properties, String name)
+    {
+        if (properties == null)
+            throw new IllegalArgumentException(format("Invalid values for %s: null is not allowed", name));
+        
+        Set<String> lowerCaseProperties = properties.stream().map(LocalizeString::toLowerCaseLocalized).collect(toSet());
+
+        Set<String> diff = Sets.difference(lowerCaseProperties, KeyspaceAttributes.allKeywords());
+
+        if (!diff.isEmpty()) 
+            throw new IllegalArgumentException(format("Invalid values for %s: '%s' do not parse as valid keyspace properties", 
+                                                    name, diff));

Review Comment:
   ```suggestion
                                                         name, diff));
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #4393:
URL: https://github.com/apache/cassandra/pull/4393#discussion_r2389208728


##########
src/java/org/apache/cassandra/db/guardrails/Guardrails.java:
##########
@@ -143,6 +143,20 @@ public final class Guardrails implements GuardrailsMBean
                  state -> CONFIG_PROVIDER.getOrCreate(state).getTablePropertiesDisallowed(),
                  "Table Properties");
 
+    /**
+     * Guardrail warning about, ignoring or rejecting the usage of certain keyspace properties.
+     */
+    public static final Values<String> keyspaceProperties =
+    new Values<>("keyspace_properties",
+                 null,
+                 state -> CONFIG_PROVIDER.getOrCreate(state).getKeyspacePropertiesWarned(),
+                 state -> CONFIG_PROVIDER.getOrCreate(state).getKeyspacePropertiesIgnored(),
+                 state -> CONFIG_PROVIDER.getOrCreate(state).getKeyspacePropertiesDisallowed()
+                          .stream()
+                          .filter(prop -> !"replication".equals(prop))

Review Comment:
   Actually, why don't we just hard fail any attempt to include a required parameter in `validateKeyspaceProperties()`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4393:
URL: https://github.com/apache/cassandra/pull/4393#discussion_r2390334114


##########
src/java/org/apache/cassandra/db/guardrails/Guardrails.java:
##########
@@ -143,6 +143,20 @@ public final class Guardrails implements GuardrailsMBean
                  state -> CONFIG_PROVIDER.getOrCreate(state).getTablePropertiesDisallowed(),
                  "Table Properties");
 
+    /**
+     * Guardrail warning about, ignoring or rejecting the usage of certain keyspace properties.
+     */
+    public static final Values<String> keyspaceProperties =
+    new Values<>("keyspace_properties",
+                 null,
+                 state -> CONFIG_PROVIDER.getOrCreate(state).getKeyspacePropertiesWarned(),
+                 state -> CONFIG_PROVIDER.getOrCreate(state).getKeyspacePropertiesIgnored(),
+                 state -> CONFIG_PROVIDER.getOrCreate(state).getKeyspacePropertiesDisallowed()
+                          .stream()
+                          .filter(prop -> !"replication".equals(prop))

Review Comment:
   @maedhroz  sure, we can do this too. So we clearly declare this to a user instead of silently proceeding and users thinking it is all fine.
   
   @aparnanaik0522 please rebase your patch on top of the current trunk, now it has like 10 commits, completely unrelated to this patch. Thank you!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4393:
URL: https://github.com/apache/cassandra/pull/4393#discussion_r2377796479


##########
src/java/org/apache/cassandra/config/GuardrailsOptions.java:
##########
@@ -1430,6 +1473,26 @@ private static Set<String> validateTableProperties(Set<String> properties, Strin
         return lowerCaseProperties;
     }
 
+    private static Set<String> validateKeyspaceProperties(Set<String> properties, String name)
+    {
+        if(properties == null)
+            throw new IllegalArgumentException(format("Invalid value for %s: null is not allowed", name));
+        
+        Set<String> lowerCaseProperties = properties.stream().map(String::toLowerCase).collect(toSet());

Review Comment:
   technically, we should do `properties.stream().map(LocalizeString::toLowerCaseLocalized)` (same for table properties validation method).  See `.build/checkstyle.xml` file and search for "block toLowerCase and toUpperCase" comment.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4393:
URL: https://github.com/apache/cassandra/pull/4393#discussion_r2377895360


##########
test/unit/org/apache/cassandra/db/guardrails/GuardrailKeyspacePropertiesTest.java:
##########
@@ -0,0 +1,224 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.db.guardrails;
+
+import static java.lang.String.format;
+import static org.apache.cassandra.db.guardrails.GuardrailTester.guardrails;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.apache.cassandra.db.guardrails.GuardrailTester;
+import org.apache.cassandra.db.guardrails.Guardrails;
+import org.apache.cassandra.schema.KeyspaceParams;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * Tests the guardrail for keyspace properties, {@link Guardrails#keyspaceProperties}.
+ */
+public class GuardrailKeyspacePropertiesTest extends GuardrailTester
+{
+    private static final String CREATE_KEYSPACE = "CREATE KEYSPACE %s %s";
+    private static final String ALTER_KEYSPACE = "ALTER KEYSPACE %s WITH %s";
+
+    private static final String WARNED_PROPERTY_NAME = "keyspace_properties_warned";
+    private static final String IGNORED_PROPERTY_NAME = "keyspace_properties_ignored";
+    private static final String DISALLOWED_PROPERTY_NAME = "keyspace_properties_disallowed";
+
+    public GuardrailKeyspacePropertiesTest()
+    {
+        super(Guardrails.keyspaceProperties);
+    }
+
+    @Before
+    public void before()
+    {
+        // Set up basic test configuration - only allow "replication" by default
+        Set<String> allowed = new HashSet<>(Arrays.asList("replication"));
+        Set<String> allKeyspaceProperties = Arrays.stream(KeyspaceParams.Option.values())
+                                                  .map(KeyspaceParams.Option::toString)
+                                                  .collect(Collectors.toSet());
+        guardrails().setKeyspacePropertiesDisallowed(allKeyspaceProperties
+                                                     .stream()
+                                                     .filter(p -> !allowed.contains(p))
+                                                     .map(String::toUpperCase)
+                                                     .collect(Collectors.toSet()));
+        // Configure "durable_writes" to be warned about (tests will override as needed)
+        guardrails().setKeyspacePropertiesWarned("durable_writes");
+        guardrails().setKeyspacePropertiesIgnored(Collections.emptySet());
+    }
+
+    @Test
+    public void testConfigValidation()
+    {
+        String message = "Invalid value for %s: null is not allowed";
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesWarned, (Set<String>) null, message, WARNED_PROPERTY_NAME);
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesIgnored, (Set<String>) null, message, IGNORED_PROPERTY_NAME);
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesDisallowed, (Set<String>) null, message, DISALLOWED_PROPERTY_NAME);
+
+        assertValidProperty(Collections.emptySet());
+        assertValidProperty(getValidKeyspaceProperties());
+
+        assertValidPropertyCSV("");
+        assertValidPropertyCSV(String.join(",", getValidKeyspaceProperties()));
+
+        assertInvalidProperty(Collections.singleton("invalid"), Collections.singleton("invalid"));
+        assertInvalidProperty(ImmutableSet.of("replication", "invalid1", "invalid2"), ImmutableSet.of("invalid1", "invalid2"));
+        assertInvalidProperty(ImmutableSet.of("invalid1", "invalid2", "replication"), ImmutableSet.of("invalid1", "invalid2"));
+        assertInvalidProperty(ImmutableSet.of("invalid1", "replication", "invalid2"), ImmutableSet.of("invalid1", "invalid2"));
+
+        assertInvalidPropertyCSV("invalid", "[invalid]");
+        assertInvalidPropertyCSV("replication,invalid1,invalid2", "[invalid1, invalid2]");
+        assertInvalidPropertyCSV("invalid1,invalid2,replication", "[invalid1, invalid2]");
+        assertInvalidPropertyCSV("invalid1,replication,invalid2", "[invalid1, invalid2]");
+    }
+
+    private void assertValidProperty(Set<String> properties)
+    {
+        assertValidProperty(Guardrails::setKeyspacePropertiesWarned, Guardrails::getKeyspacePropertiesWarned, properties);
+        assertValidProperty(Guardrails::setKeyspacePropertiesIgnored, Guardrails::getKeyspacePropertiesIgnored, properties);
+        assertValidProperty(Guardrails::setKeyspacePropertiesDisallowed, Guardrails::getKeyspacePropertiesDisallowed, properties);
+    }
+
+    private void assertValidPropertyCSV(String csv)
+    {
+        csv = sortCSV(csv);
+        assertValidProperty(Guardrails::setKeyspacePropertiesWarnedCSV, g -> sortCSV(g.getKeyspacePropertiesWarnedCSV()), csv);
+        assertValidProperty(Guardrails::setKeyspacePropertiesIgnoredCSV, g -> sortCSV(g.getKeyspacePropertiesIgnoredCSV()), csv);
+        assertValidProperty(Guardrails::setKeyspacePropertiesDisallowedCSV, g -> sortCSV(g.getKeyspacePropertiesDisallowedCSV()), csv);
+    }
+
+    private void assertInvalidProperty(Set<String> properties, Set<String> invalidProperties)
+    {
+        String message = format("Invalid value for %s: '%s' do not parse as valid keyspace properties",
+                                WARNED_PROPERTY_NAME, invalidProperties);
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesWarned, properties, message, WARNED_PROPERTY_NAME);
+
+        message = format("Invalid value for %s: '%s' do not parse as valid keyspace properties",
+                         IGNORED_PROPERTY_NAME, invalidProperties);
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesIgnored, properties, message, IGNORED_PROPERTY_NAME);
+
+        message = format("Invalid value for %s: '%s' do not parse as valid keyspace properties",
+                         DISALLOWED_PROPERTY_NAME, invalidProperties);
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesDisallowed, properties, message, DISALLOWED_PROPERTY_NAME);
+    }
+
+    private void assertInvalidPropertyCSV(String properties, String rejected)
+    {
+        String message = "Invalid value for %s: '%s' do not parse as valid keyspace properties";
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesWarnedCSV, properties, message, WARNED_PROPERTY_NAME, rejected);
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesIgnoredCSV, properties, message, IGNORED_PROPERTY_NAME, rejected);
+        assertInvalidProperty(Guardrails::setKeyspacePropertiesDisallowedCSV, properties, message, DISALLOWED_PROPERTY_NAME, rejected);
+    }
+
+    @Test
+    public void testCreateKeyspaceWithWarned() throws Throwable
+    {
+        String ks = createKeyspaceName();
+        String statement = format(CREATE_KEYSPACE, ks,
+                                 "WITH replication = {'class': 'NetworkTopologyStrategy', 'replication_factor': 1} AND durable_writes = false");
+        assertWarns(statement, "Keyspace Properties durable_writes is not recommended");
+    }
+
+    @Test
+    public void testCreateKeyspaceWithIgnored() throws Throwable
+    {
+        guardrails().setKeyspacePropertiesIgnored("durable_writes");
+        guardrails().setKeyspacePropertiesWarned(Collections.emptySet());
+        String ks = createKeyspaceName();
+        String statement = format(CREATE_KEYSPACE, ks,
+                                 "WITH replication = {'class': 'NetworkTopologyStrategy', 'replication_factor': 1} AND durable_writes = false");
+        assertValid(statement);
+    }
+
+    @Test
+    public void testCreateKeyspaceWithDisallowed() throws Throwable
+    {
+        guardrails().setKeyspacePropertiesDisallowed("durable_writes");
+        String ks = createKeyspaceName();
+        String statement = format(CREATE_KEYSPACE, ks,
+                                 "WITH replication = {'class': 'NetworkTopologyStrategy', 'replication_factor': 1} AND durable_writes = false");
+        assertFails(statement, "Keyspace Properties durable_writes is forbidden");

Review Comment:
   `Keyspace properties`? Why capitalized `P` in `Properties`? This is an opportunity to change it for table properties guardrail if it is same `P` there. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4393:
URL: https://github.com/apache/cassandra/pull/4393#discussion_r2377809088


##########
src/java/org/apache/cassandra/config/GuardrailsOptions.java:
##########
@@ -1430,6 +1473,26 @@ private static Set<String> validateTableProperties(Set<String> properties, Strin
         return lowerCaseProperties;
     }
 
+    private static Set<String> validateKeyspaceProperties(Set<String> properties, String name)
+    {
+        if(properties == null)
+            throw new IllegalArgumentException(format("Invalid value for %s: null is not allowed", name));
+        
+        Set<String> lowerCaseProperties = properties.stream().map(String::toLowerCase).collect(toSet());
+
+        Set<String> validKeyspaceProperties = Set.of(
+                                                KeyspaceParams.Option.DURABLE_WRITES.toString(),
+                                                KeyspaceParams.Option.REPLICATION.toString(),
+                                                KeyspaceParams.Option.FAST_PATH.toString()
+                                            );
+        Set<String> diff = Sets.difference(lowerCaseProperties, validKeyspaceProperties);
+
+        if(!diff.isEmpty())
+            throw new IllegalArgumentException(format("Invalid value for %s: '%s' does not parse as valid keyspace property", name, diff));

Review Comment:
   `diff` can contain multiple items, it should be `Invalid values for ...` and `... '%s' do not parse as valid keyspace properties`. Same as for table case.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #4393:
URL: https://github.com/apache/cassandra/pull/4393#discussion_r2380286957


##########
conf/cassandra.yaml:
##########
@@ -2273,6 +2273,11 @@ drop_compact_storage_enabled: false
 # table_properties_ignored: []
 # table_properties_disallowed: []
 #
+# # Guardrail to warn about, ignore or reject properties when creating or modifying keyspaces. By default all properties are allowed.

Review Comment:
   ```suggestion
   # Guardrail to warn about, ignore or reject properties when creating or modifying keyspaces. By default all properties are allowed.
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #4393:
URL: https://github.com/apache/cassandra/pull/4393#discussion_r2380345317


##########
src/java/org/apache/cassandra/config/GuardrailsOptions.java:
##########
@@ -181,6 +185,45 @@ public void setColumnsPerTableThreshold(int warn, int fail)
                                   x -> config.columns_per_table_fail_threshold = x);
     }
 
+    @Override
+    public Set<String> getKeyspacePropertiesWarned()
+    {
+        return config.keyspace_properties_warned;
+    }
+    
+    public void setKeyspacePropertiesWarned(Set<String> properties)
+    {
+        updatePropertyWithLogging("keyspace_properties_warned",
+                                validateKeyspaceProperties(properties, "keyspace_properties_warned"),
+                                () -> config.keyspace_properties_warned, x -> config.keyspace_properties_warned = x);

Review Comment:
   nit: Here and in the methods below, let's alighn the arguments horizontally. For example...
   ```suggestion
                                    () -> config.keyspace_properties_warned, x -> config.keyspace_properties_warned = x);
   ```



##########
src/java/org/apache/cassandra/config/GuardrailsOptions.java:
##########
@@ -181,6 +185,45 @@ public void setColumnsPerTableThreshold(int warn, int fail)
                                   x -> config.columns_per_table_fail_threshold = x);
     }
 
+    @Override
+    public Set<String> getKeyspacePropertiesWarned()
+    {
+        return config.keyspace_properties_warned;
+    }
+    
+    public void setKeyspacePropertiesWarned(Set<String> properties)
+    {
+        updatePropertyWithLogging("keyspace_properties_warned",
+                                validateKeyspaceProperties(properties, "keyspace_properties_warned"),
+                                () -> config.keyspace_properties_warned, x -> config.keyspace_properties_warned = x);

Review Comment:
   nit: Here and in the methods below, let's align the arguments horizontally. For example...
   ```suggestion
                                    () -> config.keyspace_properties_warned, x -> config.keyspace_properties_warned = x);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

Posted by "aparnanaik0522 (via GitHub)" <gi...@apache.org>.
aparnanaik0522 closed pull request #4393: CASSANDRA-20913 Guard Durable Writes
URL: https://github.com/apache/cassandra/pull/4393


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #4393:
URL: https://github.com/apache/cassandra/pull/4393#discussion_r2389208728


##########
src/java/org/apache/cassandra/db/guardrails/Guardrails.java:
##########
@@ -143,6 +143,20 @@ public final class Guardrails implements GuardrailsMBean
                  state -> CONFIG_PROVIDER.getOrCreate(state).getTablePropertiesDisallowed(),
                  "Table Properties");
 
+    /**
+     * Guardrail warning about, ignoring or rejecting the usage of certain keyspace properties.
+     */
+    public static final Values<String> keyspaceProperties =
+    new Values<>("keyspace_properties",
+                 null,
+                 state -> CONFIG_PROVIDER.getOrCreate(state).getKeyspacePropertiesWarned(),
+                 state -> CONFIG_PROVIDER.getOrCreate(state).getKeyspacePropertiesIgnored(),
+                 state -> CONFIG_PROVIDER.getOrCreate(state).getKeyspacePropertiesDisallowed()
+                          .stream()
+                          .filter(prop -> !"replication".equals(prop))

Review Comment:
   Actually, why don't we just hard fail any attempt to include a required parameter in `validateKeyspaceProperties()`? We already do this for invalid keyspace parameters.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4393:
URL: https://github.com/apache/cassandra/pull/4393#discussion_r2380214781


##########
test/unit/org/apache/cassandra/db/guardrails/GuardrailKeyspacePropertiesTest.java:
##########
@@ -0,0 +1,222 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.db.guardrails;
+
+import static java.lang.String.format;
+import static org.apache.cassandra.db.guardrails.GuardrailTester.guardrails;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.apache.cassandra.schema.KeyspaceParams;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * Tests the guardrail for keyspace properties, {@link Guardrails#keyspaceProperties}.
+ */
+public class GuardrailKeyspacePropertiesTest extends GuardrailTester
+{
+    private static final String CREATE_KEYSPACE = "CREATE KEYSPACE %s %s";
+    private static final String ALTER_KEYSPACE = "ALTER KEYSPACE %s WITH %s";
+
+    private static final String WARNED_PROPERTY_NAME = "keyspace_properties_warned";
+    private static final String IGNORED_PROPERTY_NAME = "keyspace_properties_ignored";
+    private static final String DISALLOWED_PROPERTY_NAME = "keyspace_properties_disallowed";
+
+    public GuardrailKeyspacePropertiesTest()
+    {
+        super(Guardrails.keyspaceProperties);
+    }
+
+    @Before
+    public void before()
+    {
+        // Set up basic test configuration - only allow "replication" by default
+        Set<String> allowed = new HashSet<>(Arrays.asList("replication"));
+        Set<String> allKeyspaceProperties = Arrays.stream(KeyspaceParams.Option.values())
+                                                  .map(KeyspaceParams.Option::toString)
+                                                  .collect(Collectors.toSet());
+        guardrails().setKeyspacePropertiesDisallowed(allKeyspaceProperties
+                                                     .stream()
+                                                     .filter(p -> !allowed.contains(p))
+                                                     .map(String::toUpperCase)

Review Comment:
   nit: we have localized version of upper case too 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #4393:
URL: https://github.com/apache/cassandra/pull/4393#discussion_r2380336188


##########
test/unit/org/apache/cassandra/db/guardrails/GuardrailKeyspacePropertiesTest.java:
##########
@@ -0,0 +1,223 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.db.guardrails;
+
+import static java.lang.String.format;
+import static org.apache.cassandra.db.guardrails.GuardrailTester.guardrails;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.apache.cassandra.schema.KeyspaceParams;
+import org.apache.cassandra.utils.LocalizeString;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * Tests the guardrail for keyspace properties, {@link Guardrails#keyspaceProperties}.
+ */
+public class GuardrailKeyspacePropertiesTest extends GuardrailTester
+{
+    private static final String CREATE_KEYSPACE = "CREATE KEYSPACE %s %s";
+    private static final String ALTER_KEYSPACE = "ALTER KEYSPACE %s WITH %s";
+
+    private static final String WARNED_PROPERTY_NAME = "keyspace_properties_warned";
+    private static final String IGNORED_PROPERTY_NAME = "keyspace_properties_ignored";
+    private static final String DISALLOWED_PROPERTY_NAME = "keyspace_properties_disallowed";
+
+    public GuardrailKeyspacePropertiesTest()
+    {
+        super(Guardrails.keyspaceProperties);
+    }
+
+    @Before
+    public void before()
+    {
+        // Set up basic test configuration - only allow "replication" by default
+        Set<String> allowed = new HashSet<>(Arrays.asList("replication"));

Review Comment:
   ```suggestion
           Set<String> allowed = new HashSet<>(List.of("replication"));
   ```
   It's just test code, but `List.of()` saves some memory.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #4393:
URL: https://github.com/apache/cassandra/pull/4393#discussion_r2380329652


##########
src/java/org/apache/cassandra/config/GuardrailsOptions.java:
##########
@@ -1424,12 +1467,28 @@ private static Set<String> validateTableProperties(Set<String> properties, Strin
         Set<String> diff = Sets.difference(lowerCaseProperties, TableAttributes.allKeywords());
 
         if (!diff.isEmpty())
-            throw new IllegalArgumentException(format("Invalid value for %s: '%s' do not parse as valid table properties",
+            throw new IllegalArgumentException(format("Invalid values for %s: '%s' do not parse as valid table properties",
                                                       name, diff));
 
         return lowerCaseProperties;
     }
 
+    private static Set<String> validateKeyspaceProperties(Set<String> properties, String name)
+    {
+        if (properties == null)
+            throw new IllegalArgumentException(format("Invalid values for %s: null is not allowed", name));
+        

Review Comment:
   nit: extra whitespace
   



##########
src/java/org/apache/cassandra/config/GuardrailsOptions.java:
##########
@@ -1424,12 +1467,28 @@ private static Set<String> validateTableProperties(Set<String> properties, Strin
         Set<String> diff = Sets.difference(lowerCaseProperties, TableAttributes.allKeywords());
 
         if (!diff.isEmpty())
-            throw new IllegalArgumentException(format("Invalid value for %s: '%s' do not parse as valid table properties",
+            throw new IllegalArgumentException(format("Invalid values for %s: '%s' do not parse as valid table properties",
                                                       name, diff));
 
         return lowerCaseProperties;
     }
 
+    private static Set<String> validateKeyspaceProperties(Set<String> properties, String name)
+    {
+        if (properties == null)
+            throw new IllegalArgumentException(format("Invalid values for %s: null is not allowed", name));
+        
+        Set<String> lowerCaseProperties = properties.stream().map(LocalizeString::toLowerCaseLocalized).collect(toSet());
+
+        Set<String> diff = Sets.difference(lowerCaseProperties, KeyspaceAttributes.allKeywords());
+
+        if (!diff.isEmpty()) 
+            throw new IllegalArgumentException(format("Invalid values for %s: '%s' do not parse as valid keyspace properties", 
+                                                    name, diff));
+        

Review Comment:
   nit: extra whitespace



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #4393:
URL: https://github.com/apache/cassandra/pull/4393#discussion_r2380345317


##########
src/java/org/apache/cassandra/config/GuardrailsOptions.java:
##########
@@ -181,6 +185,45 @@ public void setColumnsPerTableThreshold(int warn, int fail)
                                   x -> config.columns_per_table_fail_threshold = x);
     }
 
+    @Override
+    public Set<String> getKeyspacePropertiesWarned()
+    {
+        return config.keyspace_properties_warned;
+    }
+    
+    public void setKeyspacePropertiesWarned(Set<String> properties)
+    {
+        updatePropertyWithLogging("keyspace_properties_warned",
+                                validateKeyspaceProperties(properties, "keyspace_properties_warned"),
+                                () -> config.keyspace_properties_warned, x -> config.keyspace_properties_warned = x);

Review Comment:
   nit: Here and in the methods below, let's alight the arguments horizontally. For example...
   ```suggestion
                                    () -> config.keyspace_properties_warned, x -> config.keyspace_properties_warned = x);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4393:
URL: https://github.com/apache/cassandra/pull/4393#discussion_r2377796479


##########
src/java/org/apache/cassandra/config/GuardrailsOptions.java:
##########
@@ -1430,6 +1473,26 @@ private static Set<String> validateTableProperties(Set<String> properties, Strin
         return lowerCaseProperties;
     }
 
+    private static Set<String> validateKeyspaceProperties(Set<String> properties, String name)
+    {
+        if(properties == null)
+            throw new IllegalArgumentException(format("Invalid value for %s: null is not allowed", name));
+        
+        Set<String> lowerCaseProperties = properties.stream().map(String::toLowerCase).collect(toSet());

Review Comment:
   technically, we should do `properties.stream().map(LocalizeString::toLowerCaseLocalized)` (same for table properties validation method).  See `.build/checkstyle.xml` file and search for "<!-- block toLowerCase and toUpperCase -->" comment.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4393:
URL: https://github.com/apache/cassandra/pull/4393#discussion_r2383992357


##########
src/java/org/apache/cassandra/db/guardrails/Guardrails.java:
##########
@@ -143,6 +143,20 @@ public final class Guardrails implements GuardrailsMBean
                  state -> CONFIG_PROVIDER.getOrCreate(state).getTablePropertiesDisallowed(),
                  "Table Properties");
 
+    /**
+     * Guardrail warning about, ignoring or rejecting the usage of certain keyspace properties.
+     */
+    public static final Values<String> keyspaceProperties =
+    new Values<>("keyspace_properties",
+                 null,
+                 state -> CONFIG_PROVIDER.getOrCreate(state).getKeyspacePropertiesWarned(),
+                 state -> CONFIG_PROVIDER.getOrCreate(state).getKeyspacePropertiesIgnored(),
+                 state -> CONFIG_PROVIDER.getOrCreate(state).getKeyspacePropertiesDisallowed()
+                          .stream()
+                          .filter(prop -> !"replication".equals(prop))

Review Comment:
   @aparnanaik0522  this is not what we have approved, seems like this went in after the review. I do not think this is the correct way to do it. Every single time we execute guard method, this "stream and filter" is going to be executed as side effect. This is not necessary. Better way would be to filter out unsupported properties to disallow in `setKeyspacePropertiesDisallowed` method and hence by proxy in `validateKeyspaceProperties` which is used for other Values getter methods (getKeyspacePropertiesWarned/Ignored ...).
   
   Another issue is - why are we doing this for "disallowed" only? If you want to completely bypass any logic related to `replication`, as of now, you might _ignore it_ at guardrail level. So if somebody does 
   
   create keyspace abc with replication {dc1, rf: 5}
   
   and you put "replication" among ignored values (which is currently possible), a keyspace like this will be created, basically.
   
   create keyspace abc;
   
   which is actually invalid CQL. 
   
   Is this really what we want? I do not see why we would be preventing anybody from specifying their replication factors for their keyspaces.
   
   cc @maedhroz 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4393:
URL: https://github.com/apache/cassandra/pull/4393#discussion_r2383992357


##########
src/java/org/apache/cassandra/db/guardrails/Guardrails.java:
##########
@@ -143,6 +143,20 @@ public final class Guardrails implements GuardrailsMBean
                  state -> CONFIG_PROVIDER.getOrCreate(state).getTablePropertiesDisallowed(),
                  "Table Properties");
 
+    /**
+     * Guardrail warning about, ignoring or rejecting the usage of certain keyspace properties.
+     */
+    public static final Values<String> keyspaceProperties =
+    new Values<>("keyspace_properties",
+                 null,
+                 state -> CONFIG_PROVIDER.getOrCreate(state).getKeyspacePropertiesWarned(),
+                 state -> CONFIG_PROVIDER.getOrCreate(state).getKeyspacePropertiesIgnored(),
+                 state -> CONFIG_PROVIDER.getOrCreate(state).getKeyspacePropertiesDisallowed()
+                          .stream()
+                          .filter(prop -> !"replication".equals(prop))

Review Comment:
   @aparnanaik0522  this is not what we have approved, seems like this went in after the review. I really dont remember this being in before.  I do not think this is the correct way to do it. Every single time we execute guard method, this "stream and filter" is going to be executed as side effect. This is not necessary. Better way would be to filter out unsupported properties to disallow in `setKeyspacePropertiesDisallowed` method and hence by proxy in `validateKeyspaceProperties` which is used for other Values getter methods (getKeyspacePropertiesWarned/Ignored ...).
   
   Another issue is - why are we doing this for "disallowed" only? If you want to completely bypass any logic related to `replication`, as of now, you might _ignore it_ at guardrail level. So if somebody does 
   
   create keyspace abc with replication {dc1, rf: 5}
   
   and you put "replication" among ignored values (which is currently possible), a keyspace like this will be created, basically.
   
   create keyspace abc;
   
   which is actually invalid CQL. 
   
   Is this really what we want? I do not see why we would be preventing anybody from specifying their replication factors for their keyspaces.
   
   disallowed - means that a user can not specify query with "replication"
   ignored - means that when a user specifies "replication" in a query, it will be silently dropped as if it was never there
   warned - means that a user can specify it and it will be taken into account but a warning in CQLSH will be returned
   
   We do not want to warn a user when "replication" is specified, right? Nor we want to ignore "replication" parameter silently, nor we want to disallow usage of "replication". Hence I think the proper way would be to filter it out explicitly in validateKeyspaceProperties (and also inform a user, by logging, that such a property is ignored altogether when using this guardrail).
   
   cc @maedhroz 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4393:
URL: https://github.com/apache/cassandra/pull/4393#discussion_r2383992357


##########
src/java/org/apache/cassandra/db/guardrails/Guardrails.java:
##########
@@ -143,6 +143,20 @@ public final class Guardrails implements GuardrailsMBean
                  state -> CONFIG_PROVIDER.getOrCreate(state).getTablePropertiesDisallowed(),
                  "Table Properties");
 
+    /**
+     * Guardrail warning about, ignoring or rejecting the usage of certain keyspace properties.
+     */
+    public static final Values<String> keyspaceProperties =
+    new Values<>("keyspace_properties",
+                 null,
+                 state -> CONFIG_PROVIDER.getOrCreate(state).getKeyspacePropertiesWarned(),
+                 state -> CONFIG_PROVIDER.getOrCreate(state).getKeyspacePropertiesIgnored(),
+                 state -> CONFIG_PROVIDER.getOrCreate(state).getKeyspacePropertiesDisallowed()
+                          .stream()
+                          .filter(prop -> !"replication".equals(prop))

Review Comment:
   @aparnanaik0522  this is not what we have approved, seems like this went in after the review. I do not think this is the correct way to do it. Every single time we execute guard method, this "stream and filter" is going to be executed as side effect. This is not necessary. Better way would be to filter out unsupported properties to disallow in `setKeyspacePropertiesDisallowed` method and hence by proxy in `validateKeyspaceProperties` which is used for other Values getter methods (getKeyspacePropertiesWarned/Ignored ...).
   
   Another issue is - why are we doing this for "disallowed" only? If you want to completely bypass any logic related to `replication`, as of now, you might _ignore it_ at guardrail level. So if somebody does 
   
   create keyspace abc with replication {dc1, rf: 5}
   
   and you put "replication" among ignored values (which is currently possible), a keyspace like this will be created, basically.
   
   create keyspace abc;
   
   Is this really what we want? I do not see why we would be preventing anybody from specifying their replication factors for their keyspaces.
   
   cc @maedhroz 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4393:
URL: https://github.com/apache/cassandra/pull/4393#discussion_r2383992357


##########
src/java/org/apache/cassandra/db/guardrails/Guardrails.java:
##########
@@ -143,6 +143,20 @@ public final class Guardrails implements GuardrailsMBean
                  state -> CONFIG_PROVIDER.getOrCreate(state).getTablePropertiesDisallowed(),
                  "Table Properties");
 
+    /**
+     * Guardrail warning about, ignoring or rejecting the usage of certain keyspace properties.
+     */
+    public static final Values<String> keyspaceProperties =
+    new Values<>("keyspace_properties",
+                 null,
+                 state -> CONFIG_PROVIDER.getOrCreate(state).getKeyspacePropertiesWarned(),
+                 state -> CONFIG_PROVIDER.getOrCreate(state).getKeyspacePropertiesIgnored(),
+                 state -> CONFIG_PROVIDER.getOrCreate(state).getKeyspacePropertiesDisallowed()
+                          .stream()
+                          .filter(prop -> !"replication".equals(prop))

Review Comment:
   @aparnanaik0522  this is not what we have approved, seem like this went in after the review. I do not think this is the correct way to do it. Every single time we execute guard method, this "stream and filter" is going to be executed as side effect. This is not necessary. Better way would be to filter out unsupported properties to disallow in `setKeyspacePropertiesDisallowed` method and hence by proxy in `validateKeyspaceProperties` which is used for other Values getter methods (getKeyspacePropertiesWarned/Ignored ...).
   
   Another issue is - why are we doing this for "disallowed" only? If you want to completely bypass any logic related to `replication`, as of now, you might _ignore it_ at guardrail level. So if somebody does 
   
   create keyspace abc with replication {dc1, rf: 5}
   
   and you put "replication" among ignored values (which is currently possible), a keyspace like this will be created, basically.
   
   create keyspace abc;
   
   Is this really what we want? I do not see why would be preventing anybody from specifying their replication factors for their keyspaces.
   
   cc @maedhroz 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #4393:
URL: https://github.com/apache/cassandra/pull/4393#discussion_r2383992357


##########
src/java/org/apache/cassandra/db/guardrails/Guardrails.java:
##########
@@ -143,6 +143,20 @@ public final class Guardrails implements GuardrailsMBean
                  state -> CONFIG_PROVIDER.getOrCreate(state).getTablePropertiesDisallowed(),
                  "Table Properties");
 
+    /**
+     * Guardrail warning about, ignoring or rejecting the usage of certain keyspace properties.
+     */
+    public static final Values<String> keyspaceProperties =
+    new Values<>("keyspace_properties",
+                 null,
+                 state -> CONFIG_PROVIDER.getOrCreate(state).getKeyspacePropertiesWarned(),
+                 state -> CONFIG_PROVIDER.getOrCreate(state).getKeyspacePropertiesIgnored(),
+                 state -> CONFIG_PROVIDER.getOrCreate(state).getKeyspacePropertiesDisallowed()
+                          .stream()
+                          .filter(prop -> !"replication".equals(prop))

Review Comment:
   @aparnanaik0522  this is not what we have approved, seems like this went in after the review. I really dont remember this being in before.  I do not think this is the correct way to do it. Every single time we execute guard method, this "stream and filter" is going to be executed as side effect. This is not necessary. Better way would be to filter out unsupported properties to disallow in `setKeyspacePropertiesDisallowed` method and hence by proxy in `validateKeyspaceProperties` which is used for other Values getter methods (getKeyspacePropertiesWarned/Ignored ...).
   
   Another issue is - why are we doing this for "disallowed" only? If you want to completely bypass any logic related to `replication`, as of now, you might _ignore it_ at guardrail level. So if somebody does 
   
   create keyspace abc with replication {dc1, rf: 5}
   
   and you put "replication" among ignored values (which is currently possible), a keyspace like this will be created, basically.
   
   create keyspace abc;
   
   which is actually invalid CQL. 
   
   Is this really what we want? I do not see why we would be preventing anybody from specifying their replication factors for their keyspaces.
   
   cc @maedhroz 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #4393:
URL: https://github.com/apache/cassandra/pull/4393#discussion_r2380331381


##########
test/unit/org/apache/cassandra/db/guardrails/GuardrailKeyspacePropertiesTest.java:
##########
@@ -0,0 +1,223 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.db.guardrails;
+
+import static java.lang.String.format;
+import static org.apache.cassandra.db.guardrails.GuardrailTester.guardrails;

Review Comment:
   nit: unused import?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #4393:
URL: https://github.com/apache/cassandra/pull/4393#discussion_r2388433877


##########
src/java/org/apache/cassandra/db/guardrails/Guardrails.java:
##########
@@ -143,6 +143,20 @@ public final class Guardrails implements GuardrailsMBean
                  state -> CONFIG_PROVIDER.getOrCreate(state).getTablePropertiesDisallowed(),
                  "Table Properties");
 
+    /**
+     * Guardrail warning about, ignoring or rejecting the usage of certain keyspace properties.
+     */
+    public static final Values<String> keyspaceProperties =
+    new Values<>("keyspace_properties",
+                 null,
+                 state -> CONFIG_PROVIDER.getOrCreate(state).getKeyspacePropertiesWarned(),
+                 state -> CONFIG_PROVIDER.getOrCreate(state).getKeyspacePropertiesIgnored(),
+                 state -> CONFIG_PROVIDER.getOrCreate(state).getKeyspacePropertiesDisallowed()
+                          .stream()
+                          .filter(prop -> !"replication".equals(prop))

Review Comment:
   > Hence I think the proper way would be to filter it out explicitly in validateKeyspaceProperties (and also inform a user, by logging, that such a property is ignored altogether when using this guardrail).
   
   Yes, this is the way to go.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20913 Guard Durable Writes [cassandra]

Posted by "aparnanaik0522 (via GitHub)" <gi...@apache.org>.
aparnanaik0522 commented on PR #4393:
URL: https://github.com/apache/cassandra/pull/4393#issuecomment-3354087931

   I have created a new PR for this change - PTAL - https://github.com/apache/cassandra/pull/4406 
   I would be closing this one. 
   Thank you. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org