Skip to content
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

MapPreparedStatementCache.CacheKey uses DefaultSimpleStatement.toString() inherited from Object.toString() [DATACASS-814] #980

Closed
spring-projects-issues opened this issue Oct 17, 2020 · 2 comments
Assignees

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Oct 17, 2020

aldobongio opened DATACASS-814 and commented

Attached there is a screenshot from YourKit, displaying the internals of a MapPreparedStatementCache instance of a running application, using Spring Data Cassandra 3.0.3 and DataStax Driver 4.6.1.

It seems clear that the key of stored prepared statements is composed using a cql field which is not the expected CQL text coming from the prepared statement (the Javadoc says Statements are cached with a key consisting of session name, keyspace and the cql text).

Tracking down the problem, it originates from this line : instead of invoking getQuery() (which returns the CQL text) the toString() method is invoked, which is not overriden by DefaultSimpleStatement.

Luckily, the toString() method benefits from the hashCode() method, which is implemented by DefaultSimpleStatement. So in the end building different statements using the same calls to QueryBuilder results in different objects having the same internal fields and thus generating the same toString() value. So it works ... but seems a bit fragile, in case Datastax change/remove the hashCode method from DefaultSimpleStatement


Affects: 3.0.4 (Neumann SR4)

Attachments:

Referenced from: pull request #180

Backported to: 3.0.5 (Neumann SR5)

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Oct 19, 2020

Mark Paluch commented

Good catch. Do you want to submit a pull request to fix the issue?

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Oct 19, 2020

aldobongio commented

Here it is: #180

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.