cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "DOAN DuyHai (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CASSANDRA-7499) Unable to update list element by index using CAS condition
Date Mon, 07 Jul 2014 13:14:34 GMT

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

DOAN DuyHai commented on CASSANDRA-7499:
----------------------------------------

You're right, the issue is the same on Cassandra *2.0.8*.

 I said that the test passed in 2.0.8, indeed it was not the same test. When the CAS update
occurs in a *batch statement*, it works. It looks like we have some funny bug here:

{code:java}
@Test
    public void test_fail() throws Exception {
        //Given
        final Session session = manager.getNativeSession();

        session.execute("CREATE TABLE cas_update(id int PRIMARY KEY,name text,friends list<text>)");
        session.execute("INSERT INTO cas_update (id, name , friends ) VALUES ( 10,'John',['Paul','George'])");

        // When
        session.execute("UPDATE cas_update SET friends[0]='Helen' WHERE id=10 IF name='John'");

        //Then
        final Row row = session.execute("SELECT * FROM cas_update WHERE id=10").one();
        assertThat(row.getList("friends",String.class)).containsExactly("Helen","George");
    }

    @Test
    public void test_pass() throws Exception {
        //Given

        final Session session = manager.getNativeSession();

        session.execute("CREATE TABLE cas_update(id int PRIMARY KEY,name text,friends list<text>)");
        session.execute("INSERT INTO cas_update (id, name , friends ) VALUES ( 10,'John',['Paul','George'])");

        final BatchStatement batch = new BatchStatement(BatchStatement.Type.UNLOGGED);
        final SimpleStatement statement1 = new SimpleStatement("UPDATE cas_update SET friends[0]='Helen'
WHERE id=10 IF name='John'");
        final SimpleStatement statement2 = new SimpleStatement("UPDATE cas_update SET friends[1]=null
WHERE id=10 IF name='John'");
        batch.add(statement1).add(statement2);
        session.execute(batch);

        //When
        final Row row = session.execute("SELECT * FROM cas_update WHERE id=10").one();

        //Then
        assertThat(row.getList("friends",String.class)).containsExactly("Helen");
    }
{code}

> Unable to update list element by index using CAS condition
> ----------------------------------------------------------
>
>                 Key: CASSANDRA-7499
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-7499
>             Project: Cassandra
>          Issue Type: Bug
>          Components: Core
>         Environment: Cassandra *2.0.9*, Java Driver *2.0.2* & *2.0.3*
> Client: cqlsh *3.1.8*, CQL spec *3.1.0*, Thrift protocol *19.39.0*
>            Reporter: DOAN DuyHai
>             Fix For: 2.0.10
>
>
> While running IT tests for *Achilles*, I ran into a strange bug:
> *With CQLSH*
> {code:sql}
> cqlsh:test> CREATE TABLE cas_update(id int PRIMARY KEY,name text,friends list<text>);
> cqlsh:test> INSERT INTO cas_update (id, name , friends ) VALUES ( 10,'John',['Paul','George']);
> cqlsh:test> SELECT * FROM cas_update WHERE id=10;
>  id | friends            | name
> ----+--------------------+------
>  10 | ['Paul', 'George'] | John
> cqlsh:test> UPDATE cas_update SET friends[0]='Helen' WHERE id=10 IF name='John';
> Bad Request: List index 0 out of bound, list has size 0
> cqlsh:test> UPDATE cas_update SET friends[0]='Helen' WHERE id=10;
> cqlsh:test> SELECT * FROM cas_update WHERE id=10;
>  id | friends             | name
> ----+---------------------+------
>  10 | ['Helen', 'George'] | John
> {code}
> It seems that we cannot update list element by index with a CAS condition.
> *With Java driver 2.0.2 or 2.0.3*
> {code:java}
>  ACHILLES_DML_STATEMENT@:writeDMLStatementLog Prepared statement : [INSERT INTO CompleteBean(id,followers,friends,name,preferences)
VALUES (:id,:followers,:friends,:name,:preferences) USING TTL :ttl;] with CONSISTENCY LEVEL
[ONE] 
>  ACHILLES_DML_STATEMENT@:writeDMLStatementLog    bound values : [621309709026375591,
[], [Paul, Andrew], John, {}, 0] 
>  ACHILLES_DML_STATEMENT@:writeDMLStartBatch  
>  ACHILLES_DML_STATEMENT@:writeDMLStartBatch  
>  ACHILLES_DML_STATEMENT@:writeDMLStartBatch ****** BATCH UNLOGGED START ****** 
>  ACHILLES_DML_STATEMENT@:writeDMLStartBatch  
>  ACHILLES_DML_STATEMENT@:writeDMLStatementLog Parameterized statement : [UPDATE CompleteBean
USING TTL 100 SET friends[0]=? WHERE id=621309709026375591 IF name=?;] with CONSISTENCY LEVEL
[ONE] 
>  ACHILLES_DML_STATEMENT@:writeDMLStatementLog    bound values : [100, 0, Helen, 621309709026375591,
John] 
>  ACHILLES_DML_STATEMENT@:writeDMLStatementLog Parameterized statement : [UPDATE CompleteBean
USING TTL 100 SET friends[1]=null WHERE id=621309709026375591 IF name=?;] with CONSISTENCY
LEVEL [ONE] 
>  ACHILLES_DML_STATEMENT@:writeDMLStatementLog    bound values : [100, 1, null, 621309709026375591,
John] 
>  ACHILLES_DML_STATEMENT@:writeDMLEndBatch  
>  ACHILLES_DML_STATEMENT@:writeDMLEndBatch   ****** BATCH UNLOGGED END with CONSISTENCY
LEVEL [DEFAULT] ****** 
>  ACHILLES_DML_STATEMENT@:writeDMLEndBatch  
>  ACHILLES_DML_STATEMENT@:writeDMLEndBatch  
>  ACHILLES_DML_STATEMENT@:truncateTable   Simple query : [TRUNCATE entity_with_enum] with
CONSISTENCY LEVEL [ALL] 
>  ACHILLES_DML_STATEMENT@:truncateTable   Simple query : [TRUNCATE CompleteBean] with
CONSISTENCY LEVEL [ALL] 
> com.datastax.driver.core.exceptions.InvalidQueryException: List index 0 out of bound,
list has size 0
>         at com.datastax.driver.core.exceptions.InvalidQueryException.copy(InvalidQueryException.java:35)
>         at com.datastax.driver.core.DefaultResultSetFuture.extractCauseFromExecutionException(DefaultResultSetFuture.java:256)
>         at com.datastax.driver.core.DefaultResultSetFuture.getUninterruptibly(DefaultResultSetFuture.java:172)
>         at com.datastax.driver.core.AbstractSession.execute(AbstractSession.java:52)
> {code}
> With Cassandra *2.0.8* and Java Driver 2.0.2 or 2.0.3, *the test passed* so it seems
that there is a regression somewhere in the CAS update code



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Mime
View raw message