Skip to content

Commit 97013cf

Browse files
author
Abhishek Bharadwaj
committed
UDS support for R2 HTTP client
1 parent a4e7e30 commit 97013cf

File tree

4 files changed

+58
-6
lines changed

4 files changed

+58
-6
lines changed

Diff for: CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ and what APIs have changed, if applicable.
1414

1515
## [Unreleased]
1616

17+
## [29.38.5-rc.1] - 2022-09-13
18+
- Add Support for UDS transport protocol in R2 outbound traffic over HTTP1.1
19+
1720
## [29.38.4] - 2022-09-08
1821
- Use ZooKeeper 3.6.3
1922

Diff for: r2-netty/src/main/java/com/linkedin/r2/netty/client/http/HttpChannelInitializer.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.linkedin.r2.netty.handler.common.SslHandshakeTimingHandler;
2626
import com.linkedin.r2.netty.handler.http.HttpMessageDecoders;
2727
import com.linkedin.r2.netty.handler.http.HttpMessageEncoders;
28+
import io.netty.channel.Channel;
2829
import io.netty.channel.ChannelInitializer;
2930
import io.netty.channel.socket.nio.NioSocketChannel;
3031
import io.netty.handler.codec.http.HttpClientCodec;
@@ -60,7 +61,7 @@
6061
* @author Sean Sheng
6162
* @author Nizar Mankulangara
6263
*/
63-
class HttpChannelInitializer extends ChannelInitializer<NioSocketChannel>
64+
class HttpChannelInitializer extends ChannelInitializer<Channel>
6465
{
6566
/**
6667
* HTTP/2 stream channels are not recyclable and should be disposed upon completion.
@@ -93,7 +94,7 @@ class HttpChannelInitializer extends ChannelInitializer<NioSocketChannel>
9394
}
9495

9596
@Override
96-
protected void initChannel(NioSocketChannel channel)
97+
protected void initChannel(Channel channel)
9798
{
9899
if (_ssl)
99100
{

Diff for: r2-netty/src/main/java/com/linkedin/r2/netty/client/http/HttpChannelPoolFactory.java

+50-3
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,15 @@
2828
import io.netty.channel.ChannelInitializer;
2929
import io.netty.channel.ChannelOption;
3030
import io.netty.channel.EventLoopGroup;
31+
import io.netty.channel.epoll.EpollDomainSocketChannel;
3132
import io.netty.channel.group.ChannelGroup;
3233
import io.netty.channel.socket.nio.NioSocketChannel;
3334
import java.net.SocketAddress;
3435
import java.util.concurrent.ScheduledExecutorService;
3536
import javax.net.ssl.SSLContext;
3637
import javax.net.ssl.SSLParameters;
38+
import org.apache.commons.lang3.StringUtils;
39+
3740

3841
/**
3942
* Factory class to produce {@link AsyncPool}&#060;{@link Channel}&#062; for Http Channels
@@ -53,7 +56,9 @@ public class HttpChannelPoolFactory implements ChannelPoolFactory
5356
private final ScheduledExecutorService _scheduler;
5457
private final AsyncPoolImpl.Strategy _strategy;
5558
private int _channelPoolWaiterTimeout;
59+
private final String _udsAddress;
5660

61+
@Deprecated
5762
public HttpChannelPoolFactory(
5863
ScheduledExecutorService scheduler,
5964
EventLoopGroup eventLoopGroup,
@@ -76,7 +81,36 @@ public HttpChannelPoolFactory(
7681
int connectTimeout,
7782
int sslHandShakeTimeout)
7883
{
79-
ChannelInitializer<NioSocketChannel> initializer = new HttpChannelInitializer(sslContext, sslParameters,
84+
this( scheduler, eventLoopGroup, channelGroup, strategy, sslContext, sslParameters, maxPoolSize,
85+
minPoolSize, maxPoolWaiterSize, maxInitialLineLength, maxHeaderSize, maxChunkSize,
86+
maxConcurrentConnectionInitializations, idleTimeout, maxContentLength, tcpNoDelay, enableSSLSessionResumption,
87+
channelPoolWaiterTimeout, connectTimeout, sslHandShakeTimeout, null);
88+
}
89+
90+
public HttpChannelPoolFactory(
91+
ScheduledExecutorService scheduler,
92+
EventLoopGroup eventLoopGroup,
93+
ChannelGroup channelGroup,
94+
AsyncPoolImpl.Strategy strategy,
95+
SSLContext sslContext,
96+
SSLParameters sslParameters,
97+
int maxPoolSize,
98+
int minPoolSize,
99+
int maxPoolWaiterSize,
100+
int maxInitialLineLength,
101+
int maxHeaderSize,
102+
int maxChunkSize,
103+
int maxConcurrentConnectionInitializations,
104+
long idleTimeout,
105+
long maxContentLength,
106+
boolean tcpNoDelay,
107+
boolean enableSSLSessionResumption,
108+
int channelPoolWaiterTimeout,
109+
int connectTimeout,
110+
int sslHandShakeTimeout,
111+
String udsAddress)
112+
{
113+
ChannelInitializer<Channel> initializer = new HttpChannelInitializer(sslContext, sslParameters,
80114
maxInitialLineLength, maxHeaderSize, maxChunkSize, maxContentLength, enableSSLSessionResumption, sslHandShakeTimeout);
81115

82116
_scheduler = scheduler;
@@ -89,9 +123,22 @@ public HttpChannelPoolFactory(
89123
_idleTimeout = idleTimeout;
90124
_tcpNoDelay = tcpNoDelay;
91125
_channelPoolWaiterTimeout = channelPoolWaiterTimeout;
126+
_udsAddress = udsAddress;
92127

93-
_bootstrap = new Bootstrap().group(eventLoopGroup).channel(NioSocketChannel.class).
94-
option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectTimeout).handler(initializer);
128+
if (!StringUtils.isEmpty(_udsAddress)) {
129+
_bootstrap = new Bootstrap()
130+
.group(eventLoopGroup)
131+
.channel(EpollDomainSocketChannel.class)
132+
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectTimeout)
133+
.handler(initializer);
134+
}
135+
else{
136+
_bootstrap = new Bootstrap()
137+
.group(eventLoopGroup)
138+
.channel(NioSocketChannel.class)
139+
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectTimeout)
140+
.handler(initializer);
141+
}
95142
}
96143

97144
@Override

Diff for: r2-netty/src/main/java/com/linkedin/r2/transport/http/client/common/ChannelPoolManagerFactoryImpl.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ public ChannelPoolManager buildStream(ChannelPoolManagerKey channelPoolManagerKe
144144
_enableSSLSessionResumption,
145145
_channelPoolWaiterTimeout,
146146
_connectTimeout,
147-
_sslHandShakeTimeout);
147+
_sslHandShakeTimeout,
148+
channelPoolManagerKey.getUdsAddress());
148149
}
149150
else
150151
{

0 commit comments

Comments
 (0)