Skip to content

Commit

Permalink
store conn. pool instance on origin channel
Browse files Browse the repository at this point in the history
  • Loading branch information
argha-c committed Aug 15, 2023
1 parent ce4ecf7 commit eab022b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public final class NettyClientConnectionFactory {
this.channelInitializer = channelInitializer;
}

public ChannelFuture connect(final EventLoop eventLoop, SocketAddress socketAddress, CurrentPassport passport) {
public ChannelFuture connect(final EventLoop eventLoop, SocketAddress socketAddress, CurrentPassport passport, IConnectionPool pool) {
Objects.requireNonNull(socketAddress, "socketAddress");
if (socketAddress instanceof InetSocketAddress) {
// This should be checked by the ClientConnectionManager
Expand All @@ -54,6 +54,7 @@ public ChannelFuture connect(final EventLoop eventLoop, SocketAddress socketAddr
.handler(channelInitializer)
.group(eventLoop)
.attr(CurrentPassport.CHANNEL_ATTR, passport)
.attr(PerServerConnectionPool.CHANNEL_ATTR, pool)
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connPoolConfig.getConnectTimeout())
.option(ChannelOption.SO_KEEPALIVE, connPoolConfig.getTcpKeepAlive())
.option(ChannelOption.TCP_NODELAY, connPoolConfig.getTcpNoDelay())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
import com.netflix.zuul.exception.OutboundErrorType;
import com.netflix.zuul.passport.CurrentPassport;
import com.netflix.zuul.passport.PassportState;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoop;
import io.netty.util.AttributeKey;
import io.netty.util.concurrent.Promise;
import java.net.InetAddress;
import java.net.InetSocketAddress;
Expand All @@ -49,7 +51,7 @@
public class PerServerConnectionPool implements IConnectionPool
{
private static final Logger LOG = LoggerFactory.getLogger(PerServerConnectionPool.class);

public static final AttributeKey<IConnectionPool> CHANNEL_ATTR = AttributeKey.newInstance("_connection_pool");
private final ConcurrentHashMap<EventLoop, Deque<PooledConnection>> connectionsPerEventLoop =
new ConcurrentHashMap<>();
protected final PooledConnectionFactory pooledConnectionFactory;
Expand Down Expand Up @@ -277,7 +279,7 @@ protected void tryMakingNewConnection(
}

protected ChannelFuture connectToServer(EventLoop eventLoop, CurrentPassport passport, SocketAddress serverAddr) {
return connectionFactory.connect(eventLoop, serverAddr, passport);
return connectionFactory.connect(eventLoop, serverAddr, passport, this);
}

protected void handleConnectCompletion(
Expand All @@ -287,7 +289,6 @@ protected void handleConnectCompletion(
if (cf.isSuccess()) {

passport.add(PassportState.ORIGIN_CH_CONNECTED);

server.incrementOpenConnectionsCount();
createConnSucceededCounter.increment();
connsInUse.incrementAndGet();
Expand Down

0 comments on commit eab022b

Please sign in to comment.