Alexander Ryabets created CASSANDRA-11570:
---------------------------------------------

             Summary: Concurrent execution of prepared statement returns 
invalid JSON as result
                 Key: CASSANDRA-11570
                 URL: https://issues.apache.org/jira/browse/CASSANDRA-11570
             Project: Cassandra
          Issue Type: Bug
         Environment: Cassandra 3.2, C++ or C# driver
            Reporter: Alexander Ryabets
         Attachments: CassandraPreparedStatementsTest.zip, test_neptunao.cql

When I use prepared statement for async execution of multiple statements I get 
JSON with broken data. Keys got totally corrupted when values seems to be 
normal though.

First I encoutered this issue when I were performing stress testing of our 
project using custom script. We are using DataStax C++ driver and execute 
statements from different fibers.

Then I was trying to isolate problem and wrote simple C# program which starts 
multiple Tasks in a loop. Each task uses the once created prepared statement to 
read data from the base. As you can see results are totally mess.

I 've attached archive with console C# project (1 cs file) which just print 
resulting JSON to user. 
Here is the main part of C# code.

{noformat}
    static void Main(string[] args)
    {
      const int task_count = 300;

      using(var cluster = 
Cluster.Builder().AddContactPoints("127.0.0.1").Build())
      {
        using(var session = cluster.Connect())
        {
          var prepared = session.Prepare("select json * from 
test_neptunao.ubuntu");
          var tasks = new Task[task_count];
          for(int i = 0; i < task_count; i++)
          {
            tasks[i] = Query(prepared, session);
          }
          Task.WaitAll(tasks);
        }
      }
      Console.ReadKey();
    }

    private static Task Query(PreparedStatement prepared, ISession session)
    {
      var stmt = prepared.Bind();
      stmt.SetConsistencyLevel(ConsistencyLevel.One);
      return session.ExecuteAsync(stmt).ContinueWith(tr =>
      {
        foreach(var row in tr.Result)
        {
          var value = row.GetValue<string>(0);
          Console.WriteLine(value);
        }
      });
    }
{noformat}

I also attached cql script with test DB schema.

{noformat}
CREATE KEYSPACE IF NOT EXISTS test_neptunao
WITH replication = {
        'class' : 'SimpleStrategy',
        'replication_factor' : 3
};

use test_neptunao;

create table if not exists ubuntu (
        id timeuuid PRIMARY KEY,
        precise_pangolin text,
        trusty_tahr text,
        wily_werewolf text,     
        vivid_vervet text,
        saucy_salamander text,
        lucid_lynx text
);
{noformat}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to