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-6426) Lost update in Prepared statement batch when a column is inserted with null value in the same batch just before
Date Sun, 01 Dec 2013 15:24:35 GMT

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

DOAN DuyHai commented on CASSANDRA-6426:
----------------------------------------

Another remark. I've activated TRACE logs on the Java Driver side, the Update statement has
been actually sent to the server, with no avail. So the bug is not on the driver side, definitely.

{noformat}
TRACE [16:22:53,377][] com.datastax.driver.core.Connection@:write [localhost/127.0.0.1-4]
writing request PREPARE INSERT INTO test(id,name,label) VALUES (?,?,?) 
TRACE [16:22:53,377][] com.datastax.driver.core.Connection@:operationComplete [localhost/127.0.0.1-4]
request sent successfully 
TRACE [16:22:53,378][] com.datastax.driver.core.Connection@:messageReceived [localhost/127.0.0.1-4]
received: RESULT PREPARED 0x64469dfa1bd873d7f7699d5c2a45a926 [id (bigint)][name (varchar)][label
(varchar)] (resultMetadata=[0 columns]) 
TRACE [16:22:53,378][] com.datastax.driver.core.RequestHandler@:sendRequest Querying node
localhost/127.0.0.1 
TRACE [16:22:53,378][] com.datastax.driver.core.Connection@:write [localhost/127.0.0.1-4]
writing request PREPARE UPDATE test SET label=? WHERE id=? 
TRACE [16:22:53,378][] com.datastax.driver.core.Connection@:operationComplete [localhost/127.0.0.1-4]
request sent successfully 
TRACE [16:22:53,379][] com.datastax.driver.core.Connection@:messageReceived [localhost/127.0.0.1-4]
received: RESULT PREPARED 0x56c1d23c0bdcb6a9c8b37c97ed625a99 [label (varchar)][id (bigint)]
(resultMetadata=[0 columns]) 
TRACE [16:22:53,381][] com.datastax.driver.core.RequestHandler@:sendRequest Querying node
localhost/127.0.0.1 
TRACE [16:22:53,381][] com.datastax.driver.core.Connection@:write [localhost/127.0.0.1-4]
writing request BATCH of [0x64469dfa1bd873d7f7699d5c2a45a926 with 3 values, 0x56c1d23c0bdcb6a9c8b37c97ed625a99
with 2 values] at consistency ONE 
TRACE [16:22:53,382][] com.datastax.driver.core.Connection@:operationComplete [localhost/127.0.0.1-4]
request sent successfully 
WARN  [16:22:53,385][] org.apache.cassandra.utils.FBUtilities@:cassandraTriggerDir Trigger
directory doesn't exist, please create it and try again. 
TRACE [16:22:53,393][] com.datastax.driver.core.Connection@:messageReceived [localhost/127.0.0.1-4]
received: EMPTY RESULT 
TRACE [16:22:53,393][] com.datastax.driver.core.RequestHandler@:sendRequest Querying node
localhost/127.0.0.1 
TRACE [16:22:53,393][] com.datastax.driver.core.Connection@:write [localhost/127.0.0.1-4]
writing request QUERY SELECT * from test where id=3313921234424226448([cl=ONE, vals=[], skip=false,
psize=5000, state=null, serialCl=SERIAL]) 
TRACE [16:22:53,393][] com.datastax.driver.core.Connection@:operationComplete [localhost/127.0.0.1-4]
request sent successfully 
TRACE [16:22:53,396][] com.datastax.driver.core.Connection@:messageReceived [localhost/127.0.0.1-4]
received: ROWS [id (bigint)][label (varchar)][name (varchar)]
 | 3313921234424226448 | null | myName
--- 
{noformat}

> Lost update in Prepared statement batch when a column is inserted with null value in
the same batch just before
> ---------------------------------------------------------------------------------------------------------------
>
>                 Key: CASSANDRA-6426
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-6426
>             Project: Cassandra
>          Issue Type: Bug
>          Components: Core
>         Environment: Cassandra Server 2.0.3
> Java Driver Core 2.0.0-rc1
>            Reporter: DOAN DuyHai
>
> {panel:title=Test environment}
> Cassandra Server *2.0.3*
> Java Driver Core *2.0.0-rc1*
> {panel}
> While implementing batched prepared statements for Achilles, I ran into a very annoying
bug.
> {code:title=FailingUnitTest.java|borderStyle=solid}
> //Given
> Long id = RandomUtils.nextLong();
> session.execute("CREATE TABLE test(id bigint, name text,label text, PRIMARY KEY(id))");
> PreparedStatement insertPS = session.prepare("INSERT INTO test(id,name,label) VALUES
(?,?,?)");
> PreparedStatement updatePS = session.prepare("UPDATE test SET label=? WHERE id=?");
> // Notice the "label" column is inserted first with null
> BoundStatement insertBS = insertPS.bind(id, "myName", null);
> // Then "label" is updated to "myLabel"
> BoundStatement updateBS = updatePS.bind("myLabel", id);
> //When
> BatchStatement batch = new BatchStatement();
> batch.add(updateBS);
> batch.add(insertBS);
> session.execute(batch);
> //Then
> Statement statement = new SimpleStatement("SELECT * from test where id=" + id);
> Row row = manager.getNativeSession().execute(statement).one();
> // Assertion FAIL, "label" is NULL
> assertThat(row.getString("label")).isEqualTo("myLabel");
> {code}
>  The above code always fails.
>  Even if I switch the order of the bound statements, e.g. *updateBS* added to the batch
before *insertBS*, the test still fails.
> {code:title=WorkingUnitTest.java|borderStyle=solid}
> //Given
> Long id = RandomUtils.nextLong();
> session.execute("CREATE TABLE test(id bigint, name text,label text, PRIMARY KEY(id))");
> PreparedStatement insertPS = session.prepare("INSERT INTO test(id,name) VALUES (?,?)");
> PreparedStatement updatePS = session.prepare("UPDATE test SET label=? WHERE id=?");
> // Notice the "label" column is removed from the insert statement
> BoundStatement insertBS = insertPS.bind(id, "myName");
> BoundStatement updateBS = updatePS.bind("myLabel", id);
> //When
> BatchStatement batch = new BatchStatement();
> batch.add(updateBS);
> batch.add(insertBS);
> session.execute(batch);
> //Then
> Statement statement = new SimpleStatement("SELECT * from test where id=" + id);
> Row row = manager.getNativeSession().execute(statement).one();
> // Assertion SUCCEEDS here
> assertThat(row.getString("label")).isEqualTo("myLabel");
> {code}
>  Only removing column "label" from the first insert bound statement can make the test
succeed. This is pretty annoying. 
>  The rationale for inserting null values is that in Achilles I prepare generic insert
statements for all entities and setting NULL when the field is not filled at runtime.
>  Currently, there is no guarantee for batch of prepared statement to be executed in the
order they are declared.



--
This message was sent by Atlassian JIRA
(v6.1#6144)

Mime
View raw message