dcapwell commented on a change in pull request #1384:
URL: https://github.com/apache/cassandra/pull/1384#discussion_r783317900
##########
File path: src/java/org/apache/cassandra/transport/ConnectionLimitHandler.java
##########
@@ -44,10 +48,38 @@
{
private static final Logger logger =
LoggerFactory.getLogger(ConnectionLimitHandler.class);
private static final NoSpamLogger noSpamLogger =
NoSpamLogger.getLogger(logger, 1L, TimeUnit.MINUTES);
+ private static final AttributeKey<InetAddress> addressAttributeKey =
AttributeKey.valueOf(ConnectionLimitHandler.class, "address");
private final ConcurrentMap<InetAddress, AtomicLong> connectionsPerClient
= new ConcurrentHashMap<>();
private final AtomicLong counter = new AtomicLong(0);
+ // Keep the remote address as a channel attribute. The channel inactive
callback needs
+ // to know the entry into the connetionsPerClient map and depending on the
state of the remote
+ // an exception may be thrown trying to retrieve the address. Make sure
the same address used
+ // to increment is used for decrement.
+ private static InetAddress setRemoteAddressAttribute(Channel channel)
+ {
+ Attribute<InetAddress> addressAttribute =
channel.attr(addressAttributeKey);
+ SocketAddress remoteAddress = channel.remoteAddress();
+ if (remoteAddress instanceof InetSocketAddress)
+ {
+ addressAttribute.setIfAbsent(((InetSocketAddress)
remoteAddress).getAddress());
+ }
+ else
+ {
+ noSpamLogger.warn("Remote address of unknown type: {}, skipping
per-IP connection limits",
+ remoteAddress.getClass());
+ }
+ return addressAttribute.get();
+ }
+
+ private static InetAddress getRemoteAddressAttribute(Channel channel)
+ {
+ Attribute<InetAddress> addressAttribute =
channel.attr(addressAttributeKey);
Review comment:
nit: `return channel.attr(addressAttributeKey).get()`
##########
File path: src/java/org/apache/cassandra/transport/ConnectionLimitHandler.java
##########
@@ -44,10 +48,38 @@
{
private static final Logger logger =
LoggerFactory.getLogger(ConnectionLimitHandler.class);
private static final NoSpamLogger noSpamLogger =
NoSpamLogger.getLogger(logger, 1L, TimeUnit.MINUTES);
+ private static final AttributeKey<InetAddress> addressAttributeKey =
AttributeKey.valueOf(ConnectionLimitHandler.class, "address");
private final ConcurrentMap<InetAddress, AtomicLong> connectionsPerClient
= new ConcurrentHashMap<>();
private final AtomicLong counter = new AtomicLong(0);
+ // Keep the remote address as a channel attribute. The channel inactive
callback needs
Review comment:
nit, `/** ... */`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]