Uploaded image for project: 'Cassandra'
  1. Cassandra
  2. CASSANDRA-14539

cql2 insert/update/batch statements don't function unless the keyspace is specified in the statement

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Normal
    • Resolution: Won't Fix
    • Fix Version/s: 2.1.x
    • Component/s: Legacy/CQL
    • Labels:
      None
    • Severity:
      Normal

      Description

      If you perform a cql2 insert/update or batch statement without a keyspace, the following assertion will occur:

      java.lang.AssertionError: null
      at org.apache.cassandra.config.Schema.getCFMetaData(Schema.java:243) ~[apache-cassandra-2.1.20.jar:2.1.20]
      at org.apache.cassandra.cql.Attributes.maybeApplyExpirationDateOverflowPolicy(Attributes.java:81) ~[apache-cassandra-2.1.20.jar:2.1.20]
      at org.apache.cassandra.cql.AbstractModification.getTimeToLive(AbstractModification.java:95) ~[apache-cassandra-2.1.20.jar:2.1.20]
      at org.apache.cassandra.cql.UpdateStatement.mutationForKey(UpdateStatement.java:201) ~[apache-cassandra-2.1.20.jar:2.1.20]
      at org.apache.cassandra.cql.UpdateStatement.prepareRowMutations(UpdateStatement.java:154) ~[apache-cassandra-2.1.20.jar:2.1.20]
      at org.apache.cassandra.cql.UpdateStatement.prepareRowMutations(UpdateStatement.java:125) ~[apache-cassandra-2.1.20.jar:2.1.20]
      at org.apache.cassandra.cql.QueryProcessor.processStatement(QueryProcessor.java:544) ~[apache-cassandra-2.1.20.jar:2.1.20]
      at org.apache.cassandra.cql.QueryProcessor.process(QueryProcessor.java:802) ~[apache-cassandra-2.1.20.jar:2.1.20]
      at org.apache.cassandra.thrift.CassandraServer.execute_cql_query(CassandraServer.java:1962) ~[apache-cassandra-2.1.20.jar:2.1.20]
      at org.apache.cassandra.thrift.Cassandra$Processor$execute_cql_query.getResult(Cassandra.java:4558) ~[apache-cassandra-thrift-2.1.20.jar:2.1.20]
      at org.apache.cassandra.thrift.Cassandra$Processor$execute_cql_query.getResult(Cassandra.java:4542) ~[apache-cassandra-thrift-2.1.20.jar:2.1.20]
      at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:39) ~[libthrift-0.9.2.jar:0.9.2]
      at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:39) ~[libthrift-0.9.2.jar:0.9.2]
      at org.apache.cassandra.thrift.CustomTThreadPoolServer$WorkerProcess.run(CustomTThreadPoolServer.java:206) ~[apache-cassandra-2.1.20.jar:2.1.20]
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_151]
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_151]

       

      It will fail with:

          use test;

          update users set 'test'='{"d":1529683115340}' where key='c426f519100da4cb24417bc87c5bfbd6' ;

      But will work fine with:

          update test.users set 'test'='{"d":1529683115340}' where key='c426f519100da4cb24417bc87c5bfbd6' ;

       

      Going through the code, looks like this was introduced with https://issues.apache.org/jira/browse/CASSANDRA-14092 in February 2018.

      In org.apache.cassandra.cql.AbstractNotification.getTimeToLive(), and org.apache.cassandra.cql.BatchStatement.getTimeToLive()

      cassandra is using the keyspace associated with the update statement, which is set to null if its not in the query itself.

      I resolved this myself locally by changing the getTimeToLive() methods to take a default keyspace, and use that if it is unavailable on the statement.  The fix looked fairly simple.  I've attached my diff.

      P.S. Yes, I realize that cql2 is deprecated, and no longer supported, however I wanted to get this regression in if someone else hits it as I was unable to find any other reports for this issue.

       

       

        Attachments

        1. cql2.diff
          3 kB
          Michael Theroux

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              mtheroux2 Michael Theroux
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: