Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate Druid HttpClient from Netty 3 to 4 #12032

Closed
wants to merge 84 commits into from
Closed
Show file tree
Hide file tree
Changes from 77 commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
6463df9
Migrade Druid HttpClient from Netty 3 to 4
xvrl Dec 5, 2021
f1dd611
fix premature closing of input stream
xvrl Dec 7, 2021
dc7dadb
Netty already uses SLF4J by default if available
xvrl Dec 7, 2021
01cb171
fix dependencies
xvrl Dec 7, 2021
d903da6
remove unused import
xvrl Dec 7, 2021
9f11a38
fix more dependencies
xvrl Dec 10, 2021
88ae64f
remove dups
xvrl Dec 11, 2021
3f28251
add test to satisfy branch coverage
xvrl Dec 12, 2021
d8e54dc
add basic http tests for workerholder
xvrl Dec 13, 2021
79ca7e9
add missing deps
xvrl Dec 13, 2021
3d631e6
fix longstanding bug with utf-8 byte sequences straddling http chunks
xvrl Dec 15, 2021
01f2a56
add test
xvrl Dec 15, 2021
ecf95ed
attempt to fix disconnect issues after close
xvrl Dec 21, 2021
b458850
check if connection is closed before handler is removed
xvrl Dec 21, 2021
90dcb5e
remove no longer relevant comments
xvrl Jan 5, 2022
868c88f
move log msg into try block
xvrl Jan 5, 2022
7487b29
wording and typos
xvrl Jan 5, 2022
d18f9b4
simplify http request write
xvrl Jan 5, 2022
97c6e29
fix new test
xvrl Jan 5, 2022
cda13ca
fix new tests after rebasing on latest master
xvrl Feb 24, 2022
45fb849
add a simple test for Request to satisfy test coverage
xvrl Feb 24, 2022
7d3c11a
update netty to 4.1.75
xvrl Mar 18, 2022
a23dc9d
fix dependency
xvrl Mar 18, 2022
53079c1
update additional references to netty 3
xvrl Aug 2, 2022
063e900
update netty to 4.1.79
xvrl Aug 2, 2022
c555a76
fix licenses.yaml
xvrl Aug 3, 2022
035d3d9
add missing netty dependency
xvrl Aug 3, 2022
b3e81ef
fix refCnt = 0 exception in SequenceInputStreamResponseHandler
xvrl Aug 4, 2022
003d775
update comment
xvrl Aug 9, 2022
d55abc0
remove accidentally committed file
xvrl Aug 9, 2022
540927e
Merge branch 'master' into remove-netty-3
gianm Aug 9, 2022
d7ee8ec
Update FrameFileHttpResponseHandler to use Netty 4.
gianm Aug 9, 2022
902a99b
Merge Gian's change to support Netty 4 in FrameFileHttpResponseHandle…
xvrl Aug 9, 2022
a648930
Fix inclusions in processing/pom.xml.
gianm Aug 9, 2022
cb2c8e7
Merge pull request #2 from gianm/remove-netty-3
xvrl Aug 10, 2022
9c93666
return channel resources asyncronously
xvrl Aug 10, 2022
826dc6f
Merge branch 'master' into remove-netty-3
gianm Aug 11, 2022
88a2d27
Merge pull request #3 from gianm/remove-netty-3
xvrl Aug 11, 2022
dcba3c2
Fix JankyServersTest.
gianm Aug 11, 2022
6ac4aa6
Merge pull request #4 from gianm/remove-netty-3
xvrl Aug 12, 2022
a8ed2bb
fix checkstyle
xvrl Aug 16, 2022
ee154ab
Merge remote-tracking branch 'origin/master' into remove-netty-3
xvrl Aug 16, 2022
4febb43
fix for updated makeResponse signature
xvrl Aug 16, 2022
3ddd1e3
Merge remote-tracking branch 'origin/master' into remove-netty-3
xvrl Aug 16, 2022
f4af486
fix running integration tests on macos aarch64
xvrl Aug 17, 2022
743b8b2
Merge remote-tracking branch 'origin/master' into remove-netty-3
xvrl Aug 23, 2022
7e12cd6
enable netty leak detection for integration tests
xvrl Aug 23, 2022
c7c7edb
ensure we always release messages on channelRead
xvrl Aug 31, 2022
9372838
always close channel on failure
xvrl Aug 31, 2022
e8d7477
close empty buffer, just in case
xvrl Aug 31, 2022
0e17c24
update query AbstractQueryResourceTestClient to retry based on http code
xvrl Aug 31, 2022
222f69d
increase number of retries for queries to succeed
xvrl Aug 31, 2022
0d25c0a
use unpooled memory for overlord + enable netty leak detection everyw…
xvrl Aug 31, 2022
c2df563
Merge remote-tracking branch 'origin/master' into remove-netty-3
xvrl Aug 31, 2022
bfbdf12
update to use netty objects
xvrl Sep 20, 2022
a530ab3
fix additional netty 3 references
xvrl Sep 20, 2022
183dc0f
update netty package
xvrl Sep 20, 2022
0d00bcb
Merge remote-tracking branch 'origin/master' into remove-netty-3
xvrl Sep 20, 2022
2d888ee
fix additional netty 3 references
xvrl Sep 20, 2022
7425bbe
fix dependency declarations
xvrl Sep 21, 2022
5b74cae
Merge remote-tracking branch 'origin/master' into remove-netty-3
xvrl Sep 21, 2022
d9d0b36
fix additional test classes after merging master
xvrl Sep 22, 2022
a2ccb42
update netty to 4.1.82
xvrl Oct 7, 2022
20effb2
Merge remote-tracking branch 'origin/master' into remove-netty-3
xvrl Oct 11, 2022
f40ec9a
fix use of old netty 3 classes in MSQ tests
xvrl Oct 11, 2022
bd12333
update netty to 4.1.84.Final
xvrl Oct 12, 2022
3befeaf
Merge remote-tracking branch 'origin/master' into remove-netty-3
xvrl Oct 12, 2022
35fa30d
Merge remote-tracking branch 'origin/master' into remove-netty-3
xvrl Oct 19, 2022
e041930
Merge remote-tracking branch 'origin/master' into remove-netty-3
xvrl Oct 26, 2022
a1ade92
Merge remote-tracking branch 'origin/master' into remove-netty-3
xvrl Oct 29, 2022
da1d7cd
Merge remote-tracking branch 'origin/master' into remove-netty-3
xvrl Dec 3, 2022
468215a
update Netty to 4.1.85
xvrl Dec 3, 2022
d07100c
Merge remote-tracking branch 'origin/master' into remove-netty-3
xvrl Jan 6, 2023
1a375fa
update MockServiceClient for Netty 4
xvrl Jan 10, 2023
84ebbe8
Merge remote-tracking branch 'origin/master' into remove-netty-3
xvrl Jan 10, 2023
1212960
fix checkstyle
xvrl Jan 10, 2023
0d55eed
migrate new classes to Netty 4
xvrl Jan 10, 2023
04823b2
Merge remote-tracking branch 'origin/master' into remove-netty-3
xvrl Jan 12, 2023
dff9040
revert accidental comment in licenses.yaml
xvrl Jan 12, 2023
2ec6291
add undeclared dependencies
xvrl Jan 12, 2023
53d2939
Merge remote-tracking branch 'origin/master' into remove-netty-3
xvrl Jan 13, 2023
6869372
Merge remote-tracking branch 'origin/master' into remove-netty-3
xvrl Jan 20, 2023
6371a75
Merge remote-tracking branch 'origin/master' into remove-netty-3
xvrl Jan 24, 2023
c6ee5ae
Merge remote-tracking branch 'origin/master' into remove-netty-3
xvrl Feb 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 12 additions & 7 deletions core/pom.xml
Expand Up @@ -203,10 +203,22 @@
<groupId>io.netty</groupId>
<artifactId>netty-common</artifactId>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-codec</artifactId>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-codec-http</artifactId>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-handler</artifactId>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport</artifactId>
</dependency>

<dependency>
<groupId>com.opencsv</groupId>
Expand Down Expand Up @@ -285,13 +297,6 @@
<scope>provided</scope>
</dependency>

<!-- Extra dependency for http-client -->
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty</artifactId>
</dependency>


<!-- Tests -->
<dependency>
<groupId>junit</groupId>
Expand Down
Expand Up @@ -67,9 +67,6 @@ public String getEncodingString()

public static final CompressionCodec DEFAULT_COMPRESSION_CODEC = CompressionCodec.GZIP;

// Default from NioClientSocketChannelFactory.DEFAULT_BOSS_COUNT, which is private:
private static final int DEFAULT_BOSS_COUNT = 1;

// Default from SelectorUtil.DEFAULT_IO_THREADS, which is private:
private static final int DEFAULT_WORKER_COUNT = JvmUtils.getRuntimeInfo().getAvailableProcessors() * 2;

Expand All @@ -86,7 +83,6 @@ public static Builder builder()
private final HttpClientProxyConfig proxyConfig;
private final Duration readTimeout;
private final Duration sslHandshakeTimeout;
private final int bossPoolSize;
private final int workerPoolSize;
private final CompressionCodec compressionCodec;
private final Duration unusedConnectionTimeoutDuration;
Expand All @@ -98,7 +94,6 @@ private HttpClientConfig(
HttpClientProxyConfig proxyConfig,
Duration readTimeout,
Duration sslHandshakeTimeout,
int bossPoolSize,
int workerPoolSize,
CompressionCodec compressionCodec,
Duration unusedConnectionTimeoutDuration
Expand All @@ -110,7 +105,6 @@ private HttpClientConfig(
this.proxyConfig = proxyConfig;
this.readTimeout = readTimeout;
this.sslHandshakeTimeout = sslHandshakeTimeout;
this.bossPoolSize = bossPoolSize;
this.workerPoolSize = workerPoolSize;
this.compressionCodec = compressionCodec;
this.unusedConnectionTimeoutDuration = unusedConnectionTimeoutDuration;
Expand Down Expand Up @@ -146,11 +140,6 @@ public Duration getSslHandshakeTimeout()
return sslHandshakeTimeout;
}

public int getBossPoolSize()
{
return bossPoolSize;
}

public int getWorkerPoolSize()
{
return workerPoolSize;
Expand All @@ -174,7 +163,6 @@ public static class Builder
private HttpClientProxyConfig proxyConfig = null;
private Duration readTimeout = null;
private Duration sslHandshakeTimeout = null;
private int bossCount = DEFAULT_BOSS_COUNT;
private int workerCount = DEFAULT_WORKER_COUNT;
private CompressionCodec compressionCodec = DEFAULT_COMPRESSION_CODEC;
private Duration unusedConnectionTimeoutDuration = DEFAULT_UNUSED_CONNECTION_TIMEOUT_DURATION;
Expand Down Expand Up @@ -246,7 +234,6 @@ public HttpClientConfig build()
proxyConfig,
readTimeout,
sslHandshakeTimeout,
bossCount,
workerCount,
compressionCodec,
unusedConnectionTimeoutDuration
Expand Down
Expand Up @@ -21,27 +21,22 @@

import com.google.common.base.Throwables;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import org.apache.druid.java.util.common.lifecycle.Lifecycle;
import org.apache.druid.java.util.http.client.netty.HttpClientPipelineFactory;
import org.apache.druid.java.util.http.client.netty.HttpClientInitializer;
import org.apache.druid.java.util.http.client.pool.ChannelResourceFactory;
import org.apache.druid.java.util.http.client.pool.ResourcePool;
import org.apache.druid.java.util.http.client.pool.ResourcePoolConfig;
import org.jboss.netty.bootstrap.ClientBootstrap;
import org.jboss.netty.channel.socket.nio.NioClientBossPool;
import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;
import org.jboss.netty.channel.socket.nio.NioWorkerPool;
import org.jboss.netty.logging.InternalLoggerFactory;
import org.jboss.netty.logging.Slf4JLoggerFactory;
import org.jboss.netty.util.HashedWheelTimer;
import org.jboss.netty.util.ThreadNameDeterminer;
import org.jboss.netty.util.Timer;

import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManagerFactory;
import java.io.FileInputStream;
import java.security.KeyStore;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
*
Expand All @@ -51,41 +46,13 @@ public class HttpClientInit
public static HttpClient createClient(HttpClientConfig config, Lifecycle lifecycle)
{
try {
// We need to use the full constructor in order to set a ThreadNameDeterminer. The other parameters are taken
// from the defaults in HashedWheelTimer's other constructors.
final HashedWheelTimer timer = new HashedWheelTimer(
new ThreadFactoryBuilder().setDaemon(true)
.setNameFormat("HttpClient-Timer-%s")
.build(),
ThreadNameDeterminer.CURRENT,
100,
TimeUnit.MILLISECONDS,
512
);
lifecycle.addMaybeStartHandler(
new Lifecycle.Handler()
{
@Override
public void start()
{
timer.start();
}

@Override
public void stop()
{
timer.stop();
}
}
);
return lifecycle.addMaybeStartManagedInstance(
new NettyHttpClient(
new ResourcePool<>(
new ChannelResourceFactory(
createBootstrap(lifecycle, timer, config.getBossPoolSize(), config.getWorkerPoolSize()),
createBootstrap(lifecycle, config.getWorkerPoolSize()),
config.getSslContext(),
config.getProxyConfig(),
timer,
config.getSslHandshakeTimeout() == null ? -1 : config.getSslHandshakeTimeout().getMillis()
),
new ResourcePoolConfig(
Expand All @@ -95,8 +62,7 @@ public void stop()
config.isEagerInitialization()
),
config.getReadTimeout(),
config.getCompressionCodec(),
timer
config.getCompressionCodec()
)
);
}
Expand Down Expand Up @@ -125,37 +91,25 @@ public static SSLContext sslContextWithTrustedKeyStore(final String keyStorePath
}
}

private static ClientBootstrap createBootstrap(Lifecycle lifecycle, Timer timer, int bossPoolSize, int workerPoolSize)
private static Bootstrap createBootstrap(Lifecycle lifecycle, int workerPoolSize)
{
final NioClientBossPool bossPool = new NioClientBossPool(
Executors.newCachedThreadPool(
new ThreadFactoryBuilder()
.setDaemon(true)
.setNameFormat("HttpClient-Netty-Boss-%s")
.build()
),
bossPoolSize,
timer,
ThreadNameDeterminer.CURRENT
);

final NioWorkerPool workerPool = new NioWorkerPool(
final EventLoopGroup workerGroup = new NioEventLoopGroup(
workerPoolSize,
Executors.newCachedThreadPool(
new ThreadFactoryBuilder()
.setDaemon(true)
.setNameFormat("HttpClient-Netty-Worker-%s")
.build()
),
workerPoolSize,
ThreadNameDeterminer.CURRENT
)
);

final ClientBootstrap bootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(bossPool, workerPool));

bootstrap.setOption("keepAlive", true);
bootstrap.setPipelineFactory(new HttpClientPipelineFactory());

InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory());
final Bootstrap bootstrap = new Bootstrap()
.group(workerGroup)
.channel(NioSocketChannel.class)
.option(ChannelOption.SO_KEEPALIVE, true)
.option(ChannelOption.AUTO_READ, false)
.handler(new HttpClientInitializer());

try {
lifecycle.addMaybeStartHandler(
Expand All @@ -169,7 +123,7 @@ public void start()
@Override
public void stop()
{
bootstrap.releaseExternalResources();
workerGroup.shutdownGracefully();
}
}
);
Expand Down