You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Alexei Levashov <al...@arrayent.com> on 2016/10/14 01:11:13 UTC

Can not delete record with counter column in a batch.

Configuration : Cassandra 2.1
(if it matters Datastax Java driver 3.0.0 - driver users list couldn't help)
Platform Unix.

I have two tables:

CREATE TABLE unmapped_doc_type (
application_id uuid,
doc_type_id text,
metadata text,
PRIMARY KEY (application_id, doc_type_id)
)
CREATE TABLE unmapped_doc_type_counter (
application_id uuid,
doc_type_id text,
occurrences counter,
PRIMARY KEY (application_id, doc_type_id)
)

Table unmapped_doc_type has metadata for doc_type and
unmapped_doc_type_counter one has the number of occurences this doc type
was requested.
When I delete record in unmapped_doc_type I have to delete the same (same
values of application_id, doc_type_id) in unmapped_doc_type_counter table.
I am building DELETE statements using QueryBuilder, wrapping them into
com.datastax.driver.core.querybuilder.Batch as new Batch(statements, true)
and calling session.execute(batch) with this batch.

Previously I did it in a logged batch without any issues but upgrading from
Cassandra 1.2.x to 2.1 brings the following Exception message:
"Error executing batch. Message: Cannot include a counter statement in a
logged batch"
Sample of statement that fails:
"
BEGIN BATCH
DELETE FROM unmapped_doc_type
WHERE doc_type_id='567cfa05-aa41-4d4d-b65d-42dfd198ef2b' AND
application_id=41367e0c-5d6f-4b2f-897b-e25d6a52ee0e;
DELETE FROM unmapped_doc_type_counter
WHERE doc_type_id='567cfa05-aa41-4d4d-b65d-42dfd198ef2b' AND
application_id=41367e0c-5d6f-4b2f-897b-e25d6a52ee0e;
APPLY BATCH;
".

Question:
It looks like exception thrown from this line:

if (isLogged() && statement.isCounter()) throw new
InvalidRequestException("Cannot include a counter statement in a logged
batch");
<https://github.com/apache/cassandra/blob/trunk/src/java/org/apache/cassandra/cql3/statements/BatchStatement.java#L172>
Why does DELETE statement for the table containing counter field return
isCounter() == true?
Is it a bug or expected behavior?
Thank you,
Alexei.

Re: Can not delete record with counter column in a batch.

Posted by Michael Shuler <mi...@pbandjelly.org>.
On 10/13/2016 08:11 PM, Alexei Levashov wrote:
> Previously I did it in a logged batch without any issues but upgrading
> from Cassandra 1.2.x to 2.1 brings the following Exception message:
> "Error executing batch. Message: Cannot include a counter statement in a
> logged batch"
> 
> Question: 
> It looks like exception thrown from this line:
> 
> if (isLogged() && statement.isCounter()) throw new
> InvalidRequestException("Cannot include a counter statement in a logged
> batch");
> <https://github.com/apache/cassandra/blob/trunk/src/java/org/apache/cassandra/cql3/statements/BatchStatement.java#L172>
> Why does DELETE statement for the table containing counter field return
> isCounter() == true? 
> Is it a bug or expected behavior?

This appears to be expected behavior.

If you look at blame on the line you linked, it was commit ee401cf8
which you can follow to the commit:

https://github.com/apache/cassandra/commit/ee401cf8131a779069805cbe9ef4ab05d4a63b9a

Which notes: CASSANDRA-7351
 https://issues.apache.org/jira/browse/CASSANDRA-7351

It looks like you may use UNLOGGED batch.

-- 
Kind regards,
Michael