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

Avoid unnecessary String.format in QueryProcessor when getting stored prepared statement

    XMLWordPrintableJSON

Details

    Description

      In the QueryProcessor#getStoredPreparedStatement if the statement is found in the prepared statements cache, there is always unnecessary string creation using String.format in order to execute the checkTrue assertion. The string construction is necessary only when the queries are not equal.

      public static ResultMessage.Prepared getStoredPreparedStatement(String queryString, String clientKeyspace)
      throws InvalidRequestException
      {
          MD5Digest statementId = computeId(queryString, clientKeyspace);
          Prepared existing = preparedStatements.getIfPresent(statementId);
          if (existing == null)
              return null;
      
          checkTrue(queryString.equals(existing.rawCQLStatement),
                  String.format("MD5 hash collision: query with the same MD5 hash was already prepared. \n Existing: '%s'", existing.rawCQLStatement));
       

      Hopefully the JIT can optimize this once the checkTrue is inlined, but it's getting on my nerves as it's popping up on my flame graphs all the time.

       

      Attachments

        Activity

          People

            ivansenic Ivan Senic
            ivansenic Ivan Senic
            Ivan Senic
            Benjamin Lerer, Brandon Williams, Stefan Miklosovic
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 0.5h
                0.5h