Skip to content

Prepared Statements do not get cached #1229

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

Closed
Rednas92-spec opened this issue Feb 18, 2022 · 2 comments
Closed

Prepared Statements do not get cached #1229

Rednas92-spec opened this issue Feb 18, 2022 · 2 comments
Labels
status: waiting-for-triage An issue we've not yet triaged

Comments

@Rednas92-spec
Copy link

Rednas92-spec commented Feb 18, 2022

Hi,

During performance testing, we noticed a lot of threads waiting (waiting on Cassandra) while creating prepared statements.

Using Dynatrace (our monitoring tool) we see that executing the query takes the same time as preparing the statement.
image
image

According to the documentation (https://docs.spring.io/spring-data/cassandra/docs/current/reference/html/#cassandra.template.prepared-statements.caching), it should cache the prepared statement. We use a Spring Cassandra repository, which uses the CassandraTemplate.

When I tried to debug a simple case (calling a Cassandra repository method twice), I saw that the PrepareRequest does not get cached.

at line CqlPrepareAsyncProcessor::61 from java-driver-core-4.13.0.jar
CompletableFuture<PreparedStatement> result = cache.getIfPresent(request);

It should return the CompletableFuture (from the previous query), but it is always null.

When I check the request during debugging, I see that it's a DefaultPrepareRequest, holds a DefaultSimpleStatement. The hash of the DefaultPrepareRequest is the hash of the DefaultSimpleStatement.

Comparing the hash from the DefaultSimpleStatement from Cache, and the hash from the DefaultSimpleStatement from the request, I found that they are not equal.

DefaultSimpleStatement from request:
image

DefaultSimpleStatement from cache:
image

The hash gets calculated
@Override public int hashCode() { return Objects.hash( query, positionalValues, namedValues, executionProfileName, executionProfile, keyspace, routingKeyspace, routingKey, routingToken, customPayload, idempotent, tracing, timestamp, pagingState, pageSize, consistencyLevel, serialConsistencyLevel, timeout, node, nowInSeconds); }

The difference comes from the positionalValues; which are not the same for both statements.

I cannot share the code used for the performance testing, as this is production code. I could create a small example if required.

Using:
Spring Data Cassandra version 3.3.1

Thanks,
Sander

EDIT: This might be a duplicate of #1213 but I'm not sure.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 18, 2022
@samueldlightfoot
Copy link
Contributor

As mentioned this is a duplicate of #1213. The positional values are being included in the cache key, so there are never any cache hits (unless you sent exactly the same request in).

@Rednas92-spec
Copy link
Author

Because this is a duplicate, I will close this and further the discussion in #1213.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

3 participants