Repository navigation
Conversation
| String distributedMapRunArn, | ||
| DistributedMapError error, | ||
| Long totalCount, | ||
| Operation operation) { |
There was a problem hiding this comment.
Is this record serializable?
There was a problem hiding this comment.
Jackson can't serialize Operation, so returning a DsitributedMapSummary/Result from `runInChildContext or the handler failed.
The summary only holds the operation so throwIfError() can pass it to DurableOperationException. Nothing else uses it. So I just removed it from the summary so DsitributedMapSummary/Result are serializable now.
throwIfError() still builds DistributedMapException from the run's status, failure count and error. But DistributedMapException has no operation now, so getOperation() returns null. Left a comment explaining this.
| long failureCount, | ||
| String message, | ||
| DistributedMapError error) { | ||
| super(operation, toErrorObject(error, message), message); |
There was a problem hiding this comment.
Does this error always have the fields we expect?
There was a problem hiding this comment.
No. errorType and errorMessage can each be null or empty, and a run can end with no error. DistributedMapException handles these the same way as the SDK's other operation exceptions:
getErrorObject()returns the recorded error unchanged.- When there is no error,
getErrorObject()uses the exception's class name and message. - The exception message leaves out a type or message that is null or empty.
| } | ||
|
|
||
| /** Returns items that succeeded. */ | ||
| public List<Item<O>> succeeded() { |
There was a problem hiding this comment.
These method names return different things than on MapResult.
MapResult.succeeded() returns the result values and MapResult.failed() returns the errors (MapResult.java line 67 and 75). Here succeeded() and failed() return List<Item<O>>, and results() returns only the succeeded outputs. Someone moving from ctx.map to ctx.distributedMap gets different data from the same call.
is this intended? maybe it should be the similar
🤖 AI-assisted comment
There was a problem hiding this comment.
Intended, I made Dmap's behaviour consistent with map and dmap in the other SDKs, and Java's MapResult is actually inconsistent with other operations.
Here's a table of how they work:
| Accessor | JS / Python map and distributed map | Java DistributedMapResult |
Java MapResult |
|---|---|---|---|
succeeded() |
succeeded items | succeeded items | succeeded result values |
failed() |
failed items | failed items | failed errors (MapError) |
getResults() / get_results() / results() |
succeeded result values only | succeeded result values only | every item's result, null for failed and skipped items |
getErrors() / get_errors() / errors() |
failed errors only | failed errors only | no such method |
|
|
||
| /** Applies a defensive copy and defaults. */ | ||
| public DistributedMapResult { | ||
| items = items != null ? List.copyOf(items) : Collections.emptyList(); |
There was a problem hiding this comment.
A null summary fails later with a NullPointerException that has no message.
The constructor defaults items but not summary. Every getter that reads summary (status(), successCount(), throwIfError()) fails at the first call. We should populate summary.
🤖 AI-assisted comment
There was a problem hiding this comment.
The SDK always builds a DistributedMapResult with a summary, so a null summary only comes from code that builds the record by hand. Added Objects.requireNonNull(summary, "summary") to the constructor, so that mistake fails where the record is built, with a message naming summary. A summary has no sensible default, because it carries the run's status and counts.
| * cycles without requiring AWS SDK-specific Jackson modules. | ||
| */ | ||
| @JsonInclude(JsonInclude.Include.NON_NULL) | ||
| public record DistributedMapError(String errorType, String errorMessage, String errorData, List<String> stackTrace) { |
There was a problem hiding this comment.
This is a near copy of MapResult.MapError.
MapResult.MapError(errorType, errorMessage, stackTrace) has the same fields as this record minus errorData, and of(Throwable) does the same as MapError.of. Suggest one shared error record with errorData for map, parallel and distributed map, or say in the PR why a second type is needed. Also, of always sets errorData to null, while ExceptionHelper.buildErrorObject fills it for DurableOperationException types.
🤖 AI-assisted comment
There was a problem hiding this comment.
I think MapError and DistributedMapError are different enough to be separate. MapError always comes from an exception from inside a map, so its errorType is a Java class name. DistributedMapError holds the run's error and errors returned by the processors, which can be any language. So its errorType isn't always a Java class name, and it can carry errorData.
The JS SDK also has separate types for these, but the Python SDK uses a shared type. So it's valid to make a shared type in Java, but that would make a breaking change to map/parallel. I think that's out of scope for the PR, and if we wanted to we could make map/parallel/dmap use a shared type in a later PR.
Also of() leaves errorData null on purpose. buildErrorObject puts the serialized exception there so the SDK can rebuild the exception class on replay. of() builds a processor's item error, which goes back to the durable function that called ctx.distributedMap. That function may not have the processor's exception class, so it cannot use the serialized exception. This matches MapError.of, which sets no error data either.
|
Updates to address comments:
|
Add the types a distributed map run returns: DistributedMapSummary with the run's status and counts, DistributedMapResult with each item's outcome, and DistributedMapException, thrown by throwIfError when the run or an item failed. The exception extends DurableOperationException like the other operation exceptions.
0de4e34 to
fe091c4
Compare
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Issue Link, if available
#912
Description
Adds the result types a distributed map run returns, and the exception it throws. PR 1 of 6 (see the issue). It needs no new Lambda model and depends on no other PR.
model/The result types a customer receives back from a map run.
DistributedMapSummary: describes the run's overall outcome.DistributedMapResult: contains individual map run item outcomes.DistributedMapError: the error on a run or on one item.DistributedMapStatus: the run's terminal status.exception/DistributedMapException.javaThe error type a customer catches.
DistributedMapException: thrown bythrowIfError()when a run or an item fails.Demo/Screenshots
N/A
Design
See Rules for every change.
+310lines insrc/mainand+318insrc/test.model/and 1 exception type.Assumptions
Each assumption about the service, Lambda, the runtime or another library, with its evidence, or marked "unverified" (rule 6):
SUCCEEDED,FAILED,STOPPEDorTIMED_OUT. Unverified.Decisions not covered by the issue or the design note
One line each, with the reason (rule 7):
DistributedMapExceptionextendsDurableOperationException, because a run maps to one distributed map operation, like the other operation exceptions.Checklist
Testing
Unit Tests
Have unit tests been written for these changes?
Yes.
model/DistributedMapSummaryTestandmodel/DistributedMapResultTest: the result types andthrowIfError().Integration Tests
Have integration tests been written for these changes?
No.
LocalDurableTestRunnerdoes not support distributed map yet.Examples
Has a new example been added for the change? (if applicable)
No.