CASSANDRA-21139 - Feature/guardrail for misprepare statements#4596
CASSANDRA-21139 - Feature/guardrail for misprepare statements#4596omniCoder77 wants to merge 5 commits intoapache:trunkfrom
Conversation
|
@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
|
44bba46 to
586af83
Compare
73a2f0e to
f12cdbe
Compare
9d64186 to
65c0ec8
Compare
048a2d6 to
4117bb3
Compare
| # When true, warns on the usage of misprepared statements | ||
| # When false, misprepared statements will result in an error | ||
| prepared_statements_require_parameters_warn: true | ||
| prepared_statements_require_parameters_fail: false |
There was a problem hiding this comment.
could you comment it all out? Just comment it out but keep true / false there. It is on defaults like that in Config.java, same in _latest.
You should also reflect these two guardrails in the above documentation. It is not aligned anymore too much.
| } | ||
| } | ||
|
|
||
|
|
There was a problem hiding this comment.
please revert this change, if nothing was changed, no reason to "pollute" the commit like this.
| } | ||
| } | ||
|
|
||
| @Override |
There was a problem hiding this comment.
remove, just for the sake of it. we would be doing this endlessly ...
| public static final String MBEAN_NAME = "org.apache.cassandra.db:type=Guardrails"; | ||
|
|
||
| public static final GuardrailsConfigProvider CONFIG_PROVIDER = GuardrailsConfigProvider.instance; | ||
|
|
There was a problem hiding this comment.
no need to have new line here, revert
1efc4e0 to
ad5340e
Compare
… logic and include table/keyspace metadata in warnings and errors.
ad5340e to
449f9c8
Compare
| statement.validatePrepare(state); | ||
| } | ||
| // if one of the statement is misprepared and we must fail, stop the loop | ||
| catch (GuardrailViolatedException e) |
There was a problem hiding this comment.
this is not necessary, no? you want this method to throw GuardrailViolatedException. If validatePrepare throws, that break is not necessary. You escape for loop already and it is propagated up.
…emoving try ... catch block
3c15ed6 to
ab7aa24
Compare
…ore descriptive error and warning message when a query lacks bind markers.
e6fbc03 to
84ef912
Compare
84ef912 to
9fe090a
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
prepared_statements_require_parameters_enabled(which can be configured fromcassandra.yaml) whose default value is false (backward compatibility) and added functions toStorageServiceMBeanto enable dynamic runtime configuration.Added test cases to validate changes in
parseAndPreparefunction.