Class EnableFlag

java.lang.Object
org.apache.cassandra.db.guardrails.Guardrail
org.apache.cassandra.db.guardrails.EnableFlag

public class EnableFlag extends Guardrail
A guardrail that enables the use of a particular feature.

Note that this guardrail only aborts operations (if the feature is not enabled) so is only meant for query-based guardrails (we're happy to reject queries deemed dangerous, but we don't want to create a guardrail that breaks compaction for instance).

  • Constructor Details

    • EnableFlag

      public EnableFlag(String name, @Nullable String reason, Predicate<ClientState> enabled, String featureName)
      Creates a new EnableFlag guardrail.
      Parameters:
      name - the identifying name of the guardrail
      reason - the optional description of the reason for guarding the operation
      enabled - a ClientState-based supplier of boolean indicating whether the feature guarded by this guardrail is enabled.
      featureName - The feature that is guarded by this guardrail (for reporting in error messages), ensureEnabled(String, ClientState) can specify a different featureName.
    • EnableFlag

      public EnableFlag(String name, @Nullable String reason, Predicate<ClientState> warned, Predicate<ClientState> enabled, String featureName)
      Creates a new EnableFlag guardrail.
      Parameters:
      name - the identifying name of the guardrail
      reason - the optional description of the reason for guarding the operation
      warned - a ClientState-based supplier of boolean indicating whether warning should be emitted even guardrail as such has passed. If guardrail fails, the warning will not be emitted. This might be used for cases when we want to warn a user regardless of successful guardrail execution.
      enabled - a ClientState-based supplier of boolean indicating whether the feature guarded by this guardrail is enabled.
      featureName - The feature that is guarded by this guardrail (for reporting in error messages), ensureEnabled(String, ClientState) can specify a different featureName.
  • Method Details

    • isEnabled

      public boolean isEnabled(@Nullable ClientState state)
      Returns whether the guarded feature is enabled or not.
      Parameters:
      state - The client state, used to skip the check if the query is internal or is done by a superuser. A null value means that the check should be done regardless of the query.
      Returns:
      true is the feature is enabled, false otherwise.
    • ensureEnabled

      public void ensureEnabled(@Nullable ClientState state)
      Aborts the operation if this guardrail is not enabled.

      This must be called when the feature guarded by this guardrail is used to ensure such use is in fact allowed.

      Parameters:
      state - The client state, used to skip the check if the query is internal or is done by a superuser. A null value means that the check should be done regardless of the query.
    • ensureEnabled

      public void ensureEnabled(String featureName, @Nullable ClientState state)
      Aborts the operation if this guardrail is not enabled.

      This must be called when the feature guarded by this guardrail is used to ensure such use is in fact allowed.

      Parameters:
      featureName - The feature that is guarded by this guardrail (for reporting in error messages).
      state - The client state, used to skip the check if the query is internal or is done by a superuser. A null value means that the check should be done regardless of the query, although it won't throw any exception if the failure threshold is exceeded. This is so because checks without an associated client come from asynchronous processes such as compaction, and we don't want to interrupt such processes.