I am using spring -data-cassandra (1.3.1.RELEASE) to connect to the cassandra database. Is there a way to change the level of consistency in spring-data-cassandra. The default is level 1 ( What is the default level of consistency in spring-data-cassandra? ). But how to change that?
Thanks!
It is not possible to set a custom level of consistency when using the CrudRepository spring -data-cassandra interface. There is an open question https://jira.spring.io/browse/DATACASS-14 . The reason is that SimpleCassandraRepository, which implements interface methods, calls CassandraOperations methods without the WriteOptions parameter.
My solution : I wrote a custom crudrepository implementation, in this I can set the level of consistency myself.
Now you can set this level in spring boot by setting the following properties in the application.properties file.
spring.data.cassandra.consistency-level=quorum spring.data.cassandra.serial-consistency-level=quorum
, : , , , , QUORUM, , LOCAL_QUORUM, EACH_QUORUM, SERIAL, LOCAL_SERIAL, LOCAL_ONE., , , , , .,:
Select s = QueryBuilder.select().from("employee"); s.where(QueryBuilder.eq("id", "234")); s.setConsistencyLevel(ConsistencyLevel.QUORUM) ;
- application.properties: spring.data.cassandra.consistency = LOCAL_QUORUM
spring-data-cassandra 1.5, (. org.springframework.cassandra.core.QueryOptions#setConsistencyLevel(org.springframework.cassandra.core.ConsistencyLevel))
spring-data-cassandra
org.springframework.cassandra.core.QueryOptions#setConsistencyLevel(org.springframework.cassandra.core.ConsistencyLevel))
QueryOptions org.springframework.cassandra.core.CqlOperations#execute(java.lang.String, org.springframework.cassandra.core.QueryOptions), org.springframework.cassandra.core.CqlTemplate#addQueryOptions
QueryOptions
org.springframework.cassandra.core.CqlOperations#execute(java.lang.String, org.springframework.cassandra.core.QueryOptions)
org.springframework.cassandra.core.CqlTemplate#addQueryOptions
WriteOptions, org.springframework.data.cassandra.core.CassandraOperations#insert(T, org.springframework.cassandra.core.WriteOptions)
WriteOptions
org.springframework.data.cassandra.core.CassandraOperations#insert(T, org.springframework.cassandra.core.WriteOptions)
,
@Configuration public class CassandraConfig extends AbstractCassandraConfiguration { ... @Override protected QueryOptions getQueryOptions() { QueryOptions queryOptions = new QueryOptions(); queryOptions.setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM); return queryOptions; }
, https://docs.spring.io/spring-data/cassandra/docs/current/reference/html/#cassandra.repositories.queries.options.
IMO, , . :
public interface PersonRepository extends CrudRepository<Person, String> { @Consistency(ConsistencyLevel.LOCAL_ONE) List<Person> findByLastname(String lastname); List<Person> findByFirstname(String firstname, QueryOptions options); }
CassandraTemplate:
cassandraTemplate.insert(myEntity, new WriteOptions().builder() .consistencyLevel(ConsistencyLevel.QUORUM).build())
Source: https://habr.com/ru/post/1617478/More articles:How can I ensure grain consistency in orleans? - c #Laravel - why not a relative URL? - phpUnable to subscribe to channel after granting successfully - javascriptHow to generate data for a given value of the coefficient of multiple determination in R? - rF #: How to apply the Json.NET [JsonConstructor] attribute to the main constructor? - jsonHow to use Realm on Swift Playground? - iosКаков уровень согласованности по умолчанию в spring -data-cassandra? - spring-data-cassandraWhen are mongodb indexes updated? - databasePoll output from airodump-ng in Python - pythonОжидание входящего соединения с ключом ide Сообщение на PHPStorm с laravel - phpAll Articles