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

[GitHub] [cassandra] smiklosovic commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)

smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1315196421


##########
src/java/org/apache/cassandra/db/virtual/SettingsTable.java:
##########
@@ -19,103 +19,149 @@
 
 import java.util.HashMap;
 import java.util.Map;
-import java.util.Objects;
+import java.util.Optional;
+import java.util.function.Function;
+
 import com.google.common.collect.ImmutableMap;
 
 import org.apache.cassandra.config.Config;
 import org.apache.cassandra.config.DatabaseDescriptor;
-import org.apache.cassandra.config.Loader;
-import org.apache.cassandra.config.Properties;
-import org.apache.cassandra.config.Replacement;
-import org.apache.cassandra.config.Replacements;
+import org.apache.cassandra.config.YamlConfigurationLoader;
 import org.apache.cassandra.db.DecoratedKey;
+import org.apache.cassandra.db.marshal.BooleanType;
 import org.apache.cassandra.db.marshal.UTF8Type;
 import org.apache.cassandra.dht.LocalPartitioner;
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.exceptions.InvalidRequestException;
+import org.apache.cassandra.exceptions.PropertyNotFoundException;
 import org.apache.cassandra.schema.TableMetadata;
 import org.apache.cassandra.service.ClientWarn;
-import org.yaml.snakeyaml.introspector.Property;
 
-final class SettingsTable extends AbstractVirtualTable
+import static org.apache.cassandra.config.DatabaseDescriptor.getPropertyType;
+import static org.apache.cassandra.config.DatabaseDescriptor.getPropertyValue;
+import static org.apache.cassandra.cql3.statements.RequestValidations.invalidRequest;
+import static org.apache.cassandra.utils.FBUtilities.runExceptionally;
+import static org.apache.commons.lang3.ClassUtils.primitiveToWrapper;
+
+final class SettingsTable extends AbstractMutableVirtualTable
 {
     private static final String NAME = "name";
     private static final String VALUE = "value";
-
-    private static final Map<String, String> BACKWARDS_COMPATABLE_NAMES = ImmutableMap.copyOf(getBackwardsCompatableNames());
-    protected static final Map<String, Property> PROPERTIES = ImmutableMap.copyOf(getProperties());
-
-    private final Config config;
+    private static final String MUTABLE = "is_mutable";
+    static final Map<String, String> BACKWARDS_COMPATABLE_NAMES = ImmutableMap.copyOf(getBackwardsCompatableNames());
 
     SettingsTable(String keyspace)
-    {
-        this(keyspace, DatabaseDescriptor.getRawConfig());
-    }
-
-    SettingsTable(String keyspace, Config config)
     {
         super(TableMetadata.builder(keyspace, "settings")
                            .comment("current settings")
                            .kind(TableMetadata.Kind.VIRTUAL)
                            .partitioner(new LocalPartitioner(UTF8Type.instance))
                            .addPartitionKeyColumn(NAME, UTF8Type.instance)
                            .addRegularColumn(VALUE, UTF8Type.instance)
+                           .addRegularColumn(MUTABLE, BooleanType.instance)
                            .build());
-        this.config = config;
+        for (String name : BACKWARDS_COMPATABLE_NAMES.keySet())
+        {
+            if (DatabaseDescriptor.hasProperty(name))
+            {
+                throw new AssertionError(String.format("Name '%s' is present in Config, this adds a conflict as this " +
+                                                       "name had a different meaning in the '%s",
+                                                       name, SettingsTable.class.getSimpleName()));
+            }
+        }
+    }
+
+    @Override
+    protected void applyColumnUpdate(AbstractMutableVirtualTable.ColumnValues partitionKey,
+                                     AbstractMutableVirtualTable.ColumnValues clusteringColumns,
+                                     Optional<AbstractMutableVirtualTable.ColumnValue> columnValue)
+    {
+        String name = partitionKey.value(0);
+        String value = columnValue.map(v -> v.value().toString()).orElse(null);
+        if (value == null)
+            throw new InvalidRequestException(String.format("Setting the value to null is equivalent to the deletion operation. " +
+                                              "Column deletion is not supported by the '%s.%s'", metadata().keyspace, metadata().name));
+        else
+            runExceptionally(() -> setPropertyFromString(getKeyAndWarnIfObsolete(name), value),
+                             t -> invalidRequest("Invalid update request '%s'. Cause: %s", name, t.getMessage()));
     }
 
     @Override
     public DataSet data(DecoratedKey partitionKey)
     {
         SimpleDataSet result = new SimpleDataSet(metadata());
         String name = UTF8Type.instance.compose(partitionKey.getKey());
-        if (BACKWARDS_COMPATABLE_NAMES.containsKey(name))
-            ClientWarn.instance.warn("key '" + name + "' is deprecated; should switch to '" + BACKWARDS_COMPATABLE_NAMES.get(name) + "'");
-        if (PROPERTIES.containsKey(name))
-            result.row(name).column(VALUE, getValue(PROPERTIES.get(name)));
+        try
+        {
+            Object value = getPropertyAsString(getKeyAndWarnIfObsolete(name));
+            result.row(name).column(VALUE, value).column(MUTABLE, DatabaseDescriptor.isMutableProperty(name));

Review Comment:
   @Mmuzaf I was thinking about this some time ago but I just find some time to go over this again ... I think that `isMutableProperty` is too much here in such sense that it might be "cached". We are not going to introduce a new property while a node is running - it is a static set of keys and values. You can populate a map in a constructor of vtable. So it would be just a simple map lookup, or even easier, name of mutable properties would be a set. So if it is not a set it is not mutable. You do not need to do reflection every single query for every single property all over again.



-- 
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