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

Sylvain Lebresne commented on CASSANDRA-4202:
---------------------------------------------

Depends what you mean by that :). To some extent it's an artifact of how we 
index bound variables in the parser. What happened is that the parser computes 
the index of the prepared variables (incrementing the index while parsing each 
time it sees a bound variable) and only the top-level statement knows how many 
variables there is at the end. For a batch, it means that individual 
inserts/deletes inside a batch needs to refer to the batch to know how many 
variables there is in total, which is what was not done. I don't know how clear 
that is and if I have answered your question though.  
                
> CQL 3.0 prepare_cql_query fails on "BEGIN BATCH"
> ------------------------------------------------
>
>                 Key: CASSANDRA-4202
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-4202
>             Project: Cassandra
>          Issue Type: Bug
>          Components: API
>    Affects Versions: 1.1.0
>         Environment: OSX 10.7.2, Cassandra 1.1.0, Thrift 0.7
>            Reporter: Sean Billig
>            Assignee: Sylvain Lebresne
>            Priority: Minor
>              Labels: c++, cql3, thrift
>             Fix For: 1.1.1
>
>         Attachments: 4202.txt
>
>
> Preparing the following (contrived) statement with the C++ Thrift bindings 
> throws a TTransportException ("No more data to read." from TTransport.h:41)
> q = "begin batch insert into crashtest (id, val) values (?, ?); apply batch";
> client.prepare_cql_query(pr, q, Compression::NONE);
> {code:title=crashtest.cpp}
> #include <protocol/TBinaryProtocol.h>
> #include <thrift/transport/TSocket.h>
> #include <thrift/transport/TTransportUtils.h>
> #include "Cassandra.h"
> using namespace std;
> using namespace apache::thrift;
> using namespace apache::thrift::protocol;
> using namespace apache::thrift::transport;
> using namespace org::apache::cassandra;
> using namespace boost;
> int main(int argc, char **argv) {
>     shared_ptr<TTransport> socket(new TSocket("127.0.0.1", 9160));
>     shared_ptr<TTransport> transport(new TFramedTransport(socket));
>     shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
>     CassandraClient client(protocol);
>     try {
>         transport->open();
>         client.set_keyspace("test1");
>         client.set_cql_version("3.0.0");
>         CqlResult cr;
>         CqlPreparedResult pr;
>         // In cqlsh: create table crashtest (id int primary key, val text);
>         const char *q;
>         // q = "insert into crashtest (id, val) values (?, ?)"; // This works 
> fine
>         q = "begin batch insert into crashtest (id, val) values (?, ?); apply 
> batch";
>         client.prepare_cql_query(pr,  q, Compression::NONE);
>         vector<string> vtypes = pr.variable_types;
>         vector<string>::iterator it;
>         for (it = vtypes.begin(); it != vtypes.end(); it++) {
>             cout << *it << endl;
>         }
>     } catch (TException &tx) {
>         cerr << "TException ERROR: " << tx.what() << endl;
>     }
> }
> {code}
> {code:title=backtrace}
> #0  0x00007fff901800e9 in __cxa_throw ()
> #1  0x0000000100009ab9 in 
> apache::thrift::transport::readAll<apache::thrift::transport::TBufferBase> 
> (trans=@0x100401100, buf=0x7fff5fbfefc0 "??_\001", len=4) at TTransport.h:41
> #2  0x0000000100009c1d in apache::thrift::transport::TBufferBase::readAll 
> (this=0x100401100, buf=0x7fff5fbfefc0 "??_\001", len=4) at 
> TBufferTransports.h:82
> #3  0x0000000100009c5b in 
> apache::thrift::transport::TFramedTransport::readAll (this=0x100401100, 
> buf=0x7fff5fbfefc0 "??_\001", len=4) at TBufferTransports.h:390
> #4  0x0000000100004b45 in 
> apache::thrift::transport::TVirtualTransport<apache::thrift::transport::TFramedTransport,
>  apache::thrift::transport::TBufferBase>::readAll_virt (this=0x100401100, 
> buf=0x7fff5fbfefc0 "??_\001", len=4) at TVirtualTransport.h:99
> #5  0x00000001000034c1 in apache::thrift::transport::TTransport::readAll 
> (this=0x100401100, buf=0x7fff5fbfefc0 "??_\001", len=4) at TTransport.h:126
> #6  0x0000000100009f4c in 
> apache::thrift::protocol::TBinaryProtocolT<apache::thrift::transport::TTransport>::readI32
>  (this=0x100401370, i32=@0x7fff5fbff020) at TBinaryProtocol.h:372
> #7  0x000000010000b5bf in 
> apache::thrift::protocol::TBinaryProtocolT<apache::thrift::transport::TTransport>::readMessageBegin
>  (this=0x100401370, name=@0x7fff5fbff228, messageType=@0x7fff5fbff224, 
> seqid=@0x7fff5fbff234) at TBinaryProtocol.h:203
> #8  0x0000000100006b07 in 
> apache::thrift::protocol::TVirtualProtocol<apache::thrift::protocol::TBinaryProtocolT<apache::thrift::transport::TTransport>,
>  apache::thrift::protocol::TProtocolDefaults>::readMessageBegin_virt 
> (this=0x100401370, name=@0x7fff5fbff228, messageType=@0x7fff5fbff224, 
> seqid=@0x7fff5fbff234) at TVirtualProtocol.h:432
> #9  0x00000001000abe78 in 
> apache::thrift::protocol::TProtocol::readMessageBegin (this=0x100401370, 
> name=@0x7fff5fbff228, messageType=@0x7fff5fbff224, seqid=@0x7fff5fbff234) at 
> TProtocol.h:518
> #10 0x0000000100069a98 in 
> org::apache::cassandra::CassandraClient::recv_prepare_cql_query 
> (this=0x7fff5fbff5b0, _return=@0x7fff5fbff4c0) at Cassandra.cpp:10231
> #11 0x000000010003bf3f in 
> org::apache::cassandra::CassandraClient::prepare_cql_query 
> (this=0x7fff5fbff5b0, _return=@0x7fff5fbff4c0, query=@0x7fff5fbff6b0, 
> compression=org::apache::cassandra::Compression::NONE) at Cassandra.cpp:10206
> #12 0x00000001000020ea in main (argc=1, argv=0x7fff5fbff8c8) at 
> crashtest.cpp:36
> {code}
> {code:title=server error message}
> ERROR 17:13:55,089 Error occurred during processing of message.
> java.lang.ArrayIndexOutOfBoundsException: 0
>       at 
> org.apache.cassandra.cql3.statements.UpdateStatement.prepare(UpdateStatement.java:278)
>       at 
> org.apache.cassandra.cql3.statements.BatchStatement.prepare(BatchStatement.java:157)
>       at 
> org.apache.cassandra.cql3.QueryProcessor.getStatement(QueryProcessor.java:207)
>       at 
> org.apache.cassandra.cql3.QueryProcessor.prepare(QueryProcessor.java:158)
>       at 
> org.apache.cassandra.thrift.CassandraServer.prepare_cql_query(CassandraServer.java:1260)
>       at 
> org.apache.cassandra.thrift.Cassandra$Processor$prepare_cql_query.getResult(Cassandra.java:3484)
>       at 
> org.apache.cassandra.thrift.Cassandra$Processor$prepare_cql_query.getResult(Cassandra.java:3472)
>       at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:32)
>       at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:34)
>       at 
> org.apache.cassandra.thrift.CustomTThreadPoolServer$WorkerProcess.run(CustomTThreadPoolServer.java:186)
>       at 
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
>       at 
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
>       at java.lang.Thread.run(Thread.java:680)
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to