-
Notifications
You must be signed in to change notification settings - Fork 3.8k
CASSANDRA-21139 - Feature/guardrail for misprepare statements #4596
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
CASSANDRA-21139 - Feature/guardrail for misprepare statements #4596
Conversation
… CRUD, IN, and LWT operations
src/java/org/apache/cassandra/db/guardrails/GuardrailsConfig.java
Outdated
Show resolved
Hide resolved
|
@smiklosovic Added new test cases verifying warning behaviour (warn only when Centralized onMisprepare logic to Guardrails.java Refined test case to extract repeating statements to a function, increase readability. |
|
In my test cases I have tested
|
311028f to
44bba46
Compare
44bba46 to
586af83
Compare
| restrictions.hasNonPrimaryKeyRestrictions(); | ||
| if (getBindVariables().isEmpty() && hasRestriction) | ||
| { | ||
| Guardrails.onMisprepared(state); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather just copy the content of that mehod here instead of having completely arbitrary method in Guardrails. There is no precedent to that.
You might also move it to superclass of these Statement classes so both can call it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public static void onMisprepared(ClientState state)
{
mispreparedStatementsEnabled.ensureEnabled(state);
mispreparedStatementsEnabled.warn(MISPREPARED_STATEMENT_WARN_MESSAGE);
}
here warn is a protected function, can't write it inside statement classes or interface, not sure where else to put it.
src/java/org/apache/cassandra/db/guardrails/GuardrailsConfig.java
Outdated
Show resolved
Hide resolved
|
@omniCoder77 thanks for the perseverance! I am just checking overall code / design etc. Havent deeply checked the actual logic around the very guardrail application. |
21adc18 to
6dbbc90
Compare
| { | ||
| mispreparedStatementsEnabled.ensureEnabled(state); | ||
|
|
||
| // only warn if user ins't super user or a external call, these checks are handled by guardrail framework |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo on ins't -- but why is super user relevant to the warning?
|
|
||
| /** | ||
| * <p> | ||
| * A statement is considered "mis-prepared" if it contains hardcoded literal values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be "if it contains only hardcoded liter values and without any bind markers"
| what, value, isWarning ? "warning" : "failure", threshold)); | ||
|
|
||
| /** | ||
| * Prevents heap exhaustion caused by the anti-pattern of preparing queries with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not heap exhaustion, but cache eviction
Prevents cache overflow and eviction caused by ...
|
|
||
| public static final EnableFlag mispreparedStatementsEnabled = | ||
| new EnableFlag("misprepared_statements_enabled", | ||
| "misprepared statements cause server-side memory exhaustion and high GC pressure by flooding the statement cache with non-reusable query entries", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"misprepared statements create non-reusable query entries and cause cache overflow"
Co-authored-by: Brad Schoening <5796692+bschoening@users.noreply.github.com>
6b0f657 to
ae9f1f9
Compare
ae9f1f9 to
5570c30
Compare
Validation is posted on Jira Ticket
Feature suggestion:
Guardrail for miss-prepared statements
Description:
We have hundreds of application teams and several dozen of them miss-prepare statements by using literals instead of bind markers.
I.e.,
The problem causes the prepared statement cache to constantly overflow, and will print a prepared statements discarded WARN message in the Cassandra log. At present, we use a wack-a-mole approach to discuss the problem with each development team individually, and hope they fix it and train the entire team on how to prepare statements correctly.
Also, finding the root cause of the issue today requires having the knowledge and access to look at the system.prepared_statements table.
Guardrails would seem a good approach here, where the guard could WARN or REJECT when a statement was prepared using a WHERE clause and no bind markers.
Note, this should not prevent users from creating prepared statements without a WHERE clause or with one or more literal values so long as there was at least one bind marker. Thus, the following would remain valid:
Approach:
Introduced a boolean flag
use_misprepare_statements_enabled(which can be configured fromcassandra.yaml) whose default value is true (backward compatibility) and added functions toStorageServiceMBeanto enable dynamic runtime configuration.Added test cases to validate changes in
parseAndPreparefunction.