-
Notifications
You must be signed in to change notification settings - Fork 309
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
Allow keyspace customization for CassandraPersistentEntity #921
Comments
Mark Paluch commented A key principle in Spring's connection handling, regardless of whether it's JDBC or Cassandra, is to not mutate the connection state, especially regarding the database/keyspace. Each mutation requires tracking to revert the state into its original state once an operation has completed. Additionally, Note that keyspaces may be distributed across different Cassandra clusters, hence it's not possible to implement keyspace switching in such case via the built-in features. Recently, we upgraded to the Cassandra 4 driver and extended Applications may implement |
lmcdasi commented There are models where the keyspaces will have the same schema. And my objective is to have one Session (or maybe more) that I can re-use for multiple keyspaces. At the same time I cannot use a version > V4 thus setKeyspace is not useful for me. Also, I want to be able to use
Thus the query must be of form : 'insert into keyspace.tablename .....' which I can execute via any session. I do not see how It is the StatementBuilder that pre-builds the query by calling: StatementBuilder<RegularInsert> builder = getStatementFactory().insert(entityToUse, options, source.getPersistentEntity(), tableName); which translates to: StatementBuilder<RegularInsert> builder = StatementBuilder.of(QueryBuilder.insertInto(tableName)..... BUT the QueryBuilder do have the exact same methods with a keyspace ! /** Starts an INSERT query for a qualified table. */ { return new DefaultInsert(keyspace, table); } Which applies to all queries.
|
lmcdasi commented If we read the data stax manual: https://docs.datastax.com/en/developer/java-driver/4.5/manual/core/ "By default, a session isn’t tied to any specific keyspace. You’ll need to prefix table names in your queries. You’ll need to prefix table names in your queries: ...." So again, I understand that in order to use
|
Mark Paluch commented Looking at the QueryBuilder API, we could introduce an additional |
Tomasz Lelek commented Hello Mark Paluch, do you need help with this ticket? I can work on it and submit PR. Just to be clear on what was decided:
SimpleStatement insertQuery = getStatementFactory().insert(entity, options, persistentEntity, persistentEntity.getTableName()).build(); will become SimpleStatement insertQuery = getStatementFactory().insert(entity, options, persistentEntity,
persistenEntity.getKeyspace(), persistentEntity.getTableName()).build(); propagating it to the QueryBuilder.insertInto, selectFrom, etc calls. Similar changes for all usages. If yes, then I have two additional questions:
|
Mark Paluch commented We haven't decided on an approach yet. Introducing new table coordinate elements is always subject to research and the actual implementation happens on the way to getting it done. We have multiple aspects that play into this ticket:
Let's tackle the simple things first. We should consider the keyspace information optional as it wasn't there previously. For Spring Data JDBC, were solved the schema name resolution through the Does that help to come up with a first draft? |
Tomasz Lelek commented Regarding the:
So are you suggesting creating a new interface (similar to Also, regarding the:
I am not sure why do you refer to
|
Mark Paluch commented We introduced with version 3.0 a I mentioned annotations as extension point for users. Indeed, it is not related to the code changes, however it makes sense to consider how users would go about keyspace customizations. One way would be a static definition for all entities. Other implementations may leverage a mapping. Since we pass in |
Some good things take a bit longer until we get there. We introduced options to configure the keyspace for For now, we want to allow specific entities to be qualified for a specific keyspace. By configuring a Special honors go to @tomekl007 and @mipo256 for their contributions. |
lmcdasi opened DATACASS-751 and commented
In the data stax 4.5 manual it is indicated that creating session/keyspace (https://docs.datastax.com/en/developer/java-driver/4.5/manual/core/) is an anti-pattern:
"
// Anti-pattern: creating two sessions doubles the number of TCP connections opened by the driver
"You have a solution that uses the AbstractRoutingSessionFactory that just implement that anti-pattern.
But the data stax driver provides actually two different solutions to avoid having that antipattern.
The impacted classes are CassandraTemplate & StatementFactory. I attach example code of above where I test the insertTo successfully.
At the same time, while the framework allows me in CassandraConfig to specify a bean to create a cassandraTemplate that can be different than the default CassandraTemplate it does not allow me to re-use the existing framework classes in order to implement my self a template & statement factory where I can specify the keyspace without being forced to copy them out of the framework.
The keyspace can be kept in a ThreadLocal - using the same principle used for AbstractRoutingSessionFactory .
If we cannot have a template as such in the framework, can we at least have the possibility to implement a CassandraTemplace without being forced to copy a lot of code in order to access the existing framework classes ? The template requires quite a few classes that are private.
This assumes that the keyspace schema are the same.
Thank you
Affects: 3.0 RC1 (Neumann)
Attachments:
1 votes, 4 watchers
The text was updated successfully, but these errors were encountered: