Class EnableFlag
java.lang.Object
org.apache.cassandra.db.guardrails.Guardrail
org.apache.cassandra.db.guardrails.EnableFlag
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).
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionEnableFlag(String name, String reason, Predicate<ClientState> enabled, String featureName) Creates a newEnableFlagguardrail.EnableFlag(String name, String reason, Predicate<ClientState> warned, Predicate<ClientState> enabled, String featureName) Creates a newEnableFlagguardrail. -
Method Summary
Modifier and TypeMethodDescriptionvoidensureEnabled(String featureName, ClientState state) Aborts the operation if this guardrail is not enabled.voidensureEnabled(ClientState state) Aborts the operation if this guardrail is not enabled.booleanisEnabled(ClientState state) Returns whether the guarded feature is enabled or not.
-
Constructor Details
-
EnableFlag
public EnableFlag(String name, @Nullable String reason, Predicate<ClientState> enabled, String featureName) Creates a newEnableFlagguardrail.- 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(String name, @Nullable String reason, Predicate<ClientState> warned, Predicate<ClientState> enabled, String featureName) Creates a newEnableFlagguardrail.- 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 Details
-
isEnabled
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. Anullvalue means that the check should be done regardless of the query.- Returns:
trueis the feature is enabled,falseotherwise.
-
ensureEnabled
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. Anullvalue means that the check should be done regardless of the query.
-
ensureEnabled
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. Anullvalue 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.
-