Skip to content

Commit 13b4e0f

Browse files
committed
Addressed review comments for logger
1 parent 6ec44b2 commit 13b4e0f

4 files changed

Lines changed: 42 additions & 10 deletions

File tree

examples/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@
4040
<dependency>
4141
<groupId>org.apache.logging.log4j</groupId>
4242
<artifactId>log4j-slf4j2-impl</artifactId>
43-
<version>2.24.3</version>
43+
<version>2.25.3</version>
4444
</dependency>
4545
<dependency>
4646
<groupId>org.apache.logging.log4j</groupId>
4747
<artifactId>log4j-core</artifactId>
48-
<version>2.24.3</version>
48+
<version>2.25.3</version>
4949
</dependency>
5050

5151
<!-- Testing -->

examples/template.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,28 @@ Resources:
186186
DockerContext: ../
187187
DockerTag: durable-examples
188188

189+
LoggingExampleFunction:
190+
Type: AWS::Serverless::Function
191+
Properties:
192+
PackageType: Image
193+
FunctionName: logging-example
194+
ImageConfig:
195+
Command: ["com.amazonaws.lambda.durable.examples.LoggingExample::handleRequest"]
196+
DurableConfig:
197+
ExecutionTimeout: 300
198+
RetentionPeriodInDays: 7
199+
Policies:
200+
- Statement:
201+
- Effect: Allow
202+
Action:
203+
- lambda:CheckpointDurableExecutions
204+
- lambda:GetDurableExecutionState
205+
Resource: !Sub "arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:logging-example"
206+
Metadata:
207+
Dockerfile: examples/Dockerfile
208+
DockerContext: ../
209+
DockerTag: durable-examples
210+
189211
Outputs:
190212
SimpleStepExampleFunction:
191213
Description: Simple Step Example Function ARN
@@ -250,3 +272,11 @@ Outputs:
250272
CustomConfigExampleFunctionName:
251273
Description: Custom Config Example Function Name
252274
Value: !Ref CustomConfigExampleFunction
275+
276+
LoggingExampleFunction:
277+
Description: Logging Example Function ARN
278+
Value: !GetAtt LoggingExampleFunction.Arn
279+
280+
LoggingExampleFunctionName:
281+
Description: Logging Example Function Name
282+
Value: !Ref LoggingExampleFunction

sdk/src/main/java/com/amazonaws/lambda/durable/execution/ExecutionManager.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.concurrent.Executor;
1717
import java.util.concurrent.Executors;
1818
import java.util.concurrent.Phaser;
19+
import java.util.concurrent.atomic.AtomicReference;
1920
import org.slf4j.Logger;
2021
import org.slf4j.LoggerFactory;
2122
import software.amazon.awssdk.services.lambda.model.Operation;
@@ -46,10 +47,10 @@ public class ExecutionManager {
4647
private final String executionOperationId;
4748
private volatile String checkpointToken;
4849
private final String durableExecutionArn;
49-
private volatile ExecutionMode executionMode;
50+
private final AtomicReference<ExecutionMode> executionMode;
5051

5152
// ===== Current Operation Context (for logging) =====
52-
private static final ThreadLocal<OperationContext> currentOperation = new ThreadLocal<>();
53+
private static final ThreadLocal<OperationContext> currentOperation = new InheritableThreadLocal<>();
5354

5455
// ===== Thread Coordination =====
5556
private final Map<String, ThreadType> activeThreads = Collections.synchronizedMap(new HashMap<>());
@@ -76,7 +77,7 @@ public ExecutionManager(
7677
loadAllOperations(initialExecutionState);
7778

7879
// Start in REPLAY mode if we have more than just the initial EXECUTION operation
79-
this.executionMode = operations.size() > 1 ? ExecutionMode.REPLAY : ExecutionMode.EXECUTION;
80+
this.executionMode = new AtomicReference<>(operations.size() > 1 ? ExecutionMode.REPLAY : ExecutionMode.EXECUTION);
8081

8182
this.managedExecutor = executor;
8283

@@ -114,7 +115,7 @@ public String getDurableExecutionArn() {
114115
}
115116

116117
public boolean isReplaying() {
117-
return executionMode == ExecutionMode.REPLAY;
118+
return executionMode.get() == ExecutionMode.REPLAY;
118119
}
119120

120121
public String getCheckpointToken() {
@@ -152,9 +153,10 @@ public Operation getOperation(String operationId) {
152153
*/
153154
public Operation getOperationAndUpdateReplayState(String operationId) {
154155
var existing = operations.get(operationId);
155-
if (executionMode == ExecutionMode.REPLAY && existing == null) {
156-
executionMode = ExecutionMode.EXECUTION;
157-
logger.debug("Transitioned to EXECUTION mode at operation '{}'", operationId);
156+
if (existing == null) {
157+
if (executionMode.compareAndSet(ExecutionMode.REPLAY, ExecutionMode.EXECUTION)) {
158+
logger.debug("Transitioned to EXECUTION mode at operation '{}'", operationId);
159+
}
158160
}
159161
return existing;
160162
}
@@ -337,6 +339,7 @@ public CompletableFuture<Void> getSuspendExecutionFuture() {
337339

338340
public void shutdown() {
339341
checkpointBatcher.shutdown();
342+
currentOperation.remove();
340343
}
341344

342345
private boolean isTerminalStatus(OperationStatus status) {

sdk/src/test/java/com/amazonaws/lambda/durable/logging/DurableLoggerTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// SPDX-License-Identifier: Apache-2.0
33
package com.amazonaws.lambda.durable.logging;
44

5-
import static org.junit.jupiter.api.Assertions.*;
65
import static org.mockito.Mockito.*;
76

87
import com.amazonaws.lambda.durable.execution.ExecutionManager;

0 commit comments

Comments
 (0)