Skip to content

Commit 5433d65

Browse files
author
Frank Chen
committed
Merge branch 'fix/lmi-invocation-lifecycle' into feature/invocation-executor-isolation
2 parents 7f73de8 + 748b2f4 commit 5433d65

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

‎sdk/src/main/java/software/amazon/lambda/durable/execution/ApiRequestDelayedBatcher.java‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* @param <T> Request type
2626
*/
2727
public class ApiRequestDelayedBatcher<T> {
28-
private static final Duration MAX_DELAY = Duration.ofMinutes(60);
28+
private static final long NO_FLUSH_DEADLINE = Long.MAX_VALUE;
2929

3030
/** Maximum items allowed in a single batch */
3131
private final int maxItemCount;
@@ -120,8 +120,9 @@ void shutdown(Duration timeout) throws InterruptedException, ExecutionException,
120120
/** clear the current batch and creates a new batch */
121121
private void initializeDelayedBatch() {
122122
this.delayedBatch.clear();
123-
// MAX_DELAY is longer than a single Lambda invocation
124-
this.delayedBatchFlushTime = System.nanoTime() + MAX_DELAY.toNanos();
123+
// No timer is scheduled until the first item supplies an actual flush deadline. Using an unbounded sentinel
124+
// avoids coupling batching behavior to the maximum Lambda invocation duration.
125+
this.delayedBatchFlushTime = NO_FLUSH_DEADLINE;
125126

126127
// the timer future is created initially without a timeout until an item is added to the batch
127128
this.delayedBatchFlushTimer = new CompletableFuture<>();

‎sdk/src/test/java/software/amazon/lambda/durable/execution/ApiRequestDelayedBatcherTest.java‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,19 @@ void whenEarlierDelaySubmitted_batchFlushesAtEarlierTime() {
212212
verify(doBatchAction).accept(any());
213213
}
214214

215+
@Test
216+
void whenDelayExceedsNinetyMinutes_firstSubmissionStillSetsFlushDeadline() throws Exception {
217+
var submittedAt = System.nanoTime();
218+
cut.submit(input, Duration.ofMinutes(91));
219+
220+
var flushTimeField = ApiRequestDelayedBatcher.class.getDeclaredField("delayedBatchFlushTime");
221+
flushTimeField.setAccessible(true);
222+
var flushTime = flushTimeField.getLong(cut);
223+
224+
assertTrue(flushTime > submittedAt + Duration.ofMinutes(90).toNanos());
225+
cut.shutdown(SHUTDOWN_TIMEOUT);
226+
}
227+
215228
@Test
216229
void whenNoItemsSubmitted_shutdownDoesNotInvokeBatchAction() throws Exception {
217230
cut.shutdown(SHUTDOWN_TIMEOUT);

0 commit comments

Comments
 (0)