You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by GitBox <gi...@apache.org> on 2021/12/02 14:00:43 UTC

[GitHub] [cassandra] adelapena commented on a change in pull request #1321: CASSANDRA-17147 trunk: Guardrails prototype

adelapena commented on a change in pull request #1321:
URL: https://github.com/apache/cassandra/pull/1321#discussion_r761118578



##########
File path: src/java/org/apache/cassandra/config/GuardrailsOptions.java
##########
@@ -0,0 +1,262 @@
+/*
+ * 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.Collections;
+import java.util.Set;
+import javax.annotation.Nullable;
+
+import com.google.common.collect.Sets;
+
+import org.apache.cassandra.cql3.statements.schema.TableAttributes;
+import org.apache.cassandra.db.guardrails.Guardrails;
+import org.apache.cassandra.db.guardrails.GuardrailsConfig;
+import org.apache.cassandra.db.guardrails.Values;
+
+import static java.lang.String.format;
+import static java.util.stream.Collectors.toSet;
+
+/**
+ * Configuration settings for guardrails populated from the Yaml file.
+ *
+ * <p>Note that the settings here must only be used to build the {@link GuardrailsConfig} class and not directly by the
+ * code checking each guarded constraint. That code should use the higher level abstractions defined in
+ * {@link Guardrails}).
+ *
+ * <p>This contains a main setting, {@code enabled}, controlling if guardrails are globally active or not, and
+ * individual settings to control each guardrail.
+ *
+ * <p>We have 2 variants of guardrails, soft (warn) and hard (abort) limits, each guardrail having either one of the
+ * variants or both. Note in particular that hard limits only make sense for guardrails triggering during query
+ * execution. For other guardrails, say one triggering during compaction, aborting that compaction does not make sense.
+ *
+ * <p>Additionally, each individual setting should have a specific value (typically -1 for numeric settings),
+ * that allows to disable the corresponding guardrail.
+ */
+public class GuardrailsOptions implements GuardrailsConfig
+{
+    public volatile boolean enabled = false;
+    public final IntThreshold tables = new IntThreshold();
+    public final IntThreshold columns_per_table = new IntThreshold();
+    public final IntThreshold secondary_indexes_per_table = new IntThreshold();
+    public final IntThreshold materialized_views_per_table = new IntThreshold();
+    public final TableProperties table_properties = new TableProperties();
+    public volatile boolean user_timestamps_enabled = true;
+
+    public void validate()
+    {
+        tables.validate("guardrails.tables");
+        columns_per_table.validate("guardrails.columns_per_table");
+        secondary_indexes_per_table.validate("guardrails.secondary_indexes_per_table");
+        materialized_views_per_table.validate("guardrails.materialized_views_per_table");
+        table_properties.validate("guardrails.table_properties");
+    }
+
+    @Override
+    public boolean getEnabled()
+    {
+        return enabled;
+    }
+
+    /**
+     * Enable/disable guardrails.
+     *
+     * @param enabled {@code true} for enabling guardrails, {@code false} for disabling them.
+     */
+    public void setEnabled(boolean enabled)
+    {
+        validateNotNull(enabled, "guardrails.enabled");
+        this.enabled = enabled;
+    }
+
+    @Override
+    public IntThreshold getTables()
+    {
+        return tables;
+    }
+
+    @Override
+    public IntThreshold getColumnsPerTable()
+    {
+        return columns_per_table;
+    }
+
+    @Override
+    public IntThreshold getSecondaryIndexesPerTable()
+    {
+        return secondary_indexes_per_table;
+    }
+
+    @Override
+    public IntThreshold getMaterializedViewsPerTable()
+    {
+        return materialized_views_per_table;
+    }
+
+    @Override
+    public TableProperties getTableProperties()
+    {
+        return table_properties;
+    }
+
+    @Override
+    public boolean getUserTimestampsEnabled()
+    {
+        return user_timestamps_enabled;
+    }
+
+    public void setUserTimestampsEnabled(boolean enabled)
+    {
+        validateNotNull(enabled, "guardrails.user_timestamps_enabled");
+        user_timestamps_enabled = enabled;
+    }
+
+    private static <T> void validateNotNull(T value, String name)

Review comment:
       Embedded into `org.apache.cassandra.config.GuardrailsOptions.TableProperties#validateTableProperties`




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