[ 
https://issues.apache.org/jira/browse/CASSANDRA-14304?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16438908#comment-16438908
 ] 

Kurt Greaves edited comment on CASSANDRA-14304 at 4/16/18 1:20 AM:
-------------------------------------------------------------------

Fairly sure this is expected behaviour.
If you want to maintain linearizable consistency you need to also issue the 
DELETE as a LWT. If you don't there is no guarantee that the INSERT will come 
before the DELETE. I believe this is still the case when you have only 1 node, 
but regardless even if you didn't have one node you'd still want to issue the 
DELETE with IF EXISTS in an actual cluster otherwise you'll be even more prone 
to this problem.

For example:
{code}
CREATE KEYSPACE ks WITH REPLICATION = { 'class' : 'SimpleStrategy', 
'replication_factor' : 1 };
CREATE TABLE ks.ta ( id text PRIMARY KEY, col text );
INSERT INTO ks.ta (id, col) VALUES ('myId', 'myCol') IF NOT EXISTS;
CONSISTENCY QUORUM;
DELETE FROM ks.ta WHERE id = 'myId' IF EXISTS;
SELECT * FROM ks.ta WHERE id='myId';
{code}

bq. Then, if I do DELETE USING TIMESTAMP strictly inferior to the value, the 
row is not deleted, and
if I do it with a superior value, the row is correctly deleted.
This is expected, as you've ensured a timestamp for the tombstone is greater 
than the writetime of the row.

bq. It is necessary to synchronize all the server clocks, but as far as I know, 
this requirement does not apply to the client machine, or does it ?
It only applies to the servers unless you were using timestamps generated from 
the clients (e.g: with USING TIMESTAMP)




was (Author: kurtg):
Fairly sure this is expected behaviour.
If you want to maintain linearizable consistency you need to also issue the 
DELETE as a LWT. If you don't there is no guarantee that the INSERT will come 
before the DELETE. I believe this is still the case when you have only 1 node, 
but regardless even if you didn't have one node you'd still want to issue the 
DELETE with IF EXISTS in an actual cluster otherwise you'll be even more prone 
to this problem.

For example:
{code}
CREATE KEYSPACE ks WITH REPLICATION = { 'class' : 'SimpleStrategy', 
'replication_factor' : 1 };
CREATE TABLE ks.ta ( id text PRIMARY KEY, col text );
INSERT INTO ks.ta (id, col) VALUES ('myId', 'myCol') IF NOT EXISTS;
CONSISTENCY QUORUM;
DELETE FROM ks.ta WHERE id = 'myId' IF EXISTS;
SELECT * FROM ks.ta WHERE id='myId';
{code}

bq. Then, if I do DELETE USING TIMESTAMP strictly inferior to the value, the 
row is not deleted, and
if I do it with a superior value, the row is correctly deleted.
This is expected, as you've ensured a timestamp for the tombstone is greater 
than the writetime of the row.



> DELETE after INSERT IF NOT EXISTS does not work
> -----------------------------------------------
>
>                 Key: CASSANDRA-14304
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-14304
>             Project: Cassandra
>          Issue Type: Bug
>          Components: Core
>            Reporter: Julien
>            Assignee: Vinay Chella
>            Priority: Major
>         Attachments: debug.log, system.log
>
>
> DELETE a row immediately after INSERT IF NOT EXISTS does not work.
> Can be reproduced with this CQL script:
> {code:java}
> CREATE KEYSPACE ks WITH REPLICATION = { 'class' : 'SimpleStrategy', 
> 'replication_factor' : 1 };
> CREATE TABLE ks.ta ( id text PRIMARY KEY, col text );
> INSERT INTO ks.ta (id, col) VALUES ('myId', 'myCol') IF NOT EXISTS;
> DELETE FROM ks.ta WHERE id = 'myId';
> SELECT * FROM ks.ta WHERE id='myId';
> {code}
> {code:java}
> [cqlsh 5.0.1 | Cassandra 3.11.2 | CQL spec 3.4.4 | Native protocol v4]
> Use HELP for help.
> WARNING: pyreadline dependency missing.  Install to enable tab completion.
> cqlsh> CREATE KEYSPACE ks WITH REPLICATION = { 'class' : 'SimpleStrategy', 
> 'replication_factor' : 1 };
> cqlsh> CREATE TABLE ks.ta ( id text PRIMARY KEY, col text );
> cqlsh> INSERT INTO ks.ta (id, col) VALUES ('myId', 'myCol') IF NOT EXISTS;
>  [applied]
> -----------
>       True
> cqlsh> DELETE FROM ks.ta WHERE id = 'myId';
> cqlsh> SELECT * FROM ks.ta WHERE id='myId';
>  id   | col
> ------+-------
>  myId | myCol
> {code}
>  * Only happens if the client is on a different host (works as expected on 
> the same host)
>  * Works as expected without IF NOT EXISTS
>  * A ~500 ms delay between INSERT and DELETE fixes the issue.
> Logs attached.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to