Skip to content

Commit f8beddd

Browse files
authored
IoUring: Move batchAllocation setting to an extra method (#15479)
Motivation: Before we passed the allocator and the batchAllocation setting into one builder method, this is kind of inconsistent with the rest. Modifications: Add extra builder method Result: Cleanup and more consistent API
1 parent f52405d commit f8beddd

4 files changed

Lines changed: 23 additions & 14 deletions

File tree

testsuite-native-image/src/main/java/io/netty/testsuite/svm/HttpNativeServer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ public static IoHandlerFactory chooseFactory(TransportType ioType) {
124124
.bufferGroupId((short) 0)
125125
.bufferRingSize((short) 16)
126126
.batchSize(16)
127-
.allocator(new IoUringFixedBufferRingAllocator(1024), false)
127+
.allocator(new IoUringFixedBufferRingAllocator(1024))
128+
.batchAllocation(false)
128129
.build()
129130
);
130131
}

transport-classes-io_uring/src/main/java/io/netty/channel/uring/IoUringBufferRingConfig.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,16 +226,24 @@ public Builder batchSize(int batchSize) {
226226
}
227227

228228
/**
229-
* Set the {@link IoUringBufferRingAllocator} to use to allocate {@link io.netty.buffer.ByteBuf}s.
229+
* Set the {@link IoUringBufferRingAllocator} to use to allocate {@link ByteBuf}s.
230230
*
231231
* @param allocator The allocator.
232+
*/
233+
public Builder allocator(IoUringBufferRingAllocator allocator) {
234+
this.allocator = allocator;
235+
return this;
236+
}
237+
238+
/**
239+
* Set allocation strategy that is used to allocate {@link ByteBuf}s.
240+
*
232241
* @param batchAllocation {@code true} if the ring should always be filled via a batch allocation or
233-
* {@code false} if we will try to allocate a new {@link ByteBuf} as soon as
242+
* {@code false} if we will try to allocate a new {@link ByteBuf} as soon
234243
* as we used a buffer from the ring.
235244
* @return This builder.
236245
*/
237-
public Builder allocator(IoUringBufferRingAllocator allocator, boolean batchAllocation) {
238-
this.allocator = allocator;
246+
public Builder batchAllocation(boolean batchAllocation) {
239247
this.batchAllocation = batchAllocation;
240248
return this;
241249
}
@@ -245,8 +253,8 @@ public Builder allocator(IoUringBufferRingAllocator allocator, boolean batchAllo
245253
* What's-new-with-io_uring-in-6.11-and-6.12#incremental-provided-buffer-consumption">incremental mode</a>
246254
* should be used for the buffer ring.
247255
*
248-
* @param incremental {@code true} if incremental mode is used, {@code false} otherwise.
249-
* @return This builder.
256+
* @param incremental {@code true} if incremental mode is used, {@code false} otherwise.
257+
* @return This builder.
250258
*/
251259
public Builder incremental(boolean incremental) {
252260
this.incremental = incremental;

transport-native-io_uring/src/test/java/io/netty/channel/uring/IoUringBufferRingTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141
import java.util.concurrent.LinkedBlockingQueue;
4242

4343
import static org.junit.jupiter.api.Assertions.assertEquals;
44-
import static org.junit.jupiter.api.Assertions.assertNotNull;
45-
import static org.junit.jupiter.api.Assertions.assertNull;
4644
import static org.junit.jupiter.api.Assertions.assertTrue;
4745
import static org.junit.jupiter.api.Assumptions.assumeTrue;
4846

@@ -97,7 +95,8 @@ public void testProviderBufferRead(boolean incremental) throws InterruptedExcept
9795
.bufferGroupId((short) 1)
9896
.bufferRingSize((short) 2)
9997
.batchSize(2).incremental(incremental)
100-
.allocator(new IoUringFixedBufferRingAllocator(1024), false)
98+
.allocator(new IoUringFixedBufferRingAllocator(1024))
99+
.batchAllocation(false)
101100
.build();
102101

103102
IoUringBufferRingConfig bufferRingConfig1 =
@@ -106,7 +105,8 @@ public void testProviderBufferRead(boolean incremental) throws InterruptedExcept
106105
.bufferRingSize((short) 16)
107106
.batchSize(8)
108107
.incremental(incremental)
109-
.allocator(new IoUringFixedBufferRingAllocator(1024), true)
108+
.allocator(new IoUringFixedBufferRingAllocator(1024))
109+
.batchAllocation(true)
110110
.build();
111111
ioUringIoHandlerConfiguration.setBufferRingConfig(bufferRingConfig, bufferRingConfig1);
112112

transport-native-io_uring/src/test/java/io/netty/channel/uring/IoUringSocketTestPermutation.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ static IoUringIoHandlerConfig buildConfig(boolean incremental) {
5656
.bufferRingSize((short) 16)
5757
.batchSize(8)
5858
.incremental(incremental)
59-
.allocator(new IoUringFixedBufferRingAllocator(1024),
60-
// Ensure we test both variants
61-
ThreadLocalRandom.current().nextBoolean())
59+
.allocator(new IoUringFixedBufferRingAllocator(1024))
60+
// Ensure we test both variants
61+
.batchAllocation(ThreadLocalRandom.current().nextBoolean())
6262
.build()
6363
);
6464
}

0 commit comments

Comments
 (0)