Skip to content

Commit

Permalink
Merge branch 'main' into bl_anderson/RR_move_selection_to_Host
Browse files Browse the repository at this point in the history
  • Loading branch information
bryce-anderson committed Oct 17, 2023
2 parents 549b94e + f00a486 commit 24aacdc
Show file tree
Hide file tree
Showing 42 changed files with 569 additions and 141 deletions.
20 changes: 10 additions & 10 deletions docs/generation/site-remote.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,43 +30,43 @@ content:
sources:
- url: https://github.com/apple/servicetalk.git
branches: main
tags: [0.19.0, 0.20.0, 0.21.0, 0.22.0, 0.23.0, 0.24.0, 0.25.0, 0.26.0, 0.27.0, 0.28.0, 0.29.0, 0.30.0, 0.31.0, 0.32.0, 0.33.0, 0.34.0, 0.35.0, 0.36.0, 0.37.0, 0.38.0, 0.39.0, 0.40.0, 0.41.14, 0.42.37]
tags: [0.19.0, 0.20.0, 0.21.0, 0.22.0, 0.23.0, 0.24.0, 0.25.0, 0.26.0, 0.27.0, 0.28.0, 0.29.0, 0.30.0, 0.31.0, 0.32.0, 0.33.0, 0.34.0, 0.35.0, 0.36.0, 0.37.0, 0.38.0, 0.39.0, 0.40.0, 0.41.14, 0.42.38]
start_path: docs
- url: https://github.com/apple/servicetalk.git
branches: main
tags: [0.19.0, 0.20.0, 0.21.0, 0.22.0, 0.23.0, 0.24.0, 0.25.0, 0.26.0, 0.27.0, 0.28.0, 0.29.0, 0.30.0, 0.31.0, 0.32.0, 0.33.0, 0.34.0, 0.35.0, 0.36.0, 0.37.0, 0.38.0, 0.39.0, 0.40.0, 0.41.14, 0.42.37]
tags: [0.19.0, 0.20.0, 0.21.0, 0.22.0, 0.23.0, 0.24.0, 0.25.0, 0.26.0, 0.27.0, 0.28.0, 0.29.0, 0.30.0, 0.31.0, 0.32.0, 0.33.0, 0.34.0, 0.35.0, 0.36.0, 0.37.0, 0.38.0, 0.39.0, 0.40.0, 0.41.14, 0.42.38]
start_path: servicetalk-examples/docs
- url: https://github.com/apple/servicetalk.git
branches: main
tags: [0.19.0, 0.20.0, 0.21.0, 0.22.0, 0.23.0, 0.24.0, 0.25.0, 0.26.0, 0.27.0, 0.28.0, 0.29.0, 0.30.0, 0.31.0, 0.32.0, 0.33.0, 0.34.0, 0.35.0, 0.36.0, 0.37.0, 0.38.0, 0.39.0, 0.40.0, 0.41.14, 0.42.37]
tags: [0.19.0, 0.20.0, 0.21.0, 0.22.0, 0.23.0, 0.24.0, 0.25.0, 0.26.0, 0.27.0, 0.28.0, 0.29.0, 0.30.0, 0.31.0, 0.32.0, 0.33.0, 0.34.0, 0.35.0, 0.36.0, 0.37.0, 0.38.0, 0.39.0, 0.40.0, 0.41.14, 0.42.38]
start_path: servicetalk-http-api/docs
- url: https://github.com/apple/servicetalk.git
branches: main
tags: [0.19.0, 0.20.0, 0.21.0, 0.22.0, 0.23.0, 0.24.0, 0.25.0, 0.26.0, 0.27.0, 0.28.0, 0.29.0, 0.30.0, 0.31.0, 0.32.0, 0.33.0, 0.34.0, 0.35.0, 0.36.0, 0.37.0, 0.38.0, 0.39.0, 0.40.0, 0.41.14, 0.42.37]
tags: [0.19.0, 0.20.0, 0.21.0, 0.22.0, 0.23.0, 0.24.0, 0.25.0, 0.26.0, 0.27.0, 0.28.0, 0.29.0, 0.30.0, 0.31.0, 0.32.0, 0.33.0, 0.34.0, 0.35.0, 0.36.0, 0.37.0, 0.38.0, 0.39.0, 0.40.0, 0.41.14, 0.42.38]
start_path: servicetalk-http-router-jersey/docs
- url: https://github.com/apple/servicetalk.git
branches: main
tags: [0.19.0, 0.20.0, 0.21.0, 0.22.0, 0.23.0, 0.24.0, 0.25.0, 0.26.0, 0.27.0, 0.28.0, 0.29.0, 0.30.0, 0.31.0, 0.32.0, 0.33.0, 0.34.0, 0.35.0, 0.36.0, 0.37.0, 0.38.0, 0.39.0, 0.40.0, 0.41.14, 0.42.37]
tags: [0.19.0, 0.20.0, 0.21.0, 0.22.0, 0.23.0, 0.24.0, 0.25.0, 0.26.0, 0.27.0, 0.28.0, 0.29.0, 0.30.0, 0.31.0, 0.32.0, 0.33.0, 0.34.0, 0.35.0, 0.36.0, 0.37.0, 0.38.0, 0.39.0, 0.40.0, 0.41.14, 0.42.38]
start_path: servicetalk-http-security-jersey/docs
- url: https://github.com/apple/servicetalk.git
branches: main
tags: [0.19.0, 0.20.0, 0.21.0, 0.22.0, 0.23.0, 0.24.0, 0.25.0, 0.26.0, 0.27.0, 0.28.0, 0.29.0, 0.30.0, 0.31.0, 0.32.0, 0.33.0, 0.34.0, 0.35.0, 0.36.0, 0.37.0, 0.38.0, 0.39.0, 0.40.0, 0.41.14, 0.42.37]
tags: [0.19.0, 0.20.0, 0.21.0, 0.22.0, 0.23.0, 0.24.0, 0.25.0, 0.26.0, 0.27.0, 0.28.0, 0.29.0, 0.30.0, 0.31.0, 0.32.0, 0.33.0, 0.34.0, 0.35.0, 0.36.0, 0.37.0, 0.38.0, 0.39.0, 0.40.0, 0.41.14, 0.42.38]
start_path: servicetalk-concurrent-api/docs
- url: https://github.com/apple/servicetalk.git
branches: main
tags: [0.19.0, 0.20.0, 0.21.0, 0.22.0, 0.23.0, 0.24.0, 0.25.0, 0.26.0, 0.27.0, 0.28.0, 0.29.0, 0.30.0, 0.31.0, 0.32.0, 0.33.0, 0.34.0, 0.35.0, 0.36.0, 0.37.0, 0.38.0, 0.39.0, 0.40.0, 0.41.14, 0.42.37]
tags: [0.19.0, 0.20.0, 0.21.0, 0.22.0, 0.23.0, 0.24.0, 0.25.0, 0.26.0, 0.27.0, 0.28.0, 0.29.0, 0.30.0, 0.31.0, 0.32.0, 0.33.0, 0.34.0, 0.35.0, 0.36.0, 0.37.0, 0.38.0, 0.39.0, 0.40.0, 0.41.14, 0.42.38]
start_path: servicetalk-data-jackson-jersey/docs
- url: https://github.com/apple/servicetalk.git
branches: main
tags: [0.19.0, 0.20.0, 0.21.0, 0.22.0, 0.23.0, 0.24.0, 0.25.0, 0.26.0, 0.27.0, 0.28.0, 0.29.0, 0.30.0, 0.31.0, 0.32.0, 0.33.0, 0.34.0, 0.35.0, 0.36.0, 0.37.0, 0.38.0, 0.39.0, 0.40.0, 0.41.14, 0.42.37]
tags: [0.19.0, 0.20.0, 0.21.0, 0.22.0, 0.23.0, 0.24.0, 0.25.0, 0.26.0, 0.27.0, 0.28.0, 0.29.0, 0.30.0, 0.31.0, 0.32.0, 0.33.0, 0.34.0, 0.35.0, 0.36.0, 0.37.0, 0.38.0, 0.39.0, 0.40.0, 0.41.14, 0.42.38]
start_path: servicetalk-grpc-api/docs
- url: https://github.com/apple/servicetalk.git
branches: main
tags: [0.20.0, 0.21.0, 0.22.0, 0.23.0, 0.24.0, 0.25.0, 0.26.0, 0.27.0, 0.28.0, 0.29.0, 0.30.0, 0.31.0, 0.32.0, 0.33.0, 0.34.0, 0.35.0, 0.36.0, 0.37.0, 0.38.0, 0.39.0, 0.40.0, 0.41.14, 0.42.37]
tags: [0.20.0, 0.21.0, 0.22.0, 0.23.0, 0.24.0, 0.25.0, 0.26.0, 0.27.0, 0.28.0, 0.29.0, 0.30.0, 0.31.0, 0.32.0, 0.33.0, 0.34.0, 0.35.0, 0.36.0, 0.37.0, 0.38.0, 0.39.0, 0.40.0, 0.41.14, 0.42.38]
start_path: servicetalk-loadbalancer/docs
- url: https://github.com/apple/servicetalk.git
branches: main
tags: [0.25.0, 0.26.0, 0.27.0, 0.28.0, 0.29.0, 0.30.0, 0.31.0, 0.32.0, 0.33.0, 0.34.0, 0.35.0, 0.36.0, 0.37.0, 0.38.0, 0.39.0, 0.40.0, 0.41.14, 0.42.37]
tags: [0.25.0, 0.26.0, 0.27.0, 0.28.0, 0.29.0, 0.30.0, 0.31.0, 0.32.0, 0.33.0, 0.34.0, 0.35.0, 0.36.0, 0.37.0, 0.38.0, 0.39.0, 0.40.0, 0.41.14, 0.42.38]
start_path: servicetalk-client-api/docs
asciidoc:
attributes:
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ org.gradle.jvmargs=-Xms2g -Xmx4g -dsa -da -ea:io.servicetalk... -XX:+HeapDumpOnO

# project metadata used for publications
group=io.servicetalk
version=0.42.38-SNAPSHOT
version=0.42.39-SNAPSHOT
scmHost=github.com
scmPath=apple/servicetalk
issueManagementUrl=https://github.com/apple/servicetalk/issues
ciManagementUrl=https://github.com/apple/servicetalk/actions

# dependency versions
nettyVersion=4.1.99.Final
nettyVersion=4.1.100.Final
nettyIoUringVersion=0.0.23.Final

jsr305Version=3.0.2
Expand All @@ -49,7 +49,7 @@ jerseyVersion=2.37
reactiveStreamsVersion=1.0.4
jcToolsVersion=4.0.1
# backward compatible with jackson 2.9+, we do not depend on any new features from later versions.
jacksonVersion=2.14.3
jacksonVersion=2.15.2

openTracingVersion=0.33.0
zipkinReporterVersion=2.16.4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.time.Duration;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Iterator;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
Expand Down Expand Up @@ -158,23 +157,30 @@ private static final class LazyTimeLimitedReplayAccumulator<T> implements Replay

@Override
public void accumulate(@Nullable final T t) {
final long nanoTime = executor.currentTime(NANOSECONDS);
trimExpired(nanoTime);
if (items.size() >= maxItems) {
items.poll();
}
items.add(new TimeStampSignal<>(executor.currentTime(NANOSECONDS), t));
items.add(new TimeStampSignal<>(nanoTime, t));
}

@Override
public void deliverAccumulation(final Consumer<T> consumer) {
final Iterator<TimeStampSignal<T>> itr = items.iterator();
final long nanoTime = executor.currentTime(NANOSECONDS);
while (itr.hasNext()) {
final TimeStampSignal<T> next = itr.next();
if (nanoTime - next.timeStamp >= ttlNanos) {
itr.remove();
} else {
consumer.accept(next.signal);
}
if (items.isEmpty()) {
return;
}
trimExpired(executor.currentTime(NANOSECONDS));
for (TimeStampSignal<T> next : items) {
consumer.accept(next.signal);
}
}

private void trimExpired(long nanoTime) {
// Entry time stamps are monotonically increasing, so we only need to trim until the first non-stale entry.
TimeStampSignal<T> next;
while ((next = items.peek()) != null && nanoTime - next.timeStamp >= ttlNanos) {
items.poll();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion servicetalk-examples/grpc/helloworld/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<properties>
<!-- servicetalk.version is updated automatically by release.sh during the ServiceTalk release process -->
<servicetalk.version>0.42.37</servicetalk.version>
<servicetalk.version>0.42.38</servicetalk.version>
<protobuf-maven-plugin.version>0.6.1</protobuf-maven-plugin.version>
<protoc.version>3.19.2</protoc.version>
<os-maven-plugin.version>1.6.0</os-maven-plugin.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ Single<FilterableStreamingHttpConnection> newFilterableConnection(
private Single<FilterableStreamingHttpConnection> createConnection(
final Channel channel, final ConnectionObserver connectionObserver,
final ReadOnlyTcpClientConfig tcpConfig) {
return new AlpnChannelSingle(channel, new TcpClientChannelInitializer(tcpConfig, connectionObserver),
return new AlpnChannelSingle(channel,
new TcpClientChannelInitializer(tcpConfig, connectionObserver, executionContext, false),
ctx -> { /* SslHandler will automatically start handshake on channelActive */ }).flatMap(protocol -> {
switch (protocol) {
case HTTP_1_1:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2019-2021 Apple Inc. and the ServiceTalk project authors
* Copyright © 2019-2023 Apple Inc. and the ServiceTalk project authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -91,7 +91,8 @@ private static Single<NettyConnectionContext> alpnInitChannel(final SocketAddres
final StreamingHttpService service,
final boolean drainRequestPayloadBody,
final ConnectionObserver observer) {
return new AlpnChannelSingle(channel, new TcpServerChannelInitializer(config.tcpConfig(), observer),
return new AlpnChannelSingle(channel,
new TcpServerChannelInitializer(config.tcpConfig(), observer, httpExecutionContext),
// Force a read to get the SSL handshake started. We initialize pipeline before
// SslHandshakeCompletionEvent will complete, therefore, no data will be propagated before we finish
// initialization.
Expand All @@ -117,7 +118,7 @@ private static Single<NettyConnectionContext> sniInitChannel(final SocketAddress
final boolean drainRequestPayloadBody,
final ConnectionObserver observer) {
return new SniCompleteChannelSingle(channel,
new TcpServerChannelInitializer(config.tcpConfig(), observer)).flatMap(sniEvt -> {
new TcpServerChannelInitializer(config.tcpConfig(), observer, httpExecutionContext)).flatMap(sniEvt -> {
Throwable failureCause = sniEvt.cause();
if (failureCause != null) {
return failed(failureCause);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Single<FilterableStreamingHttpConnection> newFilterableConnection(
(channel, connectionObserver) -> H2ClientParentConnectionContext.initChannel(channel,
executionContext, config.h2Config(), reqRespFactoryFunc.apply(HTTP_2_0),
tcpConfig.flushStrategy(), tcpConfig.idleTimeoutMs(), tcpConfig.sslConfig(),
new TcpClientChannelInitializer(tcpConfig, connectionObserver).andThen(
new TcpClientChannelInitializer(tcpConfig, connectionObserver, executionContext, false).andThen(
new H2ClientParentChannelInitializer(config.h2Config())), connectionObserver,
config.allowDropTrailersReadFromTransport()), observer);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2019-2021 Apple Inc. and the ServiceTalk project authors
* Copyright © 2019-2023 Apple Inc. and the ServiceTalk project authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -100,7 +100,7 @@ static Single<HttpServerContext> bind(final HttpExecutionContext executionContex
final ReadOnlyTcpServerConfig tcpServerConfig = config.tcpConfig();
return TcpServerBinder.bind(listenAddress, tcpServerConfig, executionContext, connectionAcceptor,
(channel, connectionObserver) -> initChannel(listenAddress, channel, executionContext, config,
new TcpServerChannelInitializer(tcpServerConfig, connectionObserver), service,
new TcpServerChannelInitializer(tcpServerConfig, connectionObserver, executionContext), service,
drainRequestPayloadBody, connectionObserver),
serverConnection -> { /* nothing to do as h2 uses auto read on the parent channel */ },
earlyConnectionAcceptor, lateConnectionAcceptor)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2018-2021 Apple Inc. and the ServiceTalk project authors
* Copyright © 2018-2023 Apple Inc. and the ServiceTalk project authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -129,7 +129,7 @@ static Single<HttpServerContext> bind(final HttpExecutionContext executionContex
final ReadOnlyTcpServerConfig tcpServerConfig = config.tcpConfig();
return TcpServerBinder.bind(address, tcpServerConfig, executionContext, connectionAcceptor,
(channel, connectionObserver) -> initChannel(channel, executionContext, config,
new TcpServerChannelInitializer(tcpServerConfig, connectionObserver), service,
new TcpServerChannelInitializer(tcpServerConfig, connectionObserver, executionContext), service,
drainRequestPayloadBody, connectionObserver),
serverConnection -> serverConnection.process(true),
earlyConnectionAcceptor, lateConnectionAcceptor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,61 @@ final class OptimizedHttp2FrameCodecBuilder extends Http2FrameCodecBuilder {

private static final Logger LOGGER = LoggerFactory.getLogger(OptimizedHttp2FrameCodecBuilder.class);

// FIXME: 0.43 - reconsider system properties for netty-codec-http2
// These properties are introduced temporarily in case users need to disable or re-configure default values set by
// Netty. For the next major release we should either remove these properties or promote them to public API.
private static final String MAX_CONSECUTIVE_EMPTY_FRAMES_PROPERTY_NAME =
"io.servicetalk.http.netty.http2.decoderEnforceMaxRstFramesPerWindow.maxConsecutiveEmptyFrames";
private static final String SECONDS_PER_WINDOW_PROPERTY_NAME =
"io.servicetalk.http.netty.http2.decoderEnforceMaxRstFramesPerWindow.secondsPerWindow";

private static final int MAX_CONSECUTIVE_EMPTY_FRAMES;
private static final int SECONDS_PER_WINDOW;

@Nullable
private static final MethodHandle FLUSH_PREFACE;

@Nullable
private static final MethodHandle DECODER_ENFORCE_MAX_RST_FRAMES_PER_WINDOW;

static {
final Http2FrameCodecBuilder builder = Http2FrameCodecBuilder.forServer();

MethodHandle flushPreface;
try {
// Find a new method that exists only in Netty starting from 4.1.78.Final:
flushPreface = MethodHandles.publicLookup()
.findVirtual(Http2FrameCodecBuilder.class, "flushPreface",
methodType(Http2FrameCodecBuilder.class, boolean.class));
// Verify the method is working as expected:
disableFlushPreface(flushPreface, Http2FrameCodecBuilder.forClient());
disableFlushPreface(flushPreface, builder);
} catch (Throwable cause) {
LOGGER.debug("Http2FrameCodecBuilder#flushPreface(boolean) is available only starting from " +
"Netty 4.1.78.Final. Detected Netty version: {}",
Http2FrameCodecBuilder.class.getPackage().getImplementationVersion(), cause);
flushPreface = null;
}
FLUSH_PREFACE = flushPreface;

// Default values are taken from Netty's AbstractHttp2ConnectionHandlerBuilder
MAX_CONSECUTIVE_EMPTY_FRAMES = parseProperty(MAX_CONSECUTIVE_EMPTY_FRAMES_PROPERTY_NAME, 200);
SECONDS_PER_WINDOW = parseProperty(SECONDS_PER_WINDOW_PROPERTY_NAME, 30);

MethodHandle decoderEnforceMaxRstFramesPerWindow;
try {
// Find a new method that exists only in Netty starting from 4.1.100.Final:
decoderEnforceMaxRstFramesPerWindow = MethodHandles.publicLookup()
.findVirtual(Http2FrameCodecBuilder.class, "decoderEnforceMaxRstFramesPerWindow",
methodType(Http2FrameCodecBuilder.class, int.class, int.class));
// Verify the method is working as expected:
decoderEnforceMaxRstFramesPerWindow(decoderEnforceMaxRstFramesPerWindow, builder);
} catch (Throwable cause) {
LOGGER.debug("Http2FrameCodecBuilder#decoderEnforceMaxRstFramesPerWindow(int, int) is available only " +
"starting from Netty 4.1.100.Final. Detected Netty version: {}",
Http2FrameCodecBuilder.class.getPackage().getImplementationVersion(), cause);
decoderEnforceMaxRstFramesPerWindow = null;
}
DECODER_ENFORCE_MAX_RST_FRAMES_PER_WINDOW = decoderEnforceMaxRstFramesPerWindow;
}

private final boolean server;
Expand All @@ -74,6 +110,7 @@ final class OptimizedHttp2FrameCodecBuilder extends Http2FrameCodecBuilder {
this.server = server;
this.flowControlQuantum = flowControlQuantum;
disableFlushPreface(FLUSH_PREFACE, this);
decoderEnforceMaxRstFramesPerWindow(DECODER_ENFORCE_MAX_RST_FRAMES_PER_WINDOW, this);
}

@Override
Expand Down Expand Up @@ -115,4 +152,44 @@ private static Http2FrameCodecBuilder disableFlushPreface(@Nullable final Method
return builderInstance;
}
}

// To avoid a strict dependency on Netty 4.1.100.Final in the classpath, we use {@link MethodHandle} to check if
// the new method is available or not.
private static Http2FrameCodecBuilder decoderEnforceMaxRstFramesPerWindow(
@Nullable final MethodHandle methodHandle, final Http2FrameCodecBuilder builderInstance) {
if (methodHandle == null) {
return builderInstance;
}
try {
// invokeExact requires return type cast to match the type signature
return (Http2FrameCodecBuilder) methodHandle.invokeExact(builderInstance,
MAX_CONSECUTIVE_EMPTY_FRAMES, SECONDS_PER_WINDOW);
} catch (Throwable t) {
throwException(t);
return builderInstance;
}
}

private static int parseProperty(final String name, final int defaultValue) {
final String value = System.getProperty(name);
final int intValue;
if (value == null || value.isEmpty()) {
intValue = defaultValue;
} else {
try {
intValue = Integer.parseInt(value);
if (intValue < 0) {
LOGGER.error("Found invalid value -D{}={} (expected >= 0), using fallback value={}",
name, value, defaultValue);
return defaultValue;
}
} catch (NumberFormatException e) {
LOGGER.error("Could not parse -D{}={} (expected int >= 0), using fallback value={}",
name, value, defaultValue, e);
return defaultValue;
}
}
LOGGER.debug("-D{}={}", name, intValue);
return intValue;
}
}
Loading

0 comments on commit 24aacdc

Please sign in to comment.