-
Notifications
You must be signed in to change notification settings - Fork 94
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
Internal reusable CQL statements should be prepared #417
Comments
It is not as easy as it may seem. The simplest approach would go like this:
Here I'm going to discuss some issues with this approach but I believe that at least some of them will still be relevant even if someone more clever than me comes out with a better solution. For the sake of clarity the parenting structs we will be dealing with are There are some issues with step 2.ii.: For So how to get out of this mess? One way to do it would obviously be to store the statements as There is also another idea. We can simply delegate the preparing to some other object that we can access in the constructor by some refactor. This works great with Ok, so with that out of the way there's still the There is an issue with step 2.iv: The method that executes the queries is |
You can prepare the statements needed for fetching tracing info in
I think we should keep the logic of
I think that preparing the statements right after (re)initializing
All methods of It's better to clone the prepared statement and set the consistency for the new statement. It's not perfect because it requires cloning, but doesn't require mutual exclusion, so it scales better. |
@psarna @Ponewor @piodul Hi! I'm looking for some rust practice and want to try to fix it. I've found, that there is the CachingSession, which internally use a cache for prepared statements (although I haven't found any usages of it, i guess it's using for client requests). Maybe is it better to extract the cache and use same struct for a both client and internal requests? Instances of the client and internal cache could be different. |
Hi @akoshchiy,
It would make sense to do it for the queries sent on the control connection. The slight overhead is not important there and it will be trivial to adapt the existing code that sends internal unprepared queries. You could try to extract some code from the Note that
There are not too many types of internal queries, so it's perfectly fine and will probably simplify the implementation. However, it's also worth mentioning that, while the issue's description was mainly about |
Our driver issues a bunch of internal CQL statements periodically, e.g. to fetch topology and schema information. These statements are currently not prepared, which forces the database to meticulously parse their CQL over and over, which is a waste of CPU.
The solution is to rewrite all internal statements so that they're prepared once, and then executed. We have a helper function used mainly for internal queries -
query_all
. Ideally, all call sites of that function should be translated toexecute_all
.Example:
scylla-rust-driver/scylla/src/transport/topology.rs
Line 322 in 2cf503b
Ref: scylladb/scylladb#10225
The text was updated successfully, but these errors were encountered: