CASSANDRA-21139 - Feature/guardrail for misprepare statements#4596
CASSANDRA-21139 - Feature/guardrail for misprepare statements#4596omniCoder77 wants to merge 17 commits intoapache:trunkfrom
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.
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.
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
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.