GeezerVison is showing github.com — Max ack ext by davidtorres · Pull Request #1773 · googleapis/google-cloud-java
Max ack ext
#1773
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
Uh oh!
There was an error while loading. Please reload this page.
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c4c6174
Enabling client-side compression in the library, with an option to
davidtorres Feb 22, 2017
27338a4
Merge remote-tracking branch 'upstream/master'
davidtorres Feb 23, 2017
d6a1043
Revert "Enabling client-side compression in the library, with an opti…
davidtorres Feb 23, 2017
823ad09
Merge remote-tracking branch 'upstream/master'
davidtorres Mar 15, 2017
ec14abe
Changing the AckReplyConsumer interface to comply to just the Java 8 …
davidtorres Mar 15, 2017
652894a
Merge remote-tracking branch 'upstream/master'
davidtorres Mar 20, 2017
3e906e6
Example fixes to comply with changes to the AckReplyConsumer interface.
davidtorres Mar 20, 2017
32af932
Allowing for setting a maximum for message lease extensions.
davidtorres Mar 29, 2017
7779e37
Setting so the max ack deadline duration is always respected even when
davidtorres Mar 30, 2017
45248f0
Merge branch 'master' into max-ack-ext
davidtorres Apr 5, 2017
d4f0048
Merge remote-tracking branch 'upstream/master' into max-ack-ext
davidtorres Apr 5, 2017
File filter
Filter by extension
.java
(5)
All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
Expand Up
@@ -61,6 +61,7 @@ class MessageDispatcher {
private final ApiClock clock;
private final Duration ackExpirationPadding;
private final Duration maxAckExtensionPeriod;
private final MessageReceiver receiver;
private final AckProcessor ackProcessor;
Expand All
@@ -87,20 +88,27 @@ class MessageDispatcher {
// it is not modified while inside the queue.
// The hashcode and equals methods are explicitly not implemented to discourage
// the use of this class as keys in maps or similar containers.
private static class ExtensionJob implements Comparable<ExtensionJob> {
private class ExtensionJob implements Comparable<ExtensionJob> {
Instant creation;
Instant expiration;
int nextExtensionSeconds;
ArrayList<AckHandler> ackHandlers;
ExtensionJob(
Instant expiration, int initialAckDeadlineExtension, ArrayList<AckHandler> ackHandlers) {
Instant creation,
Instant expiration,
int initialAckDeadlineExtension,
ArrayList<AckHandler> ackHandlers) {
this.creation = creation;
this.expiration = expiration;
nextExtensionSeconds = initialAckDeadlineExtension;
this.ackHandlers = ackHandlers;
}
void extendExpiration(Instant now) {
expiration = now.plus(Duration.standardSeconds(nextExtensionSeconds));
Instant possibleExtension = now.plus(Duration.standardSeconds(nextExtensionSeconds));
Instant maxExtension = creation.plus(maxAckExtensionPeriod);
expiration = possibleExtension.isBefore(maxExtension) ? possibleExtension : maxExtension;
nextExtensionSeconds = Math.min(2 * nextExtensionSeconds, MAX_ACK_DEADLINE_EXTENSION_SECS);
}
Expand Down
Expand Up
@@ -217,12 +225,14 @@ void sendAckOperations(
MessageReceiver receiver,
AckProcessor ackProcessor,
Duration ackExpirationPadding,
Duration maxAckExtensionPeriod,
Distribution ackLatencyDistribution,
FlowController flowController,
ScheduledExecutorService executor,
ApiClock clock) {
this.executor = executor;
this.ackExpirationPadding = ackExpirationPadding;
this.maxAckExtensionPeriod = maxAckExtensionPeriod;
this.receiver = receiver;
this.ackProcessor = ackProcessor;
this.flowController = flowController;
Expand Down
Expand Up
@@ -305,7 +315,11 @@ public void run() {
synchronized (outstandingAckHandlers) {
outstandingAckHandlers.add(
new ExtensionJob(expiration, INITIAL_ACK_DEADLINE_EXTENSION_SECONDS, ackHandlers));
new ExtensionJob(
new Instant(clock.millis()),
expiration,
INITIAL_ACK_DEADLINE_EXTENSION_SECONDS,
ackHandlers));
}
setupNextAckDeadlineExtensionAlarm(expiration);
Expand Down
Expand Up
@@ -380,6 +394,13 @@ public void run() {
&& outstandingAckHandlers.peek().expiration.compareTo(cutOverTime) <= 0) {
ExtensionJob job = outstandingAckHandlers.poll();
if (maxAckExtensionPeriod.getMillis() > 0
&& job.creation.plus(maxAckExtensionPeriod).compareTo(now) <= 0) {
// The job has expired, according to the maxAckExtensionPeriod, we are just going to
// drop it.
continue;
}
// If a message has already been acked, remove it, nothing to do.
for (int i = 0; i < job.ackHandlers.size(); ) {
if (job.ackHandlers.get(i).acked.get()) {
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -67,6 +67,7 @@ public PollingSubscriberConnection(
Credentials credentials,
MessageReceiver receiver,
Duration ackExpirationPadding,
Duration maxAckExtensionPeriod,
Distribution ackLatencyDistribution,
Channel channel,
FlowController flowController,
Expand All
@@ -82,6 +83,7 @@ public PollingSubscriberConnection(
receiver,
this,
ackExpirationPadding,
maxAckExtensionPeriod,
ackLatencyDistribution,
flowController,
executor,
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -70,6 +70,7 @@ public StreamingSubscriberConnection(
Credentials credentials,
MessageReceiver receiver,
Duration ackExpirationPadding,
Duration maxAckExtensionPeriod,
int streamAckDeadlineSeconds,
Distribution ackLatencyDistribution,
Channel channel,
Expand All
@@ -85,6 +86,7 @@ public StreamingSubscriberConnection(
receiver,
this,
ackExpirationPadding,
maxAckExtensionPeriod,
ackLatencyDistribution,
flowController,
executor,
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -92,6 +92,7 @@ public class Subscriber extends AbstractApiService {
private final String cachedSubscriptionNameString;
private final FlowControlSettings flowControlSettings;
private final Duration ackExpirationPadding;
private final Duration maxAckExtensionPeriod;
private final ScheduledExecutorService executor;
private final Distribution ackLatencyDistribution =
new Distribution(MAX_ACK_DEADLINE_SECONDS + 1);
Expand All
@@ -113,6 +114,7 @@ private Subscriber(Builder builder) throws IOException {
subscriptionName = builder.subscriptionName;
cachedSubscriptionNameString = subscriptionName.toString();
ackExpirationPadding = builder.ackExpirationPadding;
maxAckExtensionPeriod = builder.maxAckExtensionPeriod;
streamAckDeadlineSeconds =
Math.max(
INITIAL_ACK_DEADLINE_SECONDS,
Expand Down
Expand Up
@@ -241,6 +243,7 @@ private void startStreamingConnections() {
credentials,
receiver,
ackExpirationPadding,
maxAckExtensionPeriod,
streamAckDeadlineSeconds,
ackLatencyDistribution,
channelBuilder.build(),
Expand Down
Expand Up
@@ -317,6 +320,7 @@ private void startPollingConnections() {
credentials,
receiver,
ackExpirationPadding,
maxAckExtensionPeriod,
ackLatencyDistribution,
channelBuilder.build(),
flowController,
Expand Down
Expand Up
@@ -405,6 +409,7 @@ public void run() {
public static final class Builder {
private static final Duration MIN_ACK_EXPIRATION_PADDING = Duration.millis(100);
private static final Duration DEFAULT_ACK_EXPIRATION_PADDING = Duration.millis(500);
private static final Duration DEFAULT_MAX_ACK_EXTENSION_PERIOD = Duration.standardMinutes(60);
static final ExecutorProvider DEFAULT_EXECUTOR_PROVIDER =
InstantiatingExecutorProvider.newBuilder()
Expand All
@@ -419,6 +424,7 @@ public static final class Builder {
MessageReceiver receiver;
Duration ackExpirationPadding = DEFAULT_ACK_EXPIRATION_PADDING;
Duration maxAckExtensionPeriod = DEFAULT_MAX_ACK_EXTENSION_PERIOD;
FlowControlSettings flowControlSettings = FlowControlSettings.getDefaultInstance();
Expand Down
Expand Up
@@ -479,6 +485,21 @@ public Builder setAckExpirationPadding(Duration ackExpirationPadding) {
return this;
}
/**
* Set the maximum period a message ack deadline will be extended.
*
* <p>It is recommended to set this value to a reasonable upper bound of the subscriber time to
* process any message. This maximum period avoids messages to be <i>locked</i> by a subscriber
* in cases when the {@link AckReply} is lost.
*
* <p>A zero duration effectively disables auto deadline extensions.
*/
public Builder setMaxAckExtensionPeriod(Duration maxAckExtensionPeriod) {
Preconditions.checkArgument(maxAckExtensionPeriod.getMillis() >= 0);
this.maxAckExtensionPeriod = maxAckExtensionPeriod;
return this;
}
/** Gives the ability to set a custom executor. */
public Builder setExecutorProvider(ExecutorProvider executorProvider) {
this.executorProvider = Preconditions.checkNotNull(executorProvider);
Expand All
@@ -496,3 +517,4 @@ public Subscriber build() throws IOException {
}
}
}
Original file line number
Diff line number
Diff line change
Expand Up
@@ -18,6 +18,7 @@
import static com.google.cloud.pubsub.spi.v1.MessageDispatcher.PENDING_ACKS_SEND_DELAY;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import com.google.api.gax.grpc.FixedExecutorProvider;
import com.google.api.gax.grpc.InstantiatingExecutorProvider;
Expand Down
Expand Up
@@ -276,8 +277,8 @@ public void testModifyAckDeadline() throws Exception {
Subscriber subscriber =
startSubscriber(
getTestSubscriberBuilder(testReceiver)
.setAckExpirationPadding(Duration.standardSeconds(1)));
.setAckExpirationPadding(Duration.standardSeconds(1))
.setMaxAckExtensionPeriod(Duration.standardSeconds(13)));
// Send messages to be acked
List<String> testAckIdsBatch = ImmutableList.of("A", "B", "C");
testReceiver.setExplicitAck(true);
Expand Down
Expand Up
@@ -305,10 +306,17 @@ public ModifyAckDeadline apply(String ack) {
new Function<String, ModifyAckDeadline>() {
@Override
public ModifyAckDeadline apply(String ack) {
return new ModifyAckDeadline(ack, 4);
return new ModifyAckDeadline(ack, 2); // It is expected that the deadline is renewed
// only two more seconds to not pass the max
// ack deadline ext.
}
});
// No more modify ack deadline extension should be triggered at this point
fakeExecutor.advanceTime(Duration.standardSeconds(20));
assertTrue(fakeSubscriberServiceImpl.getModifyAckDeadlines().isEmpty());
testReceiver.replyAllOutstandingMessage();
subscriber.stopAsync().awaitTerminated();
}
Expand Down
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.