Class Guardrail

java.lang.Object
org.apache.cassandra.db.guardrails.Guardrail
Direct Known Subclasses:
EnableFlag, Predicates, Threshold, Values

public abstract class Guardrail extends Object
General class defining a given guardrail that guards against some particular usage/condition.

Some guardrails only emit warnings when triggered, while others abort the query that triggers them. Some may do one or the other based on specific threshold. The queries are aborted with an InvalidRequestException.

Note that all the defined classes support live updates, which is why each guardrail class constructor takes suppliers of the condition the guardrail acts on rather than the condition itself. This implies that said suppliers should be fast and non-blocking to avoid surprises.

  • Field Details

    • logger

      protected static final NoSpamLogger logger
    • REDACTED

      protected static final String REDACTED
      See Also:
    • name

      public final String name
      A name identifying the guardrail (mainly for shipping with diagnostic events).
    • reason

      @Nullable public final String reason
      An optional description of the reason for guarding the operation.
  • Method Details

    • enabled

      public boolean enabled()
      Checks whether this guardrail is enabled or not when the check is done for a background opperation that is not associated to a specific ClientState, such as compaction or other background processes. Operations that are associated to a ClientState, such as CQL queries, should use enabled(ClientState).
      Returns:
      true if this guardrail is enabled, false otherwise.
    • enabled

      public boolean enabled(@Nullable ClientState state)
      Checks whether this guardrail is enabled or not. This will be enabled if the database is initialized and the authenticated user (if specified) is not system nor superuser.
      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 if this guardrail is enabled, false otherwise.
    • warn

      protected void warn(String message)
    • warn

      protected void warn(String message, String redactedMessage)
    • fail

      protected void fail(String message, @Nullable ClientState state)
    • fail

      protected void fail(String message, String redactedMessage, @Nullable ClientState state)