Skip to content

Commit 8e3b57a

Browse files
Use Existing Netty Allocator in Azure Repository (#93906)
Since we're now using the Netty transport exclusively, we can reuse the Netty module in the Azure plugin. As we're already aligning versions across the Netty transport and the Azure plugin this shouldn't change any behavior and saves code for Gradle exclusions. Also, we can then just reuse the memory allocator we use in the transport in the Azure repository to eliminate direct allocations.
1 parent 8666136 commit 8e3b57a

File tree

3 files changed

+5
-153
lines changed

3 files changed

+5
-153
lines changed

modules/repository-azure/build.gradle

Lines changed: 2 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ import org.elasticsearch.gradle.PropertyNormalization
33
import org.elasticsearch.gradle.internal.info.BuildParams
44
import org.elasticsearch.gradle.internal.test.InternalClusterTestPlugin
55

6-
import static org.elasticsearch.gradle.PropertyNormalization.DEFAULT
7-
import static org.elasticsearch.gradle.PropertyNormalization.IGNORE_VALUE
8-
96
/*
107
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
118
* or more contributor license agreements. Licensed under the Elastic License
@@ -62,26 +59,20 @@ dependencies {
6259
api "com.fasterxml.woodstox:woodstox-core:${versions.woodstox}"
6360

6461
// netty
65-
api "io.netty:netty-buffer:${versions.netty}"
6662
api "io.netty:netty-codec-dns:${versions.netty}"
67-
api "io.netty:netty-codec-http:${versions.netty}"
6863
api "io.netty:netty-codec-http2:${versions.netty}"
6964
api "io.netty:netty-codec-socks:${versions.netty}"
70-
api "io.netty:netty-codec:${versions.netty}"
71-
api "io.netty:netty-common:${versions.netty}"
7265
api "io.netty:netty-handler-proxy:${versions.netty}"
73-
api "io.netty:netty-handler:${versions.netty}"
74-
api "io.netty:netty-resolver:${versions.netty}"
7566
api "io.netty:netty-resolver-dns:${versions.netty}"
76-
api "io.netty:netty-transport:${versions.netty}"
77-
api "io.netty:netty-transport-native-unix-common:${versions.netty}"
7867

7968
// reactor
8069
api "io.projectreactor.netty:reactor-netty-core:${versions.reactorNetty}"
8170
api "io.projectreactor.netty:reactor-netty-http:${versions.reactorNetty}"
8271
api "io.projectreactor:reactor-core:${versions.reactorCore}"
8372
api "org.reactivestreams:reactive-streams:${versions.reactiveStreams}"
8473

74+
implementation project(":modules:transport-netty4")
75+
8576
runtimeOnly("org.slf4j:slf4j-api:${versions.slf4j}")
8677
runtimeOnly("org.apache.logging.log4j:log4j-slf4j-impl:${versions.log4j}")
8778

@@ -116,14 +107,6 @@ tasks.named("dependencyLicenses").configure {
116107

117108
tasks.named("thirdPartyAudit").configure {
118109
ignoreMissingClasses(
119-
'com.aayushatharva.brotli4j.Brotli4jLoader',
120-
'com.aayushatharva.brotli4j.decoder.DecoderJNI$Status',
121-
'com.aayushatharva.brotli4j.decoder.DecoderJNI$Wrapper',
122-
'com.aayushatharva.brotli4j.encoder.BrotliEncoderChannel',
123-
'com.aayushatharva.brotli4j.encoder.Encoder',
124-
'com.aayushatharva.brotli4j.encoder.Encoder$Mode',
125-
'com.aayushatharva.brotli4j.encoder.Encoder$Parameters',
126-
127110
'com.azure.storage.internal.avro.implementation.AvroObject',
128111
'com.azure.storage.internal.avro.implementation.AvroReader',
129112
'com.azure.storage.internal.avro.implementation.AvroReaderFactory',
@@ -162,103 +145,6 @@ tasks.named("thirdPartyAudit").configure {
162145
'kotlin.reflect.KDeclarationContainer',
163146
'kotlin.sequences.Sequence',
164147

165-
// from io.netty.handler.codec.protobuf.ProtobufDecoder (netty)
166-
'com.google.protobuf.ExtensionRegistry',
167-
'com.google.protobuf.MessageLite$Builder',
168-
'com.google.protobuf.MessageLite',
169-
'com.google.protobuf.Parser',
170-
'com.google.protobuf.ExtensionRegistryLite',
171-
'com.google.protobuf.MessageLiteOrBuilder',
172-
'com.google.protobuf.nano.CodedOutputByteBufferNano',
173-
'com.google.protobuf.nano.MessageNano',
174-
175-
// from io.netty.logging.CommonsLoggerFactory (netty)
176-
'org.apache.commons.logging.Log',
177-
'org.apache.commons.logging.LogFactory',
178-
179-
// from Log4j (deliberate, Netty will fallback to Log4j 2)
180-
'org.apache.log4j.Level',
181-
'org.apache.log4j.Logger',
182-
183-
// from io.netty.handler.ssl.util.BouncyCastleSelfSignedCertGenerator (netty)
184-
'org.bouncycastle.cert.X509v3CertificateBuilder',
185-
'org.bouncycastle.cert.jcajce.JcaX509CertificateConverter',
186-
'org.bouncycastle.operator.jcajce.JcaContentSignerBuilder',
187-
'org.bouncycastle.openssl.PEMEncryptedKeyPair',
188-
'org.bouncycastle.openssl.PEMParser',
189-
'org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter',
190-
'org.bouncycastle.openssl.jcajce.JceOpenSSLPKCS8DecryptorProviderBuilder',
191-
'org.bouncycastle.openssl.jcajce.JcePEMDecryptorProviderBuilder',
192-
'org.bouncycastle.pkcs.PKCS8EncryptedPrivateKeyInfo',
193-
194-
// from io.netty.handler.ssl.JettyNpnSslEngine (netty)
195-
'org.eclipse.jetty.npn.NextProtoNego$ClientProvider',
196-
'org.eclipse.jetty.npn.NextProtoNego$ServerProvider',
197-
'org.eclipse.jetty.npn.NextProtoNego',
198-
199-
// from io.netty.handler.codec.marshalling.ChannelBufferByteInput (netty)
200-
'org.jboss.marshalling.ByteInput',
201-
202-
// from io.netty.handler.codec.marshalling.ChannelBufferByteOutput (netty)
203-
'org.jboss.marshalling.ByteOutput',
204-
205-
// from io.netty.handler.codec.marshalling.CompatibleMarshallingEncoder (netty)
206-
'org.jboss.marshalling.Marshaller',
207-
208-
// from io.netty.handler.codec.marshalling.ContextBoundUnmarshallerProvider (netty)
209-
'org.jboss.marshalling.MarshallerFactory',
210-
'org.jboss.marshalling.MarshallingConfiguration',
211-
'org.jboss.marshalling.Unmarshaller',
212-
213-
// from io.netty.handler.codec.spdy.SpdyHeaderBlockJZlibEncoder (netty-codec-http)
214-
'com.jcraft.jzlib.Deflater',
215-
'com.jcraft.jzlib.Inflater',
216-
'com.jcraft.jzlib.JZlib$WrapperType',
217-
'com.jcraft.jzlib.JZlib',
218-
219-
'com.github.luben.zstd.Zstd',
220-
221-
// from io.netty.handler.codec.compression.LzfDecoder
222-
// from io.netty.handler.codec.compression.LzfEncoder (netty-codec)
223-
'com.ning.compress.BufferRecycler',
224-
'com.ning.compress.lzf.ChunkDecoder',
225-
'com.ning.compress.lzf.ChunkEncoder',
226-
'com.ning.compress.lzf.LZFChunk',
227-
'com.ning.compress.lzf.LZFEncoder',
228-
'com.ning.compress.lzf.util.ChunkDecoderFactory',
229-
'com.ning.compress.lzf.util.ChunkEncoderFactory',
230-
231-
// from io.netty.handler.codec.compression.LzmaFrameEncoder (netty-codec)
232-
'lzma.sdk.lzma.Encoder',
233-
234-
// from io.netty.handler.ssl.JettyAlpnSslEngin (netty-handler optional dependency)
235-
'org.eclipse.jetty.alpn.ALPN$ClientProvider',
236-
'org.eclipse.jetty.alpn.ALPN$ServerProvider',
237-
'org.eclipse.jetty.alpn.ALPN',
238-
239-
// from io.netty.handler.ssl.ConscryptAlpnSslEngine (netty-handler optional dependency)
240-
'org.conscrypt.AllocatedBuffer',
241-
'org.conscrypt.BufferAllocator',
242-
'org.conscrypt.Conscrypt',
243-
'org.conscrypt.HandshakeListener',
244-
245-
// from io.netty.handler.ssl.OpenSslEngine (netty)
246-
'io.netty.internal.tcnative.AsyncSSLPrivateKeyMethod',
247-
'io.netty.internal.tcnative.AsyncTask',
248-
'io.netty.internal.tcnative.Buffer',
249-
'io.netty.internal.tcnative.Library',
250-
'io.netty.internal.tcnative.SSL',
251-
'io.netty.internal.tcnative.SSLContext',
252-
'io.netty.internal.tcnative.SSLPrivateKeyMethod',
253-
'io.netty.internal.tcnative.CertificateCallback',
254-
'io.netty.internal.tcnative.CertificateCompressionAlgo',
255-
'io.netty.internal.tcnative.CertificateVerifier',
256-
'io.netty.internal.tcnative.ResultCallback',
257-
'io.netty.internal.tcnative.SessionTicketKey',
258-
'io.netty.internal.tcnative.SniHostNameMatcher',
259-
'io.netty.internal.tcnative.SSLSession',
260-
'io.netty.internal.tcnative.SSLSessionCache',
261-
262148
// from io.netty.util.internal.Hidden (netty-common optional dependency)
263149
'reactor.blockhound.BlockHound$Builder',
264150
'reactor.blockhound.integration.BlockHoundIntegration',
@@ -294,26 +180,6 @@ tasks.named("thirdPartyAudit").configure {
294180
)
295181

296182
ignoreViolations(
297-
'io.netty.handler.ssl.util.OpenJdkSelfSignedCertGenerator',
298-
299-
'io.netty.util.internal.PlatformDependent0',
300-
'io.netty.util.internal.PlatformDependent0$1',
301-
'io.netty.util.internal.PlatformDependent0$2',
302-
'io.netty.util.internal.PlatformDependent0$3',
303-
'io.netty.util.internal.PlatformDependent0$4',
304-
'io.netty.util.internal.PlatformDependent0$6',
305-
'io.netty.util.internal.shaded.org.jctools.queues.BaseLinkedQueueConsumerNodeRef',
306-
'io.netty.util.internal.shaded.org.jctools.queues.BaseLinkedQueueProducerNodeRef',
307-
'io.netty.util.internal.shaded.org.jctools.queues.BaseMpscLinkedArrayQueueColdProducerFields',
308-
'io.netty.util.internal.shaded.org.jctools.queues.BaseMpscLinkedArrayQueueConsumerFields',
309-
'io.netty.util.internal.shaded.org.jctools.queues.BaseMpscLinkedArrayQueueProducerFields',
310-
'io.netty.util.internal.shaded.org.jctools.queues.LinkedQueueNode',
311-
'io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueueConsumerIndexField',
312-
'io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueueProducerIndexField',
313-
'io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueueProducerLimitField',
314-
'io.netty.util.internal.shaded.org.jctools.util.UnsafeAccess',
315-
'io.netty.util.internal.shaded.org.jctools.util.UnsafeRefArrayAccess',
316-
317183
'javax.activation.MailcapCommandMap',
318184
'javax.activation.MimetypesFileTypeMap',
319185
'reactor.core.publisher.Traces$SharedSecretsCallSiteSupplierFactory$TracingException',

modules/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureClientProvider.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
package org.elasticsearch.repositories.azure;
1010

1111
import io.netty.buffer.ByteBufAllocator;
12-
import io.netty.buffer.PooledByteBufAllocator;
1312
import io.netty.channel.ChannelOption;
1413
import io.netty.channel.EventLoopGroup;
1514
import io.netty.channel.nio.NioEventLoopGroup;
@@ -45,6 +44,7 @@
4544
import org.elasticsearch.repositories.azure.executors.PrivilegedExecutor;
4645
import org.elasticsearch.repositories.azure.executors.ReactorScheduledExecutorService;
4746
import org.elasticsearch.threadpool.ThreadPool;
47+
import org.elasticsearch.transport.netty4.NettyAllocator;
4848

4949
import java.io.IOException;
5050
import java.net.URL;
@@ -141,22 +141,9 @@ static AzureClientProvider create(ThreadPool threadPool, Settings settings) {
141141
.maxIdleTime(Duration.ofMillis(maxIdleTime.millis()))
142142
.build();
143143

144-
ByteBufAllocator pooledByteBufAllocator = createByteBufAllocator();
145-
146144
// Just to verify that this executor exists
147145
threadPool.executor(REPOSITORY_THREAD_POOL_NAME);
148-
return new AzureClientProvider(threadPool, REPOSITORY_THREAD_POOL_NAME, eventLoopGroup, provider, pooledByteBufAllocator);
149-
}
150-
151-
private static ByteBufAllocator createByteBufAllocator() {
152-
int nHeapArena = 1;
153-
int pageSize = PooledByteBufAllocator.defaultPageSize();
154-
int maxOrder = PooledByteBufAllocator.defaultMaxOrder();
155-
int tinyCacheSize = PooledByteBufAllocator.defaultTinyCacheSize();
156-
int smallCacheSize = PooledByteBufAllocator.defaultSmallCacheSize();
157-
int normalCacheSize = PooledByteBufAllocator.defaultNormalCacheSize();
158-
159-
return new PooledByteBufAllocator(false, nHeapArena, 0, pageSize, maxOrder, tinyCacheSize, smallCacheSize, normalCacheSize, false);
146+
return new AzureClientProvider(threadPool, REPOSITORY_THREAD_POOL_NAME, eventLoopGroup, provider, NettyAllocator.getAllocator());
160147
}
161148

162149
AzureBlobServiceClient createClient(

modules/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureRepositoryPlugin.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,10 @@ public class AzureRepositoryPlugin extends Plugin implements RepositoryPlugin, R
6060
// protected for testing
6161
final SetOnce<AzureStorageService> azureStoreService = new SetOnce<>();
6262
private final Settings settings;
63-
private final Map<String, AzureStorageSettings> initialClientSettings;
6463

6564
public AzureRepositoryPlugin(Settings settings) {
6665
// eagerly load client settings so that secure settings are read
67-
this.initialClientSettings = AzureStorageSettings.load(settings);
66+
AzureStorageSettings.load(settings);
6867
this.settings = settings;
6968
}
7069

0 commit comments

Comments
 (0)