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

Replace uses of AttributeKey.newInstance with AttributeKey.valueOf in cassandra-java-driver

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Needs Committer
    • Normal
    • Resolution: Unresolved
    • None
    • Client/java-driver
    • None
    • Code - Bug - Unclear Impact
    • Low
    • Low Hanging Fruit
    • User Report
    • All
    • None
    • Hide

      While the change is somewhat straightforward, i'd like to run the full integration test at least locally, and also familiarize myself with whatever testing options we have for the driver.

      Show
      While the change is somewhat straightforward, i'd like to run the full integration test at least locally, and also familiarize myself with whatever testing options we have for the driver.

    Description

      The java driver uses netty channel attributes to decorate a connection's channel with the cluster name (returned from the system.local table) and the map from the OPTIONS response, both of which are obtained on connection initialization.

      There's an issue here that I wouldn't expect to see in practice in that the AttributeKey's used are created using AttributeKey.newInstance, which throws an exception if an AttributeKey of that name is defined anywhere else in evaluated code.

      https://github.com/apache/cassandra-java-driver/blob/8d5849cb38995b312f29314d18256c0c3e94cf07/core/src/main/java/com/datastax/oss/driver/internal/core/channel/DriverChannel.java#L52-L54

        static final AttributeKey<String> CLUSTER_NAME_KEY = AttributeKey.newInstance("cluster_name");
        static final AttributeKey<Map<String, List<String>>> OPTIONS_KEY =
            AttributeKey.newInstance("options");
      

      This was encountered by a user that was creating driver connections within a trigger: https://the-asf.slack.com/archives/CJZLTM05A/p1705537114305579

      	Caused by: java.lang.IllegalArgumentException: 'cluster_name' is already in use
      		at io.netty.util.ConstantPool.createOrThrow(ConstantPool.java:109)
      		at io.netty.util.ConstantPool.newInstance(ConstantPool.java:91)
      		at io.netty.util.AttributeKey.newInstance(AttributeKey.java:55)
      		at com.datastax.oss.driver.internal.core.channel.DriverChannel.<clinit>(DriverChannel.java:50)
      		... 30 common frames omitted
      

      There is likely some class loading oddness in the Trigger implementation that exacerbates the problem. But at the least, if the driver were to use AttributeKey.valueOf instead (like Cassandra does where it uses them: https://github.com/search?q=repo%3Aapache%2Fcassandra+AttributeKey.valueOf&type=code), this particular issue could be avoided.

      Debatably we could use valueOf(firstNameComponent,secondNameComponent) as a way of namespacing the attribute (e.g. AttributeKey.newInstance("com.datastax.oss.driver.internal.core.channel", "cluster_name");, this does not seem necessary though.

      Attachments

        Issue Links

          Activity

            People

              andrew.tolbert Andy Tolbert
              andrew.tolbert Andy Tolbert
              Andy Tolbert
              Abe Ratnofsky, absurdfarce#1
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h 10m
                  1h 10m