{"comment":{"created_at":"2011-10-10T21:02:44Z","body":"Fixed on 0.8.0, master and 1.0-upgrade branch.","updated_at":"2011-10-10T21:02:44Z","url":"https://api.github.com/repos/rantav/hector/issues/comments/2352182","id":2352182,"user":{"avatar_url":"https://secure.gravatar.com/avatar/5b4123fdaaef44abe5cc1f33304444bc?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","url":"https://api.github.com/users/patricioe","id":250893,"login":"patricioe"}},"action":"created","issue":{"number":299,"created_at":"2011-10-10T09:01:31Z","pull_request":{"diff_url":null,"patch_url":null,"html_url":null},"body":"I originally created this issue in the Cassandra project, but the issue was closed with the comment that the real issue is in Hector, not Cassandra. So this is copy from the original issue in Cassandra:\r\nhttps://issues.apache.org/jira/browse/CASSANDRA-3339\r\n-----\r\nFirst of all; I'm quite new to Cassandra, so I hope that my analysis is correct. \r\nI am using the Hector client to perform queries on Cassandra. The problem is that once I invoked an invalid slice query with a null rowKey, subsequent queries also fail with roughly the same error. So the first time I invoke the invalid query, I get this exception:\r\n\r\norg.apache.thrift.protocol.TProtocolException: Required field 'key' was not present! \r\nStruct: get_slice_args(key:null, column_parent:ColumnParent(column_family:AmdatuToken), predicate:SlicePredicate(slice_range:SliceRange(start:, finish:, reversed:false, count:1000000)), consistency_level:ONE)\r\n       at me.prettyprint.cassandra.service.ExceptionsTranslatorImpl.translate(ExceptionsTranslatorImpl.java:56)\r\n       at me.prettyprint.cassandra.service.KeyspaceServiceImpl$7.execute(KeyspaceServiceImpl.java:285)\r\n       at me.prettyprint.cassandra.service.KeyspaceServiceImpl$7.execute(KeyspaceServiceImpl.java:268)\r\n       ...\r\n\r\nwhich is expected behavior. However, after invoking this invalid query, subsequent valid calls also fail with roughly the same error:\r\n\r\nme.prettyprint.hector.api.exceptions.HCassandraInternalException: Cassandra encountered an internal error processing this request: TApplicationError type: 7 message:Required field 'key' was not present! Struct: get_slice_args(key:null, column_parent:null, predicate:null, consistency_level:ONE) \r\norg.apache.felix.log.LogException: me.prettyprint.hector.api.exceptions.HCassandraInternalException: \r\nCassandra encountered an internal error processing this request: TApplicationError type: 7 message:Required field 'key' was not present! Struct: get_slice_args(key:null, column_parent:null, predicate:null, consistency_level:ONE)\r\n        at me.prettyprint.cassandra.service.ExceptionsTranslatorImpl.translate(ExceptionsTranslatorImpl.java:29)\r\n        at me.prettyprint.cassandra.service.KeyspaceServiceImpl$2.execute(KeyspaceServiceImpl.java:121)\r\n        at me.prettyprint.cassandra.service.KeyspaceServiceImpl$2.execute(KeyspaceServiceImpl.java:114)\r\n        ...\r\n\r\nIn the case of Hector it goes downhill from there, ending in socket write errors and marking the Cassandra host as being down.\r\n\r\nNow this is what I think happens:\r\nThe Hector client uses the org.apache.cassandra.thrift.Cassandra.Client class to execute the queries on Cassandra.\r\nWhen I perform a Thrift slice query from Hector, it invokes the get_slice method in the Cassandra.Client, which in its turn invokes send_get_slice. In my case a bug in my own software caused an invocation of this method with a rowKey that equals null. Now although the rowKey is invalid, the method call continues all the way to send_get_slice. This send_get_slice method looks like this:\r\n\r\n(from org.apache.cassandra.thrift.Cassandra)\r\npublic void send_get_slice(ByteBuffer key, ColumnParent column_parent, SlicePredicate predicate, ConsistencyLevel consistency_level) throws org.apache.thrift.TException\r\n{\r\n  oprot_.writeMessageBegin(new org.apache.thrift.protocol.TMessage(\"get_slice\", org.apache.thrift.protocol.TMessageType.CALL, ++seqid_));\r\n  get_slice_args args = new get_slice_args();\r\n  args.setKey(key);\r\n  args.setColumn_parent(column_parent);\r\n  args.setPredicate(predicate);\r\n  args.setConsistency_level(consistency_level);\r\n  args.write(oprot_);\r\n  oprot_.writeMessageEnd();\r\n  oprot_.getTransport().flush();\r\n}\r\n\r\nThe problem is that the TMessage is written to the output protocol at the first line. When subsequently the arguments are written in args.write(oprot_), it first calls validate(). The validate() method detects the null rowKey and throws an exception:\r\n\r\npublic void validate() throws org.apache.thrift.TException {\r\n  // check for required fields\r\n  if (key == null) {\r\n    throw new org.apache.thrift.protocol.TProtocolException(\"Required field 'key' was not present! Struct: \" + toString());\r\n  }\r\n  ...\r\n}\r\n    \r\nNow Hector finally catches the exception and returns the Cassandra client to its connection pool. When that Cassandra client is drawn from the pool and reused for another query, it still has the TMessage written to its oprot, resulting in another failed call. Call reusing this client from the connection pool keep getting such errors, and in the end result in socket write errors.\r\n\r\nThe problem is not only restricted to this particular method by the way, the same construct is used in many more methods in this class. Also passing a null value for columnsPath or ConsistencyLevel seems to cause the same issue.\r\n","comments":2,"title":"Invalid queries from KeyspaceServiceImpl causes subsequent, valid, queries to fail","updated_at":"2011-10-10T21:02:44Z","url":"https://api.github.com/repos/rantav/hector/issues/299","id":1861859,"assignee":{"avatar_url":"https://secure.gravatar.com/avatar/5b4123fdaaef44abe5cc1f33304444bc?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","url":"https://api.github.com/users/patricioe","id":250893,"login":"patricioe"},"milestone":null,"closed_at":"2011-10-10T21:02:44Z","user":{"avatar_url":"https://secure.gravatar.com/avatar/2ed69ff168f4fe993fecb8424e232bcb?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","url":"https://api.github.com/users/Ivol","id":1115814,"login":"Ivol"},"html_url":"https://github.com/rantav/hector/issues/299","labels":[],"state":"closed"},"legacy":{"issue_id":1861859,"comment_id":2352182}}