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 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 newEnableFlag
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 newEnableFlag
guardrail.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
ensureEnabled(java.lang.String featureName, ClientState state)
Aborts the operation if this guardrail is not enabled.void
ensureEnabled(ClientState state)
Aborts the operation if this guardrail is not enabled.boolean
isEnabled(ClientState state)
Returns whether the guarded feature is enabled or not.
-
-
-
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 newEnableFlag
guardrail.- Parameters:
name
- the identifying name of the guardrailreason
- the optional description of the reason for guarding the operationenabled
- aClientState
-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 differentfeatureName
.
-
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 newEnableFlag
guardrail.- Parameters:
name
- the identifying name of the guardrailreason
- the optional description of the reason for guarding the operationwarned
- aClientState
-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
- aClientState
-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 differentfeatureName
.
-
-
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. Anull
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. Anull
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. Anull
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.
-
-