You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by "Andy Tolbert (Jira)" <ji...@apache.org> on 2024/01/23 16:17:00 UTC

[jira] [Created] (CASSANDRA-19290) Replace uses of AttributeKey.newInstance with AttributeKey.valueOf in cassandra-java-driver

Andy Tolbert created CASSANDRA-19290:
----------------------------------------

             Summary: Replace uses of AttributeKey.newInstance with AttributeKey.valueOf in cassandra-java-driver
                 Key: CASSANDRA-19290
                 URL: https://issues.apache.org/jira/browse/CASSANDRA-19290
             Project: Cassandra
          Issue Type: Bug
          Components: Client/java-driver
            Reporter: Andy Tolbert
            Assignee: Henry Hughes


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

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

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

{noformat}
	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
{noformat}

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.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org