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

      Constructors 
      Constructor Description
      EnableFlag​(java.lang.String name, java.lang.String reason, java.util.function.Predicate<ClientState> enabled, java.lang.String featureName)
      Creates a new EnableFlag guardrail.
      EnableFlag​(java.lang.String name, java.lang.String reason, java.util.function.Predicate<ClientState> warned, java.util.function.Predicate<ClientState> enabled, java.lang.String featureName)
      Creates a new EnableFlag guardrail.
    • Constructor Detail

      • EnableFlag

        public EnableFlag​(java.lang.String name,
                          @Nullable
                          java.lang.String reason,
                          java.util.function.Predicate<ClientState> enabled,
                          java.lang.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​(java.lang.String name,
                          @Nullable
                          java.lang.String reason,
                          java.util.function.Predicate<ClientState> warned,
                          java.util.function.Predicate<ClientState> enabled,
                          java.lang.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 Detail

      • 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​(java.lang.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.