You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "Mmuzaf (via GitHub)" <gi...@apache.org> on 2023/05/14 15:08:23 UTC
[GitHub] [cassandra] Mmuzaf opened a new pull request, #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Mmuzaf opened a new pull request, #2334:
URL: https://github.com/apache/cassandra/pull/2334
Thanks for sending a pull request! Here are some tips if you're new here:
* Ensure you have added or run the [appropriate tests](https://cassandra.apache.org/_/development/testing.html) for your PR.
* Be sure to keep the PR description updated to reflect all changes.
* Write your PR title to summarize what this PR proposes.
* If possible, provide a concise example to reproduce the issue for a faster review.
* Read our [contributor guidelines](https://cassandra.apache.org/_/development/index.html)
* If you're making a documentation change, see our [guide to documentation contribution](https://cassandra.apache.org/_/development/documentation.html)
Commit messages should follow the following format:
```
<One sentence description, usually Jira title or CHANGES.txt summary>
<Optional lengthier description (context on patch)>
patch by <Authors>; reviewed by <Reviewers> for CASSANDRA-#####
Co-authored-by: Name1 <email1>
Co-authored-by: Name2 <email2>
```
The [Cassandra Jira](https://issues.apache.org/jira/projects/CASSANDRA/issues/)
--
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
[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)
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1241953707
##########
src/java/org/apache/cassandra/config/ValidatedPropertyLoader.java:
##########
@@ -0,0 +1,183 @@
+/*
+ * 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.config;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.stream.Collectors;
+
+import org.apache.commons.lang3.ArrayUtils;
+
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.utils.FBUtilities;
+import org.yaml.snakeyaml.introspector.FieldProperty;
+import org.yaml.snakeyaml.introspector.Property;
+
+public final class ValidatedPropertyLoader implements Loader
+{
+ private final Loader loader;
+
+ public ValidatedPropertyLoader()
+ {
+ this.loader = new DefaultLoader(ValidatedPropertyLoader::listenablePropertyFactory);
+ }
+
+ @Override
+ public Map<String, Property> getProperties(Class<?> root)
+ {
+ return loader.getProperties(root);
+ }
+
+ private static Property listenablePropertyFactory(Field field)
+ {
+ ListenableProperty<?, ?> listenable = new ListenableProperty<>(new FieldProperty(field));
+ ValidatedByList validatedByList = field.getAnnotation(ValidatedByList.class);
+ ValidatedBy[] validatedByArray;
+ if (validatedByList == null)
+ {
+ if (field.getAnnotation(ValidatedBy.class) == null)
+ return listenable;
+ else
+ validatedByArray = new ValidatedBy[]{ field.getAnnotation(ValidatedBy.class) };
+ }
+ else
+ validatedByArray = validatedByList.value();
+
+ for (ValidatedBy validatedBy : validatedByArray)
+ listenable.addListener(createValidationListener(field, validatedBy));
+
+ return listenable;
+ }
+
+ private static <S, T> ListenableProperty.Listener<S, T> createValidationListener(Field field, ValidatedBy annotation)
+ {
+ Class<?> clazz = FBUtilities.classForName(annotation.useClass(), "validate method");
+ List<Method> matches = Arrays.stream(clazz.getDeclaredMethods())
Review Comment:
maybe add it to org.apache.cassandra.utils.ReflectionUtils ? Try to put there as much as possible which is in this PR and make it reusable if possible.
--
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
[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)
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1241930648
##########
src/java/org/apache/cassandra/db/virtual/SettingsTable.java:
##########
@@ -59,63 +57,104 @@ final class SettingsTable extends AbstractVirtualTable
.addPartitionKeyColumn(NAME, UTF8Type.instance)
.addRegularColumn(VALUE, UTF8Type.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,
Review Comment:
I would add a new column into this vtable called "mutable" of type `boolean`. That way, a user would see which properties are mutable and which are not. Currently, I do not see this instantly, do I? How do I know what I am able to change?
So if some specific column is not mutable, I would just make the call to this method no-op (returned instantly with a client warning) and we might just focus on the logic where we indeed going to update something.
--
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
[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)
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1241930648
##########
src/java/org/apache/cassandra/db/virtual/SettingsTable.java:
##########
@@ -59,63 +57,104 @@ final class SettingsTable extends AbstractVirtualTable
.addPartitionKeyColumn(NAME, UTF8Type.instance)
.addRegularColumn(VALUE, UTF8Type.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,
Review Comment:
I would add a new column into this vtable called "mutable" of type `boolean`. That way, a user would see what properties are mutable and what are not. Currently, I do not see this instantly, do I? How do I know what I am able to change?
So if some specific column is not mutable, I would just make the call to this method no-op and we might just focus on the logic where we indeed going to update something.
--
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
[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)
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1241942163
##########
src/java/org/apache/cassandra/config/ValidatedBy.java:
##########
@@ -0,0 +1,38 @@
+/*
+ * 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.config;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Repeatable;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Validate annotation to be used on configuration fields to validate the value of the field with
+ * a custom validator class and its method.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+@Repeatable(ValidatedByList.class)
+public @interface ValidatedBy
+{
+ String useClass();
Review Comment:
here I would use `Class` as mentioned above.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1220075737
##########
src/java/org/apache/cassandra/config/DatabaseDescriptor.java:
##########
@@ -576,14 +606,7 @@ else if (conf.disk_access_mode == Config.DiskAccessMode.mmap_index_only)
conf.repair_session_max_tree_depth = 20;
}
- if (conf.repair_session_space == null)
- conf.repair_session_space = new DataStorageSpec.IntMebibytesBound(Math.max(1, (int) (Runtime.getRuntime().maxMemory() / (16 * 1048576))));
-
- if (conf.repair_session_space.toMebibytes() < 1)
- throw new ConfigurationException("repair_session_space must be > 0, but was " + conf.repair_session_space);
- else if (conf.repair_session_space.toMebibytes() > (int) (Runtime.getRuntime().maxMemory() / (4 * 1048576)))
- logger.warn("A repair_session_space of " + conf.repair_session_space+ " mebibytes is likely to cause heap pressure");
-
+ conf.repair_session_space = validateRepairSessionSpace(conf, ConfigFields.REPAIR_SESSION_SPACE, conf.repair_session_space);
Review Comment:
We are doing this on the pre-parse stage, so no longer needed.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1220023330
##########
src/java/org/apache/cassandra/db/virtual/SettingsTable.java:
##########
@@ -18,39 +18,33 @@
package org.apache.cassandra.db.virtual;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
-import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+
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.db.DecoratedKey;
import org.apache.cassandra.db.marshal.UTF8Type;
import org.apache.cassandra.dht.LocalPartitioner;
+import org.apache.cassandra.exceptions.ConfigurationException;
+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.getStringProperty;
+import static org.apache.cassandra.cql3.statements.RequestValidations.invalidRequest;
+import static org.apache.cassandra.utils.FBUtilities.runExceptionally;
+
+final class SettingsTable extends AbstractMutableVirtualTable
Review Comment:
Originally I used them in the `DatabaseDescriptor` class because JMX and SettingsTable have the same type conversions, so it made sense to keep them there. But as we discussed, we currently moving them to SettingsTable only and will take care (if any) about JMX later.
--
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
[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)
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1251213091
##########
src/java/org/apache/cassandra/config/ListenableProperty.java:
##########
@@ -0,0 +1,81 @@
+/*
+ * 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.config;
+
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.yaml.snakeyaml.introspector.Property;
+
+/**
+ *
Review Comment:
@Mmuzaf empty 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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1205943004
##########
src/java/org/apache/cassandra/config/ValidatedPropertyLoader.java:
##########
@@ -0,0 +1,117 @@
+/*
+ * 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.config;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+import com.google.common.base.Preconditions;
+import org.apache.commons.lang3.ArrayUtils;
+
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.utils.FBUtilities;
+import org.yaml.snakeyaml.introspector.FieldProperty;
+import org.yaml.snakeyaml.introspector.Property;
+
+public class ValidatedPropertyLoader extends DefaultLoader
+{
+ private final Predicate<Property> nonListenableProperty;
+
+ public ValidatedPropertyLoader(Predicate<Property> nonListenableProperty)
+ {
+ this.nonListenableProperty = nonListenableProperty;
+ }
+
+ @Override
+ protected Property createPropertyForField(Class<?> root, Field field)
Review Comment:
The part of the code was reworked, so no longer relevant.
The main comment here:
https://github.com/apache/cassandra/pull/2334#discussion_r1205942419
--
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
[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)
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1241944361
##########
src/java/org/apache/cassandra/config/ValidatedPropertyLoader.java:
##########
@@ -0,0 +1,183 @@
+/*
+ * 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.config;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.stream.Collectors;
+
+import org.apache.commons.lang3.ArrayUtils;
+
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.utils.FBUtilities;
+import org.yaml.snakeyaml.introspector.FieldProperty;
+import org.yaml.snakeyaml.introspector.Property;
+
+public final class ValidatedPropertyLoader implements Loader
+{
+ private final Loader loader;
+
+ public ValidatedPropertyLoader()
+ {
+ this.loader = new DefaultLoader(ValidatedPropertyLoader::listenablePropertyFactory);
+ }
+
+ @Override
+ public Map<String, Property> getProperties(Class<?> root)
+ {
+ return loader.getProperties(root);
+ }
+
+ private static Property listenablePropertyFactory(Field field)
+ {
+ ListenableProperty<?, ?> listenable = new ListenableProperty<>(new FieldProperty(field));
+ ValidatedByList validatedByList = field.getAnnotation(ValidatedByList.class);
+ ValidatedBy[] validatedByArray;
+ if (validatedByList == null)
+ {
+ if (field.getAnnotation(ValidatedBy.class) == null)
+ return listenable;
+ else
+ validatedByArray = new ValidatedBy[]{ field.getAnnotation(ValidatedBy.class) };
+ }
+ else
+ validatedByArray = validatedByList.value();
+
+ for (ValidatedBy validatedBy : validatedByArray)
+ listenable.addListener(createValidationListener(field, validatedBy));
+
+ return listenable;
+ }
+
+ private static <S, T> ListenableProperty.Listener<S, T> createValidationListener(Field field, ValidatedBy annotation)
+ {
+ Class<?> clazz = FBUtilities.classForName(annotation.useClass(), "validate method");
+ List<Method> matches = Arrays.stream(clazz.getDeclaredMethods())
Review Comment:
Dont we have something in FBUtilties for this logic? We could probably move it there for greater good if not there yet.
--
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
[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)
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1241924285
##########
src/java/org/apache/cassandra/db/virtual/SettingsTable.java:
##########
@@ -59,63 +57,104 @@ final class SettingsTable extends AbstractVirtualTable
.addPartitionKeyColumn(NAME, UTF8Type.instance)
.addRegularColumn(VALUE, UTF8Type.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("Setting the value to null is equivalent to the deletion operation. " +
+ "Column deletion is not supported by table vts.settings");
+ else
+ runExceptionally(() -> setPropertyFromString(getKeyAndWarn(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(getKeyAndWarn(name));
+ result.row(name).column(VALUE, value);
+ }
+ catch (PropertyNotFoundException e)
+ {
+ // ignore
+ }
return result;
}
@Override
public DataSet data()
{
SimpleDataSet result = new SimpleDataSet(metadata());
- for (Map.Entry<String, Property> e : PROPERTIES.entrySet())
- result.row(e.getKey()).column(VALUE, getValue(e.getValue()));
+ for (String key : DatabaseDescriptor.getAllProperties())
Review Comment:
can you please explain the logic here? I see runExceptionally 2x here ... Just guide me through it 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
[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)
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1241944361
##########
src/java/org/apache/cassandra/config/ValidatedPropertyLoader.java:
##########
@@ -0,0 +1,183 @@
+/*
+ * 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.config;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.stream.Collectors;
+
+import org.apache.commons.lang3.ArrayUtils;
+
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.utils.FBUtilities;
+import org.yaml.snakeyaml.introspector.FieldProperty;
+import org.yaml.snakeyaml.introspector.Property;
+
+public final class ValidatedPropertyLoader implements Loader
+{
+ private final Loader loader;
+
+ public ValidatedPropertyLoader()
+ {
+ this.loader = new DefaultLoader(ValidatedPropertyLoader::listenablePropertyFactory);
+ }
+
+ @Override
+ public Map<String, Property> getProperties(Class<?> root)
+ {
+ return loader.getProperties(root);
+ }
+
+ private static Property listenablePropertyFactory(Field field)
+ {
+ ListenableProperty<?, ?> listenable = new ListenableProperty<>(new FieldProperty(field));
+ ValidatedByList validatedByList = field.getAnnotation(ValidatedByList.class);
+ ValidatedBy[] validatedByArray;
+ if (validatedByList == null)
+ {
+ if (field.getAnnotation(ValidatedBy.class) == null)
+ return listenable;
+ else
+ validatedByArray = new ValidatedBy[]{ field.getAnnotation(ValidatedBy.class) };
+ }
+ else
+ validatedByArray = validatedByList.value();
+
+ for (ValidatedBy validatedBy : validatedByArray)
+ listenable.addListener(createValidationListener(field, validatedBy));
+
+ return listenable;
+ }
+
+ private static <S, T> ListenableProperty.Listener<S, T> createValidationListener(Field field, ValidatedBy annotation)
+ {
+ Class<?> clazz = FBUtilities.classForName(annotation.useClass(), "validate method");
+ List<Method> matches = Arrays.stream(clazz.getDeclaredMethods())
Review Comment:
Dont we have something in FBUtilties for logic? We could probably move it there for greater good if not there yet.
--
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
[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)
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1251177567
##########
src/java/org/apache/cassandra/db/virtual/SettingsTable.java:
##########
@@ -59,63 +57,104 @@ final class SettingsTable extends AbstractVirtualTable
.addPartitionKeyColumn(NAME, UTF8Type.instance)
.addRegularColumn(VALUE, UTF8Type.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,
Review Comment:
As you wish but I dont see that to be problematic. VT are just local tables which dont survive the restart ... there is also implicit `allow filtering` on them ... it is not part of primary key so whats the big deal? 5.0 is ideal place to put this in. When do we want to do that, in a patch release?
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1260062746
##########
src/java/org/apache/cassandra/db/virtual/SettingsTable.java:
##########
@@ -59,63 +57,104 @@ final class SettingsTable extends AbstractVirtualTable
.addPartitionKeyColumn(NAME, UTF8Type.instance)
.addRegularColumn(VALUE, UTF8Type.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,
Review Comment:
I have updated the PR according to the ML discussion.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1196597186
##########
src/java/org/apache/cassandra/db/virtual/SettingsTable.java:
##########
@@ -59,63 +51,88 @@ final class SettingsTable extends AbstractVirtualTable
.addPartitionKeyColumn(NAME, UTF8Type.instance)
.addRegularColumn(VALUE, UTF8Type.instance)
.build());
- this.config = config;
+ }
+
+ @Override
+ protected void applyColumnDeletion(AbstractMutableVirtualTable.ColumnValues partitionKey, AbstractMutableVirtualTable.ColumnValues clusteringColumns, String columnName)
+ {
+ String name = partitionKey.value(0);
+ String key = getKeyAndWarn(name);
+ runExceptionally(() -> DatabaseDescriptor.setProperty(key, null),
+ t -> invalidRequest("Unable to clear property '%s': %s", key, t.getMessage()));
+ }
+
+ @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);
+ runExceptionally(() -> DatabaseDescriptor.setProperty(getKeyAndWarn(name), value),
+ t -> invalidRequest("Invalid update request for property '%s'. %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 = getStringProperty(getKeyAndWarn(name));
+ result.row(name).column(VALUE, value);
+ }
+ catch (PropertyNotFoundException e)
+ {
+ // ignore
+ }
return result;
}
@Override
public DataSet data()
{
SimpleDataSet result = new SimpleDataSet(metadata());
- for (Map.Entry<String, Property> e : PROPERTIES.entrySet())
- result.row(e.getKey()).column(VALUE, getValue(e.getValue()));
+ DatabaseDescriptor.visit(withBackwardsCompatableNamesVisitor((key, type, ro) ->
+ result.row(key).column(VALUE, getStringProperty(BACKWARDS_COMPATABLE_NAMES.getOrDefault(key, key)))),
+ t -> new ConfigurationException(t.getMessage(), false));
return result;
}
- private String getValue(Property prop)
+ static String getKeyAndWarn(String name)
{
- Object value = prop.get(config);
- return value == null ? null : value.toString();
+ String key = BACKWARDS_COMPATABLE_NAMES.getOrDefault(name, name);
+ if (BACKWARDS_COMPATABLE_NAMES.containsKey(name))
+ ClientWarn.instance.warn("key '" + name + "' is deprecated; should switch to '" + BACKWARDS_COMPATABLE_NAMES.get(name) + '\'');
+ return key;
+ }
+
+ static DatabaseDescriptor.PropertyVisitor withBackwardsCompatableNamesVisitor(DatabaseDescriptor.PropertyVisitor visitor)
+ {
+ BiMap<String, String> inversedNames = BACKWARDS_COMPATABLE_NAMES.inverse();
+ return (name, type, readOnly) -> {
+ if (inversedNames.containsKey(name))
+ visitor.visit(inversedNames.get(name), type, readOnly);
+ visitor.visit(name, type, readOnly);
+ };
Review Comment:
You're right. This is unnecessary, so I have removed it.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1205937387
##########
src/java/org/apache/cassandra/config/ListenableProperty.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.config;
+
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.function.BiConsumer;
+
+import org.yaml.snakeyaml.introspector.Property;
+
+/**
+ *
+ */
+public class ListenableProperty<S, T> extends ForwardingProperty
+{
+ private final Map<EventType, List<Handler<S, T>>> handlers = new EnumMap<>(EventType.class);
+
+ public ListenableProperty(Property property)
+ {
+ super(property.getName(), property);
+ for (EventType eventType : EventType.values())
+ handlers.put(eventType, new CopyOnWriteArrayList<>());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public synchronized void set(Object source, Object newValue) throws Exception
Review Comment:
Removed.
##########
src/java/org/apache/cassandra/config/ListenableProperty.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.config;
+
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.function.BiConsumer;
+
+import org.yaml.snakeyaml.introspector.Property;
+
+/**
+ *
+ */
+public class ListenableProperty<S, T> extends ForwardingProperty
+{
+ private final Map<EventType, List<Handler<S, T>>> handlers = new EnumMap<>(EventType.class);
+
+ public ListenableProperty(Property property)
+ {
+ super(property.getName(), property);
+ for (EventType eventType : EventType.values())
+ handlers.put(eventType, new CopyOnWriteArrayList<>());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public synchronized void set(Object source, Object newValue) throws Exception
+ {
+ T oldValue = (T) get(source);
+ T value = Handler.compose(handlers.get(EventType.BEFORE)).handle((S) source, oldValue, (T) newValue);
+ delegate().set(source, value);
+ Handler.compose(handlers.get(EventType.AFTER)).handle((S) source, oldValue, value);
+ }
+
+ public synchronized Remover addBeforeHandler(Handler<S, T> handler)
Review Comment:
Removed.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1205937015
##########
src/java/org/apache/cassandra/config/ListenableProperty.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.config;
+
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.function.BiConsumer;
+
+import org.yaml.snakeyaml.introspector.Property;
+
+/**
+ *
+ */
+public class ListenableProperty<S, T> extends ForwardingProperty
+{
+ private final Map<EventType, List<Handler<S, T>>> handlers = new EnumMap<>(EventType.class);
+
+ public ListenableProperty(Property property)
+ {
+ super(property.getName(), property);
+ for (EventType eventType : EventType.values())
+ handlers.put(eventType, new CopyOnWriteArrayList<>());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public synchronized void set(Object source, Object newValue) throws Exception
+ {
+ T oldValue = (T) get(source);
+ T value = Handler.compose(handlers.get(EventType.BEFORE)).handle((S) source, oldValue, (T) newValue);
+ delegate().set(source, value);
+ Handler.compose(handlers.get(EventType.AFTER)).handle((S) source, oldValue, value);
+ }
+
+ public synchronized Remover addBeforeHandler(Handler<S, T> handler)
+ {
+ handlers.computeIfAbsent(EventType.BEFORE, k -> new CopyOnWriteArrayList<>()).add(handler);
+ return () -> handlers.get(EventType.BEFORE).remove(handler);
+ }
+
+ public synchronized Remover addAfterHandler(Handler<S, T> handler)
+ {
+ handlers.computeIfAbsent(EventType.AFTER, k -> new CopyOnWriteArrayList<>()).add(handler);
+ return () -> handlers.get(EventType.AFTER).remove(handler);
+ }
+
+ private enum EventType
+ {
+ BEFORE, AFTER
+ }
+
+ /**
+ * The handler to be notified before and after a configuration value is changed.
+ * @param <S> the type of the object to mutate.
+ * @param <V> the type of the value to mutate.
+ */
+ @FunctionalInterface
+ public interface Handler<S, V>
Review Comment:
Renamed.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1220017419
##########
src/java/org/apache/cassandra/config/DatabaseDescriptor.java:
##########
@@ -4763,4 +4756,159 @@ public static OptionalDouble getSeverityDuringDecommission()
OptionalDouble.of(conf.severity_during_decommission) :
OptionalDouble.empty();
}
+
+ public static void visit(PropertyVisitor visitor)
+ {
+ visit(visitor, RuntimeException::new);
+ }
+
+ public static void visit(PropertyVisitor visitor, Function<Throwable, ? extends RuntimeException> handler)
+ {
+ try
+ {
+ for (Property property : ofNullable(confValueAccessors).orElse(Collections.emptyMap()).values())
+ visitor.visit(property.getName(), property.getType(), property.getAnnotation(Mutable.class) == null);
+ }
+ catch (Throwable t)
+ {
+ throw handler.apply(t);
+ }
+ }
+
+ public static <T> ListenableProperty.Remover addBeforeChangePropertyListener(String name, Class<T> clazz, BiConsumer<T, T> consumer)
+ {
+ return addPropertyListener(name, clazz, p -> p.addBeforeHandler(ListenableProperty.Handler.consume(consumer)));
+ }
+
+ public static <T> ListenableProperty.Remover addAfterChangePropertyListener(String name, Class<T> clazz, BiConsumer<T, T> consumer)
+ {
+ return addPropertyListener(name, clazz, p -> p.addAfterHandler(ListenableProperty.Handler.consume(consumer)));
+ }
+
+ @SuppressWarnings("unchecked")
+ private static <T> ListenableProperty.Remover addPropertyListener(String name,
+ Class<T> clazz,
+ Function<ListenableProperty<Config, T>, ListenableProperty.Remover> adder)
+ {
+ Property property = ofNullable(confValueAccessors.get(name))
+ .map(p -> {
+ // The case when replacement property is used and match the property's name.
+ if (p instanceof Replacement.ReplacementProperty)
+ return ((Replacement.ReplacementProperty) p).delegate();
+ else
+ return p;
+ })
+ .orElseThrow(() -> new PropertyNotFoundException(name));
+ if (!(property instanceof ListenableProperty))
+ throw new ConfigurationException(String.format("Property '%s' is not listenable.", name));
+
+ if (clazz.equals(property.getType()))
+ return adder.apply((ListenableProperty<Config, T>) property);
+ else
+ throw new ConfigurationException(String.format("Listener type '%s' doesn't match the property '%s' type '%s'.",
+ clazz.getSimpleName(), name, clazz.getSimpleName()));
+ }
+
+ public static Object getProperty(String name)
+ {
+ return ofNullable(confValueAccessors.get(name)).orElseThrow(() -> new PropertyNotFoundException(name))
+ .get(conf);
Review Comment:
Simplified.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1220080355
##########
src/java/org/apache/cassandra/config/Config.java:
##########
@@ -531,6 +545,7 @@ public MemtableOptions()
@Replaces(oldName = "index_summary_capacity_in_mb", converter = Converters.MEBIBYTES_DATA_STORAGE_LONG, deprecated = true)
public volatile DataStorageSpec.LongMebibytesBound index_summary_capacity;
+ @Mutable
Review Comment:
I guess we can skip this case in the initial changes as the `DELETE` operation is not supported as well as setting `null` values to the virtual table columns (this is equivalent to the delete operation).
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1205952069
##########
src/java/org/apache/cassandra/config/ListenableProperty.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.config;
+
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.function.BiConsumer;
+
+import org.yaml.snakeyaml.introspector.Property;
+
+/**
+ *
+ */
+public class ListenableProperty<S, T> extends ForwardingProperty
+{
+ private final Map<EventType, List<Handler<S, T>>> handlers = new EnumMap<>(EventType.class);
+
+ public ListenableProperty(Property property)
+ {
+ super(property.getName(), property);
+ for (EventType eventType : EventType.values())
+ handlers.put(eventType, new CopyOnWriteArrayList<>());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public synchronized void set(Object source, Object newValue) throws Exception
+ {
+ T oldValue = (T) get(source);
+ T value = Handler.compose(handlers.get(EventType.BEFORE)).handle((S) source, oldValue, (T) newValue);
+ delegate().set(source, value);
+ Handler.compose(handlers.get(EventType.AFTER)).handle((S) source, oldValue, value);
+ }
+
+ public synchronized Remover addBeforeHandler(Handler<S, T> handler)
+ {
+ handlers.computeIfAbsent(EventType.BEFORE, k -> new CopyOnWriteArrayList<>()).add(handler);
+ return () -> handlers.get(EventType.BEFORE).remove(handler);
+ }
+
+ public synchronized Remover addAfterHandler(Handler<S, T> handler)
+ {
+ handlers.computeIfAbsent(EventType.AFTER, k -> new CopyOnWriteArrayList<>()).add(handler);
+ return () -> handlers.get(EventType.AFTER).remove(handler);
+ }
+
+ private enum EventType
+ {
+ BEFORE, AFTER
+ }
+
+ /**
+ * The handler to be notified before and after a configuration value is changed.
+ * @param <S> the type of the object to mutate.
+ * @param <V> the type of the value to mutate.
+ */
+ @FunctionalInterface
+ public interface Handler<S, V>
+ {
+ V handle(S source, V oldValue, V newValue);
+
+ static <S, V> Handler<S, V> consume(BiConsumer<? super V, ? super V> consumer)
+ {
+ return (source, oldValue, newValue) -> {
+ consumer.accept(oldValue, newValue);
+ return newValue;
+ };
+ }
+
+ static <S, V> Handler<S, V > compose(List<Handler < S, V >> handlers)
+ {
+ return (source, oldValue, newValue) -> {
Review Comment:
agree, but I guess as we agreed to rework the code and listeners, so this method is no longer needed.
Fixed.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1205937566
##########
src/java/org/apache/cassandra/config/ListenableProperty.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.config;
+
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.function.BiConsumer;
+
+import org.yaml.snakeyaml.introspector.Property;
+
+/**
+ *
+ */
+public class ListenableProperty<S, T> extends ForwardingProperty
+{
+ private final Map<EventType, List<Handler<S, T>>> handlers = new EnumMap<>(EventType.class);
+
+ public ListenableProperty(Property property)
+ {
+ super(property.getName(), property);
+ for (EventType eventType : EventType.values())
+ handlers.put(eventType, new CopyOnWriteArrayList<>());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public synchronized void set(Object source, Object newValue) throws Exception
+ {
+ T oldValue = (T) get(source);
+ T value = Handler.compose(handlers.get(EventType.BEFORE)).handle((S) source, oldValue, (T) newValue);
+ delegate().set(source, value);
+ Handler.compose(handlers.get(EventType.AFTER)).handle((S) source, oldValue, value);
+ }
+
+ public synchronized Remover addBeforeHandler(Handler<S, T> handler)
+ {
+ handlers.computeIfAbsent(EventType.BEFORE, k -> new CopyOnWriteArrayList<>()).add(handler);
+ return () -> handlers.get(EventType.BEFORE).remove(handler);
+ }
+
+ public synchronized Remover addAfterHandler(Handler<S, T> handler)
Review Comment:
Removed.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1205938549
##########
src/java/org/apache/cassandra/config/ValidatedPropertyLoader.java:
##########
@@ -0,0 +1,117 @@
+/*
+ * 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.config;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+import com.google.common.base.Preconditions;
+import org.apache.commons.lang3.ArrayUtils;
+
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.utils.FBUtilities;
+import org.yaml.snakeyaml.introspector.FieldProperty;
+import org.yaml.snakeyaml.introspector.Property;
+
+public class ValidatedPropertyLoader extends DefaultLoader
+{
+ private final Predicate<Property> nonListenableProperty;
+
+ public ValidatedPropertyLoader(Predicate<Property> nonListenableProperty)
+ {
+ this.nonListenableProperty = nonListenableProperty;
+ }
+
+ @Override
+ protected Property createPropertyForField(Class<?> root, Field field)
+ {
+ Property property = new FieldProperty(field);
+ if (nonListenableProperty.test(property))
+ return property;
+
+ ListenableProperty<?, ?> listenable = new ListenableProperty<>(property);
+ if (property.getAnnotation(ValidatedBy.class) != null)
+ listenable.addBeforeHandler(ValidationPropertyHandler.create(root, listenable.delegate()));
+ return listenable;
+ }
+
+ private static class ValidationPropertyHandler<S, T> implements ListenableProperty.Handler<S, T>
+ {
+ private final Method method;
+ private final String name;
+
+ private ValidationPropertyHandler(Method method, String name)
+ {
+ this.method = method;
+ this.name = name;
+ }
+
+ public static <S, T> ValidationPropertyHandler<S, T> create(Class<?> root, Property property)
+ {
+ Preconditions.checkNotNull(property.getAnnotation(ValidatedBy.class));
+ ValidatedBy annotation = property.getAnnotation(ValidatedBy.class);
+ Class<?> clazz = FBUtilities.classForName(annotation.useClass(), "validate method");
+ Class<?>[] searchPattern = ArrayUtils.addAll(new Class<?>[]{ root, property.getType() });
+ for (Method refMethod : clazz.getDeclaredMethods())
+ {
+ int modifiers = refMethod.getModifiers();
+ if (Modifier.isPrivate(modifiers) || Modifier.isProtected(modifiers))
Review Comment:
Agree, I have reworked this part of the code.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1251264500
##########
src/java/org/apache/cassandra/db/virtual/SettingsTable.java:
##########
@@ -59,63 +57,104 @@ final class SettingsTable extends AbstractVirtualTable
.addPartitionKeyColumn(NAME, UTF8Type.instance)
.addRegularColumn(VALUE, UTF8Type.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,
Review Comment:
Sure, but there is a lack of feedback on this :-) we can leave it for now and come back to it when everything else is ready for the merge.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1251216614
##########
src/java/org/apache/cassandra/db/virtual/SettingsTable.java:
##########
@@ -59,63 +57,104 @@ final class SettingsTable extends AbstractVirtualTable
.addPartitionKeyColumn(NAME, UTF8Type.instance)
.addRegularColumn(VALUE, UTF8Type.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,
Review Comment:
I was targeting this for 5.0 and 4.1 releases, so I tried to avoid any public API changes. For that case, we can cherry-pick the changes that make SettingsTable updatable for 4.1, leaving the column addition for 5.0 only, but as we made `allow filtering` the default for vtable (I forgot about it) I don't see much difference now.
@dcapwell what do you think about adding a new column?
--
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
[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)
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1251180235
##########
src/java/org/apache/cassandra/config/ConfigFields.java:
##########
@@ -0,0 +1,49 @@
+/*
+ * 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.config;
+
+/**
+ * This class is created by {@link org.apache.cassandra.utils.ConfigFieldsGenerateUtil} based on provided
+ * the {@link org.apache.cassandra.config.Config} class. It contains non-private non-static {@code Cofig}'s fields
+ * marked with the {@link org.apache.cassandra.config.Mutable} annotation to expose them to public APIs.
+
+ * @see org.apache.cassandra.config.Mutable
+ * @see org.apache.cassandra.config.Config
+ */
+public class ConfigFields
Review Comment:
I dont know ... feels like a hack. Is that really necessary? Why not to put these constants directly in DatabaseDescriptor and be done with it?
--
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
[GitHub] [cassandra] dcapwell commented on pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "dcapwell (via GitHub)" <gi...@apache.org>.
dcapwell commented on PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#issuecomment-1716246907
Sorry, been away from this patch for a very long time. If 2 committers are +1 to this patch please don't wait for me and feel free to merge. I don't know when I will have time to review 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
Re: [PR] CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation) [cassandra]
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1431607296
##########
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";
Review Comment:
@Mmuzaf can be this renamed just to `mutable`? I think that is just enough ... no need to put there `is_`.
--
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-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation) [cassandra]
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1431581657
##########
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())
Review Comment:
@Mmuzaf COMPATIBLE, not COMPATABLE
--
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-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation) [cassandra]
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1431590737
##########
src/java/org/apache/cassandra/io/sstable/indexsummary/IndexSummaryManager.java:
##########
@@ -114,10 +122,24 @@ public int getResizeIntervalInMinutes()
return DatabaseDescriptor.getIndexSummaryResizeIntervalInMinutes();
}
+ private static int getDurationInMinutes(DurationSpec.IntMinutesBound duration)
+ {
+ return duration == null ? -1 : duration.toMinutes();
+ }
+
public void setResizeIntervalInMinutes(int resizeIntervalInMinutes)
{
- int oldInterval = getResizeIntervalInMinutes();
- DatabaseDescriptor.setIndexSummaryResizeIntervalInMinutes(resizeIntervalInMinutes);
+ runExceptionally(() -> DatabaseDescriptor.setIndexSummaryResizeIntervalInMinutes(resizeIntervalInMinutes),
+ e -> {
+ logger.error("Unable to update index_summary_resize_interval", e);
+ throw new RuntimeException(e.getMessage());
+ });
+ }
+
+ private void handleResizeIntervalInMinutes(DurationSpec.IntMinutesBound oldValue, DurationSpec.IntMinutesBound newValue)
+ {
+ int oldInterval = getDurationInMinutes(oldValue);
+ int resizeIntervalInMinutes = getDurationInMinutes(newValue);
Review Comment:
@Mmuzaf where was this property taken from before? I see it is already used in this method further down bellow ...
--
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
[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)
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1241938389
##########
src/java/org/apache/cassandra/config/ConfigFields.java:
##########
@@ -0,0 +1,49 @@
+/*
+ * 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.config;
+
+/**
+ * This class is created by {@link org.apache.cassandra.utils.ConfigFieldsGenerateUtil} based on provided
+ * the {@link org.apache.cassandra.config.Config} class. It contains non-private non-static {@code Cofig}'s fields
+ * marked with the {@link org.apache.cassandra.config.Mutable} annotation to expose them to public APIs.
+
+ * @see org.apache.cassandra.config.Mutable
+ * @see org.apache.cassandra.config.Config
+ */
+public class ConfigFields
Review Comment:
how is this class going to be updated when something changes? I see we have a generator for that but maybe we should hook the execution of this generator to the build process so we would generate this automatically? (or we would fail the build if the generated class is different from what is committed so people have to be aware of the fact they have to regenerate it themselves)
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1252075157
##########
src/java/org/apache/cassandra/config/ConfigFields.java:
##########
@@ -0,0 +1,49 @@
+/*
+ * 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.config;
+
+/**
+ * This class is created by {@link org.apache.cassandra.utils.ConfigFieldsGenerateUtil} based on provided
+ * the {@link org.apache.cassandra.config.Config} class. It contains non-private non-static {@code Cofig}'s fields
+ * marked with the {@link org.apache.cassandra.config.Mutable} annotation to expose them to public APIs.
+
+ * @see org.apache.cassandra.config.Mutable
+ * @see org.apache.cassandra.config.Config
+ */
+public class ConfigFields
Review Comment:
Moved under the `Config`, and the name was updated accordingly.
--
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
[GitHub] [cassandra] dcapwell commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "dcapwell (via GitHub)" <gi...@apache.org>.
dcapwell commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1200731420
##########
src/java/org/apache/cassandra/config/Config.java:
##########
@@ -531,6 +545,7 @@ public MemtableOptions()
@Replaces(oldName = "index_summary_capacity_in_mb", converter = Converters.MEBIBYTES_DATA_STORAGE_LONG, deprecated = true)
public volatile DataStorageSpec.LongMebibytesBound index_summary_capacity;
+ @Mutable
Review Comment:
this case doesn't have any validation, so if someone tries to `DELETE` then we would get NPE in our code. Might be good to have `@Mutable` list what is allowed (default to all), so something maybe like `@Mutable(operations = {INSERT})`?
##########
src/java/org/apache/cassandra/config/ListenableProperty.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.config;
+
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.function.BiConsumer;
+
+import org.yaml.snakeyaml.introspector.Property;
+
+/**
+ *
+ */
+public class ListenableProperty<S, T> extends ForwardingProperty
+{
+ private final Map<EventType, List<Handler<S, T>>> handlers = new EnumMap<>(EventType.class);
+
+ public ListenableProperty(Property property)
+ {
+ super(property.getName(), property);
+ for (EventType eventType : EventType.values())
+ handlers.put(eventType, new CopyOnWriteArrayList<>());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public synchronized void set(Object source, Object newValue) throws Exception
+ {
+ T oldValue = (T) get(source);
+ T value = Handler.compose(handlers.get(EventType.BEFORE)).handle((S) source, oldValue, (T) newValue);
+ delegate().set(source, value);
+ Handler.compose(handlers.get(EventType.AFTER)).handle((S) source, oldValue, value);
Review Comment:
the API doesn't make a lot of sense as the API is mutable, yet *after* can not mutate... prob want 2 different `Listener` types, something like `OnBefore` and `OnAfter`; or anything with better names.
##########
src/java/org/apache/cassandra/config/ValidatedPropertyLoader.java:
##########
@@ -0,0 +1,117 @@
+/*
+ * 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.config;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+import com.google.common.base.Preconditions;
+import org.apache.commons.lang3.ArrayUtils;
+
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.utils.FBUtilities;
+import org.yaml.snakeyaml.introspector.FieldProperty;
+import org.yaml.snakeyaml.introspector.Property;
+
+public class ValidatedPropertyLoader extends DefaultLoader
Review Comment:
please don't use inherence
##########
src/java/org/apache/cassandra/db/virtual/SettingsTable.java:
##########
@@ -59,63 +53,77 @@ final class SettingsTable extends AbstractVirtualTable
.addPartitionKeyColumn(NAME, UTF8Type.instance)
.addRegularColumn(VALUE, UTF8Type.instance)
.build());
- this.config = config;
+ Set<String> unprocessed = new HashSet<>(BACKWARDS_COMPATABLE_NAMES.values());
+ DatabaseDescriptor.visit((key, type, ro) -> {
+ if (BACKWARDS_COMPATABLE_NAMES.containsKey(key))
+ {
+ 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",
+ key, SettingsTable.class.getSimpleName()));
+ }
+ unprocessed.remove(key);
+ });
+ if (!unprocessed.isEmpty())
+ throw new AssertionError("The following keys must be present in the Config: " + unprocessed);
+ }
+
+ @Override
+ protected void applyColumnDeletion(AbstractMutableVirtualTable.ColumnValues partitionKey, AbstractMutableVirtualTable.ColumnValues clusteringColumns, String columnName)
Review Comment:
pointed this out in `Config`; not all properties support `DELETE`, all support `INSERT` but only a small subset support `DELETE`... I would recommend dropping `DELETE` support for this patch to keep things simple... as you need to understand what are the semantics for `DELETE`... is `DELETE` "use default" or "disable" or something else?
##########
src/java/org/apache/cassandra/db/virtual/SettingsTable.java:
##########
@@ -59,63 +53,77 @@ final class SettingsTable extends AbstractVirtualTable
.addPartitionKeyColumn(NAME, UTF8Type.instance)
.addRegularColumn(VALUE, UTF8Type.instance)
.build());
- this.config = config;
+ Set<String> unprocessed = new HashSet<>(BACKWARDS_COMPATABLE_NAMES.values());
+ DatabaseDescriptor.visit((key, type, ro) -> {
+ if (BACKWARDS_COMPATABLE_NAMES.containsKey(key))
+ {
+ 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",
+ key, SettingsTable.class.getSimpleName()));
+ }
+ unprocessed.remove(key);
+ });
+ if (!unprocessed.isEmpty())
+ throw new AssertionError("The following keys must be present in the Config: " + unprocessed);
+ }
+
+ @Override
+ protected void applyColumnDeletion(AbstractMutableVirtualTable.ColumnValues partitionKey, AbstractMutableVirtualTable.ColumnValues clusteringColumns, String columnName)
+ {
+ String name = partitionKey.value(0);
+ String key = getKeyAndWarn(name);
+ runExceptionally(() -> DatabaseDescriptor.setProperty(key, null),
+ t -> invalidRequest("Invalid delete request. Cause: %s", t.getMessage()));
+ }
+
+ @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);
+ runExceptionally(() -> DatabaseDescriptor.setProperty(getKeyAndWarn(name), value),
Review Comment:
this doesn't work, properties are not `String` in most cases, so you need to convert
##########
src/java/org/apache/cassandra/config/ListenableProperty.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.config;
+
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.function.BiConsumer;
+
+import org.yaml.snakeyaml.introspector.Property;
+
+/**
+ *
+ */
+public class ListenableProperty<S, T> extends ForwardingProperty
+{
+ private final Map<EventType, List<Handler<S, T>>> handlers = new EnumMap<>(EventType.class);
+
+ public ListenableProperty(Property property)
+ {
+ super(property.getName(), property);
+ for (EventType eventType : EventType.values())
+ handlers.put(eventType, new CopyOnWriteArrayList<>());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public synchronized void set(Object source, Object newValue) throws Exception
+ {
+ T oldValue = (T) get(source);
+ T value = Handler.compose(handlers.get(EventType.BEFORE)).handle((S) source, oldValue, (T) newValue);
+ delegate().set(source, value);
+ Handler.compose(handlers.get(EventType.AFTER)).handle((S) source, oldValue, value);
+ }
+
+ public synchronized Remover addBeforeHandler(Handler<S, T> handler)
+ {
+ handlers.computeIfAbsent(EventType.BEFORE, k -> new CopyOnWriteArrayList<>()).add(handler);
+ return () -> handlers.get(EventType.BEFORE).remove(handler);
+ }
+
+ public synchronized Remover addAfterHandler(Handler<S, T> handler)
+ {
+ handlers.computeIfAbsent(EventType.AFTER, k -> new CopyOnWriteArrayList<>()).add(handler);
+ return () -> handlers.get(EventType.AFTER).remove(handler);
+ }
+
+ private enum EventType
+ {
+ BEFORE, AFTER
+ }
+
+ /**
+ * The handler to be notified before and after a configuration value is changed.
+ * @param <S> the type of the object to mutate.
+ * @param <V> the type of the value to mutate.
+ */
+ @FunctionalInterface
+ public interface Handler<S, V>
Review Comment:
given the name of the parent class, and what we are doing, prob want to make this a `Listener`
##########
src/java/org/apache/cassandra/config/DefaultLoader.java:
##########
@@ -52,7 +52,7 @@ public Map<String, Property> getProperties(Class<?> root)
&& !Modifier.isTransient(modifiers)
&& Modifier.isPublic(modifiers)
&& !properties.containsKey(name))
- properties.put(name, new FieldProperty(f));
+ properties.put(name, createPropertyForField(c, f));
Review Comment:
can you revert this change? Methods are also able to override fields, so this API doesn't make too much sense
##########
src/java/org/apache/cassandra/config/DatabaseDescriptor.java:
##########
@@ -4763,4 +4756,159 @@ public static OptionalDouble getSeverityDuringDecommission()
OptionalDouble.of(conf.severity_during_decommission) :
OptionalDouble.empty();
}
+
+ public static void visit(PropertyVisitor visitor)
+ {
+ visit(visitor, RuntimeException::new);
+ }
+
+ public static void visit(PropertyVisitor visitor, Function<Throwable, ? extends RuntimeException> handler)
+ {
+ try
+ {
+ for (Property property : ofNullable(confValueAccessors).orElse(Collections.emptyMap()).values())
+ visitor.visit(property.getName(), property.getType(), property.getAnnotation(Mutable.class) == null);
+ }
+ catch (Throwable t)
+ {
+ throw handler.apply(t);
+ }
+ }
+
+ public static <T> ListenableProperty.Remover addBeforeChangePropertyListener(String name, Class<T> clazz, BiConsumer<T, T> consumer)
+ {
+ return addPropertyListener(name, clazz, p -> p.addBeforeHandler(ListenableProperty.Handler.consume(consumer)));
+ }
+
+ public static <T> ListenableProperty.Remover addAfterChangePropertyListener(String name, Class<T> clazz, BiConsumer<T, T> consumer)
+ {
+ return addPropertyListener(name, clazz, p -> p.addAfterHandler(ListenableProperty.Handler.consume(consumer)));
+ }
+
+ @SuppressWarnings("unchecked")
+ private static <T> ListenableProperty.Remover addPropertyListener(String name,
+ Class<T> clazz,
+ Function<ListenableProperty<Config, T>, ListenableProperty.Remover> adder)
+ {
+ Property property = ofNullable(confValueAccessors.get(name))
+ .map(p -> {
+ // The case when replacement property is used and match the property's name.
+ if (p instanceof Replacement.ReplacementProperty)
+ return ((Replacement.ReplacementProperty) p).delegate();
+ else
+ return p;
+ })
+ .orElseThrow(() -> new PropertyNotFoundException(name));
Review Comment:
can we simplify, trying to use `Optional` actually makes this less clear and cost more
```
if (! confValueAccessors.containsKey(name) new PropertyNotFoundException(name)
Property p = confValueAccessors,get(name);
```
##########
src/java/org/apache/cassandra/config/ListenableProperty.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.config;
+
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.function.BiConsumer;
+
+import org.yaml.snakeyaml.introspector.Property;
+
+/**
+ *
+ */
+public class ListenableProperty<S, T> extends ForwardingProperty
+{
+ private final Map<EventType, List<Handler<S, T>>> handlers = new EnumMap<>(EventType.class);
+
+ public ListenableProperty(Property property)
+ {
+ super(property.getName(), property);
+ for (EventType eventType : EventType.values())
+ handlers.put(eventType, new CopyOnWriteArrayList<>());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public synchronized void set(Object source, Object newValue) throws Exception
+ {
+ T oldValue = (T) get(source);
+ T value = Handler.compose(handlers.get(EventType.BEFORE)).handle((S) source, oldValue, (T) newValue);
+ delegate().set(source, value);
+ Handler.compose(handlers.get(EventType.AFTER)).handle((S) source, oldValue, value);
+ }
+
+ public synchronized Remover addBeforeHandler(Handler<S, T> handler)
+ {
+ handlers.computeIfAbsent(EventType.BEFORE, k -> new CopyOnWriteArrayList<>()).add(handler);
Review Comment:
you don't need/want `computeIfAbsent`, you added in the constructor
##########
src/java/org/apache/cassandra/config/ListenableProperty.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.config;
+
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.function.BiConsumer;
+
+import org.yaml.snakeyaml.introspector.Property;
+
+/**
+ *
+ */
+public class ListenableProperty<S, T> extends ForwardingProperty
+{
+ private final Map<EventType, List<Handler<S, T>>> handlers = new EnumMap<>(EventType.class);
+
+ public ListenableProperty(Property property)
+ {
+ super(property.getName(), property);
+ for (EventType eventType : EventType.values())
+ handlers.put(eventType, new CopyOnWriteArrayList<>());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public synchronized void set(Object source, Object newValue) throws Exception
+ {
+ T oldValue = (T) get(source);
+ T value = Handler.compose(handlers.get(EventType.BEFORE)).handle((S) source, oldValue, (T) newValue);
+ delegate().set(source, value);
+ Handler.compose(handlers.get(EventType.AFTER)).handle((S) source, oldValue, value);
+ }
+
+ public synchronized Remover addBeforeHandler(Handler<S, T> handler)
+ {
+ handlers.computeIfAbsent(EventType.BEFORE, k -> new CopyOnWriteArrayList<>()).add(handler);
+ return () -> handlers.get(EventType.BEFORE).remove(handler);
+ }
+
+ public synchronized Remover addAfterHandler(Handler<S, T> handler)
+ {
+ handlers.computeIfAbsent(EventType.AFTER, k -> new CopyOnWriteArrayList<>()).add(handler);
+ return () -> handlers.get(EventType.AFTER).remove(handler);
+ }
+
+ private enum EventType
+ {
+ BEFORE, AFTER
+ }
+
+ /**
+ * The handler to be notified before and after a configuration value is changed.
+ * @param <S> the type of the object to mutate.
+ * @param <V> the type of the value to mutate.
+ */
+ @FunctionalInterface
+ public interface Handler<S, V>
+ {
+ V handle(S source, V oldValue, V newValue);
+
+ static <S, V> Handler<S, V> consume(BiConsumer<? super V, ? super V> consumer)
+ {
+ return (source, oldValue, newValue) -> {
+ consumer.accept(oldValue, newValue);
+ return newValue;
+ };
+ }
+
+ static <S, V> Handler<S, V > compose(List<Handler < S, V >> handlers)
+ {
+ return (source, oldValue, newValue) -> {
Review Comment:
why return a lambda if we trigger right away? Its more efficient to just have a static function that returns `value`
##########
src/java/org/apache/cassandra/config/ListenableProperty.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.config;
+
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.function.BiConsumer;
+
+import org.yaml.snakeyaml.introspector.Property;
+
+/**
+ *
+ */
+public class ListenableProperty<S, T> extends ForwardingProperty
+{
+ private final Map<EventType, List<Handler<S, T>>> handlers = new EnumMap<>(EventType.class);
+
+ public ListenableProperty(Property property)
+ {
+ super(property.getName(), property);
+ for (EventType eventType : EventType.values())
+ handlers.put(eventType, new CopyOnWriteArrayList<>());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public synchronized void set(Object source, Object newValue) throws Exception
+ {
+ T oldValue = (T) get(source);
+ T value = Handler.compose(handlers.get(EventType.BEFORE)).handle((S) source, oldValue, (T) newValue);
+ delegate().set(source, value);
+ Handler.compose(handlers.get(EventType.AFTER)).handle((S) source, oldValue, value);
+ }
+
+ public synchronized Remover addBeforeHandler(Handler<S, T> handler)
+ {
+ handlers.computeIfAbsent(EventType.BEFORE, k -> new CopyOnWriteArrayList<>()).add(handler);
+ return () -> handlers.get(EventType.BEFORE).remove(handler);
+ }
+
+ public synchronized Remover addAfterHandler(Handler<S, T> handler)
+ {
+ handlers.computeIfAbsent(EventType.AFTER, k -> new CopyOnWriteArrayList<>()).add(handler);
+ return () -> handlers.get(EventType.AFTER).remove(handler);
+ }
+
+ private enum EventType
+ {
+ BEFORE, AFTER
+ }
+
+ /**
+ * The handler to be notified before and after a configuration value is changed.
+ * @param <S> the type of the object to mutate.
+ * @param <V> the type of the value to mutate.
+ */
+ @FunctionalInterface
+ public interface Handler<S, V>
+ {
+ V handle(S source, V oldValue, V newValue);
+
+ static <S, V> Handler<S, V> consume(BiConsumer<? super V, ? super V> consumer)
+ {
+ return (source, oldValue, newValue) -> {
+ consumer.accept(oldValue, newValue);
+ return newValue;
+ };
+ }
+
+ static <S, V> Handler<S, V > compose(List<Handler < S, V >> handlers)
Review Comment:
can you fix the formatting? should remove the extra spaces
##########
src/java/org/apache/cassandra/config/DataRateSpec.java:
##########
@@ -209,6 +209,14 @@ public boolean equals(Object obj)
return unit.convert(other.quantity, other.unit) == quantity && other.unit.convert(quantity, unit) == other.quantity;
}
+ @SuppressWarnings("unchecked")
+ public final Class<T> getDeclaringClass()
Review Comment:
looks like dead code, can you revert?
##########
src/java/org/apache/cassandra/config/ListenableProperty.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.config;
+
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.function.BiConsumer;
+
+import org.yaml.snakeyaml.introspector.Property;
+
+/**
+ *
+ */
+public class ListenableProperty<S, T> extends ForwardingProperty
+{
+ private final Map<EventType, List<Handler<S, T>>> handlers = new EnumMap<>(EventType.class);
+
+ public ListenableProperty(Property property)
+ {
+ super(property.getName(), property);
+ for (EventType eventType : EventType.values())
+ handlers.put(eventType, new CopyOnWriteArrayList<>());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public synchronized void set(Object source, Object newValue) throws Exception
Review Comment:
remove `synchronized`; this isn't thread safe
##########
src/java/org/apache/cassandra/config/ListenableProperty.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.config;
+
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.function.BiConsumer;
+
+import org.yaml.snakeyaml.introspector.Property;
+
+/**
+ *
+ */
+public class ListenableProperty<S, T> extends ForwardingProperty
+{
+ private final Map<EventType, List<Handler<S, T>>> handlers = new EnumMap<>(EventType.class);
+
+ public ListenableProperty(Property property)
+ {
+ super(property.getName(), property);
+ for (EventType eventType : EventType.values())
+ handlers.put(eventType, new CopyOnWriteArrayList<>());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public synchronized void set(Object source, Object newValue) throws Exception
+ {
+ T oldValue = (T) get(source);
+ T value = Handler.compose(handlers.get(EventType.BEFORE)).handle((S) source, oldValue, (T) newValue);
+ delegate().set(source, value);
+ Handler.compose(handlers.get(EventType.AFTER)).handle((S) source, oldValue, value);
+ }
+
+ public synchronized Remover addBeforeHandler(Handler<S, T> handler)
Review Comment:
remove `synchronized`; this isn't thread safe
##########
src/java/org/apache/cassandra/config/ListenableProperty.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.config;
+
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.function.BiConsumer;
+
+import org.yaml.snakeyaml.introspector.Property;
+
+/**
+ *
+ */
+public class ListenableProperty<S, T> extends ForwardingProperty
+{
+ private final Map<EventType, List<Handler<S, T>>> handlers = new EnumMap<>(EventType.class);
+
+ public ListenableProperty(Property property)
+ {
+ super(property.getName(), property);
+ for (EventType eventType : EventType.values())
+ handlers.put(eventType, new CopyOnWriteArrayList<>());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public synchronized void set(Object source, Object newValue) throws Exception
+ {
+ T oldValue = (T) get(source);
+ T value = Handler.compose(handlers.get(EventType.BEFORE)).handle((S) source, oldValue, (T) newValue);
+ delegate().set(source, value);
+ Handler.compose(handlers.get(EventType.AFTER)).handle((S) source, oldValue, value);
+ }
+
+ public synchronized Remover addBeforeHandler(Handler<S, T> handler)
+ {
+ handlers.computeIfAbsent(EventType.BEFORE, k -> new CopyOnWriteArrayList<>()).add(handler);
+ return () -> handlers.get(EventType.BEFORE).remove(handler);
+ }
+
+ public synchronized Remover addAfterHandler(Handler<S, T> handler)
Review Comment:
remove `synchronized`; this isn't thread safe
##########
src/java/org/apache/cassandra/config/ListenableProperty.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.config;
+
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.function.BiConsumer;
+
+import org.yaml.snakeyaml.introspector.Property;
+
+/**
+ *
+ */
+public class ListenableProperty<S, T> extends ForwardingProperty
+{
+ private final Map<EventType, List<Handler<S, T>>> handlers = new EnumMap<>(EventType.class);
+
+ public ListenableProperty(Property property)
+ {
+ super(property.getName(), property);
+ for (EventType eventType : EventType.values())
+ handlers.put(eventType, new CopyOnWriteArrayList<>());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public synchronized void set(Object source, Object newValue) throws Exception
+ {
+ T oldValue = (T) get(source);
+ T value = Handler.compose(handlers.get(EventType.BEFORE)).handle((S) source, oldValue, (T) newValue);
+ delegate().set(source, value);
+ Handler.compose(handlers.get(EventType.AFTER)).handle((S) source, oldValue, value);
+ }
+
+ public synchronized Remover addBeforeHandler(Handler<S, T> handler)
+ {
+ handlers.computeIfAbsent(EventType.BEFORE, k -> new CopyOnWriteArrayList<>()).add(handler);
+ return () -> handlers.get(EventType.BEFORE).remove(handler);
+ }
+
+ public synchronized Remover addAfterHandler(Handler<S, T> handler)
+ {
+ handlers.computeIfAbsent(EventType.AFTER, k -> new CopyOnWriteArrayList<>()).add(handler);
+ return () -> handlers.get(EventType.AFTER).remove(handler);
+ }
+
+ private enum EventType
+ {
+ BEFORE, AFTER
+ }
+
+ /**
+ * The handler to be notified before and after a configuration value is changed.
+ * @param <S> the type of the object to mutate.
+ * @param <V> the type of the value to mutate.
+ */
+ @FunctionalInterface
+ public interface Handler<S, V>
+ {
+ V handle(S source, V oldValue, V newValue);
+
+ static <S, V> Handler<S, V> consume(BiConsumer<? super V, ? super V> consumer)
Review Comment:
can we remove, looks like dead code
##########
src/java/org/apache/cassandra/config/DatabaseDescriptor.java:
##########
@@ -4763,4 +4756,159 @@ public static OptionalDouble getSeverityDuringDecommission()
OptionalDouble.of(conf.severity_during_decommission) :
OptionalDouble.empty();
}
+
+ public static void visit(PropertyVisitor visitor)
+ {
+ visit(visitor, RuntimeException::new);
+ }
+
+ public static void visit(PropertyVisitor visitor, Function<Throwable, ? extends RuntimeException> handler)
+ {
+ try
+ {
+ for (Property property : ofNullable(confValueAccessors).orElse(Collections.emptyMap()).values())
+ visitor.visit(property.getName(), property.getType(), property.getAnnotation(Mutable.class) == null);
+ }
+ catch (Throwable t)
+ {
+ throw handler.apply(t);
+ }
+ }
+
+ public static <T> ListenableProperty.Remover addBeforeChangePropertyListener(String name, Class<T> clazz, BiConsumer<T, T> consumer)
+ {
+ return addPropertyListener(name, clazz, p -> p.addBeforeHandler(ListenableProperty.Handler.consume(consumer)));
+ }
+
+ public static <T> ListenableProperty.Remover addAfterChangePropertyListener(String name, Class<T> clazz, BiConsumer<T, T> consumer)
+ {
+ return addPropertyListener(name, clazz, p -> p.addAfterHandler(ListenableProperty.Handler.consume(consumer)));
+ }
+
+ @SuppressWarnings("unchecked")
+ private static <T> ListenableProperty.Remover addPropertyListener(String name,
+ Class<T> clazz,
+ Function<ListenableProperty<Config, T>, ListenableProperty.Remover> adder)
+ {
+ Property property = ofNullable(confValueAccessors.get(name))
+ .map(p -> {
+ // The case when replacement property is used and match the property's name.
+ if (p instanceof Replacement.ReplacementProperty)
+ return ((Replacement.ReplacementProperty) p).delegate();
+ else
+ return p;
+ })
+ .orElseThrow(() -> new PropertyNotFoundException(name));
+ if (!(property instanceof ListenableProperty))
+ throw new ConfigurationException(String.format("Property '%s' is not listenable.", name));
+
+ if (clazz.equals(property.getType()))
+ return adder.apply((ListenableProperty<Config, T>) property);
+ else
+ throw new ConfigurationException(String.format("Listener type '%s' doesn't match the property '%s' type '%s'.",
+ clazz.getSimpleName(), name, clazz.getSimpleName()));
+ }
+
+ public static Object getProperty(String name)
+ {
+ return ofNullable(confValueAccessors.get(name)).orElseThrow(() -> new PropertyNotFoundException(name))
+ .get(conf);
Review Comment:
please simplify, trying to use `Optional` is adding complexity and overhead, a simple `null` check is simpler
##########
src/java/org/apache/cassandra/config/ValidatedPropertyLoader.java:
##########
@@ -0,0 +1,117 @@
+/*
+ * 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.config;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+import com.google.common.base.Preconditions;
+import org.apache.commons.lang3.ArrayUtils;
+
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.utils.FBUtilities;
+import org.yaml.snakeyaml.introspector.FieldProperty;
+import org.yaml.snakeyaml.introspector.Property;
+
+public class ValidatedPropertyLoader extends DefaultLoader
+{
+ private final Predicate<Property> nonListenableProperty;
+
+ public ValidatedPropertyLoader(Predicate<Property> nonListenableProperty)
+ {
+ this.nonListenableProperty = nonListenableProperty;
+ }
+
+ @Override
+ protected Property createPropertyForField(Class<?> root, Field field)
+ {
+ Property property = new FieldProperty(field);
+ if (nonListenableProperty.test(property))
+ return property;
+
+ ListenableProperty<?, ?> listenable = new ListenableProperty<>(property);
+ if (property.getAnnotation(ValidatedBy.class) != null)
+ listenable.addBeforeHandler(ValidationPropertyHandler.create(root, listenable.delegate()));
+ return listenable;
+ }
+
+ private static class ValidationPropertyHandler<S, T> implements ListenableProperty.Handler<S, T>
+ {
+ private final Method method;
+ private final String name;
+
+ private ValidationPropertyHandler(Method method, String name)
+ {
+ this.method = method;
+ this.name = name;
+ }
+
+ public static <S, T> ValidationPropertyHandler<S, T> create(Class<?> root, Property property)
+ {
+ Preconditions.checkNotNull(property.getAnnotation(ValidatedBy.class));
+ ValidatedBy annotation = property.getAnnotation(ValidatedBy.class);
+ Class<?> clazz = FBUtilities.classForName(annotation.useClass(), "validate method");
+ Class<?>[] searchPattern = ArrayUtils.addAll(new Class<?>[]{ root, property.getType() });
+ for (Method refMethod : clazz.getDeclaredMethods())
+ {
+ int modifiers = refMethod.getModifiers();
+ if (Modifier.isPrivate(modifiers) || Modifier.isProtected(modifiers))
Review Comment:
simpler to check `isPublic`, as I think this will include `package-private` as well atm.
Also, think you need `static` as you don't have access to `DatabaseDescriptor` instance
##########
src/java/org/apache/cassandra/config/ListenableProperty.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.config;
+
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.function.BiConsumer;
+
+import org.yaml.snakeyaml.introspector.Property;
+
+/**
+ *
+ */
+public class ListenableProperty<S, T> extends ForwardingProperty
+{
+ private final Map<EventType, List<Handler<S, T>>> handlers = new EnumMap<>(EventType.class);
+
+ public ListenableProperty(Property property)
+ {
+ super(property.getName(), property);
+ for (EventType eventType : EventType.values())
+ handlers.put(eventType, new CopyOnWriteArrayList<>());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public synchronized void set(Object source, Object newValue) throws Exception
+ {
+ T oldValue = (T) get(source);
+ T value = Handler.compose(handlers.get(EventType.BEFORE)).handle((S) source, oldValue, (T) newValue);
+ delegate().set(source, value);
+ Handler.compose(handlers.get(EventType.AFTER)).handle((S) source, oldValue, value);
+ }
+
+ public synchronized Remover addBeforeHandler(Handler<S, T> handler)
+ {
+ handlers.computeIfAbsent(EventType.BEFORE, k -> new CopyOnWriteArrayList<>()).add(handler);
+ return () -> handlers.get(EventType.BEFORE).remove(handler);
+ }
+
+ public synchronized Remover addAfterHandler(Handler<S, T> handler)
+ {
+ handlers.computeIfAbsent(EventType.AFTER, k -> new CopyOnWriteArrayList<>()).add(handler);
Review Comment:
you don't need/want `computeIfAbsent`, you added in the constructor
##########
src/java/org/apache/cassandra/config/ValidatedPropertyLoader.java:
##########
@@ -0,0 +1,117 @@
+/*
+ * 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.config;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+import com.google.common.base.Preconditions;
+import org.apache.commons.lang3.ArrayUtils;
+
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.utils.FBUtilities;
+import org.yaml.snakeyaml.introspector.FieldProperty;
+import org.yaml.snakeyaml.introspector.Property;
+
+public class ValidatedPropertyLoader extends DefaultLoader
+{
+ private final Predicate<Property> nonListenableProperty;
+
+ public ValidatedPropertyLoader(Predicate<Property> nonListenableProperty)
+ {
+ this.nonListenableProperty = nonListenableProperty;
+ }
+
+ @Override
+ protected Property createPropertyForField(Class<?> root, Field field)
+ {
+ Property property = new FieldProperty(field);
+ if (nonListenableProperty.test(property))
+ return property;
+
+ ListenableProperty<?, ?> listenable = new ListenableProperty<>(property);
+ if (property.getAnnotation(ValidatedBy.class) != null)
+ listenable.addBeforeHandler(ValidationPropertyHandler.create(root, listenable.delegate()));
+ return listenable;
+ }
+
+ private static class ValidationPropertyHandler<S, T> implements ListenableProperty.Handler<S, T>
+ {
+ private final Method method;
+ private final String name;
+
+ private ValidationPropertyHandler(Method method, String name)
+ {
+ this.method = method;
+ this.name = name;
+ }
+
+ public static <S, T> ValidationPropertyHandler<S, T> create(Class<?> root, Property property)
+ {
+ Preconditions.checkNotNull(property.getAnnotation(ValidatedBy.class));
+ ValidatedBy annotation = property.getAnnotation(ValidatedBy.class);
+ Class<?> clazz = FBUtilities.classForName(annotation.useClass(), "validate method");
+ Class<?>[] searchPattern = ArrayUtils.addAll(new Class<?>[]{ root, property.getType() });
+ for (Method refMethod : clazz.getDeclaredMethods())
+ {
+ int modifiers = refMethod.getModifiers();
+ if (Modifier.isPrivate(modifiers) || Modifier.isProtected(modifiers))
+ continue;
+
+ if (refMethod.getName().equals(annotation.useClassMethod()) &&
+ Arrays.equals(refMethod.getParameterTypes(), searchPattern) &&
+ (refMethod.getReturnType() == Void.TYPE || refMethod.getReturnType().equals(property.getType())))
+ {
+ return new ValidationPropertyHandler<>(refMethod, property.getName());
+ }
+ }
+ throw new ConfigurationException(String.format("Required method '%s(%s)' not found for field '%s'",
+ annotation.useClassMethod(),
+ Arrays.stream(searchPattern)
+ .map(Class::getCanonicalName)
+ .collect(Collectors.joining(", ")),
+ property.getName()), false);
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
+ @Override
+ public T handle(S source, T oldValue, T newValue)
+ {
+ try
+ {
+ Object result = method.invoke(source, source, newValue);
Review Comment:
Also, you only searched for `Parent, Value`, so this should fail as the arguments you pass in are different
##########
src/java/org/apache/cassandra/config/ValidatedPropertyLoader.java:
##########
@@ -0,0 +1,117 @@
+/*
+ * 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.config;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+import com.google.common.base.Preconditions;
+import org.apache.commons.lang3.ArrayUtils;
+
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.utils.FBUtilities;
+import org.yaml.snakeyaml.introspector.FieldProperty;
+import org.yaml.snakeyaml.introspector.Property;
+
+public class ValidatedPropertyLoader extends DefaultLoader
+{
+ private final Predicate<Property> nonListenableProperty;
+
+ public ValidatedPropertyLoader(Predicate<Property> nonListenableProperty)
+ {
+ this.nonListenableProperty = nonListenableProperty;
+ }
+
+ @Override
+ protected Property createPropertyForField(Class<?> root, Field field)
+ {
+ Property property = new FieldProperty(field);
+ if (nonListenableProperty.test(property))
+ return property;
+
+ ListenableProperty<?, ?> listenable = new ListenableProperty<>(property);
+ if (property.getAnnotation(ValidatedBy.class) != null)
Review Comment:
if you take a look at my branch I sent you, its trivial to add support for multiple `ValidatedBy`, can you add support? My main use case are for reusable properties
##########
src/java/org/apache/cassandra/config/ValidatedPropertyLoader.java:
##########
@@ -0,0 +1,117 @@
+/*
+ * 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.config;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+import com.google.common.base.Preconditions;
+import org.apache.commons.lang3.ArrayUtils;
+
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.utils.FBUtilities;
+import org.yaml.snakeyaml.introspector.FieldProperty;
+import org.yaml.snakeyaml.introspector.Property;
+
+public class ValidatedPropertyLoader extends DefaultLoader
+{
+ private final Predicate<Property> nonListenableProperty;
+
+ public ValidatedPropertyLoader(Predicate<Property> nonListenableProperty)
+ {
+ this.nonListenableProperty = nonListenableProperty;
+ }
+
+ @Override
+ protected Property createPropertyForField(Class<?> root, Field field)
Review Comment:
commented in `DefaultLoader`, this API is unsafe
##########
src/java/org/apache/cassandra/config/ValidatedPropertyLoader.java:
##########
@@ -0,0 +1,117 @@
+/*
+ * 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.config;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+import com.google.common.base.Preconditions;
+import org.apache.commons.lang3.ArrayUtils;
+
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.utils.FBUtilities;
+import org.yaml.snakeyaml.introspector.FieldProperty;
+import org.yaml.snakeyaml.introspector.Property;
+
+public class ValidatedPropertyLoader extends DefaultLoader
+{
+ private final Predicate<Property> nonListenableProperty;
+
+ public ValidatedPropertyLoader(Predicate<Property> nonListenableProperty)
+ {
+ this.nonListenableProperty = nonListenableProperty;
+ }
+
+ @Override
+ protected Property createPropertyForField(Class<?> root, Field field)
+ {
+ Property property = new FieldProperty(field);
+ if (nonListenableProperty.test(property))
+ return property;
+
+ ListenableProperty<?, ?> listenable = new ListenableProperty<>(property);
+ if (property.getAnnotation(ValidatedBy.class) != null)
+ listenable.addBeforeHandler(ValidationPropertyHandler.create(root, listenable.delegate()));
+ return listenable;
+ }
+
+ private static class ValidationPropertyHandler<S, T> implements ListenableProperty.Handler<S, T>
+ {
+ private final Method method;
+ private final String name;
+
+ private ValidationPropertyHandler(Method method, String name)
+ {
+ this.method = method;
+ this.name = name;
+ }
+
+ public static <S, T> ValidationPropertyHandler<S, T> create(Class<?> root, Property property)
+ {
+ Preconditions.checkNotNull(property.getAnnotation(ValidatedBy.class));
+ ValidatedBy annotation = property.getAnnotation(ValidatedBy.class);
+ Class<?> clazz = FBUtilities.classForName(annotation.useClass(), "validate method");
+ Class<?>[] searchPattern = ArrayUtils.addAll(new Class<?>[]{ root, property.getType() });
+ for (Method refMethod : clazz.getDeclaredMethods())
+ {
+ int modifiers = refMethod.getModifiers();
+ if (Modifier.isPrivate(modifiers) || Modifier.isProtected(modifiers))
+ continue;
+
+ if (refMethod.getName().equals(annotation.useClassMethod()) &&
+ Arrays.equals(refMethod.getParameterTypes(), searchPattern) &&
+ (refMethod.getReturnType() == Void.TYPE || refMethod.getReturnType().equals(property.getType())))
+ {
+ return new ValidationPropertyHandler<>(refMethod, property.getName());
+ }
+ }
+ throw new ConfigurationException(String.format("Required method '%s(%s)' not found for field '%s'",
+ annotation.useClassMethod(),
+ Arrays.stream(searchPattern)
+ .map(Class::getCanonicalName)
+ .collect(Collectors.joining(", ")),
+ property.getName()), false);
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
+ @Override
+ public T handle(S source, T oldValue, T newValue)
+ {
+ try
+ {
+ Object result = method.invoke(source, source, newValue);
Review Comment:
this isn't correct, should have `null` as the first argument, as you don't have access to `DatabaseDescriptor`
##########
src/java/org/apache/cassandra/config/DatabaseDescriptor.java:
##########
@@ -4763,4 +4756,159 @@ public static OptionalDouble getSeverityDuringDecommission()
OptionalDouble.of(conf.severity_during_decommission) :
OptionalDouble.empty();
}
+
+ public static void visit(PropertyVisitor visitor)
+ {
+ visit(visitor, RuntimeException::new);
+ }
+
+ public static void visit(PropertyVisitor visitor, Function<Throwable, ? extends RuntimeException> handler)
+ {
+ try
+ {
+ for (Property property : ofNullable(confValueAccessors).orElse(Collections.emptyMap()).values())
+ visitor.visit(property.getName(), property.getType(), property.getAnnotation(Mutable.class) == null);
+ }
+ catch (Throwable t)
+ {
+ throw handler.apply(t);
+ }
+ }
+
+ public static <T> ListenableProperty.Remover addBeforeChangePropertyListener(String name, Class<T> clazz, BiConsumer<T, T> consumer)
+ {
+ return addPropertyListener(name, clazz, p -> p.addBeforeHandler(ListenableProperty.Handler.consume(consumer)));
+ }
+
+ public static <T> ListenableProperty.Remover addAfterChangePropertyListener(String name, Class<T> clazz, BiConsumer<T, T> consumer)
+ {
+ return addPropertyListener(name, clazz, p -> p.addAfterHandler(ListenableProperty.Handler.consume(consumer)));
+ }
+
+ @SuppressWarnings("unchecked")
+ private static <T> ListenableProperty.Remover addPropertyListener(String name,
+ Class<T> clazz,
+ Function<ListenableProperty<Config, T>, ListenableProperty.Remover> adder)
+ {
+ Property property = ofNullable(confValueAccessors.get(name))
+ .map(p -> {
+ // The case when replacement property is used and match the property's name.
+ if (p instanceof Replacement.ReplacementProperty)
+ return ((Replacement.ReplacementProperty) p).delegate();
+ else
+ return p;
+ })
+ .orElseThrow(() -> new PropertyNotFoundException(name));
+ if (!(property instanceof ListenableProperty))
+ throw new ConfigurationException(String.format("Property '%s' is not listenable.", name));
+
+ if (clazz.equals(property.getType()))
+ return adder.apply((ListenableProperty<Config, T>) property);
+ else
+ throw new ConfigurationException(String.format("Listener type '%s' doesn't match the property '%s' type '%s'.",
+ clazz.getSimpleName(), name, clazz.getSimpleName()));
+ }
+
+ public static Object getProperty(String name)
+ {
+ return ofNullable(confValueAccessors.get(name)).orElseThrow(() -> new PropertyNotFoundException(name))
+ .get(conf);
+ }
+
+ public static String getStringProperty(String name)
+ {
+ Property property = ofNullable(confValueAccessors.get(name))
+ .orElseThrow(() -> new PropertyNotFoundException(name));
+ return property.getType().equals(String.class) ?
+ (String) property.get(conf) :
+ propertyToStringConverter().convertNullable(property.get(conf));
+ }
+
+ /**
+ * Set configuration property for the given name to {@link #conf} if a safe manner
+ * with handling internal Cassandra exceptions.
+ *
+ * @param name Property name.
+ * @param value Property value.
+ */
+ public static void setProperty(String name, Object value)
+ {
+ try
+ {
+ Property property = ofNullable(confValueAccessors.get(name)).orElseThrow(() -> new PropertyNotFoundException(name));
+ if (property.getAnnotation(Mutable.class) == null)
+ throw new ConfigurationException("Property is read-only: " + property.getName());
+
+ if (value == null)
+ {
+ property.set(conf, null);
+ return;
+ }
+
+ if (property.getType().isAssignableFrom(value.getClass()))
+ property.set(conf, value);
+ else if (String.class.equals(value.getClass()))
+ property.set(conf, propertyFromStringConverter(primitiveToWrapper(property.getType())).convert((String) value));
Review Comment:
push this into `SettingsTable`, you are leaking details cross classes, we should keep this very simple
##########
src/java/org/apache/cassandra/config/ValidatedPropertyLoader.java:
##########
@@ -0,0 +1,117 @@
+/*
+ * 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.config;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+import com.google.common.base.Preconditions;
+import org.apache.commons.lang3.ArrayUtils;
+
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.utils.FBUtilities;
+import org.yaml.snakeyaml.introspector.FieldProperty;
+import org.yaml.snakeyaml.introspector.Property;
+
+public class ValidatedPropertyLoader extends DefaultLoader
+{
+ private final Predicate<Property> nonListenableProperty;
+
+ public ValidatedPropertyLoader(Predicate<Property> nonListenableProperty)
+ {
+ this.nonListenableProperty = nonListenableProperty;
+ }
+
+ @Override
+ protected Property createPropertyForField(Class<?> root, Field field)
+ {
+ Property property = new FieldProperty(field);
+ if (nonListenableProperty.test(property))
+ return property;
+
+ ListenableProperty<?, ?> listenable = new ListenableProperty<>(property);
+ if (property.getAnnotation(ValidatedBy.class) != null)
+ listenable.addBeforeHandler(ValidationPropertyHandler.create(root, listenable.delegate()));
+ return listenable;
+ }
+
+ private static class ValidationPropertyHandler<S, T> implements ListenableProperty.Handler<S, T>
+ {
+ private final Method method;
+ private final String name;
+
+ private ValidationPropertyHandler(Method method, String name)
+ {
+ this.method = method;
+ this.name = name;
+ }
+
+ public static <S, T> ValidationPropertyHandler<S, T> create(Class<?> root, Property property)
+ {
+ Preconditions.checkNotNull(property.getAnnotation(ValidatedBy.class));
+ ValidatedBy annotation = property.getAnnotation(ValidatedBy.class);
+ Class<?> clazz = FBUtilities.classForName(annotation.useClass(), "validate method");
+ Class<?>[] searchPattern = ArrayUtils.addAll(new Class<?>[]{ root, property.getType() });
Review Comment:
are you not missing `String`? the interface is `Parent, Name, Value`, but you only have `Parent, Value` here
##########
src/java/org/apache/cassandra/db/virtual/SettingsTable.java:
##########
@@ -59,63 +53,77 @@ final class SettingsTable extends AbstractVirtualTable
.addPartitionKeyColumn(NAME, UTF8Type.instance)
.addRegularColumn(VALUE, UTF8Type.instance)
.build());
- this.config = config;
+ Set<String> unprocessed = new HashSet<>(BACKWARDS_COMPATABLE_NAMES.values());
+ DatabaseDescriptor.visit((key, type, ro) -> {
+ if (BACKWARDS_COMPATABLE_NAMES.containsKey(key))
+ {
+ 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",
+ key, SettingsTable.class.getSimpleName()));
+ }
+ unprocessed.remove(key);
+ });
+ if (!unprocessed.isEmpty())
+ throw new AssertionError("The following keys must be present in the Config: " + unprocessed);
Review Comment:
If you add `DatabaseDescriptor.hasProperty(String name)` you can drastically simplify this code...
```
for (String name : BACKWARDS_COMPATABLE_NAMES)
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",
key, SettingsTable.class.getSimpleName()));
```
This is also cheaper
##########
src/java/org/apache/cassandra/config/WithReplacementLoader.java:
##########
@@ -0,0 +1,47 @@
+/*
+ * 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.config;
+
+import java.util.Map;
+
+import org.yaml.snakeyaml.introspector.Property;
+
+public class WithReplacementLoader implements Loader
+{
+ private final Loader delegate;
Review Comment:
newline
##########
src/java/org/apache/cassandra/db/virtual/SettingsTable.java:
##########
@@ -18,39 +18,33 @@
package org.apache.cassandra.db.virtual;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
-import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+
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.db.DecoratedKey;
import org.apache.cassandra.db.marshal.UTF8Type;
import org.apache.cassandra.dht.LocalPartitioner;
+import org.apache.cassandra.exceptions.ConfigurationException;
+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.getStringProperty;
+import static org.apache.cassandra.cql3.statements.RequestValidations.invalidRequest;
+import static org.apache.cassandra.utils.FBUtilities.runExceptionally;
+
+final class SettingsTable extends AbstractMutableVirtualTable
Review Comment:
where are you handing yaml string conversions (to / from)? I don't see anything do that; did you push that out of this patch? I saw you did a large refactor to YamlConfigLoader but that isn't used here?
##########
src/java/org/apache/cassandra/db/virtual/SettingsTable.java:
##########
@@ -59,63 +53,77 @@ final class SettingsTable extends AbstractVirtualTable
.addPartitionKeyColumn(NAME, UTF8Type.instance)
.addRegularColumn(VALUE, UTF8Type.instance)
.build());
- this.config = config;
+ Set<String> unprocessed = new HashSet<>(BACKWARDS_COMPATABLE_NAMES.values());
+ DatabaseDescriptor.visit((key, type, ro) -> {
+ if (BACKWARDS_COMPATABLE_NAMES.containsKey(key))
+ {
+ 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",
+ key, SettingsTable.class.getSimpleName()));
+ }
+ unprocessed.remove(key);
+ });
+ if (!unprocessed.isEmpty())
+ throw new AssertionError("The following keys must be present in the Config: " + unprocessed);
+ }
+
+ @Override
+ protected void applyColumnDeletion(AbstractMutableVirtualTable.ColumnValues partitionKey, AbstractMutableVirtualTable.ColumnValues clusteringColumns, String columnName)
+ {
+ String name = partitionKey.value(0);
+ String key = getKeyAndWarn(name);
+ runExceptionally(() -> DatabaseDescriptor.setProperty(key, null),
+ t -> invalidRequest("Invalid delete request. Cause: %s", t.getMessage()));
+ }
+
+ @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);
Review Comment:
`orElse(null)` doesn't look correct, you would be changing a `UPDATE` to a `DELETE`, which would be a bug
##########
src/java/org/apache/cassandra/config/DatabaseDescriptor.java:
##########
@@ -151,13 +161,21 @@
*/
private static final int MAX_NUM_TOKENS = 1536;
+ /**
+ * The metadata source of configuration properties. It is used to access the configuration class instance loaded
+ * from the {@link #conf} and must be initialized the same time the {@link #conf} is initialized, usually
+ * by calling {@link #toolInitialization()}, {@link #daemonInitialization()} or {@link #clientInitialization()}.
+ */
+ private static Map<String, ? extends Property> confValueAccessors;
private static Config conf;
/**
* Request timeouts can not be less than below defined value (see CASSANDRA-9375)
*/
static final DurationSpec.LongMillisecondsBound LOWEST_ACCEPTED_TIMEOUT = new DurationSpec.LongMillisecondsBound(10L);
+ public static final int SPACE_UPPER_BOUND_MB = (int) (Runtime.getRuntime().maxMemory() / (16 * 1048576));
Review Comment:
`private`
##########
src/java/org/apache/cassandra/config/DatabaseDescriptor.java:
##########
@@ -415,9 +433,12 @@ private static InetAddress getNetworkInterfaceAddress(String intf, String config
}
}
- private static void setConfig(Config config)
+ private static void setConfig(Supplier<Config> config)
{
- conf = config;
+ conf = config.get();
+ confValueAccessors = ImmutableMap.copyOf(
Review Comment:
this is static, why are you setting it on `setConfig`? `static final` is far easier to make sure safe than mutable
##########
src/java/org/apache/cassandra/config/DatabaseDescriptor.java:
##########
@@ -415,9 +433,12 @@ private static InetAddress getNetworkInterfaceAddress(String intf, String config
}
}
- private static void setConfig(Config config)
+ private static void setConfig(Supplier<Config> config)
{
- conf = config;
+ conf = config.get();
+ confValueAccessors = ImmutableMap.copyOf(
+ withReplacementsLoader(
+ validatedPropertyLoader(p -> p.getAnnotation(Mutable.class) == null)).flatten(Config.class));
Review Comment:
IMO its cleaner to push this property into the loader itself, the loader 100% makes assumptions about this interface, but what is selected is external just adds extra confusion.
##########
src/java/org/apache/cassandra/config/DatabaseDescriptor.java:
##########
@@ -4763,4 +4756,159 @@ public static OptionalDouble getSeverityDuringDecommission()
OptionalDouble.of(conf.severity_during_decommission) :
OptionalDouble.empty();
}
+
+ public static void visit(PropertyVisitor visitor)
+ {
+ visit(visitor, RuntimeException::new);
+ }
+
+ public static void visit(PropertyVisitor visitor, Function<Throwable, ? extends RuntimeException> handler)
+ {
+ try
+ {
+ for (Property property : ofNullable(confValueAccessors).orElse(Collections.emptyMap()).values())
+ visitor.visit(property.getName(), property.getType(), property.getAnnotation(Mutable.class) == null);
+ }
+ catch (Throwable t)
+ {
+ throw handler.apply(t);
+ }
+ }
+
+ public static <T> ListenableProperty.Remover addBeforeChangePropertyListener(String name, Class<T> clazz, BiConsumer<T, T> consumer)
+ {
+ return addPropertyListener(name, clazz, p -> p.addBeforeHandler(ListenableProperty.Handler.consume(consumer)));
+ }
+
+ public static <T> ListenableProperty.Remover addAfterChangePropertyListener(String name, Class<T> clazz, BiConsumer<T, T> consumer)
+ {
+ return addPropertyListener(name, clazz, p -> p.addAfterHandler(ListenableProperty.Handler.consume(consumer)));
+ }
+
+ @SuppressWarnings("unchecked")
+ private static <T> ListenableProperty.Remover addPropertyListener(String name,
+ Class<T> clazz,
+ Function<ListenableProperty<Config, T>, ListenableProperty.Remover> adder)
+ {
+ Property property = ofNullable(confValueAccessors.get(name))
+ .map(p -> {
+ // The case when replacement property is used and match the property's name.
+ if (p instanceof Replacement.ReplacementProperty)
+ return ((Replacement.ReplacementProperty) p).delegate();
+ else
+ return p;
+ })
+ .orElseThrow(() -> new PropertyNotFoundException(name));
+ if (!(property instanceof ListenableProperty))
+ throw new ConfigurationException(String.format("Property '%s' is not listenable.", name));
+
+ if (clazz.equals(property.getType()))
+ return adder.apply((ListenableProperty<Config, T>) property);
+ else
+ throw new ConfigurationException(String.format("Listener type '%s' doesn't match the property '%s' type '%s'.",
+ clazz.getSimpleName(), name, clazz.getSimpleName()));
+ }
+
+ public static Object getProperty(String name)
+ {
+ return ofNullable(confValueAccessors.get(name)).orElseThrow(() -> new PropertyNotFoundException(name))
+ .get(conf);
+ }
+
+ public static String getStringProperty(String name)
+ {
+ Property property = ofNullable(confValueAccessors.get(name))
+ .orElseThrow(() -> new PropertyNotFoundException(name));
Review Comment:
please refactor so `getProperty` has the same logic, can do something simple like
```
private static Property getProp(String name)
{
Property prop = confValueAccessor.get(name);
if (prop == null) new PropertyNotFoundException(name);
return prop;
}
```
Then in both methods you call `getProp(name)` and avoid duplicate check code
##########
src/java/org/apache/cassandra/config/DatabaseDescriptor.java:
##########
@@ -452,7 +473,12 @@ private static void applySimpleConfig()
//InetAddressAndPort and get the right defaults
InetAddressAndPort.initializeDefaultPort(getStoragePort());
- validateUpperBoundStreamingConfig();
+ // below 2 checks are needed in order to match the pre-CASSANDRA-15234 upper bound for those parameters which were still in megabits per second
+ setProperty(ConfigFields.STREAM_THROUGHPUT_OUTBOUND, conf.stream_throughput_outbound);
+ setProperty(ConfigFields.INTER_DC_STREAM_THROUGHPUT_OUTBOUND, conf.inter_dc_stream_throughput_outbound);
+ setProperty(ConfigFields.ENTIRE_SSTABLE_STREAM_THROUGHPUT_OUTBOUND, conf.entire_sstable_stream_throughput_outbound);
+ setProperty(ConfigFields.ENTIRE_SSTABLE_INTER_DC_STREAM_THROUGHPUT_OUTBOUND, conf.entire_sstable_inter_dc_stream_throughput_outbound);
+ setProperty(ConfigFields.COMPACTION_THROUGHPUT, conf.compaction_throughput);
Review Comment:
please revert, `setProperty` should not be used in apply.
##########
src/java/org/apache/cassandra/config/DatabaseDescriptor.java:
##########
@@ -4763,4 +4756,159 @@ public static OptionalDouble getSeverityDuringDecommission()
OptionalDouble.of(conf.severity_during_decommission) :
OptionalDouble.empty();
}
+
+ public static void visit(PropertyVisitor visitor)
+ {
+ visit(visitor, RuntimeException::new);
+ }
+
+ public static void visit(PropertyVisitor visitor, Function<Throwable, ? extends RuntimeException> handler)
+ {
+ try
+ {
+ for (Property property : ofNullable(confValueAccessors).orElse(Collections.emptyMap()).values())
+ visitor.visit(property.getName(), property.getType(), property.getAnnotation(Mutable.class) == null);
+ }
+ catch (Throwable t)
+ {
+ throw handler.apply(t);
+ }
+ }
Review Comment:
I find this API makes the callers less clear, can we delete and replace with something simpler? such as `Set<String> getProperties()`?
##########
src/java/org/apache/cassandra/config/DatabaseDescriptor.java:
##########
@@ -4763,4 +4756,159 @@ public static OptionalDouble getSeverityDuringDecommission()
OptionalDouble.of(conf.severity_during_decommission) :
OptionalDouble.empty();
}
+
+ public static void visit(PropertyVisitor visitor)
+ {
+ visit(visitor, RuntimeException::new);
+ }
+
+ public static void visit(PropertyVisitor visitor, Function<Throwable, ? extends RuntimeException> handler)
+ {
+ try
+ {
+ for (Property property : ofNullable(confValueAccessors).orElse(Collections.emptyMap()).values())
+ visitor.visit(property.getName(), property.getType(), property.getAnnotation(Mutable.class) == null);
+ }
+ catch (Throwable t)
+ {
+ throw handler.apply(t);
+ }
+ }
+
+ public static <T> ListenableProperty.Remover addBeforeChangePropertyListener(String name, Class<T> clazz, BiConsumer<T, T> consumer)
+ {
+ return addPropertyListener(name, clazz, p -> p.addBeforeHandler(ListenableProperty.Handler.consume(consumer)));
+ }
+
+ public static <T> ListenableProperty.Remover addAfterChangePropertyListener(String name, Class<T> clazz, BiConsumer<T, T> consumer)
+ {
+ return addPropertyListener(name, clazz, p -> p.addAfterHandler(ListenableProperty.Handler.consume(consumer)));
+ }
+
+ @SuppressWarnings("unchecked")
+ private static <T> ListenableProperty.Remover addPropertyListener(String name,
+ Class<T> clazz,
+ Function<ListenableProperty<Config, T>, ListenableProperty.Remover> adder)
+ {
+ Property property = ofNullable(confValueAccessors.get(name))
+ .map(p -> {
+ // The case when replacement property is used and match the property's name.
+ if (p instanceof Replacement.ReplacementProperty)
+ return ((Replacement.ReplacementProperty) p).delegate();
Review Comment:
this is a bug, why are you unwrapping? If I want to listen to a old property why are you blocking me?
##########
src/java/org/apache/cassandra/config/DatabaseDescriptor.java:
##########
@@ -4763,4 +4756,159 @@ public static OptionalDouble getSeverityDuringDecommission()
OptionalDouble.of(conf.severity_during_decommission) :
OptionalDouble.empty();
}
+
+ public static void visit(PropertyVisitor visitor)
+ {
+ visit(visitor, RuntimeException::new);
+ }
+
+ public static void visit(PropertyVisitor visitor, Function<Throwable, ? extends RuntimeException> handler)
+ {
+ try
+ {
+ for (Property property : ofNullable(confValueAccessors).orElse(Collections.emptyMap()).values())
+ visitor.visit(property.getName(), property.getType(), property.getAnnotation(Mutable.class) == null);
+ }
+ catch (Throwable t)
+ {
+ throw handler.apply(t);
+ }
+ }
+
+ public static <T> ListenableProperty.Remover addBeforeChangePropertyListener(String name, Class<T> clazz, BiConsumer<T, T> consumer)
+ {
+ return addPropertyListener(name, clazz, p -> p.addBeforeHandler(ListenableProperty.Handler.consume(consumer)));
+ }
+
+ public static <T> ListenableProperty.Remover addAfterChangePropertyListener(String name, Class<T> clazz, BiConsumer<T, T> consumer)
+ {
+ return addPropertyListener(name, clazz, p -> p.addAfterHandler(ListenableProperty.Handler.consume(consumer)));
+ }
+
+ @SuppressWarnings("unchecked")
+ private static <T> ListenableProperty.Remover addPropertyListener(String name,
+ Class<T> clazz,
+ Function<ListenableProperty<Config, T>, ListenableProperty.Remover> adder)
+ {
+ Property property = ofNullable(confValueAccessors.get(name))
+ .map(p -> {
+ // The case when replacement property is used and match the property's name.
+ if (p instanceof Replacement.ReplacementProperty)
+ return ((Replacement.ReplacementProperty) p).delegate();
+ else
+ return p;
+ })
+ .orElseThrow(() -> new PropertyNotFoundException(name));
+ if (!(property instanceof ListenableProperty))
+ throw new ConfigurationException(String.format("Property '%s' is not listenable.", name));
+
+ if (clazz.equals(property.getType()))
+ return adder.apply((ListenableProperty<Config, T>) property);
+ else
+ throw new ConfigurationException(String.format("Listener type '%s' doesn't match the property '%s' type '%s'.",
+ clazz.getSimpleName(), name, clazz.getSimpleName()));
+ }
+
+ public static Object getProperty(String name)
+ {
+ return ofNullable(confValueAccessors.get(name)).orElseThrow(() -> new PropertyNotFoundException(name))
+ .get(conf);
+ }
+
+ public static String getStringProperty(String name)
+ {
+ Property property = ofNullable(confValueAccessors.get(name))
+ .orElseThrow(() -> new PropertyNotFoundException(name));
+ return property.getType().equals(String.class) ?
+ (String) property.get(conf) :
+ propertyToStringConverter().convertNullable(property.get(conf));
+ }
+
+ /**
+ * Set configuration property for the given name to {@link #conf} if a safe manner
+ * with handling internal Cassandra exceptions.
+ *
+ * @param name Property name.
+ * @param value Property value.
+ */
+ public static void setProperty(String name, Object value)
+ {
+ try
+ {
+ Property property = ofNullable(confValueAccessors.get(name)).orElseThrow(() -> new PropertyNotFoundException(name));
+ if (property.getAnnotation(Mutable.class) == null)
+ throw new ConfigurationException("Property is read-only: " + property.getName());
+
+ if (value == null)
+ {
+ property.set(conf, null);
+ return;
+ }
+
+ if (property.getType().isAssignableFrom(value.getClass()))
+ property.set(conf, value);
+ else if (String.class.equals(value.getClass()))
+ property.set(conf, propertyFromStringConverter(primitiveToWrapper(property.getType())).convert((String) value));
+ else
+ throw new ConfigurationException(String.format("Cannot convert value '%s' to type '%s'.",
+ value, property.getType().getSimpleName()), false);
+ logger.info("Property {} updated to {}", name, value);
+ }
+ catch (ConfigurationException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new ConfigurationException(e.getMessage(), false);
+ }
+ }
+
+ /**
+ * @return A converter that converts given object to a string.
+ * @param <T> Type to convert from.
+ */
+ public static <T> TypeConverter<T, String> propertyToStringConverter()
+ {
+ return obj -> YamlConfigurationLoader.YamlFactory.instance.newYamlInstance(Config.class).dump(obj).trim();
+ }
+
+ /**
+ * @param toClass Class to convert to.
+ * @return A converter that converts given string to an object of the given class.
+ * @param <R> Type to convert to.
+ */
+ public static <R> TypeConverter<String, R> propertyFromStringConverter(Class<R> toClass)
+ {
+ return obj -> YamlConfigurationLoader.YamlFactory.instance.newYamlInstance(toClass).loadAs(obj, toClass);
+ }
Review Comment:
this belongs in `SettingsTable`, this is leaking details to unrelated classes
--
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
[GitHub] [cassandra] smiklosovic commented on pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#issuecomment-1619022184
@Mmuzaf I think you did a good job and David already saw it too so ... I may go through it next days again but seems robust enough to me! I would be nice to have yet another pair of eyes on this, if you happen to get somebody to take a look, that would be great!
--
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
[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)
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
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 and I found 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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1220047640
##########
src/java/org/apache/cassandra/config/DatabaseDescriptor.java:
##########
@@ -4763,4 +4756,159 @@ public static OptionalDouble getSeverityDuringDecommission()
OptionalDouble.of(conf.severity_during_decommission) :
OptionalDouble.empty();
}
+
+ public static void visit(PropertyVisitor visitor)
+ {
+ visit(visitor, RuntimeException::new);
+ }
+
+ public static void visit(PropertyVisitor visitor, Function<Throwable, ? extends RuntimeException> handler)
+ {
+ try
+ {
+ for (Property property : ofNullable(confValueAccessors).orElse(Collections.emptyMap()).values())
+ visitor.visit(property.getName(), property.getType(), property.getAnnotation(Mutable.class) == null);
+ }
+ catch (Throwable t)
+ {
+ throw handler.apply(t);
+ }
+ }
+
+ public static <T> ListenableProperty.Remover addBeforeChangePropertyListener(String name, Class<T> clazz, BiConsumer<T, T> consumer)
+ {
+ return addPropertyListener(name, clazz, p -> p.addBeforeHandler(ListenableProperty.Handler.consume(consumer)));
+ }
+
+ public static <T> ListenableProperty.Remover addAfterChangePropertyListener(String name, Class<T> clazz, BiConsumer<T, T> consumer)
+ {
+ return addPropertyListener(name, clazz, p -> p.addAfterHandler(ListenableProperty.Handler.consume(consumer)));
+ }
+
+ @SuppressWarnings("unchecked")
+ private static <T> ListenableProperty.Remover addPropertyListener(String name,
+ Class<T> clazz,
+ Function<ListenableProperty<Config, T>, ListenableProperty.Remover> adder)
+ {
+ Property property = ofNullable(confValueAccessors.get(name))
+ .map(p -> {
+ // The case when replacement property is used and match the property's name.
+ if (p instanceof Replacement.ReplacementProperty)
+ return ((Replacement.ReplacementProperty) p).delegate();
Review Comment:
I think we should not be able to listen to any replacements changes for the following reasons:
- there are few replacements with the same name, but their type has been replaced; For example, key_cache_save_period, row_cache_save_period, counter_cache_save_period. This means that both of these types a new one and the replaced one will be listenable, there is no way to pick up the correct property to listen to. We end up with a listener type that doesn't match the property type, which sounds like a bad design;
- Replacements exist only for users and public API (Yaml, SettingsTable). In fact, internally all the code that depends on them has been migrated on that was migrated to new properties; There is no need to support it;
- most of the Replacements are deprecated: 86 out of 92.
So, as we discussed privately let's skip the Replacements for now.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1220018076
##########
src/java/org/apache/cassandra/config/DatabaseDescriptor.java:
##########
@@ -4763,4 +4756,159 @@ public static OptionalDouble getSeverityDuringDecommission()
OptionalDouble.of(conf.severity_during_decommission) :
OptionalDouble.empty();
}
+
+ public static void visit(PropertyVisitor visitor)
+ {
+ visit(visitor, RuntimeException::new);
+ }
+
+ public static void visit(PropertyVisitor visitor, Function<Throwable, ? extends RuntimeException> handler)
+ {
+ try
+ {
+ for (Property property : ofNullable(confValueAccessors).orElse(Collections.emptyMap()).values())
+ visitor.visit(property.getName(), property.getType(), property.getAnnotation(Mutable.class) == null);
+ }
+ catch (Throwable t)
+ {
+ throw handler.apply(t);
+ }
+ }
+
+ public static <T> ListenableProperty.Remover addBeforeChangePropertyListener(String name, Class<T> clazz, BiConsumer<T, T> consumer)
+ {
+ return addPropertyListener(name, clazz, p -> p.addBeforeHandler(ListenableProperty.Handler.consume(consumer)));
+ }
+
+ public static <T> ListenableProperty.Remover addAfterChangePropertyListener(String name, Class<T> clazz, BiConsumer<T, T> consumer)
+ {
+ return addPropertyListener(name, clazz, p -> p.addAfterHandler(ListenableProperty.Handler.consume(consumer)));
+ }
+
+ @SuppressWarnings("unchecked")
+ private static <T> ListenableProperty.Remover addPropertyListener(String name,
+ Class<T> clazz,
+ Function<ListenableProperty<Config, T>, ListenableProperty.Remover> adder)
+ {
+ Property property = ofNullable(confValueAccessors.get(name))
+ .map(p -> {
+ // The case when replacement property is used and match the property's name.
+ if (p instanceof Replacement.ReplacementProperty)
+ return ((Replacement.ReplacementProperty) p).delegate();
+ else
+ return p;
+ })
+ .orElseThrow(() -> new PropertyNotFoundException(name));
+ if (!(property instanceof ListenableProperty))
+ throw new ConfigurationException(String.format("Property '%s' is not listenable.", name));
+
+ if (clazz.equals(property.getType()))
+ return adder.apply((ListenableProperty<Config, T>) property);
+ else
+ throw new ConfigurationException(String.format("Listener type '%s' doesn't match the property '%s' type '%s'.",
+ clazz.getSimpleName(), name, clazz.getSimpleName()));
+ }
+
+ public static Object getProperty(String name)
+ {
+ return ofNullable(confValueAccessors.get(name)).orElseThrow(() -> new PropertyNotFoundException(name))
+ .get(conf);
+ }
+
+ public static String getStringProperty(String name)
+ {
+ Property property = ofNullable(confValueAccessors.get(name))
+ .orElseThrow(() -> new PropertyNotFoundException(name));
+ return property.getType().equals(String.class) ?
+ (String) property.get(conf) :
+ propertyToStringConverter().convertNullable(property.get(conf));
+ }
+
+ /**
+ * Set configuration property for the given name to {@link #conf} if a safe manner
+ * with handling internal Cassandra exceptions.
+ *
+ * @param name Property name.
+ * @param value Property value.
+ */
+ public static void setProperty(String name, Object value)
+ {
+ try
+ {
+ Property property = ofNullable(confValueAccessors.get(name)).orElseThrow(() -> new PropertyNotFoundException(name));
+ if (property.getAnnotation(Mutable.class) == null)
+ throw new ConfigurationException("Property is read-only: " + property.getName());
+
+ if (value == null)
+ {
+ property.set(conf, null);
+ return;
+ }
+
+ if (property.getType().isAssignableFrom(value.getClass()))
+ property.set(conf, value);
+ else if (String.class.equals(value.getClass()))
+ property.set(conf, propertyFromStringConverter(primitiveToWrapper(property.getType())).convert((String) value));
Review Comment:
Moved to SettingsTable.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1220065001
##########
src/java/org/apache/cassandra/config/DatabaseDescriptor.java:
##########
@@ -151,13 +161,21 @@
*/
private static final int MAX_NUM_TOKENS = 1536;
+ /**
+ * The metadata source of configuration properties. It is used to access the configuration class instance loaded
+ * from the {@link #conf} and must be initialized the same time the {@link #conf} is initialized, usually
+ * by calling {@link #toolInitialization()}, {@link #daemonInitialization()} or {@link #clientInitialization()}.
+ */
+ private static Map<String, ? extends Property> confValueAccessors;
private static Config conf;
/**
* Request timeouts can not be less than below defined value (see CASSANDRA-9375)
*/
static final DurationSpec.LongMillisecondsBound LOWEST_ACCEPTED_TIMEOUT = new DurationSpec.LongMillisecondsBound(10L);
+ public static final int SPACE_UPPER_BOUND_MB = (int) (Runtime.getRuntime().maxMemory() / (16 * 1048576));
Review Comment:
This was used in tests, but along with removing support for the delete operation, I made it private as you suggested.
--
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
[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)
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1251177567
##########
src/java/org/apache/cassandra/db/virtual/SettingsTable.java:
##########
@@ -59,63 +57,104 @@ final class SettingsTable extends AbstractVirtualTable
.addPartitionKeyColumn(NAME, UTF8Type.instance)
.addRegularColumn(VALUE, UTF8Type.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,
Review Comment:
As you wish but I dont see that to be problematic. VT are just local tables ... there is also implicit `allow filtering` on them ... it is not part of primary key so whats the big deal? 5.0 is ideal place to put this in. When do we want to do that, in a patch release?
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1220061226
##########
src/java/org/apache/cassandra/db/virtual/SettingsTable.java:
##########
@@ -59,63 +53,77 @@ final class SettingsTable extends AbstractVirtualTable
.addPartitionKeyColumn(NAME, UTF8Type.instance)
.addRegularColumn(VALUE, UTF8Type.instance)
.build());
- this.config = config;
+ Set<String> unprocessed = new HashSet<>(BACKWARDS_COMPATABLE_NAMES.values());
+ DatabaseDescriptor.visit((key, type, ro) -> {
+ if (BACKWARDS_COMPATABLE_NAMES.containsKey(key))
+ {
+ 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",
+ key, SettingsTable.class.getSimpleName()));
+ }
+ unprocessed.remove(key);
+ });
+ if (!unprocessed.isEmpty())
+ throw new AssertionError("The following keys must be present in the Config: " + unprocessed);
+ }
+
+ @Override
+ protected void applyColumnDeletion(AbstractMutableVirtualTable.ColumnValues partitionKey, AbstractMutableVirtualTable.ColumnValues clusteringColumns, String columnName)
+ {
+ String name = partitionKey.value(0);
+ String key = getKeyAndWarn(name);
+ runExceptionally(() -> DatabaseDescriptor.setProperty(key, null),
+ t -> invalidRequest("Invalid delete request. Cause: %s", t.getMessage()));
+ }
+
+ @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);
Review Comment:
Agree, this might be confusing. An exception was added for this 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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1196857111
##########
src/java/org/apache/cassandra/config/WithReplacementLoader.java:
##########
@@ -0,0 +1,45 @@
+/*
+ * 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.config;
+
+import java.util.Map;
+
+import org.yaml.snakeyaml.introspector.Property;
+
+public class WithReplacementLoader extends DefaultLoader
Review Comment:
Fixed.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1196863682
##########
src/java/org/apache/cassandra/config/WithReplacementLoader.java:
##########
@@ -0,0 +1,45 @@
+/*
+ * 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.config;
+
+import java.util.Map;
+
+import org.yaml.snakeyaml.introspector.Property;
+
+public class WithReplacementLoader extends DefaultLoader
+{
+ @Override
+ public Map<String, Property> getProperties(Class<?> root)
+ {
+ Map<String, Property> properties = super.getProperties(root);
+ // only handling top-level replacements for now, previous logic was only top level so not a regression
+ Map<String, Replacement> replacements = Replacements.getNameReplacements(Config.class).get(root);
Review Comment:
I think you're right and we can avoid using it here. I have reused `getReplacements` and it seems to work perfectly. We need to use the same `Loader` for the `YamlConfigurationLoader.PropertiesChecker` to have a guarantee that the class will do checks on the same set of properties.
So I think I have fixed your comment, but there are still some code improvements to be made: we can get rid of `Replacements` and move `YamlConfigurationLoader#verifyReplacements` right to the `PropertiesChecker`, but I think it is part of another improvement.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1196632478
##########
src/java/org/apache/cassandra/config/Validate.java:
##########
@@ -0,0 +1,36 @@
+/*
+ * 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.config;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Validate annotation to be used on configuration fields to validate the value of the field with
+ * a custom validator class and its method.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface Validate
+{
+ String useClass() default "";
Review Comment:
Yes, these fields - `useClass` and `useClassMethod` must be mandatory, so I have fixed them.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1251248041
##########
src/java/org/apache/cassandra/db/virtual/SettingsTable.java:
##########
@@ -59,63 +57,104 @@ final class SettingsTable extends AbstractVirtualTable
.addPartitionKeyColumn(NAME, UTF8Type.instance)
.addRegularColumn(VALUE, UTF8Type.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,
Review Comment:
To improve cluster manageability in general, I thought that since the 4.x has an EOL until mid-2025 and the 5.0 stabilisation takes at least a few months as I understand the whole process, I thought it would be great to get users used to with managing their cluster with tables before they switch to the 5.0.
The feature itself is big enough but not too big as other CEPs.
--
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
[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)
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1241953707
##########
src/java/org/apache/cassandra/config/ValidatedPropertyLoader.java:
##########
@@ -0,0 +1,183 @@
+/*
+ * 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.config;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.stream.Collectors;
+
+import org.apache.commons.lang3.ArrayUtils;
+
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.utils.FBUtilities;
+import org.yaml.snakeyaml.introspector.FieldProperty;
+import org.yaml.snakeyaml.introspector.Property;
+
+public final class ValidatedPropertyLoader implements Loader
+{
+ private final Loader loader;
+
+ public ValidatedPropertyLoader()
+ {
+ this.loader = new DefaultLoader(ValidatedPropertyLoader::listenablePropertyFactory);
+ }
+
+ @Override
+ public Map<String, Property> getProperties(Class<?> root)
+ {
+ return loader.getProperties(root);
+ }
+
+ private static Property listenablePropertyFactory(Field field)
+ {
+ ListenableProperty<?, ?> listenable = new ListenableProperty<>(new FieldProperty(field));
+ ValidatedByList validatedByList = field.getAnnotation(ValidatedByList.class);
+ ValidatedBy[] validatedByArray;
+ if (validatedByList == null)
+ {
+ if (field.getAnnotation(ValidatedBy.class) == null)
+ return listenable;
+ else
+ validatedByArray = new ValidatedBy[]{ field.getAnnotation(ValidatedBy.class) };
+ }
+ else
+ validatedByArray = validatedByList.value();
+
+ for (ValidatedBy validatedBy : validatedByArray)
+ listenable.addListener(createValidationListener(field, validatedBy));
+
+ return listenable;
+ }
+
+ private static <S, T> ListenableProperty.Listener<S, T> createValidationListener(Field field, ValidatedBy annotation)
+ {
+ Class<?> clazz = FBUtilities.classForName(annotation.useClass(), "validate method");
+ List<Method> matches = Arrays.stream(clazz.getDeclaredMethods())
Review Comment:
maybe add it to org.apache.cassandra.utils.ReflectionUtils ?
--
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
[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)
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1241901004
##########
src/java/org/apache/cassandra/config/Config.java:
##########
@@ -199,6 +200,8 @@ public MemtableOptions()
// Limit the maximum depth of repair session merkle trees
@Deprecated
public volatile Integer repair_session_max_tree_depth = null;
+ @Mutable
+ @ValidatedBy(useClass = DATABASE_DESCRIPTOR_CLASS, useClassMethod = "validateRepairSessionSpace")
Review Comment:
@Mmuzaf I would expect that if a parameter is called "useClass", then the actual value of that parameter will be indeed a class.
@Mutable
@ValidatedBy(useClass = DatabaseDescriptor.class, useClassMethod = "validateRepairSessionSpace")
and then in the implementation you would use ".getName()" or something like that.
The minor problem with this approach is that if a class changes its name or location, this would not be updated.
I am not sure we can do the same for "method" as it is not so easy to reference here like class is but it is still an improvement.
--
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-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation) [cassandra]
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1431593168
##########
src/java/org/apache/cassandra/io/sstable/indexsummary/IndexSummaryManager.java:
##########
@@ -296,6 +318,7 @@ public void shutdownAndWait(long timeout, TimeUnit unit) throws InterruptedExcep
future.cancel(false);
future = null;
}
+ shutdownTasks.forEach(Runnable::run);
Review Comment:
what if `Runnable#run` throws? Then it will never get to ExecutorUtils.shutdownAndWait on the next line?
--
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-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation) [cassandra]
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1431633220
##########
src/java/org/apache/cassandra/config/ValidatedPropertyLoader.java:
##########
@@ -0,0 +1,183 @@
+/*
+ * 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.config;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.stream.Collectors;
+
+import org.apache.commons.lang3.ArrayUtils;
+
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.utils.FBUtilities;
+import org.yaml.snakeyaml.introspector.FieldProperty;
+import org.yaml.snakeyaml.introspector.Property;
+
+public final class ValidatedPropertyLoader implements Loader
+{
+ private final Loader loader;
+
+ public ValidatedPropertyLoader()
+ {
+ this.loader = new DefaultLoader(ValidatedPropertyLoader::listenablePropertyFactory);
+ }
+
+ @Override
+ public Map<String, Property> getProperties(Class<?> root)
+ {
+ return loader.getProperties(root);
+ }
+
+ private static Property listenablePropertyFactory(Field field)
+ {
+ ListenableProperty<?, ?> listenable = new ListenableProperty<>(new FieldProperty(field));
+ ValidatedByList validatedByList = field.getAnnotation(ValidatedByList.class);
+ ValidatedBy[] validatedByArray;
+ if (validatedByList == null)
+ {
+ if (field.getAnnotation(ValidatedBy.class) == null)
+ return listenable;
+ else
+ validatedByArray = new ValidatedBy[]{ field.getAnnotation(ValidatedBy.class) };
+ }
+ else
+ validatedByArray = validatedByList.value();
Review Comment:
@Mmuzaf could it happen that validatedByList would not be null but the array would be null? Then the next `for` would loop over null?
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1205942419
##########
src/java/org/apache/cassandra/config/ValidatedPropertyLoader.java:
##########
@@ -0,0 +1,117 @@
+/*
+ * 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.config;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+import com.google.common.base.Preconditions;
+import org.apache.commons.lang3.ArrayUtils;
+
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.utils.FBUtilities;
+import org.yaml.snakeyaml.introspector.FieldProperty;
+import org.yaml.snakeyaml.introspector.Property;
+
+public class ValidatedPropertyLoader extends DefaultLoader
Review Comment:
The code was reworked, but I don't think this is something bad :-) Until we are using the `Loader` interface only as we do now it should be OK :-)
But I don't see any problems going with the 'decoration' approach.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1220078071
##########
src/java/org/apache/cassandra/config/DatabaseDescriptor.java:
##########
@@ -3613,14 +3618,28 @@ public static int getRepairSessionSpaceInMiB()
public static void setRepairSessionSpaceInMiB(int sizeInMiB)
{
- if (sizeInMiB < 1)
- throw new ConfigurationException("Cannot set repair_session_space to " + sizeInMiB +
- " < 1 mebibyte");
- else if (sizeInMiB > (int) (Runtime.getRuntime().maxMemory() / (4 * 1048576)))
- logger.warn("A repair_session_space of " + conf.repair_session_space +
- " is likely to cause heap pressure.");
+ setProperty(ConfigFields.REPAIR_SESSION_SPACE, sizeInMiB == -1 ? null : new DataStorageSpec.IntMebibytesBound(sizeInMiB));
+ }
- conf.repair_session_space = new DataStorageSpec.IntMebibytesBound(sizeInMiB);
+ public static DataStorageSpec.IntMebibytesBound validateRepairSessionSpace(Config conf, String name, DataStorageSpec.IntMebibytesBound newValue)
+ {
+ DataStorageSpec.IntMebibytesBound value0 = newValue == null ? new DataStorageSpec.IntMebibytesBound(Math.max(1, SPACE_UPPER_BOUND_MB)) : newValue;
Review Comment:
Discussed privately. The validation model is the following:
Parent, Name, Value -> void | Value
Name, Value -> void | Value
Value -> void | Value
--
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
[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)
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1241921349
##########
src/java/org/apache/cassandra/db/virtual/SettingsTable.java:
##########
@@ -59,63 +57,104 @@ final class SettingsTable extends AbstractVirtualTable
.addPartitionKeyColumn(NAME, UTF8Type.instance)
.addRegularColumn(VALUE, UTF8Type.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("Setting the value to null is equivalent to the deletion operation. " +
+ "Column deletion is not supported by table vts.settings");
+ else
+ runExceptionally(() -> setPropertyFromString(getKeyAndWarn(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(getKeyAndWarn(name));
+ result.row(name).column(VALUE, value);
+ }
+ catch (PropertyNotFoundException e)
+ {
+ // ignore
+ }
return result;
}
@Override
public DataSet data()
{
SimpleDataSet result = new SimpleDataSet(metadata());
- for (Map.Entry<String, Property> e : PROPERTIES.entrySet())
- result.row(e.getKey()).column(VALUE, getValue(e.getValue()));
+ for (String key : DatabaseDescriptor.getAllProperties())
+ {
+ if (BACKWARDS_COMPATABLE_NAMES.containsKey(key))
+ continue;
+ runExceptionally(() -> result.row(key).column(VALUE, getPropertyAsString(key)),
+ t -> new ConfigurationException(t.getMessage(), false));
+ }
+
+ runExceptionally(() -> BACKWARDS_COMPATABLE_NAMES.forEach((oldName, newName) ->
+ result.row(oldName).column(VALUE, getPropertyAsString(newName))),
+ t -> new ConfigurationException(t.getMessage(), false));
return result;
}
- private String getValue(Property prop)
+ static String getKeyAndWarn(String name)
Review Comment:
should be renamed to "getKeyAndMaybeWarn" as we are not going to warn everytime, are we?
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1251062152
##########
src/java/org/apache/cassandra/db/virtual/SettingsTable.java:
##########
@@ -59,63 +57,104 @@ final class SettingsTable extends AbstractVirtualTable
.addPartitionKeyColumn(NAME, UTF8Type.instance)
.addRegularColumn(VALUE, UTF8Type.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("Setting the value to null is equivalent to the deletion operation. " +
+ "Column deletion is not supported by table vts.settings");
Review Comment:
Fixed.
##########
src/java/org/apache/cassandra/db/virtual/SettingsTable.java:
##########
@@ -59,63 +57,104 @@ final class SettingsTable extends AbstractVirtualTable
.addPartitionKeyColumn(NAME, UTF8Type.instance)
.addRegularColumn(VALUE, UTF8Type.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("Setting the value to null is equivalent to the deletion operation. " +
+ "Column deletion is not supported by table vts.settings");
+ else
+ runExceptionally(() -> setPropertyFromString(getKeyAndWarn(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(getKeyAndWarn(name));
+ result.row(name).column(VALUE, value);
+ }
+ catch (PropertyNotFoundException e)
+ {
+ // ignore
+ }
return result;
}
@Override
public DataSet data()
{
SimpleDataSet result = new SimpleDataSet(metadata());
- for (Map.Entry<String, Property> e : PROPERTIES.entrySet())
- result.row(e.getKey()).column(VALUE, getValue(e.getValue()));
+ for (String key : DatabaseDescriptor.getAllProperties())
+ {
+ if (BACKWARDS_COMPATABLE_NAMES.containsKey(key))
+ continue;
+ runExceptionally(() -> result.row(key).column(VALUE, getPropertyAsString(key)),
+ t -> new ConfigurationException(t.getMessage(), false));
+ }
+
+ runExceptionally(() -> BACKWARDS_COMPATABLE_NAMES.forEach((oldName, newName) ->
+ result.row(oldName).column(VALUE, getPropertyAsString(newName))),
+ t -> new ConfigurationException(t.getMessage(), false));
return result;
}
- private String getValue(Property prop)
+ static String getKeyAndWarn(String name)
Review Comment:
Fixed.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1251062446
##########
src/java/org/apache/cassandra/config/DatabaseDescriptor.java:
##########
@@ -4787,4 +4752,131 @@ public static StorageCompatibilityMode getStorageCompatibilityMode()
else
return conf.storage_compatibility_mode;
}
+
+ public static <T> ListenableProperty.Remover addBeforeChangePropertyListener(String name, Class<T> clazz, BiConsumer<T, T> consumer)
+ {
+ return addPropertyListener(name, clazz, p -> p.addListener(new ListenableProperty.Listener<Config, T>()
+ {
+ @Override
+ public T before(Config source, String name, T oldValue, T newValue)
+ {
+ consumer.accept(oldValue, newValue);
+ return newValue;
+ }
+ }));
+ }
+
+ public static <T> ListenableProperty.Remover addAfterChangePropertyListener(String name, Class<T> clazz, BiConsumer<T, T> consumer)
+ {
+ return addPropertyListener(name, clazz, p -> p.addListener(new ListenableProperty.Listener<Config, T>()
+ {
+ @Override
+ public void after(Config source, String name, T oldValue, T newValue)
+ {
+ consumer.accept(oldValue, newValue);
+ }
+ }));
+ }
+
+ @SuppressWarnings("unchecked")
+ private static <T> ListenableProperty.Remover addPropertyListener(String name,
+ Class<T> clazz,
+ Function<ListenableProperty<Config, T>, ListenableProperty.Remover> adder)
+ {
+ Property property = getPropertyAccessor(name);
+ // The case when replacement property is used and match the property's name.
+ Property property0 = property instanceof Replacement.ReplacementProperty ?
Review Comment:
Fixed.
--
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
[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)
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1251178062
##########
src/java/org/apache/cassandra/db/virtual/SettingsTable.java:
##########
@@ -59,63 +57,104 @@ final class SettingsTable extends AbstractVirtualTable
.addPartitionKeyColumn(NAME, UTF8Type.instance)
.addRegularColumn(VALUE, UTF8Type.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,
Review Comment:
no SettingsV2, no no .... unnecessary, we can not do new versions of a table and duplicate it all just because we added a column
--
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
[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)
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1251182518
##########
src/java/org/apache/cassandra/config/ValidatedPropertyLoader.java:
##########
@@ -0,0 +1,183 @@
+/*
+ * 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.config;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.stream.Collectors;
+
+import org.apache.commons.lang3.ArrayUtils;
+
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.utils.FBUtilities;
+import org.yaml.snakeyaml.introspector.FieldProperty;
+import org.yaml.snakeyaml.introspector.Property;
+
+public final class ValidatedPropertyLoader implements Loader
+{
+ private final Loader loader;
+
+ public ValidatedPropertyLoader()
+ {
+ this.loader = new DefaultLoader(ValidatedPropertyLoader::listenablePropertyFactory);
+ }
+
+ @Override
+ public Map<String, Property> getProperties(Class<?> root)
+ {
+ return loader.getProperties(root);
+ }
+
+ private static Property listenablePropertyFactory(Field field)
+ {
+ ListenableProperty<?, ?> listenable = new ListenableProperty<>(new FieldProperty(field));
+ ValidatedByList validatedByList = field.getAnnotation(ValidatedByList.class);
+ ValidatedBy[] validatedByArray;
+ if (validatedByList == null)
+ {
+ if (field.getAnnotation(ValidatedBy.class) == null)
+ return listenable;
+ else
+ validatedByArray = new ValidatedBy[]{ field.getAnnotation(ValidatedBy.class) };
+ }
+ else
+ validatedByArray = validatedByList.value();
+
+ for (ValidatedBy validatedBy : validatedByArray)
+ listenable.addListener(createValidationListener(field, validatedBy));
+
+ return listenable;
+ }
+
+ private static <S, T> ListenableProperty.Listener<S, T> createValidationListener(Field field, ValidatedBy annotation)
+ {
+ Class<?> clazz = FBUtilities.classForName(annotation.useClass(), "validate method");
+ List<Method> matches = Arrays.stream(clazz.getDeclaredMethods())
Review Comment:
I havent looked into the usage too much but it just felt like "we are filtering some methods with annotations on them", seems like that might be handy in future if we "generify" it enough .... up to 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
[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)
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1251253625
##########
src/java/org/apache/cassandra/db/virtual/SettingsTable.java:
##########
@@ -59,63 +57,104 @@ final class SettingsTable extends AbstractVirtualTable
.addPartitionKeyColumn(NAME, UTF8Type.instance)
.addRegularColumn(VALUE, UTF8Type.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,
Review Comment:
Rumor has it that I think the freeze for 5.0 should be done around August so we should hurry up if you want to see this in 5.0 too. Another option would be to put it to 4.1 and then in 5.0 we would just add that column as a "breaking change".
I can not answer what to do with 4.1 though (if it should be there, this whole feature), would you mind to drop an email to ML?
--
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
[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)
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1241901004
##########
src/java/org/apache/cassandra/config/Config.java:
##########
@@ -199,6 +200,8 @@ public MemtableOptions()
// Limit the maximum depth of repair session merkle trees
@Deprecated
public volatile Integer repair_session_max_tree_depth = null;
+ @Mutable
+ @ValidatedBy(useClass = DATABASE_DESCRIPTOR_CLASS, useClassMethod = "validateRepairSessionSpace")
Review Comment:
@Mmuzaf I would expect that if a parameter is called "useClass", then the actual value of that parameter will be indeed a class.
@Mutable
@ValidatedBy(useClass = DatabaseDescriptor.class, useClassMethod = "validateRepairSessionSpace")
and the in the implementation you would use ".getName()" or something like that.
The minor problem with this approach is that if a class changes its name or location, this would not be updated.
I am not sure we can do the same for "method" as it is not so easy to reference here like class is but it is still an improvement.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1205944418
##########
src/java/org/apache/cassandra/config/ListenableProperty.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.config;
+
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.function.BiConsumer;
+
+import org.yaml.snakeyaml.introspector.Property;
+
+/**
+ *
+ */
+public class ListenableProperty<S, T> extends ForwardingProperty
+{
+ private final Map<EventType, List<Handler<S, T>>> handlers = new EnumMap<>(EventType.class);
+
+ public ListenableProperty(Property property)
+ {
+ super(property.getName(), property);
+ for (EventType eventType : EventType.values())
+ handlers.put(eventType, new CopyOnWriteArrayList<>());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public synchronized void set(Object source, Object newValue) throws Exception
+ {
+ T oldValue = (T) get(source);
+ T value = Handler.compose(handlers.get(EventType.BEFORE)).handle((S) source, oldValue, (T) newValue);
+ delegate().set(source, value);
+ Handler.compose(handlers.get(EventType.AFTER)).handle((S) source, oldValue, value);
+ }
+
+ public synchronized Remover addBeforeHandler(Handler<S, T> handler)
+ {
+ handlers.computeIfAbsent(EventType.BEFORE, k -> new CopyOnWriteArrayList<>()).add(handler);
Review Comment:
Agree, in that case, we don't need such a thing.
The code was reworked.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1205957903
##########
src/java/org/apache/cassandra/config/DatabaseDescriptor.java:
##########
@@ -415,9 +433,12 @@ private static InetAddress getNetworkInterfaceAddress(String intf, String config
}
}
- private static void setConfig(Config config)
+ private static void setConfig(Supplier<Config> config)
{
- conf = config;
+ conf = config.get();
+ confValueAccessors = ImmutableMap.copyOf(
+ withReplacementsLoader(
+ validatedPropertyLoader(p -> p.getAnnotation(Mutable.class) == null)).flatten(Config.class));
Review Comment:
I have simplified the @Mutable usage, so we don't need it now.
Removed.
--
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
[GitHub] [cassandra] dcapwell commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "dcapwell (via GitHub)" <gi...@apache.org>.
dcapwell commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1195515796
##########
src/java/org/apache/cassandra/config/Config.java:
##########
@@ -204,6 +205,8 @@ public MemtableOptions()
// Limit the maximum depth of repair session merkle trees
@Deprecated
public volatile Integer repair_session_max_tree_depth = null;
+ @Mutable
+ @Validate(useClass = DATABASE_DESCRIPTOR_CLASS, useClassMethod = "validateRepairSessionSpace")
Review Comment:
do you do string because `Class<DatabaseDescriptor>` would cause a circular ref?
##########
src/java/org/apache/cassandra/config/DatabaseDescriptor.java:
##########
@@ -3613,14 +3618,28 @@ public static int getRepairSessionSpaceInMiB()
public static void setRepairSessionSpaceInMiB(int sizeInMiB)
{
- if (sizeInMiB < 1)
- throw new ConfigurationException("Cannot set repair_session_space to " + sizeInMiB +
- " < 1 mebibyte");
- else if (sizeInMiB > (int) (Runtime.getRuntime().maxMemory() / (4 * 1048576)))
- logger.warn("A repair_session_space of " + conf.repair_session_space +
- " is likely to cause heap pressure.");
+ setProperty(ConfigFields.REPAIR_SESSION_SPACE, sizeInMiB == -1 ? null : new DataStorageSpec.IntMebibytesBound(sizeInMiB));
+ }
- conf.repair_session_space = new DataStorageSpec.IntMebibytesBound(sizeInMiB);
+ public static DataStorageSpec.IntMebibytesBound validateRepairSessionSpace(Config conf, String name, DataStorageSpec.IntMebibytesBound newValue)
+ {
+ DataStorageSpec.IntMebibytesBound value0 = newValue == null ? new DataStorageSpec.IntMebibytesBound(Math.max(1, SPACE_UPPER_BOUND_MB)) : newValue;
Review Comment:
think this gets back to a convo we had on slack, `delete` to C* is `DELETE` statement, which you are not supporting in this ticket... so `null` is only possible in 2 cases
1) Config default
2) `repair_session_space: null` or `repair_session_space: ~` (`~` because yaml is fancy...)
since you can define `null` in yaml, we can't really rely on changing the default... so we do need to "delay" defaults in some cases... lame...
I don't like a `validate` method "changing" the value, but we need to keep that behavior else we cause a regression in the `repair_session_space: null` case...
which I guess means the validation model can't be
```
Object obj = get()
for (Validator v : validators)
v.validate(obj)
```
and must be
```
Object obj = get()
for (Validator v : validators)
obj = v.validate(obj)
```
The issue with this model is we need to have deterministic ordering... I don't know if your patch allows multiple `@Validate` but if we do allow in the future, we would need to make sure the order is well understood (prob definition order if possible?)... If you add a validation *after* the fact, then insertion order I guess makes sense... but with static init, this can be tricky...
##########
src/java/org/apache/cassandra/config/DatabaseDescriptor.java:
##########
@@ -576,14 +606,7 @@ else if (conf.disk_access_mode == Config.DiskAccessMode.mmap_index_only)
conf.repair_session_max_tree_depth = 20;
}
- if (conf.repair_session_space == null)
- conf.repair_session_space = new DataStorageSpec.IntMebibytesBound(Math.max(1, (int) (Runtime.getRuntime().maxMemory() / (16 * 1048576))));
-
- if (conf.repair_session_space.toMebibytes() < 1)
- throw new ConfigurationException("repair_session_space must be > 0, but was " + conf.repair_session_space);
- else if (conf.repair_session_space.toMebibytes() > (int) (Runtime.getRuntime().maxMemory() / (4 * 1048576)))
- logger.warn("A repair_session_space of " + conf.repair_session_space+ " mebibytes is likely to cause heap pressure");
-
+ conf.repair_session_space = validateRepairSessionSpace(conf, ConfigFields.REPAIR_SESSION_SPACE, conf.repair_session_space);
Review Comment:
with `@Validate` do you still need to do this here? This *should* be validated in yaml now right?
##########
src/java/org/apache/cassandra/config/Validate.java:
##########
@@ -0,0 +1,36 @@
+/*
+ * 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.config;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Validate annotation to be used on configuration fields to validate the value of the field with
+ * a custom validator class and its method.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface Validate
+{
+ String useClass() default "";
Review Comment:
shouldn't class be required? what does `@Validate` mean?
##########
src/java/org/apache/cassandra/config/WithReplacementLoader.java:
##########
@@ -0,0 +1,45 @@
+/*
+ * 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.config;
+
+import java.util.Map;
+
+import org.yaml.snakeyaml.introspector.Property;
+
+public class WithReplacementLoader extends DefaultLoader
+{
+ @Override
+ public Map<String, Property> getProperties(Class<?> root)
+ {
+ Map<String, Property> properties = super.getProperties(root);
+ // only handling top-level replacements for now, previous logic was only top level so not a regression
+ Map<String, Replacement> replacements = Replacements.getNameReplacements(Config.class).get(root);
Review Comment:
`Loader` is generic and doesn't (nor should it) really know about `Config`... If you want to add this, you should create a different method than `org.apache.cassandra.config.Replacements#getNameReplacements` which doesn't do `getReplacementsRecursive` and logically does `getReplacements` (without recursive)
That function was created before we went the `Loader` route, which meant we needed the map *before* snake yaml started parsing... since you are *during* parsing, we can lazy load w/e we need
##########
src/java/org/apache/cassandra/config/WithReplacementLoader.java:
##########
@@ -0,0 +1,45 @@
+/*
+ * 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.config;
+
+import java.util.Map;
+
+import org.yaml.snakeyaml.introspector.Property;
+
+public class WithReplacementLoader extends DefaultLoader
Review Comment:
I find that object decorating >>>> inherence. So rather than `extends`, take a `Loader` as input is best, so we can use a different loader and keep this property
```
Loader loader = new WithReplacementLoader(new JacksonLoader(objectMapper));
```
##########
src/java/org/apache/cassandra/config/YamlConfigurationLoader.java:
##########
@@ -424,5 +428,140 @@ public void check() throws ConfigurationException
logger.warn("{} parameters have been deprecated. They have new names and/or value format; For more information, please refer to NEWS.txt", deprecationWarnings);
}
}
+
+ /**
+ * Creates a YAML instance based on Cassandra's custom configuration classes and types. Yaml factory here is used
+ * to {@link org.yaml.snakeyaml.Yaml#dumpAs} and {@link org.yaml.snakeyaml.Yaml#load(String)} given object or
+ * string respectively, that in turn is used to serialize and deserialize configuration properties.
+ */
+ public static class YamlFactory
+ {
+ private static final List<TypeDescription> scalarCassandraTypes = new ArrayList<>();
+ private static final List<TypeDescription> javaBeanCassandraTypes = new ArrayList<>();
+ private static volatile YamlFactory instance;
+
+ private YamlFactory()
+ {
+ loadScalarTypeDescriptions(scalarCassandraTypes);
+ loadJavaBeanTypeDescriptions(javaBeanCassandraTypes);
+ }
+
+ public static YamlFactory getInstance()
+ {
+ YamlFactory instance0 = instance;
Review Comment:
why make this mutable, its far simpler to do `private static final YamlFactory instance = new YamlFactory();`; double-check locking is an anti-pattern and far better to use class init to solve this problem
##########
src/java/org/apache/cassandra/config/YamlConfigurationLoader.java:
##########
@@ -218,7 +222,7 @@ public static <T> T fromMap(Map<String,Object> map, boolean shouldCheck, Class<T
verifyReplacements(replacements, map);
YamlConfigurationLoader.PropertiesChecker propertiesChecker = new YamlConfigurationLoader.PropertiesChecker(replacements);
constructor.setPropertyUtils(propertiesChecker);
- Yaml yaml = new Yaml(constructor);
+ Yaml yaml = YamlFactory.getInstance().newYamlInstance(constructor, propertiesChecker);
Review Comment:
do we need `, propertiesChecker`? We did `constructor.setPropertyUtils(propertiesChecker);` already... we also override it in this method... so prob best to cleanup this relationship
##########
src/java/org/apache/cassandra/config/YamlConfigurationLoader.java:
##########
@@ -424,5 +428,140 @@ public void check() throws ConfigurationException
logger.warn("{} parameters have been deprecated. They have new names and/or value format; For more information, please refer to NEWS.txt", deprecationWarnings);
}
}
+
+ /**
+ * Creates a YAML instance based on Cassandra's custom configuration classes and types. Yaml factory here is used
+ * to {@link org.yaml.snakeyaml.Yaml#dumpAs} and {@link org.yaml.snakeyaml.Yaml#load(String)} given object or
+ * string respectively, that in turn is used to serialize and deserialize configuration properties.
+ */
+ public static class YamlFactory
+ {
+ private static final List<TypeDescription> scalarCassandraTypes = new ArrayList<>();
+ private static final List<TypeDescription> javaBeanCassandraTypes = new ArrayList<>();
+ private static volatile YamlFactory instance;
+
+ private YamlFactory()
+ {
+ loadScalarTypeDescriptions(scalarCassandraTypes);
+ loadJavaBeanTypeDescriptions(javaBeanCassandraTypes);
+ }
+
+ public static YamlFactory getInstance()
+ {
+ YamlFactory instance0 = instance;
+ if (instance0 == null)
+ {
+ synchronized (YamlFactory.class)
+ {
+ instance0 = instance;
+ if (instance0 == null)
+ instance = instance0 = new YamlFactory();
+ }
+ }
+ return instance0;
+ }
+
+ /**
+ * Creates a new Yaml instance with the given root class.
+ * @param root The class (usually JavaBean) to be constructed.
+ * @return A new Yaml instance with the given root class.
+ */
+ public Yaml newYamlInstance(Class<?> root)
+ {
+ PropertyUtils propertyUtils = new PropertyUtils();
+ propertyUtils.setBeanAccess(BeanAccess.FIELD);
+ propertyUtils.setAllowReadOnlyProperties(true);
+ return newYamlInstance(new CustomConstructor(root, Config.class.getClassLoader()), propertyUtils);
+ }
+
+ public Yaml newYamlInstance(SafeConstructor constructor, PropertyUtils propertyUtils)
+ {
+ return create(constructor, propertyUtils);
+ }
+
+ private static Yaml create(SafeConstructor constructor, PropertyUtils propertyUtils)
+ {
+ DumperOptions options = new DumperOptions();
+ options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
+ options.setDefaultScalarStyle(DumperOptions.ScalarStyle.PLAIN);
+ options.setSplitLines(true);
+ options.setPrettyFlow(true); // to remove brackets around
+ Representer representer = new CassandraRepresenter(scalarCassandraTypes, options);
+ representer.setPropertyUtils(propertyUtils);
+ constructor.setPropertyUtils(propertyUtils);
+ Yaml yaml = new Yaml(constructor, representer);
+
+ scalarCassandraTypes.forEach(yaml::addTypeDescription);
+ javaBeanCassandraTypes.forEach(yaml::addTypeDescription);
+ return yaml;
+ }
+
+ private static void loadScalarTypeDescriptions(List<TypeDescription> types)
Review Comment:
rather than taking a mutable list, can this method return an immutable list? Its far better to limit mutability and have this function own that
##########
src/java/org/apache/cassandra/config/Validate.java:
##########
@@ -0,0 +1,36 @@
+/*
+ * 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.config;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Validate annotation to be used on configuration fields to validate the value of the field with
+ * a custom validator class and its method.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface Validate
Review Comment:
This class looks like dead code? I don't see us actually use it in yaml loading/setting?
##########
src/java/org/apache/cassandra/config/WithReplacementLoader.java:
##########
@@ -0,0 +1,45 @@
+/*
+ * 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.config;
+
+import java.util.Map;
+
+import org.yaml.snakeyaml.introspector.Property;
+
+public class WithReplacementLoader extends DefaultLoader
+{
+ @Override
+ public Map<String, Property> getProperties(Class<?> root)
+ {
+ Map<String, Property> properties = super.getProperties(root);
+ // only handling top-level replacements for now, previous logic was only top level so not a regression
+ Map<String, Replacement> replacements = Replacements.getNameReplacements(Config.class).get(root);
Review Comment:
You don't need a *new* method if all usage goes through this new type, you can *replace* and just drop the recursive logic
##########
src/java/org/apache/cassandra/config/YamlConfigurationLoader.java:
##########
@@ -424,5 +428,140 @@ public void check() throws ConfigurationException
logger.warn("{} parameters have been deprecated. They have new names and/or value format; For more information, please refer to NEWS.txt", deprecationWarnings);
}
}
+
+ /**
+ * Creates a YAML instance based on Cassandra's custom configuration classes and types. Yaml factory here is used
+ * to {@link org.yaml.snakeyaml.Yaml#dumpAs} and {@link org.yaml.snakeyaml.Yaml#load(String)} given object or
+ * string respectively, that in turn is used to serialize and deserialize configuration properties.
+ */
+ public static class YamlFactory
+ {
+ private static final List<TypeDescription> scalarCassandraTypes = new ArrayList<>();
+ private static final List<TypeDescription> javaBeanCassandraTypes = new ArrayList<>();
+ private static volatile YamlFactory instance;
+
+ private YamlFactory()
+ {
+ loadScalarTypeDescriptions(scalarCassandraTypes);
+ loadJavaBeanTypeDescriptions(javaBeanCassandraTypes);
+ }
+
+ public static YamlFactory getInstance()
+ {
+ YamlFactory instance0 = instance;
+ if (instance0 == null)
+ {
+ synchronized (YamlFactory.class)
+ {
+ instance0 = instance;
+ if (instance0 == null)
+ instance = instance0 = new YamlFactory();
+ }
+ }
+ return instance0;
+ }
+
+ /**
+ * Creates a new Yaml instance with the given root class.
+ * @param root The class (usually JavaBean) to be constructed.
+ * @return A new Yaml instance with the given root class.
+ */
+ public Yaml newYamlInstance(Class<?> root)
+ {
+ PropertyUtils propertyUtils = new PropertyUtils();
+ propertyUtils.setBeanAccess(BeanAccess.FIELD);
+ propertyUtils.setAllowReadOnlyProperties(true);
+ return newYamlInstance(new CustomConstructor(root, Config.class.getClassLoader()), propertyUtils);
Review Comment:
shouldn't this be `root.getClassLoader()`?
##########
src/java/org/apache/cassandra/config/YamlConfigurationLoader.java:
##########
@@ -424,5 +428,140 @@ public void check() throws ConfigurationException
logger.warn("{} parameters have been deprecated. They have new names and/or value format; For more information, please refer to NEWS.txt", deprecationWarnings);
}
}
+
+ /**
+ * Creates a YAML instance based on Cassandra's custom configuration classes and types. Yaml factory here is used
+ * to {@link org.yaml.snakeyaml.Yaml#dumpAs} and {@link org.yaml.snakeyaml.Yaml#load(String)} given object or
+ * string respectively, that in turn is used to serialize and deserialize configuration properties.
+ */
+ public static class YamlFactory
+ {
+ private static final List<TypeDescription> scalarCassandraTypes = new ArrayList<>();
+ private static final List<TypeDescription> javaBeanCassandraTypes = new ArrayList<>();
+ private static volatile YamlFactory instance;
+
+ private YamlFactory()
+ {
+ loadScalarTypeDescriptions(scalarCassandraTypes);
+ loadJavaBeanTypeDescriptions(javaBeanCassandraTypes);
+ }
+
+ public static YamlFactory getInstance()
+ {
+ YamlFactory instance0 = instance;
+ if (instance0 == null)
+ {
+ synchronized (YamlFactory.class)
+ {
+ instance0 = instance;
+ if (instance0 == null)
+ instance = instance0 = new YamlFactory();
+ }
+ }
+ return instance0;
+ }
+
+ /**
+ * Creates a new Yaml instance with the given root class.
+ * @param root The class (usually JavaBean) to be constructed.
+ * @return A new Yaml instance with the given root class.
+ */
+ public Yaml newYamlInstance(Class<?> root)
+ {
+ PropertyUtils propertyUtils = new PropertyUtils();
+ propertyUtils.setBeanAccess(BeanAccess.FIELD);
+ propertyUtils.setAllowReadOnlyProperties(true);
+ return newYamlInstance(new CustomConstructor(root, Config.class.getClassLoader()), propertyUtils);
+ }
+
+ public Yaml newYamlInstance(SafeConstructor constructor, PropertyUtils propertyUtils)
+ {
+ return create(constructor, propertyUtils);
+ }
+
+ private static Yaml create(SafeConstructor constructor, PropertyUtils propertyUtils)
+ {
+ DumperOptions options = new DumperOptions();
+ options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
+ options.setDefaultScalarStyle(DumperOptions.ScalarStyle.PLAIN);
+ options.setSplitLines(true);
+ options.setPrettyFlow(true); // to remove brackets around
+ Representer representer = new CassandraRepresenter(scalarCassandraTypes, options);
+ representer.setPropertyUtils(propertyUtils);
+ constructor.setPropertyUtils(propertyUtils);
+ Yaml yaml = new Yaml(constructor, representer);
+
+ scalarCassandraTypes.forEach(yaml::addTypeDescription);
+ javaBeanCassandraTypes.forEach(yaml::addTypeDescription);
+ return yaml;
+ }
+
+ private static void loadScalarTypeDescriptions(List<TypeDescription> types)
+ {
+ // Enum types resolved with a custom overridden handler DefaultRepresentEnum() as a smiple string.
+ types.add(createTypeDescription(DataRateSpec.LongBytesPerSecondBound.class));
+ types.add(createTypeDescription(DataStorageSpec.IntBytesBound.class));
+ types.add(createTypeDescription(DataStorageSpec.IntKibibytesBound.class));
+ types.add(createTypeDescription(DataStorageSpec.IntMebibytesBound.class));
+ types.add(createTypeDescription(DataStorageSpec.LongBytesBound.class));
+ types.add(createTypeDescription(DataStorageSpec.LongMebibytesBound.class));
+ types.add(createTypeDescription(DurationSpec.IntMillisecondsBound.class));
+ types.add(createTypeDescription(DurationSpec.IntMinutesBound.class));
+ types.add(createTypeDescription(DurationSpec.IntSecondsBound.class));
+ types.add(createTypeDescription(DurationSpec.LongMillisecondsBound.class));
+ types.add(createTypeDescription(DurationSpec.LongNanosecondsBound.class));
+ types.add(createTypeDescription(DurationSpec.LongSecondsBound.class));
+ }
+
+ private static void loadJavaBeanTypeDescriptions(List<TypeDescription> types)
Review Comment:
rather than taking a mutable list, can this method return an immutable list? Its far better to limit mutability and have this function own that
##########
src/java/org/apache/cassandra/config/Validate.java:
##########
@@ -0,0 +1,36 @@
+/*
+ * 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.config;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Validate annotation to be used on configuration fields to validate the value of the field with
+ * a custom validator class and its method.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
Review Comment:
for now this is fine, if we need to can allow in method later, just need to update the loader
##########
src/java/org/apache/cassandra/db/virtual/SettingsTable.java:
##########
@@ -59,63 +51,88 @@ final class SettingsTable extends AbstractVirtualTable
.addPartitionKeyColumn(NAME, UTF8Type.instance)
.addRegularColumn(VALUE, UTF8Type.instance)
.build());
- this.config = config;
+ }
+
+ @Override
+ protected void applyColumnDeletion(AbstractMutableVirtualTable.ColumnValues partitionKey, AbstractMutableVirtualTable.ColumnValues clusteringColumns, String columnName)
+ {
+ String name = partitionKey.value(0);
+ String key = getKeyAndWarn(name);
+ runExceptionally(() -> DatabaseDescriptor.setProperty(key, null),
+ t -> invalidRequest("Unable to clear property '%s': %s", key, t.getMessage()));
+ }
+
+ @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);
+ runExceptionally(() -> DatabaseDescriptor.setProperty(getKeyAndWarn(name), value),
+ t -> invalidRequest("Invalid update request for property '%s'. %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 = getStringProperty(getKeyAndWarn(name));
+ result.row(name).column(VALUE, value);
+ }
+ catch (PropertyNotFoundException e)
+ {
+ // ignore
+ }
return result;
}
@Override
public DataSet data()
{
SimpleDataSet result = new SimpleDataSet(metadata());
- for (Map.Entry<String, Property> e : PROPERTIES.entrySet())
- result.row(e.getKey()).column(VALUE, getValue(e.getValue()));
+ DatabaseDescriptor.visit(withBackwardsCompatableNamesVisitor((key, type, ro) ->
+ result.row(key).column(VALUE, getStringProperty(BACKWARDS_COMPATABLE_NAMES.getOrDefault(key, key)))),
+ t -> new ConfigurationException(t.getMessage(), false));
return result;
}
- private String getValue(Property prop)
+ static String getKeyAndWarn(String name)
{
- Object value = prop.get(config);
- return value == null ? null : value.toString();
+ String key = BACKWARDS_COMPATABLE_NAMES.getOrDefault(name, name);
+ if (BACKWARDS_COMPATABLE_NAMES.containsKey(name))
+ ClientWarn.instance.warn("key '" + name + "' is deprecated; should switch to '" + BACKWARDS_COMPATABLE_NAMES.get(name) + '\'');
+ return key;
+ }
+
+ static DatabaseDescriptor.PropertyVisitor withBackwardsCompatableNamesVisitor(DatabaseDescriptor.PropertyVisitor visitor)
+ {
+ BiMap<String, String> inversedNames = BACKWARDS_COMPATABLE_NAMES.inverse();
+ return (name, type, readOnly) -> {
+ if (inversedNames.containsKey(name))
+ visitor.visit(inversedNames.get(name), type, readOnly);
+ visitor.visit(name, type, readOnly);
+ };
Review Comment:
Can you remove this concept, this adds more complexity than we need... We need a few things
# On Init
8 did someone add a new config that conflicts with one of the old names defined by this class? If so fail fast (needed so that config doesn't get added and is blocked before merge)
# At runtime
* any usage of the old name gets mapped to the new name
given this, `getKeyAndWarn(name)` is all we need, and a `visitor` is too heavy weight.
--
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
[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)
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1241918597
##########
src/java/org/apache/cassandra/db/virtual/SettingsTable.java:
##########
@@ -59,63 +57,104 @@ final class SettingsTable extends AbstractVirtualTable
.addPartitionKeyColumn(NAME, UTF8Type.instance)
.addRegularColumn(VALUE, UTF8Type.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("Setting the value to null is equivalent to the deletion operation. " +
+ "Column deletion is not supported by table vts.settings");
Review Comment:
vts.settings should be probably "system_views.settings" or something like that. Use constants for rendering that string if they are somewhere available.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1220017012
##########
src/java/org/apache/cassandra/config/DatabaseDescriptor.java:
##########
@@ -4763,4 +4756,159 @@ public static OptionalDouble getSeverityDuringDecommission()
OptionalDouble.of(conf.severity_during_decommission) :
OptionalDouble.empty();
}
+
+ public static void visit(PropertyVisitor visitor)
+ {
+ visit(visitor, RuntimeException::new);
+ }
+
+ public static void visit(PropertyVisitor visitor, Function<Throwable, ? extends RuntimeException> handler)
+ {
+ try
+ {
+ for (Property property : ofNullable(confValueAccessors).orElse(Collections.emptyMap()).values())
+ visitor.visit(property.getName(), property.getType(), property.getAnnotation(Mutable.class) == null);
+ }
+ catch (Throwable t)
+ {
+ throw handler.apply(t);
+ }
+ }
+
+ public static <T> ListenableProperty.Remover addBeforeChangePropertyListener(String name, Class<T> clazz, BiConsumer<T, T> consumer)
+ {
+ return addPropertyListener(name, clazz, p -> p.addBeforeHandler(ListenableProperty.Handler.consume(consumer)));
+ }
+
+ public static <T> ListenableProperty.Remover addAfterChangePropertyListener(String name, Class<T> clazz, BiConsumer<T, T> consumer)
+ {
+ return addPropertyListener(name, clazz, p -> p.addAfterHandler(ListenableProperty.Handler.consume(consumer)));
+ }
+
+ @SuppressWarnings("unchecked")
+ private static <T> ListenableProperty.Remover addPropertyListener(String name,
+ Class<T> clazz,
+ Function<ListenableProperty<Config, T>, ListenableProperty.Remover> adder)
+ {
+ Property property = ofNullable(confValueAccessors.get(name))
+ .map(p -> {
+ // The case when replacement property is used and match the property's name.
+ if (p instanceof Replacement.ReplacementProperty)
+ return ((Replacement.ReplacementProperty) p).delegate();
+ else
+ return p;
+ })
+ .orElseThrow(() -> new PropertyNotFoundException(name));
Review Comment:
Simplified.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1220014812
##########
src/java/org/apache/cassandra/db/virtual/SettingsTable.java:
##########
@@ -59,63 +53,77 @@ final class SettingsTable extends AbstractVirtualTable
.addPartitionKeyColumn(NAME, UTF8Type.instance)
.addRegularColumn(VALUE, UTF8Type.instance)
.build());
- this.config = config;
+ Set<String> unprocessed = new HashSet<>(BACKWARDS_COMPATABLE_NAMES.values());
+ DatabaseDescriptor.visit((key, type, ro) -> {
+ if (BACKWARDS_COMPATABLE_NAMES.containsKey(key))
+ {
+ 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",
+ key, SettingsTable.class.getSimpleName()));
+ }
+ unprocessed.remove(key);
+ });
+ if (!unprocessed.isEmpty())
+ throw new AssertionError("The following keys must be present in the Config: " + unprocessed);
Review Comment:
Fixed.
--
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
[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)
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1251180235
##########
src/java/org/apache/cassandra/config/ConfigFields.java:
##########
@@ -0,0 +1,49 @@
+/*
+ * 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.config;
+
+/**
+ * This class is created by {@link org.apache.cassandra.utils.ConfigFieldsGenerateUtil} based on provided
+ * the {@link org.apache.cassandra.config.Config} class. It contains non-private non-static {@code Cofig}'s fields
+ * marked with the {@link org.apache.cassandra.config.Mutable} annotation to expose them to public APIs.
+
+ * @see org.apache.cassandra.config.Mutable
+ * @see org.apache.cassandra.config.Config
+ */
+public class ConfigFields
Review Comment:
I dont know ... feels like a hack. Is that really necessary? Why not to put these constants directly in DatabaseDescriptor / Config and be done with it? Circular dependency 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
[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)
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1251176298
##########
src/java/org/apache/cassandra/config/Config.java:
##########
@@ -199,6 +200,8 @@ public MemtableOptions()
// Limit the maximum depth of repair session merkle trees
@Deprecated
public volatile Integer repair_session_max_tree_depth = null;
+ @Mutable
+ @ValidatedBy(useClass = DATABASE_DESCRIPTOR_CLASS, useClassMethod = "validateRepairSessionSpace")
Review Comment:
ok
--
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
[GitHub] [cassandra] Mmuzaf commented on pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#issuecomment-1618957280
@smiklosovic Thank you for the comments.
Do you agree with the proposed solution design? Do you have any comments on that?
--
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
[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)
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1251225950
##########
src/java/org/apache/cassandra/db/virtual/SettingsTable.java:
##########
@@ -59,63 +57,104 @@ final class SettingsTable extends AbstractVirtualTable
.addPartitionKeyColumn(NAME, UTF8Type.instance)
.addRegularColumn(VALUE, UTF8Type.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,
Review Comment:
I was thinking this goes only to 5.0. Why are you targeting 4.1 too? It seems to be too big of a feature / change to do that in 4.1 as well. (not just a column, whole stuff).
--
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
[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)
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1251225950
##########
src/java/org/apache/cassandra/db/virtual/SettingsTable.java:
##########
@@ -59,63 +57,104 @@ final class SettingsTable extends AbstractVirtualTable
.addPartitionKeyColumn(NAME, UTF8Type.instance)
.addRegularColumn(VALUE, UTF8Type.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,
Review Comment:
I was thinking this goes only to 5.0. Why are you targeting 4.1 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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1252075157
##########
src/java/org/apache/cassandra/config/ConfigFields.java:
##########
@@ -0,0 +1,49 @@
+/*
+ * 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.config;
+
+/**
+ * This class is created by {@link org.apache.cassandra.utils.ConfigFieldsGenerateUtil} based on provided
+ * the {@link org.apache.cassandra.config.Config} class. It contains non-private non-static {@code Cofig}'s fields
+ * marked with the {@link org.apache.cassandra.config.Mutable} annotation to expose them to public APIs.
+
+ * @see org.apache.cassandra.config.Mutable
+ * @see org.apache.cassandra.config.Config
+ */
+public class ConfigFields
Review Comment:
Moved to the `Config`, the name updated accordingdly.
--
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-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation) [cassandra]
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1431602162
##########
test/unit/org/apache/cassandra/db/virtual/UpdateSettingsTableTest.java:
##########
@@ -0,0 +1,204 @@
+/*
+ * 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.virtual;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import javax.annotation.Nullable;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.datastax.driver.core.exceptions.InvalidQueryException;
+import org.apache.cassandra.config.Config;
+import org.apache.cassandra.config.DataRateSpec;
+import org.apache.cassandra.config.DataStorageSpec;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.config.DurationSpec;
+import org.apache.cassandra.cql3.CQLTester;
+import org.apache.cassandra.db.ConsistencyLevel;
+
+import static org.apache.cassandra.db.virtual.SettingsTable.propertyToStringConverter;
+import static org.apache.cassandra.db.virtual.SettingsTableTest.KS_NAME;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+/**
+ * The set of tests for {@link SettingsTable} for updating settings through virtual table. Since the Config class and
+ * the {@link DatabaseDescriptor} are static, we need to return back changes to the original state after each update.
+ */
+public class UpdateSettingsTableTest extends CQLTester
+{
+ private static final Set<String> updatableProperties = new HashSet<>();
+ private static final Map<String, Class<?>> propertyTypes = new HashMap<>();
+ private static final Map<Class<?>, Object[]> defaultTestValues = registerTestConfigurationValues();
+
+ @BeforeClass
+ public static void setUpClass()
+ {
+ CQLTester.setUpClass();
+ for (String key : DatabaseDescriptor.getAllProperties())
+ {
+ propertyTypes.put(key, DatabaseDescriptor.getPropertyType(key));
+ if (DatabaseDescriptor.isMutableProperty(key))
+ updatableProperties.add(key);
+ }
+ }
+
+ @Before
+ public void prepare()
+ {
+ // Creating a new instence will avoid calling listeners registered in the registry.
+ VirtualKeyspaceRegistry.instance.register(new VirtualKeyspace(KS_NAME, ImmutableList.of(new SettingsTable(KS_NAME))));
+ disablePreparedReuseForTest();
+ }
+
+ @Test
+ public void testUpdateAllSettings() throws Throwable
+ {
+ for (String propertyName : updatableProperties)
+ doUpdateSettingAndRevertBack(String.format("UPDATE %s.settings SET value = ? WHERE name = ?;", KS_NAME), propertyName);
+ }
+
+ @Test(expected = InvalidQueryException.class)
+ public void testUpdateRepairSessionSpaceToNull() throws Throwable
+ {
+ assertRowsNet(executeNet(String.format("UPDATE %s.settings SET value = ? WHERE name = ?;", KS_NAME),
+ null, Config.Names.REPAIR_SESSION_SPACE));
+ }
+
+ @Test
+ public void testUpdateSettingsValidationFail() throws Throwable
+ {
+ InvalidQueryException e = null;
+ try
+ {
+ updateConfigurationProperty(String.format("UPDATE %s.settings SET value = ? WHERE name = ?;", KS_NAME),
+ Config.Names.STREAM_THROUGHPUT_OUTBOUND,
+ propertyToStringConverter()
+ // This is the value for the property that overflows property's limit in bytes bet second.
+ .apply(new DataRateSpec.LongBytesPerSecondBound(Integer.MAX_VALUE, DataRateSpec.DataRateUnit.MEBIBYTES_PER_SECOND)));
+ }
+ catch (InvalidQueryException ex)
+ {
+ e = ex;
+ }
+ assertNotNull(e);
+ assertEquals("Unexpected error: " + e.getMessage(),
+ "Invalid update request 'stream_throughput_outbound'. Cause: Property 'stream_throughput_outbound' " +
+ "validation failed: Invalid value: '2147483647MiB/s' is too large",
+ e.getMessage());
+ }
+
+ @Test
+ public void testInsertSettingsNewValues() throws Throwable
+ {
+ for (String propertyName : updatableProperties)
+ doUpdateSettingAndRevertBack(String.format("INSERT INTO %s.settings (value, name) VALUES (?, ?);", KS_NAME), propertyName);
+ }
+
+ @Test
+ public void testBactchUpdateSettings() throws Throwable
Review Comment:
`testBatch...`
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1205956790
##########
src/java/org/apache/cassandra/config/ListenableProperty.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.config;
+
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.function.BiConsumer;
+
+import org.yaml.snakeyaml.introspector.Property;
+
+/**
+ *
+ */
+public class ListenableProperty<S, T> extends ForwardingProperty
+{
+ private final Map<EventType, List<Handler<S, T>>> handlers = new EnumMap<>(EventType.class);
+
+ public ListenableProperty(Property property)
+ {
+ super(property.getName(), property);
+ for (EventType eventType : EventType.values())
+ handlers.put(eventType, new CopyOnWriteArrayList<>());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public synchronized void set(Object source, Object newValue) throws Exception
+ {
+ T oldValue = (T) get(source);
+ T value = Handler.compose(handlers.get(EventType.BEFORE)).handle((S) source, oldValue, (T) newValue);
+ delegate().set(source, value);
+ Handler.compose(handlers.get(EventType.AFTER)).handle((S) source, oldValue, value);
Review Comment:
I have added `BeforeChangeListener`, and `AfterChangeListener` instead of the `Handler` as you pointed out above. We can still merge them into a single interface with two methods, `onBefore` and `onAfter`, but in the latter case the API looks like a stateful interface, which I'd like to avoid adding.
##########
src/java/org/apache/cassandra/config/ListenableProperty.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.config;
+
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.function.BiConsumer;
+
+import org.yaml.snakeyaml.introspector.Property;
+
+/**
+ *
+ */
+public class ListenableProperty<S, T> extends ForwardingProperty
+{
+ private final Map<EventType, List<Handler<S, T>>> handlers = new EnumMap<>(EventType.class);
+
+ public ListenableProperty(Property property)
+ {
+ super(property.getName(), property);
+ for (EventType eventType : EventType.values())
+ handlers.put(eventType, new CopyOnWriteArrayList<>());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public synchronized void set(Object source, Object newValue) throws Exception
+ {
+ T oldValue = (T) get(source);
+ T value = Handler.compose(handlers.get(EventType.BEFORE)).handle((S) source, oldValue, (T) newValue);
+ delegate().set(source, value);
+ Handler.compose(handlers.get(EventType.AFTER)).handle((S) source, oldValue, value);
Review Comment:
Fixed.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1220018413
##########
src/java/org/apache/cassandra/config/DatabaseDescriptor.java:
##########
@@ -4763,4 +4756,159 @@ public static OptionalDouble getSeverityDuringDecommission()
OptionalDouble.of(conf.severity_during_decommission) :
OptionalDouble.empty();
}
+
+ public static void visit(PropertyVisitor visitor)
+ {
+ visit(visitor, RuntimeException::new);
+ }
+
+ public static void visit(PropertyVisitor visitor, Function<Throwable, ? extends RuntimeException> handler)
+ {
+ try
+ {
+ for (Property property : ofNullable(confValueAccessors).orElse(Collections.emptyMap()).values())
+ visitor.visit(property.getName(), property.getType(), property.getAnnotation(Mutable.class) == null);
+ }
+ catch (Throwable t)
+ {
+ throw handler.apply(t);
+ }
+ }
+
+ public static <T> ListenableProperty.Remover addBeforeChangePropertyListener(String name, Class<T> clazz, BiConsumer<T, T> consumer)
+ {
+ return addPropertyListener(name, clazz, p -> p.addBeforeHandler(ListenableProperty.Handler.consume(consumer)));
+ }
+
+ public static <T> ListenableProperty.Remover addAfterChangePropertyListener(String name, Class<T> clazz, BiConsumer<T, T> consumer)
+ {
+ return addPropertyListener(name, clazz, p -> p.addAfterHandler(ListenableProperty.Handler.consume(consumer)));
+ }
+
+ @SuppressWarnings("unchecked")
+ private static <T> ListenableProperty.Remover addPropertyListener(String name,
+ Class<T> clazz,
+ Function<ListenableProperty<Config, T>, ListenableProperty.Remover> adder)
+ {
+ Property property = ofNullable(confValueAccessors.get(name))
+ .map(p -> {
+ // The case when replacement property is used and match the property's name.
+ if (p instanceof Replacement.ReplacementProperty)
+ return ((Replacement.ReplacementProperty) p).delegate();
+ else
+ return p;
+ })
+ .orElseThrow(() -> new PropertyNotFoundException(name));
+ if (!(property instanceof ListenableProperty))
+ throw new ConfigurationException(String.format("Property '%s' is not listenable.", name));
+
+ if (clazz.equals(property.getType()))
+ return adder.apply((ListenableProperty<Config, T>) property);
+ else
+ throw new ConfigurationException(String.format("Listener type '%s' doesn't match the property '%s' type '%s'.",
+ clazz.getSimpleName(), name, clazz.getSimpleName()));
+ }
+
+ public static Object getProperty(String name)
+ {
+ return ofNullable(confValueAccessors.get(name)).orElseThrow(() -> new PropertyNotFoundException(name))
+ .get(conf);
+ }
+
+ public static String getStringProperty(String name)
+ {
+ Property property = ofNullable(confValueAccessors.get(name))
+ .orElseThrow(() -> new PropertyNotFoundException(name));
+ return property.getType().equals(String.class) ?
+ (String) property.get(conf) :
+ propertyToStringConverter().convertNullable(property.get(conf));
+ }
+
+ /**
+ * Set configuration property for the given name to {@link #conf} if a safe manner
+ * with handling internal Cassandra exceptions.
+ *
+ * @param name Property name.
+ * @param value Property value.
+ */
+ public static void setProperty(String name, Object value)
+ {
+ try
+ {
+ Property property = ofNullable(confValueAccessors.get(name)).orElseThrow(() -> new PropertyNotFoundException(name));
+ if (property.getAnnotation(Mutable.class) == null)
+ throw new ConfigurationException("Property is read-only: " + property.getName());
+
+ if (value == null)
+ {
+ property.set(conf, null);
+ return;
+ }
+
+ if (property.getType().isAssignableFrom(value.getClass()))
+ property.set(conf, value);
+ else if (String.class.equals(value.getClass()))
+ property.set(conf, propertyFromStringConverter(primitiveToWrapper(property.getType())).convert((String) value));
+ else
+ throw new ConfigurationException(String.format("Cannot convert value '%s' to type '%s'.",
+ value, property.getType().getSimpleName()), false);
+ logger.info("Property {} updated to {}", name, value);
+ }
+ catch (ConfigurationException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new ConfigurationException(e.getMessage(), false);
+ }
+ }
+
+ /**
+ * @return A converter that converts given object to a string.
+ * @param <T> Type to convert from.
+ */
+ public static <T> TypeConverter<T, String> propertyToStringConverter()
+ {
+ return obj -> YamlConfigurationLoader.YamlFactory.instance.newYamlInstance(Config.class).dump(obj).trim();
+ }
+
+ /**
+ * @param toClass Class to convert to.
+ * @return A converter that converts given string to an object of the given class.
+ * @param <R> Type to convert to.
+ */
+ public static <R> TypeConverter<String, R> propertyFromStringConverter(Class<R> toClass)
+ {
+ return obj -> YamlConfigurationLoader.YamlFactory.instance.newYamlInstance(toClass).loadAs(obj, toClass);
+ }
Review Comment:
Moved to the SettingsTable.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1220013504
##########
src/java/org/apache/cassandra/config/WithReplacementLoader.java:
##########
@@ -0,0 +1,47 @@
+/*
+ * 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.config;
+
+import java.util.Map;
+
+import org.yaml.snakeyaml.introspector.Property;
+
+public class WithReplacementLoader implements Loader
+{
+ private final Loader delegate;
Review Comment:
Fixed.
##########
src/java/org/apache/cassandra/config/ListenableProperty.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.config;
+
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.function.BiConsumer;
+
+import org.yaml.snakeyaml.introspector.Property;
+
+/**
+ *
+ */
+public class ListenableProperty<S, T> extends ForwardingProperty
+{
+ private final Map<EventType, List<Handler<S, T>>> handlers = new EnumMap<>(EventType.class);
+
+ public ListenableProperty(Property property)
+ {
+ super(property.getName(), property);
+ for (EventType eventType : EventType.values())
+ handlers.put(eventType, new CopyOnWriteArrayList<>());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public synchronized void set(Object source, Object newValue) throws Exception
+ {
+ T oldValue = (T) get(source);
+ T value = Handler.compose(handlers.get(EventType.BEFORE)).handle((S) source, oldValue, (T) newValue);
+ delegate().set(source, value);
+ Handler.compose(handlers.get(EventType.AFTER)).handle((S) source, oldValue, value);
+ }
+
+ public synchronized Remover addBeforeHandler(Handler<S, T> handler)
+ {
+ handlers.computeIfAbsent(EventType.BEFORE, k -> new CopyOnWriteArrayList<>()).add(handler);
+ return () -> handlers.get(EventType.BEFORE).remove(handler);
+ }
+
+ public synchronized Remover addAfterHandler(Handler<S, T> handler)
+ {
+ handlers.computeIfAbsent(EventType.AFTER, k -> new CopyOnWriteArrayList<>()).add(handler);
+ return () -> handlers.get(EventType.AFTER).remove(handler);
+ }
+
+ private enum EventType
+ {
+ BEFORE, AFTER
+ }
+
+ /**
+ * The handler to be notified before and after a configuration value is changed.
+ * @param <S> the type of the object to mutate.
+ * @param <V> the type of the value to mutate.
+ */
+ @FunctionalInterface
+ public interface Handler<S, V>
+ {
+ V handle(S source, V oldValue, V newValue);
+
+ static <S, V> Handler<S, V> consume(BiConsumer<? super V, ? super V> consumer)
Review Comment:
Removed.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1220016472
##########
src/java/org/apache/cassandra/config/DatabaseDescriptor.java:
##########
@@ -4763,4 +4756,159 @@ public static OptionalDouble getSeverityDuringDecommission()
OptionalDouble.of(conf.severity_during_decommission) :
OptionalDouble.empty();
}
+
+ public static void visit(PropertyVisitor visitor)
+ {
+ visit(visitor, RuntimeException::new);
+ }
+
+ public static void visit(PropertyVisitor visitor, Function<Throwable, ? extends RuntimeException> handler)
+ {
+ try
+ {
+ for (Property property : ofNullable(confValueAccessors).orElse(Collections.emptyMap()).values())
+ visitor.visit(property.getName(), property.getType(), property.getAnnotation(Mutable.class) == null);
+ }
+ catch (Throwable t)
+ {
+ throw handler.apply(t);
+ }
+ }
Review Comment:
Method added, the Visitor interface removed.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1196622529
##########
src/java/org/apache/cassandra/config/YamlConfigurationLoader.java:
##########
@@ -424,5 +428,140 @@ public void check() throws ConfigurationException
logger.warn("{} parameters have been deprecated. They have new names and/or value format; For more information, please refer to NEWS.txt", deprecationWarnings);
}
}
+
+ /**
+ * Creates a YAML instance based on Cassandra's custom configuration classes and types. Yaml factory here is used
+ * to {@link org.yaml.snakeyaml.Yaml#dumpAs} and {@link org.yaml.snakeyaml.Yaml#load(String)} given object or
+ * string respectively, that in turn is used to serialize and deserialize configuration properties.
+ */
+ public static class YamlFactory
+ {
+ private static final List<TypeDescription> scalarCassandraTypes = new ArrayList<>();
+ private static final List<TypeDescription> javaBeanCassandraTypes = new ArrayList<>();
+ private static volatile YamlFactory instance;
+
+ private YamlFactory()
+ {
+ loadScalarTypeDescriptions(scalarCassandraTypes);
+ loadJavaBeanTypeDescriptions(javaBeanCassandraTypes);
+ }
+
+ public static YamlFactory getInstance()
+ {
+ YamlFactory instance0 = instance;
Review Comment:
This is only for lazy initialization, as it 'touches' a lot of configuration-type classes directly.
Fixed.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1205936373
##########
src/java/org/apache/cassandra/config/ListenableProperty.java:
##########
@@ -0,0 +1,177 @@
+/*
+ * 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.config;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import com.google.common.base.Preconditions;
+import org.apache.commons.lang3.ArrayUtils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.yaml.snakeyaml.introspector.Property;
+
+/**
+ *
+ */
+public class ListenableProperty<T> extends Property
+{
+ private static final Logger logger = LoggerFactory.getLogger(ListenableProperty.class);
+ private final Property delegate;
+ private final Invoker<T> validateInvoker;
+ private final List<PropertyListener<T>> listeners = new CopyOnWriteArrayList<>();
+
+ public ListenableProperty(Property property)
+ {
+ super(property.getName(), property.getType());
+ this.delegate = property;
+ this.validateInvoker = property.getAnnotation(Validate.class) == null ?
+ (conf, val) -> val :
+ PropertyValidateInvoker.create(property);
+ }
+
+ @Override
+ public boolean isWritable()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean isReadable()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Class<?>[] getActualTypeArguments()
+ {
+ return delegate.getActualTypeArguments();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public synchronized void set(Object config, Object newValue) throws Exception
+ {
+ if (getAnnotation(Mutable.class) == null)
+ throw new ConfigurationException("Property is read-only: " + getName());
+
+ T validatedValue = validateInvoker.invoke((Config) config, (T) newValue);
+ T oldValue = get(config);
+ Iterator<PropertyListener<T>> iterator = listeners.iterator();
+ while (iterator.hasNext())
+ iterator.next().onBeforeChange(oldValue, validatedValue);
+ delegate.set(config, validatedValue);
+ while (iterator.hasNext())
Review Comment:
The comment is taken into account and is no longer relevant, so I'm resolving it.
But, this is a good catch :-)
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1205939691
##########
src/java/org/apache/cassandra/config/ValidatedPropertyLoader.java:
##########
@@ -0,0 +1,117 @@
+/*
+ * 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.config;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+import com.google.common.base.Preconditions;
+import org.apache.commons.lang3.ArrayUtils;
+
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.utils.FBUtilities;
+import org.yaml.snakeyaml.introspector.FieldProperty;
+import org.yaml.snakeyaml.introspector.Property;
+
+public class ValidatedPropertyLoader extends DefaultLoader
+{
+ private final Predicate<Property> nonListenableProperty;
+
+ public ValidatedPropertyLoader(Predicate<Property> nonListenableProperty)
+ {
+ this.nonListenableProperty = nonListenableProperty;
+ }
+
+ @Override
+ protected Property createPropertyForField(Class<?> root, Field field)
+ {
+ Property property = new FieldProperty(field);
+ if (nonListenableProperty.test(property))
+ return property;
+
+ ListenableProperty<?, ?> listenable = new ListenableProperty<>(property);
+ if (property.getAnnotation(ValidatedBy.class) != null)
+ listenable.addBeforeHandler(ValidationPropertyHandler.create(root, listenable.delegate()));
+ return listenable;
+ }
+
+ private static class ValidationPropertyHandler<S, T> implements ListenableProperty.Handler<S, T>
+ {
+ private final Method method;
+ private final String name;
+
+ private ValidationPropertyHandler(Method method, String name)
+ {
+ this.method = method;
+ this.name = name;
+ }
+
+ public static <S, T> ValidationPropertyHandler<S, T> create(Class<?> root, Property property)
+ {
+ Preconditions.checkNotNull(property.getAnnotation(ValidatedBy.class));
+ ValidatedBy annotation = property.getAnnotation(ValidatedBy.class);
+ Class<?> clazz = FBUtilities.classForName(annotation.useClass(), "validate method");
+ Class<?>[] searchPattern = ArrayUtils.addAll(new Class<?>[]{ root, property.getType() });
Review Comment:
As discussed privately, I have added support for the following method patterns that perform validation:
- `Parent`, `Name`, `Value`
- `Name`, `Value`
- `Value`
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1205943846
##########
src/java/org/apache/cassandra/config/ListenableProperty.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.config;
+
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.function.BiConsumer;
+
+import org.yaml.snakeyaml.introspector.Property;
+
+/**
+ *
+ */
+public class ListenableProperty<S, T> extends ForwardingProperty
+{
+ private final Map<EventType, List<Handler<S, T>>> handlers = new EnumMap<>(EventType.class);
+
+ public ListenableProperty(Property property)
+ {
+ super(property.getName(), property);
+ for (EventType eventType : EventType.values())
+ handlers.put(eventType, new CopyOnWriteArrayList<>());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public synchronized void set(Object source, Object newValue) throws Exception
+ {
+ T oldValue = (T) get(source);
+ T value = Handler.compose(handlers.get(EventType.BEFORE)).handle((S) source, oldValue, (T) newValue);
+ delegate().set(source, value);
+ Handler.compose(handlers.get(EventType.AFTER)).handle((S) source, oldValue, value);
+ }
+
+ public synchronized Remover addBeforeHandler(Handler<S, T> handler)
+ {
+ handlers.computeIfAbsent(EventType.BEFORE, k -> new CopyOnWriteArrayList<>()).add(handler);
+ return () -> handlers.get(EventType.BEFORE).remove(handler);
+ }
+
+ public synchronized Remover addAfterHandler(Handler<S, T> handler)
+ {
+ handlers.computeIfAbsent(EventType.AFTER, k -> new CopyOnWriteArrayList<>()).add(handler);
Review Comment:
The code was reworked, no longer relevant.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1251104171
##########
src/java/org/apache/cassandra/db/virtual/SettingsTable.java:
##########
@@ -59,63 +57,104 @@ final class SettingsTable extends AbstractVirtualTable
.addPartitionKeyColumn(NAME, UTF8Type.instance)
.addRegularColumn(VALUE, UTF8Type.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,
Review Comment:
I tend to agree that this column must appear, but this raises the question of backward compatibility of the virtual table if we add a new column: "Are we able to add new columns to VT? How do users use VTs?". As these changes require a lot of discussion in themselves and require collecting user experience with VTs, I have left them to be followed up.
So my plan is:
- prepare and merge the initial changes;
- start a discussion with VT about backwards compatibility and then add an extra column to the SettingsTable (or as an option create SettingsTableV2 in the worst case);
- migrate other properties that should be updatable as well;
The reason for not including the column in this PR is to minimize the changes and make them less debatable.
WDYT?
--
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
[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)
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1251203541
##########
src/java/org/apache/cassandra/config/ConfigFields.java:
##########
@@ -0,0 +1,49 @@
+/*
+ * 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.config;
+
+/**
+ * This class is created by {@link org.apache.cassandra.utils.ConfigFieldsGenerateUtil} based on provided
+ * the {@link org.apache.cassandra.config.Config} class. It contains non-private non-static {@code Cofig}'s fields
+ * marked with the {@link org.apache.cassandra.config.Mutable} annotation to expose them to public APIs.
+
+ * @see org.apache.cassandra.config.Mutable
+ * @see org.apache.cassandra.config.Config
+ */
+public class ConfigFields
Review Comment:
Yeah something like that, up to you. The goal is to not generate and have code around that.
--
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
[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)
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1241930648
##########
src/java/org/apache/cassandra/db/virtual/SettingsTable.java:
##########
@@ -59,63 +57,104 @@ final class SettingsTable extends AbstractVirtualTable
.addPartitionKeyColumn(NAME, UTF8Type.instance)
.addRegularColumn(VALUE, UTF8Type.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,
Review Comment:
I would add a new column into this vtable called "mutable" of type `boolean`. That way, a user would see which properties are mutable and which are not. Currently, I do not see this instantly, do I? How do I know what I am able to change?
So if some specific column is not mutable, I would just make the call to this method no-op and we might just focus on the logic where we indeed going to update something.
--
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
[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)
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1241901004
##########
src/java/org/apache/cassandra/config/Config.java:
##########
@@ -199,6 +200,8 @@ public MemtableOptions()
// Limit the maximum depth of repair session merkle trees
@Deprecated
public volatile Integer repair_session_max_tree_depth = null;
+ @Mutable
+ @ValidatedBy(useClass = DATABASE_DESCRIPTOR_CLASS, useClassMethod = "validateRepairSessionSpace")
Review Comment:
@Mmuzaf I would expect that if a parameter is called "useClass", then the actual value of that parameter will be indeed a class.
@Mutable
@ValidatedBy(useClass = DatabaseDescriptor.class, useClassMethod = "validateRepairSessionSpace")
and then in the implementation you would use ".getName()" or something like that.
The minor problem with this approach, as it is currently done, is that if a class changes its name or location, this would not be updated.
I am not sure we can do the same for "method" as it is not so easy to reference here like class is but it is still an improvement.
--
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
[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)
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
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
Re: [PR] CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation) [cassandra]
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1431584987
##########
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));
+ }
+ catch (PropertyNotFoundException e)
+ {
+ // ignore
+ }
return result;
}
@Override
public DataSet data()
{
SimpleDataSet result = new SimpleDataSet(metadata());
- for (Map.Entry<String, Property> e : PROPERTIES.entrySet())
- result.row(e.getKey()).column(VALUE, getValue(e.getValue()));
+ for (String key : DatabaseDescriptor.getAllProperties())
+ {
+ if (BACKWARDS_COMPATABLE_NAMES.containsKey(key))
+ continue;
+ runExceptionally(() -> result.row(key)
+ .column(VALUE, getPropertyAsString(key))
+ .column(MUTABLE, DatabaseDescriptor.isMutableProperty(key)),
+ t -> new ConfigurationException(t.getMessage(), false));
+ }
+
+ runExceptionally(() -> BACKWARDS_COMPATABLE_NAMES.forEach((oldName, newName) ->
+ result.row(oldName)
+ .column(VALUE, getPropertyAsString(newName))
+ .column(MUTABLE, DatabaseDescriptor.isMutableProperty(newName))),
+ t -> new ConfigurationException(t.getMessage(), false));
return result;
}
- private String getValue(Property prop)
+ static String getKeyAndWarnIfObsolete(String name)
{
- Object value = prop.get(config);
- return value == null ? null : value.toString();
+ String key = BACKWARDS_COMPATABLE_NAMES.getOrDefault(name, name);
+ if (BACKWARDS_COMPATABLE_NAMES.containsKey(name))
Review Comment:
@Mmuzaf can't be this rewritten like `if (name.equals(key))`? So we dont need to look into map.
--
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-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation) [cassandra]
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1431633220
##########
src/java/org/apache/cassandra/config/ValidatedPropertyLoader.java:
##########
@@ -0,0 +1,183 @@
+/*
+ * 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.config;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.stream.Collectors;
+
+import org.apache.commons.lang3.ArrayUtils;
+
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.utils.FBUtilities;
+import org.yaml.snakeyaml.introspector.FieldProperty;
+import org.yaml.snakeyaml.introspector.Property;
+
+public final class ValidatedPropertyLoader implements Loader
+{
+ private final Loader loader;
+
+ public ValidatedPropertyLoader()
+ {
+ this.loader = new DefaultLoader(ValidatedPropertyLoader::listenablePropertyFactory);
+ }
+
+ @Override
+ public Map<String, Property> getProperties(Class<?> root)
+ {
+ return loader.getProperties(root);
+ }
+
+ private static Property listenablePropertyFactory(Field field)
+ {
+ ListenableProperty<?, ?> listenable = new ListenableProperty<>(new FieldProperty(field));
+ ValidatedByList validatedByList = field.getAnnotation(ValidatedByList.class);
+ ValidatedBy[] validatedByArray;
+ if (validatedByList == null)
+ {
+ if (field.getAnnotation(ValidatedBy.class) == null)
+ return listenable;
+ else
+ validatedByArray = new ValidatedBy[]{ field.getAnnotation(ValidatedBy.class) };
+ }
+ else
+ validatedByArray = validatedByList.value();
Review Comment:
@Mmuzaf could it happen that validatedByList would not be null but the array would be null? Then then next `for` would loop over null?
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1205940390
##########
src/java/org/apache/cassandra/config/ValidatedPropertyLoader.java:
##########
@@ -0,0 +1,117 @@
+/*
+ * 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.config;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+import com.google.common.base.Preconditions;
+import org.apache.commons.lang3.ArrayUtils;
+
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.utils.FBUtilities;
+import org.yaml.snakeyaml.introspector.FieldProperty;
+import org.yaml.snakeyaml.introspector.Property;
+
+public class ValidatedPropertyLoader extends DefaultLoader
+{
+ private final Predicate<Property> nonListenableProperty;
+
+ public ValidatedPropertyLoader(Predicate<Property> nonListenableProperty)
+ {
+ this.nonListenableProperty = nonListenableProperty;
+ }
+
+ @Override
+ protected Property createPropertyForField(Class<?> root, Field field)
+ {
+ Property property = new FieldProperty(field);
+ if (nonListenableProperty.test(property))
+ return property;
+
+ ListenableProperty<?, ?> listenable = new ListenableProperty<>(property);
+ if (property.getAnnotation(ValidatedBy.class) != null)
+ listenable.addBeforeHandler(ValidationPropertyHandler.create(root, listenable.delegate()));
+ return listenable;
+ }
+
+ private static class ValidationPropertyHandler<S, T> implements ListenableProperty.Handler<S, T>
+ {
+ private final Method method;
+ private final String name;
+
+ private ValidationPropertyHandler(Method method, String name)
+ {
+ this.method = method;
+ this.name = name;
+ }
+
+ public static <S, T> ValidationPropertyHandler<S, T> create(Class<?> root, Property property)
+ {
+ Preconditions.checkNotNull(property.getAnnotation(ValidatedBy.class));
+ ValidatedBy annotation = property.getAnnotation(ValidatedBy.class);
+ Class<?> clazz = FBUtilities.classForName(annotation.useClass(), "validate method");
+ Class<?>[] searchPattern = ArrayUtils.addAll(new Class<?>[]{ root, property.getType() });
+ for (Method refMethod : clazz.getDeclaredMethods())
+ {
+ int modifiers = refMethod.getModifiers();
+ if (Modifier.isPrivate(modifiers) || Modifier.isProtected(modifiers))
+ continue;
+
+ if (refMethod.getName().equals(annotation.useClassMethod()) &&
+ Arrays.equals(refMethod.getParameterTypes(), searchPattern) &&
+ (refMethod.getReturnType() == Void.TYPE || refMethod.getReturnType().equals(property.getType())))
+ {
+ return new ValidationPropertyHandler<>(refMethod, property.getName());
+ }
+ }
+ throw new ConfigurationException(String.format("Required method '%s(%s)' not found for field '%s'",
+ annotation.useClassMethod(),
+ Arrays.stream(searchPattern)
+ .map(Class::getCanonicalName)
+ .collect(Collectors.joining(", ")),
+ property.getName()), false);
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
+ @Override
+ public T handle(S source, T oldValue, T newValue)
+ {
+ try
+ {
+ Object result = method.invoke(source, source, newValue);
Review Comment:
Patterns added here:
https://github.com/apache/cassandra/pull/2334#discussion_r1205939691
The `null` is used, as you mentioned about 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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1205937184
##########
src/java/org/apache/cassandra/config/ListenableProperty.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.config;
+
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.function.BiConsumer;
+
+import org.yaml.snakeyaml.introspector.Property;
+
+/**
+ *
+ */
+public class ListenableProperty<S, T> extends ForwardingProperty
+{
+ private final Map<EventType, List<Handler<S, T>>> handlers = new EnumMap<>(EventType.class);
+
+ public ListenableProperty(Property property)
+ {
+ super(property.getName(), property);
+ for (EventType eventType : EventType.values())
+ handlers.put(eventType, new CopyOnWriteArrayList<>());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public synchronized void set(Object source, Object newValue) throws Exception
+ {
+ T oldValue = (T) get(source);
+ T value = Handler.compose(handlers.get(EventType.BEFORE)).handle((S) source, oldValue, (T) newValue);
+ delegate().set(source, value);
+ Handler.compose(handlers.get(EventType.AFTER)).handle((S) source, oldValue, value);
+ }
+
+ public synchronized Remover addBeforeHandler(Handler<S, T> handler)
+ {
+ handlers.computeIfAbsent(EventType.BEFORE, k -> new CopyOnWriteArrayList<>()).add(handler);
+ return () -> handlers.get(EventType.BEFORE).remove(handler);
+ }
+
+ public synchronized Remover addAfterHandler(Handler<S, T> handler)
+ {
+ handlers.computeIfAbsent(EventType.AFTER, k -> new CopyOnWriteArrayList<>()).add(handler);
+ return () -> handlers.get(EventType.AFTER).remove(handler);
+ }
+
+ private enum EventType
+ {
+ BEFORE, AFTER
+ }
+
+ /**
+ * The handler to be notified before and after a configuration value is changed.
+ * @param <S> the type of the object to mutate.
+ * @param <V> the type of the value to mutate.
+ */
+ @FunctionalInterface
+ public interface Handler<S, V>
+ {
+ V handle(S source, V oldValue, V newValue);
+
+ static <S, V> Handler<S, V> consume(BiConsumer<? super V, ? super V> consumer)
+ {
+ return (source, oldValue, newValue) -> {
+ consumer.accept(oldValue, newValue);
+ return newValue;
+ };
+ }
+
+ static <S, V> Handler<S, V > compose(List<Handler < S, V >> handlers)
Review Comment:
Method removed, no longer relevant.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1205956790
##########
src/java/org/apache/cassandra/config/ListenableProperty.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.config;
+
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.function.BiConsumer;
+
+import org.yaml.snakeyaml.introspector.Property;
+
+/**
+ *
+ */
+public class ListenableProperty<S, T> extends ForwardingProperty
+{
+ private final Map<EventType, List<Handler<S, T>>> handlers = new EnumMap<>(EventType.class);
+
+ public ListenableProperty(Property property)
+ {
+ super(property.getName(), property);
+ for (EventType eventType : EventType.values())
+ handlers.put(eventType, new CopyOnWriteArrayList<>());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public synchronized void set(Object source, Object newValue) throws Exception
+ {
+ T oldValue = (T) get(source);
+ T value = Handler.compose(handlers.get(EventType.BEFORE)).handle((S) source, oldValue, (T) newValue);
+ delegate().set(source, value);
+ Handler.compose(handlers.get(EventType.AFTER)).handle((S) source, oldValue, value);
Review Comment:
I have added `BeforeChangeListener`, and `AfterChangeListener` instead of the `Handler` as you pointed out above. We can still merge them into a single interface with two methods, `onBefore` and `onAfter`, but in the latter case the API looks like a stateful interface, which I'd like to avoid adding.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1205950015
##########
src/java/org/apache/cassandra/config/Validate.java:
##########
@@ -0,0 +1,36 @@
+/*
+ * 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.config;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Validate annotation to be used on configuration fields to validate the value of the field with
+ * a custom validator class and its method.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface Validate
+{
+ String useClass() default "";
Review Comment:
Renamed to `@ValidatedBy`, I think it's more suitable, however any other naming suggestion are really appreciated :-)
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1205951252
##########
src/java/org/apache/cassandra/config/Validate.java:
##########
@@ -0,0 +1,36 @@
+/*
+ * 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.config;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Validate annotation to be used on configuration fields to validate the value of the field with
+ * a custom validator class and its method.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface Validate
Review Comment:
I have added `@ValidatedBy` and `@ValidatedByList` annotations to make the validation method reusable for other fields.
--
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
[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)
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1241930648
##########
src/java/org/apache/cassandra/db/virtual/SettingsTable.java:
##########
@@ -59,63 +57,104 @@ final class SettingsTable extends AbstractVirtualTable
.addPartitionKeyColumn(NAME, UTF8Type.instance)
.addRegularColumn(VALUE, UTF8Type.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,
Review Comment:
I would add a new column into this vtable called "mutable" of type `boolean`. That way, a user would see which properties are mutable and which are not. Currently, I do not see this instantly, do I? How do I know what I am able to change?
So if some specific column is not mutable, I would just make the call to this method no-op (returned instantly) and we might just focus on the logic where we indeed going to update something.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1196620553
##########
src/java/org/apache/cassandra/config/YamlConfigurationLoader.java:
##########
@@ -218,7 +222,7 @@ public static <T> T fromMap(Map<String,Object> map, boolean shouldCheck, Class<T
verifyReplacements(replacements, map);
YamlConfigurationLoader.PropertiesChecker propertiesChecker = new YamlConfigurationLoader.PropertiesChecker(replacements);
constructor.setPropertyUtils(propertiesChecker);
- Yaml yaml = new Yaml(constructor);
+ Yaml yaml = YamlFactory.getInstance().newYamlInstance(constructor, propertiesChecker);
Review Comment:
You're right. Fixed.
--
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
[GitHub] [cassandra] dcapwell commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "dcapwell (via GitHub)" <gi...@apache.org>.
dcapwell commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1197077170
##########
src/java/org/apache/cassandra/config/ListenableProperty.java:
##########
@@ -0,0 +1,177 @@
+/*
+ * 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.config;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import com.google.common.base.Preconditions;
+import org.apache.commons.lang3.ArrayUtils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.yaml.snakeyaml.introspector.Property;
+
+/**
+ *
+ */
+public class ListenableProperty<T> extends Property
+{
+ private static final Logger logger = LoggerFactory.getLogger(ListenableProperty.class);
+ private final Property delegate;
+ private final Invoker<T> validateInvoker;
+ private final List<PropertyListener<T>> listeners = new CopyOnWriteArrayList<>();
+
+ public ListenableProperty(Property property)
+ {
+ super(property.getName(), property.getType());
+ this.delegate = property;
+ this.validateInvoker = property.getAnnotation(Validate.class) == null ?
+ (conf, val) -> val :
+ PropertyValidateInvoker.create(property);
+ }
+
+ @Override
+ public boolean isWritable()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean isReadable()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Class<?>[] getActualTypeArguments()
+ {
+ return delegate.getActualTypeArguments();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public synchronized void set(Object config, Object newValue) throws Exception
+ {
+ if (getAnnotation(Mutable.class) == null)
+ throw new ConfigurationException("Property is read-only: " + getName());
+
+ T validatedValue = validateInvoker.invoke((Config) config, (T) newValue);
+ T oldValue = get(config);
+ Iterator<PropertyListener<T>> iterator = listeners.iterator();
+ while (iterator.hasNext())
+ iterator.next().onBeforeChange(oldValue, validatedValue);
+ delegate.set(config, validatedValue);
+ while (iterator.hasNext())
Review Comment:
this doesn't work with iterators... this is `false` as you already iterated
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1251093906
##########
src/java/org/apache/cassandra/db/virtual/SettingsTable.java:
##########
@@ -59,63 +57,104 @@ final class SettingsTable extends AbstractVirtualTable
.addPartitionKeyColumn(NAME, UTF8Type.instance)
.addRegularColumn(VALUE, UTF8Type.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("Setting the value to null is equivalent to the deletion operation. " +
+ "Column deletion is not supported by table vts.settings");
+ else
+ runExceptionally(() -> setPropertyFromString(getKeyAndWarn(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(getKeyAndWarn(name));
+ result.row(name).column(VALUE, value);
+ }
+ catch (PropertyNotFoundException e)
+ {
+ // ignore
+ }
return result;
}
@Override
public DataSet data()
{
SimpleDataSet result = new SimpleDataSet(metadata());
- for (Map.Entry<String, Property> e : PROPERTIES.entrySet())
- result.row(e.getKey()).column(VALUE, getValue(e.getValue()));
+ for (String key : DatabaseDescriptor.getAllProperties())
Review Comment:
Firstly, the `DatabaseDescriptor#getPropertyValue` method, which is used to get the configuration property value, may throw runtime exceptions (e.g. `YAMLException`) that are not handled by the SettingsTable API. Virtual tables are expected to throw the `RequestValidationException`, so we need to follow that.
Second, the previously used `PROPERTIES.entrySet()` was a collection of all sorts of available properties needed to make the `SettingsTable` backwards compatible with previous releases, including replaced properties, the normal properties themselves, and properties that used to be plain and were moved to the nested structure some time ago. So, now we need to keep the same output and:
- `DatabaseDescriptor.getAllProperties()` is used to iterate though the `replaces` + common properties;
- `BACKWARDS_COMPATABLE_NAMES#forEach` is used to enrich the output with old-styled 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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1251150705
##########
src/java/org/apache/cassandra/config/ConfigFields.java:
##########
@@ -0,0 +1,49 @@
+/*
+ * 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.config;
+
+/**
+ * This class is created by {@link org.apache.cassandra.utils.ConfigFieldsGenerateUtil} based on provided
+ * the {@link org.apache.cassandra.config.Config} class. It contains non-private non-static {@code Cofig}'s fields
+ * marked with the {@link org.apache.cassandra.config.Mutable} annotation to expose them to public APIs.
+
+ * @see org.apache.cassandra.config.Mutable
+ * @see org.apache.cassandra.config.Config
+ */
+public class ConfigFields
Review Comment:
The problem with having this class generated at the build is the number of classes the Config depends on: 43. We have to compile them all first (and their dependencies accordingly), which makes the build process itself more complicated than it needs to be. Using an external library to achieve the same result also seems like over-engineering.
We've argued with David about the `ConfigFields` class itself (he doesn't like it at all), but I don't see any other good options here, as a Config field name can be used several times in the codebase mostly in the `DatabaseDescription` class. If we want to rename a config field we either rename it once in the `ConfigFields` class followed by the link to the class in javadoc, or we have to search for the name in all the sources.
So the `ConfigFieldsGenerateUtil` is just used as a convenient way to create these constants until they all have the @Mutable annotation (or none if it is not needed for a field) and then remove it from the source code. Thoughts?
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1251156603
##########
src/java/org/apache/cassandra/config/ValidatedBy.java:
##########
@@ -0,0 +1,38 @@
+/*
+ * 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.config;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Repeatable;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Validate annotation to be used on configuration fields to validate the value of the field with
+ * a custom validator class and its method.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+@Repeatable(ValidatedByList.class)
+public @interface ValidatedBy
+{
+ String useClass();
Review Comment:
This refers to the same comment as a circular dependency: https://github.com/apache/cassandra/pull/2334#discussion_r1251156139
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1251156139
##########
src/java/org/apache/cassandra/config/Config.java:
##########
@@ -199,6 +200,8 @@ public MemtableOptions()
// Limit the maximum depth of repair session merkle trees
@Deprecated
public volatile Integer repair_session_max_tree_depth = null;
+ @Mutable
+ @ValidatedBy(useClass = DATABASE_DESCRIPTOR_CLASS, useClassMethod = "validateRepairSessionSpace")
Review Comment:
The problem with this approach is a circular dependency: the `DatabaseDescriptor` class has the `confValueAccessors` which are built from the `Config.class` and here we are trying to have a reference to the `DatabaseDescriptor.class` which is not good. So, since we still need to refer to a method by its name and considering the fact that the DatabaseDescriptor doesn't change its name or package at all because there are too many dependencies on it, we can refer to it by string representation. This seems to be a good compromise, wdyt?
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1251163326
##########
src/java/org/apache/cassandra/config/ValidatedPropertyLoader.java:
##########
@@ -0,0 +1,183 @@
+/*
+ * 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.config;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.stream.Collectors;
+
+import org.apache.commons.lang3.ArrayUtils;
+
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.utils.FBUtilities;
+import org.yaml.snakeyaml.introspector.FieldProperty;
+import org.yaml.snakeyaml.introspector.Property;
+
+public final class ValidatedPropertyLoader implements Loader
+{
+ private final Loader loader;
+
+ public ValidatedPropertyLoader()
+ {
+ this.loader = new DefaultLoader(ValidatedPropertyLoader::listenablePropertyFactory);
+ }
+
+ @Override
+ public Map<String, Property> getProperties(Class<?> root)
+ {
+ return loader.getProperties(root);
+ }
+
+ private static Property listenablePropertyFactory(Field field)
+ {
+ ListenableProperty<?, ?> listenable = new ListenableProperty<>(new FieldProperty(field));
+ ValidatedByList validatedByList = field.getAnnotation(ValidatedByList.class);
+ ValidatedBy[] validatedByArray;
+ if (validatedByList == null)
+ {
+ if (field.getAnnotation(ValidatedBy.class) == null)
+ return listenable;
+ else
+ validatedByArray = new ValidatedBy[]{ field.getAnnotation(ValidatedBy.class) };
+ }
+ else
+ validatedByArray = validatedByList.value();
+
+ for (ValidatedBy validatedBy : validatedByArray)
+ listenable.addListener(createValidationListener(field, validatedBy));
+
+ return listenable;
+ }
+
+ private static <S, T> ListenableProperty.Listener<S, T> createValidationListener(Field field, ValidatedBy annotation)
+ {
+ Class<?> clazz = FBUtilities.classForName(annotation.useClass(), "validate method");
+ List<Method> matches = Arrays.stream(clazz.getDeclaredMethods())
Review Comment:
Can you share your idea of moving the code to `ReflectionUtils `? I have searched the codebase for usages of the same approach and haven't found anything in common for this. Did you mean some specific examples?
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1251198318
##########
src/java/org/apache/cassandra/config/ConfigFields.java:
##########
@@ -0,0 +1,49 @@
+/*
+ * 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.config;
+
+/**
+ * This class is created by {@link org.apache.cassandra.utils.ConfigFieldsGenerateUtil} based on provided
+ * the {@link org.apache.cassandra.config.Config} class. It contains non-private non-static {@code Cofig}'s fields
+ * marked with the {@link org.apache.cassandra.config.Mutable} annotation to expose them to public APIs.
+
+ * @see org.apache.cassandra.config.Mutable
+ * @see org.apache.cassandra.config.Config
+ */
+public class ConfigFields
Review Comment:
I think this is possible, or just move the constants under the inner `Fields` class in the `Config` itself. Both are ok.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1252073866
##########
src/java/org/apache/cassandra/config/ListenableProperty.java:
##########
@@ -0,0 +1,81 @@
+/*
+ * 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.config;
+
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.yaml.snakeyaml.introspector.Property;
+
+/**
+ *
Review Comment:
Updated.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1321861524
##########
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:
@smiklosovic agree, this makes sense to me. I'll try to figure out the best way to avoid using reflection every time we need to get the mutability state.
--
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
[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)
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1241941085
##########
src/java/org/apache/cassandra/config/DatabaseDescriptor.java:
##########
@@ -4787,4 +4752,131 @@ public static StorageCompatibilityMode getStorageCompatibilityMode()
else
return conf.storage_compatibility_mode;
}
+
+ public static <T> ListenableProperty.Remover addBeforeChangePropertyListener(String name, Class<T> clazz, BiConsumer<T, T> consumer)
+ {
+ return addPropertyListener(name, clazz, p -> p.addListener(new ListenableProperty.Listener<Config, T>()
+ {
+ @Override
+ public T before(Config source, String name, T oldValue, T newValue)
+ {
+ consumer.accept(oldValue, newValue);
+ return newValue;
+ }
+ }));
+ }
+
+ public static <T> ListenableProperty.Remover addAfterChangePropertyListener(String name, Class<T> clazz, BiConsumer<T, T> consumer)
+ {
+ return addPropertyListener(name, clazz, p -> p.addListener(new ListenableProperty.Listener<Config, T>()
+ {
+ @Override
+ public void after(Config source, String name, T oldValue, T newValue)
+ {
+ consumer.accept(oldValue, newValue);
+ }
+ }));
+ }
+
+ @SuppressWarnings("unchecked")
+ private static <T> ListenableProperty.Remover addPropertyListener(String name,
+ Class<T> clazz,
+ Function<ListenableProperty<Config, T>, ListenableProperty.Remover> adder)
+ {
+ Property property = getPropertyAccessor(name);
+ // The case when replacement property is used and match the property's name.
+ Property property0 = property instanceof Replacement.ReplacementProperty ?
Review Comment:
`property0`? :) Come on ... we can do better.
--
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
[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)
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1241953707
##########
src/java/org/apache/cassandra/config/ValidatedPropertyLoader.java:
##########
@@ -0,0 +1,183 @@
+/*
+ * 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.config;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.stream.Collectors;
+
+import org.apache.commons.lang3.ArrayUtils;
+
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.utils.FBUtilities;
+import org.yaml.snakeyaml.introspector.FieldProperty;
+import org.yaml.snakeyaml.introspector.Property;
+
+public final class ValidatedPropertyLoader implements Loader
+{
+ private final Loader loader;
+
+ public ValidatedPropertyLoader()
+ {
+ this.loader = new DefaultLoader(ValidatedPropertyLoader::listenablePropertyFactory);
+ }
+
+ @Override
+ public Map<String, Property> getProperties(Class<?> root)
+ {
+ return loader.getProperties(root);
+ }
+
+ private static Property listenablePropertyFactory(Field field)
+ {
+ ListenableProperty<?, ?> listenable = new ListenableProperty<>(new FieldProperty(field));
+ ValidatedByList validatedByList = field.getAnnotation(ValidatedByList.class);
+ ValidatedBy[] validatedByArray;
+ if (validatedByList == null)
+ {
+ if (field.getAnnotation(ValidatedBy.class) == null)
+ return listenable;
+ else
+ validatedByArray = new ValidatedBy[]{ field.getAnnotation(ValidatedBy.class) };
+ }
+ else
+ validatedByArray = validatedByList.value();
+
+ for (ValidatedBy validatedBy : validatedByArray)
+ listenable.addListener(createValidationListener(field, validatedBy));
+
+ return listenable;
+ }
+
+ private static <S, T> ListenableProperty.Listener<S, T> createValidationListener(Field field, ValidatedBy annotation)
+ {
+ Class<?> clazz = FBUtilities.classForName(annotation.useClass(), "validate method");
+ List<Method> matches = Arrays.stream(clazz.getDeclaredMethods())
Review Comment:
maybe org.apache.cassandra.utils.ReflectionUtils ?
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1220044216
##########
src/java/org/apache/cassandra/config/DatabaseDescriptor.java:
##########
@@ -415,9 +433,12 @@ private static InetAddress getNetworkInterfaceAddress(String intf, String config
}
}
- private static void setConfig(Config config)
+ private static void setConfig(Supplier<Config> config)
{
- conf = config;
+ conf = config.get();
+ confValueAccessors = ImmutableMap.copyOf(
Review Comment:
Fixed.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1220074934
##########
src/java/org/apache/cassandra/config/YamlConfigurationLoader.java:
##########
@@ -424,5 +428,140 @@ public void check() throws ConfigurationException
logger.warn("{} parameters have been deprecated. They have new names and/or value format; For more information, please refer to NEWS.txt", deprecationWarnings);
}
}
+
+ /**
+ * Creates a YAML instance based on Cassandra's custom configuration classes and types. Yaml factory here is used
+ * to {@link org.yaml.snakeyaml.Yaml#dumpAs} and {@link org.yaml.snakeyaml.Yaml#load(String)} given object or
+ * string respectively, that in turn is used to serialize and deserialize configuration properties.
+ */
+ public static class YamlFactory
+ {
+ private static final List<TypeDescription> scalarCassandraTypes = new ArrayList<>();
+ private static final List<TypeDescription> javaBeanCassandraTypes = new ArrayList<>();
+ private static volatile YamlFactory instance;
+
+ private YamlFactory()
+ {
+ loadScalarTypeDescriptions(scalarCassandraTypes);
+ loadJavaBeanTypeDescriptions(javaBeanCassandraTypes);
+ }
+
+ public static YamlFactory getInstance()
+ {
+ YamlFactory instance0 = instance;
+ if (instance0 == null)
+ {
+ synchronized (YamlFactory.class)
+ {
+ instance0 = instance;
+ if (instance0 == null)
+ instance = instance0 = new YamlFactory();
+ }
+ }
+ return instance0;
+ }
+
+ /**
+ * Creates a new Yaml instance with the given root class.
+ * @param root The class (usually JavaBean) to be constructed.
+ * @return A new Yaml instance with the given root class.
+ */
+ public Yaml newYamlInstance(Class<?> root)
+ {
+ PropertyUtils propertyUtils = new PropertyUtils();
+ propertyUtils.setBeanAccess(BeanAccess.FIELD);
+ propertyUtils.setAllowReadOnlyProperties(true);
+ return newYamlInstance(new CustomConstructor(root, Config.class.getClassLoader()), propertyUtils);
Review Comment:
Fixed.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1220060682
##########
src/java/org/apache/cassandra/db/virtual/SettingsTable.java:
##########
@@ -59,63 +53,77 @@ final class SettingsTable extends AbstractVirtualTable
.addPartitionKeyColumn(NAME, UTF8Type.instance)
.addRegularColumn(VALUE, UTF8Type.instance)
.build());
- this.config = config;
+ Set<String> unprocessed = new HashSet<>(BACKWARDS_COMPATABLE_NAMES.values());
+ DatabaseDescriptor.visit((key, type, ro) -> {
+ if (BACKWARDS_COMPATABLE_NAMES.containsKey(key))
+ {
+ 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",
+ key, SettingsTable.class.getSimpleName()));
+ }
+ unprocessed.remove(key);
+ });
+ if (!unprocessed.isEmpty())
+ throw new AssertionError("The following keys must be present in the Config: " + unprocessed);
+ }
+
+ @Override
+ protected void applyColumnDeletion(AbstractMutableVirtualTable.ColumnValues partitionKey, AbstractMutableVirtualTable.ColumnValues clusteringColumns, String columnName)
Review Comment:
Support of the `DELETE` operation was removed.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1220017805
##########
src/java/org/apache/cassandra/config/DatabaseDescriptor.java:
##########
@@ -4763,4 +4756,159 @@ public static OptionalDouble getSeverityDuringDecommission()
OptionalDouble.of(conf.severity_during_decommission) :
OptionalDouble.empty();
}
+
+ public static void visit(PropertyVisitor visitor)
+ {
+ visit(visitor, RuntimeException::new);
+ }
+
+ public static void visit(PropertyVisitor visitor, Function<Throwable, ? extends RuntimeException> handler)
+ {
+ try
+ {
+ for (Property property : ofNullable(confValueAccessors).orElse(Collections.emptyMap()).values())
+ visitor.visit(property.getName(), property.getType(), property.getAnnotation(Mutable.class) == null);
+ }
+ catch (Throwable t)
+ {
+ throw handler.apply(t);
+ }
+ }
+
+ public static <T> ListenableProperty.Remover addBeforeChangePropertyListener(String name, Class<T> clazz, BiConsumer<T, T> consumer)
+ {
+ return addPropertyListener(name, clazz, p -> p.addBeforeHandler(ListenableProperty.Handler.consume(consumer)));
+ }
+
+ public static <T> ListenableProperty.Remover addAfterChangePropertyListener(String name, Class<T> clazz, BiConsumer<T, T> consumer)
+ {
+ return addPropertyListener(name, clazz, p -> p.addAfterHandler(ListenableProperty.Handler.consume(consumer)));
+ }
+
+ @SuppressWarnings("unchecked")
+ private static <T> ListenableProperty.Remover addPropertyListener(String name,
+ Class<T> clazz,
+ Function<ListenableProperty<Config, T>, ListenableProperty.Remover> adder)
+ {
+ Property property = ofNullable(confValueAccessors.get(name))
+ .map(p -> {
+ // The case when replacement property is used and match the property's name.
+ if (p instanceof Replacement.ReplacementProperty)
+ return ((Replacement.ReplacementProperty) p).delegate();
+ else
+ return p;
+ })
+ .orElseThrow(() -> new PropertyNotFoundException(name));
+ if (!(property instanceof ListenableProperty))
+ throw new ConfigurationException(String.format("Property '%s' is not listenable.", name));
+
+ if (clazz.equals(property.getType()))
+ return adder.apply((ListenableProperty<Config, T>) property);
+ else
+ throw new ConfigurationException(String.format("Listener type '%s' doesn't match the property '%s' type '%s'.",
+ clazz.getSimpleName(), name, clazz.getSimpleName()));
+ }
+
+ public static Object getProperty(String name)
+ {
+ return ofNullable(confValueAccessors.get(name)).orElseThrow(() -> new PropertyNotFoundException(name))
+ .get(conf);
+ }
+
+ public static String getStringProperty(String name)
+ {
+ Property property = ofNullable(confValueAccessors.get(name))
+ .orElseThrow(() -> new PropertyNotFoundException(name));
Review Comment:
Fixed the way you suggested.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1220015321
##########
src/java/org/apache/cassandra/db/virtual/SettingsTable.java:
##########
@@ -59,63 +53,77 @@ final class SettingsTable extends AbstractVirtualTable
.addPartitionKeyColumn(NAME, UTF8Type.instance)
.addRegularColumn(VALUE, UTF8Type.instance)
.build());
- this.config = config;
+ Set<String> unprocessed = new HashSet<>(BACKWARDS_COMPATABLE_NAMES.values());
+ DatabaseDescriptor.visit((key, type, ro) -> {
+ if (BACKWARDS_COMPATABLE_NAMES.containsKey(key))
+ {
+ 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",
+ key, SettingsTable.class.getSimpleName()));
+ }
+ unprocessed.remove(key);
+ });
+ if (!unprocessed.isEmpty())
+ throw new AssertionError("The following keys must be present in the Config: " + unprocessed);
+ }
+
+ @Override
+ protected void applyColumnDeletion(AbstractMutableVirtualTable.ColumnValues partitionKey, AbstractMutableVirtualTable.ColumnValues clusteringColumns, String columnName)
+ {
+ String name = partitionKey.value(0);
+ String key = getKeyAndWarn(name);
+ runExceptionally(() -> DatabaseDescriptor.setProperty(key, null),
+ t -> invalidRequest("Invalid delete request. Cause: %s", t.getMessage()));
+ }
+
+ @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);
+ runExceptionally(() -> DatabaseDescriptor.setProperty(getKeyAndWarn(name), value),
Review Comment:
Fixed.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1220016150
##########
src/java/org/apache/cassandra/config/DatabaseDescriptor.java:
##########
@@ -452,7 +473,12 @@ private static void applySimpleConfig()
//InetAddressAndPort and get the right defaults
InetAddressAndPort.initializeDefaultPort(getStoragePort());
- validateUpperBoundStreamingConfig();
+ // below 2 checks are needed in order to match the pre-CASSANDRA-15234 upper bound for those parameters which were still in megabits per second
+ setProperty(ConfigFields.STREAM_THROUGHPUT_OUTBOUND, conf.stream_throughput_outbound);
+ setProperty(ConfigFields.INTER_DC_STREAM_THROUGHPUT_OUTBOUND, conf.inter_dc_stream_throughput_outbound);
+ setProperty(ConfigFields.ENTIRE_SSTABLE_STREAM_THROUGHPUT_OUTBOUND, conf.entire_sstable_stream_throughput_outbound);
+ setProperty(ConfigFields.ENTIRE_SSTABLE_INTER_DC_STREAM_THROUGHPUT_OUTBOUND, conf.entire_sstable_inter_dc_stream_throughput_outbound);
+ setProperty(ConfigFields.COMPACTION_THROUGHPUT, conf.compaction_throughput);
Review Comment:
As we discussed handling of such cases was moved to the pre-parse stage.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1220024808
##########
src/java/org/apache/cassandra/config/DataRateSpec.java:
##########
@@ -209,6 +209,14 @@ public boolean equals(Object obj)
return unit.convert(other.quantity, other.unit) == quantity && other.unit.convert(quantity, unit) == other.quantity;
}
+ @SuppressWarnings("unchecked")
+ public final Class<T> getDeclaringClass()
Review Comment:
Removed.
--
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-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation) [cassandra]
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1431584987
##########
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));
+ }
+ catch (PropertyNotFoundException e)
+ {
+ // ignore
+ }
return result;
}
@Override
public DataSet data()
{
SimpleDataSet result = new SimpleDataSet(metadata());
- for (Map.Entry<String, Property> e : PROPERTIES.entrySet())
- result.row(e.getKey()).column(VALUE, getValue(e.getValue()));
+ for (String key : DatabaseDescriptor.getAllProperties())
+ {
+ if (BACKWARDS_COMPATABLE_NAMES.containsKey(key))
+ continue;
+ runExceptionally(() -> result.row(key)
+ .column(VALUE, getPropertyAsString(key))
+ .column(MUTABLE, DatabaseDescriptor.isMutableProperty(key)),
+ t -> new ConfigurationException(t.getMessage(), false));
+ }
+
+ runExceptionally(() -> BACKWARDS_COMPATABLE_NAMES.forEach((oldName, newName) ->
+ result.row(oldName)
+ .column(VALUE, getPropertyAsString(newName))
+ .column(MUTABLE, DatabaseDescriptor.isMutableProperty(newName))),
+ t -> new ConfigurationException(t.getMessage(), false));
return result;
}
- private String getValue(Property prop)
+ static String getKeyAndWarnIfObsolete(String name)
{
- Object value = prop.get(config);
- return value == null ? null : value.toString();
+ String key = BACKWARDS_COMPATABLE_NAMES.getOrDefault(name, name);
+ if (BACKWARDS_COMPATABLE_NAMES.containsKey(name))
Review Comment:
@Mmuzaf can't be this rewritten like `if (name.equals(key))`? So we dont need to look into map.
--
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-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation) [cassandra]
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1431633220
##########
src/java/org/apache/cassandra/config/ValidatedPropertyLoader.java:
##########
@@ -0,0 +1,183 @@
+/*
+ * 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.config;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.stream.Collectors;
+
+import org.apache.commons.lang3.ArrayUtils;
+
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.utils.FBUtilities;
+import org.yaml.snakeyaml.introspector.FieldProperty;
+import org.yaml.snakeyaml.introspector.Property;
+
+public final class ValidatedPropertyLoader implements Loader
+{
+ private final Loader loader;
+
+ public ValidatedPropertyLoader()
+ {
+ this.loader = new DefaultLoader(ValidatedPropertyLoader::listenablePropertyFactory);
+ }
+
+ @Override
+ public Map<String, Property> getProperties(Class<?> root)
+ {
+ return loader.getProperties(root);
+ }
+
+ private static Property listenablePropertyFactory(Field field)
+ {
+ ListenableProperty<?, ?> listenable = new ListenableProperty<>(new FieldProperty(field));
+ ValidatedByList validatedByList = field.getAnnotation(ValidatedByList.class);
+ ValidatedBy[] validatedByArray;
+ if (validatedByList == null)
+ {
+ if (field.getAnnotation(ValidatedBy.class) == null)
+ return listenable;
+ else
+ validatedByArray = new ValidatedBy[]{ field.getAnnotation(ValidatedBy.class) };
+ }
+ else
+ validatedByArray = validatedByList.value();
Review Comment:
@Mmuzaf could it happen that validatedByList would not be null but the array would be null? Then next `for` would loop over null?
--
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
[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)
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
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 and I found 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, names of all mutable properties would be in a set. So if it is not in s 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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1196620026
##########
src/java/org/apache/cassandra/config/YamlConfigurationLoader.java:
##########
@@ -424,5 +428,140 @@ public void check() throws ConfigurationException
logger.warn("{} parameters have been deprecated. They have new names and/or value format; For more information, please refer to NEWS.txt", deprecationWarnings);
}
}
+
+ /**
+ * Creates a YAML instance based on Cassandra's custom configuration classes and types. Yaml factory here is used
+ * to {@link org.yaml.snakeyaml.Yaml#dumpAs} and {@link org.yaml.snakeyaml.Yaml#load(String)} given object or
+ * string respectively, that in turn is used to serialize and deserialize configuration properties.
+ */
+ public static class YamlFactory
+ {
+ private static final List<TypeDescription> scalarCassandraTypes = new ArrayList<>();
+ private static final List<TypeDescription> javaBeanCassandraTypes = new ArrayList<>();
+ private static volatile YamlFactory instance;
+
+ private YamlFactory()
+ {
+ loadScalarTypeDescriptions(scalarCassandraTypes);
+ loadJavaBeanTypeDescriptions(javaBeanCassandraTypes);
+ }
+
+ public static YamlFactory getInstance()
+ {
+ YamlFactory instance0 = instance;
+ if (instance0 == null)
+ {
+ synchronized (YamlFactory.class)
+ {
+ instance0 = instance;
+ if (instance0 == null)
+ instance = instance0 = new YamlFactory();
+ }
+ }
+ return instance0;
+ }
+
+ /**
+ * Creates a new Yaml instance with the given root class.
+ * @param root The class (usually JavaBean) to be constructed.
+ * @return A new Yaml instance with the given root class.
+ */
+ public Yaml newYamlInstance(Class<?> root)
+ {
+ PropertyUtils propertyUtils = new PropertyUtils();
+ propertyUtils.setBeanAccess(BeanAccess.FIELD);
+ propertyUtils.setAllowReadOnlyProperties(true);
+ return newYamlInstance(new CustomConstructor(root, Config.class.getClassLoader()), propertyUtils);
+ }
+
+ public Yaml newYamlInstance(SafeConstructor constructor, PropertyUtils propertyUtils)
+ {
+ return create(constructor, propertyUtils);
+ }
+
+ private static Yaml create(SafeConstructor constructor, PropertyUtils propertyUtils)
+ {
+ DumperOptions options = new DumperOptions();
+ options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
+ options.setDefaultScalarStyle(DumperOptions.ScalarStyle.PLAIN);
+ options.setSplitLines(true);
+ options.setPrettyFlow(true); // to remove brackets around
+ Representer representer = new CassandraRepresenter(scalarCassandraTypes, options);
+ representer.setPropertyUtils(propertyUtils);
+ constructor.setPropertyUtils(propertyUtils);
+ Yaml yaml = new Yaml(constructor, representer);
+
+ scalarCassandraTypes.forEach(yaml::addTypeDescription);
+ javaBeanCassandraTypes.forEach(yaml::addTypeDescription);
+ return yaml;
+ }
+
+ private static void loadScalarTypeDescriptions(List<TypeDescription> types)
Review Comment:
Fixed.
##########
src/java/org/apache/cassandra/config/YamlConfigurationLoader.java:
##########
@@ -424,5 +428,140 @@ public void check() throws ConfigurationException
logger.warn("{} parameters have been deprecated. They have new names and/or value format; For more information, please refer to NEWS.txt", deprecationWarnings);
}
}
+
+ /**
+ * Creates a YAML instance based on Cassandra's custom configuration classes and types. Yaml factory here is used
+ * to {@link org.yaml.snakeyaml.Yaml#dumpAs} and {@link org.yaml.snakeyaml.Yaml#load(String)} given object or
+ * string respectively, that in turn is used to serialize and deserialize configuration properties.
+ */
+ public static class YamlFactory
+ {
+ private static final List<TypeDescription> scalarCassandraTypes = new ArrayList<>();
+ private static final List<TypeDescription> javaBeanCassandraTypes = new ArrayList<>();
+ private static volatile YamlFactory instance;
+
+ private YamlFactory()
+ {
+ loadScalarTypeDescriptions(scalarCassandraTypes);
+ loadJavaBeanTypeDescriptions(javaBeanCassandraTypes);
+ }
+
+ public static YamlFactory getInstance()
+ {
+ YamlFactory instance0 = instance;
+ if (instance0 == null)
+ {
+ synchronized (YamlFactory.class)
+ {
+ instance0 = instance;
+ if (instance0 == null)
+ instance = instance0 = new YamlFactory();
+ }
+ }
+ return instance0;
+ }
+
+ /**
+ * Creates a new Yaml instance with the given root class.
+ * @param root The class (usually JavaBean) to be constructed.
+ * @return A new Yaml instance with the given root class.
+ */
+ public Yaml newYamlInstance(Class<?> root)
+ {
+ PropertyUtils propertyUtils = new PropertyUtils();
+ propertyUtils.setBeanAccess(BeanAccess.FIELD);
+ propertyUtils.setAllowReadOnlyProperties(true);
+ return newYamlInstance(new CustomConstructor(root, Config.class.getClassLoader()), propertyUtils);
+ }
+
+ public Yaml newYamlInstance(SafeConstructor constructor, PropertyUtils propertyUtils)
+ {
+ return create(constructor, propertyUtils);
+ }
+
+ private static Yaml create(SafeConstructor constructor, PropertyUtils propertyUtils)
+ {
+ DumperOptions options = new DumperOptions();
+ options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
+ options.setDefaultScalarStyle(DumperOptions.ScalarStyle.PLAIN);
+ options.setSplitLines(true);
+ options.setPrettyFlow(true); // to remove brackets around
+ Representer representer = new CassandraRepresenter(scalarCassandraTypes, options);
+ representer.setPropertyUtils(propertyUtils);
+ constructor.setPropertyUtils(propertyUtils);
+ Yaml yaml = new Yaml(constructor, representer);
+
+ scalarCassandraTypes.forEach(yaml::addTypeDescription);
+ javaBeanCassandraTypes.forEach(yaml::addTypeDescription);
+ return yaml;
+ }
+
+ private static void loadScalarTypeDescriptions(List<TypeDescription> types)
+ {
+ // Enum types resolved with a custom overridden handler DefaultRepresentEnum() as a smiple string.
+ types.add(createTypeDescription(DataRateSpec.LongBytesPerSecondBound.class));
+ types.add(createTypeDescription(DataStorageSpec.IntBytesBound.class));
+ types.add(createTypeDescription(DataStorageSpec.IntKibibytesBound.class));
+ types.add(createTypeDescription(DataStorageSpec.IntMebibytesBound.class));
+ types.add(createTypeDescription(DataStorageSpec.LongBytesBound.class));
+ types.add(createTypeDescription(DataStorageSpec.LongMebibytesBound.class));
+ types.add(createTypeDescription(DurationSpec.IntMillisecondsBound.class));
+ types.add(createTypeDescription(DurationSpec.IntMinutesBound.class));
+ types.add(createTypeDescription(DurationSpec.IntSecondsBound.class));
+ types.add(createTypeDescription(DurationSpec.LongMillisecondsBound.class));
+ types.add(createTypeDescription(DurationSpec.LongNanosecondsBound.class));
+ types.add(createTypeDescription(DurationSpec.LongSecondsBound.class));
+ }
+
+ private static void loadJavaBeanTypeDescriptions(List<TypeDescription> types)
Review Comment:
Fixed.
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1205946565
##########
src/java/org/apache/cassandra/config/DefaultLoader.java:
##########
@@ -52,7 +52,7 @@ public Map<String, Property> getProperties(Class<?> root)
&& !Modifier.isTransient(modifiers)
&& Modifier.isPublic(modifiers)
&& !properties.containsKey(name))
- properties.put(name, new FieldProperty(f));
+ properties.put(name, createPropertyForField(c, f));
Review Comment:
Fixed.
inheritance -> decoration
--
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
[GitHub] [cassandra] Mmuzaf commented on a diff in pull request #2334: CASSANDRA-15254 Support updates on the virtuabl table SettingsTable (use annotations for property updates validation)
Posted by "Mmuzaf (via GitHub)" <gi...@apache.org>.
Mmuzaf commented on code in PR #2334:
URL: https://github.com/apache/cassandra/pull/2334#discussion_r1205938137
##########
src/java/org/apache/cassandra/config/ValidatedPropertyLoader.java:
##########
@@ -0,0 +1,117 @@
+/*
+ * 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.config;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+import com.google.common.base.Preconditions;
+import org.apache.commons.lang3.ArrayUtils;
+
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.utils.FBUtilities;
+import org.yaml.snakeyaml.introspector.FieldProperty;
+import org.yaml.snakeyaml.introspector.Property;
+
+public class ValidatedPropertyLoader extends DefaultLoader
+{
+ private final Predicate<Property> nonListenableProperty;
+
+ public ValidatedPropertyLoader(Predicate<Property> nonListenableProperty)
+ {
+ this.nonListenableProperty = nonListenableProperty;
+ }
+
+ @Override
+ protected Property createPropertyForField(Class<?> root, Field field)
+ {
+ Property property = new FieldProperty(field);
+ if (nonListenableProperty.test(property))
+ return property;
+
+ ListenableProperty<?, ?> listenable = new ListenableProperty<>(property);
+ if (property.getAnnotation(ValidatedBy.class) != null)
Review Comment:
I have added the support of multiple 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