crystal-cassandra
crystal-cassandra copied to clipboard
Setting consistency does not work
Hello,
I am trying to execute the following statements:
stmt = <<-CQL
begin batch
insert into #{@tbl_customer} (team_id) values (?) if not exists
update #{@tbl_customer} set customer_id = ?, created_at = ? where team_id = ?
apply batch
CQL
@db.exec stmt, team_id, cust_id, now, team_id
However, I am getting the following error when @db.exec executes:
ErrorServerProtocolError: Consistency level for LWT is missing for a request with conditions
To fix this, I am trying to set consistency level like this:
Cassandra::LibCass.execution_profile_set_consistency(profile, Cassandra::LibCass::CassConsistency::ConsistencyAny)
Cassandra::LibCass.execution_profile_set_serial_consistency(profile, Cassandra::LibCass::CassConsistency::ConsistencySerial)
stmt = <<-CQL
begin batch
insert into #{@tbl_customer} (team_id) values (?) if not exists
update #{@tbl_customer} set customer_id = ?, created_at = ? where team_id = ?
apply batch
CQL
@db.exec stmt, team_id, cust_id, now, team_id
However, seeing consistency in the profile does not seem to make any difference.
cc: @kaukas
How did you create the profile? How did you set it to be used for the cluster or statement?
Currently this lib does not support execution profiles. But you could extend it by writing a wrapper object and allowing it to be set on clusters or statements.
You should also be able to set consistency via CQL.
Thanks @kaukas . Setting consistency keeps erroring with message of syntax error.
I do not see a straightforward way for crystal-cassandra to expose statement objects through crystal-db. And apparently you do need to expose them because I did not find a way to change the default execution profile (unlike Python which has EXEC_PROFILE_DEFAULT).
In other words, the simplest might be to extend crystal-cassandra to take consistency as an URI param, assign a profile to the cluster and then use that profile for every statement. Still no access through db but 🤷♂️.
Alternatively, perhaps it's easier to skip the crystal-db layer altogether. Could crystal-cassandra be used directly?
db_context = DB::ConnectionContext.new…
cluster = Cassandra::DBApi::Cluster.acquire(db_context)
# set the exec profile on cluster
session = Cassandra::DBApi::Session.new(db_context)
statement = session.build_unprepared_statement("SELECT ...")
# set the exec profile on statement
@bcardiff, do you think it would be reasonable to support random extra parameters for exec?
Apparently random extra parameters are exactly what exec takes. Here is my attempt at supporting statement options.