Repository navigation
Conversation
Add distributed map, a durable operation that processes a large set of items in separate processor Lambda functions run by the service, and returns the run's outcome to the parent durable function. - DurableContext.distributedMap starts a run and waits for it to finish. It returns a summary of the counts and status, or a result that also holds each item's output or error. The run is checkpointed, so it is started once and its outcome is reused on replay. - Items come from an inline list, S3 objects (JSON, JSON Lines or CSV), or a custom reader function. Configuration covers the processor, batch size, concurrency, failure tolerance and S3 result destinations, and is validated before the start checkpoint. - DistributedMapHandlers wraps a customer's function as a processor or reader Lambda handler, with durable and non-durable variants. The wrappers handle the service's event and response formats, and pass the run ARN and item ids to the customer's function.
Contributor
|
@nvasiu could you split this PR into smaller ones so that the changes don't rely on new models can be merged early? |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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
N/A
Description
Adds the distributed map operation (
ctx.distributedMap) to the Java SDK:A map run processes a bounded dataset in parallel. A customer starts a map run from a durable function, naming a source to read items from, a processor function to invoke per batch, and concurrency, retry, and failure settings. The service reads items from the source, groups them into batches, invokes the processor for each batch, retries failures, tracks progress, routes successful results and failed items to destinations, and reports completion.
config/The input types a customer constructs to describe a map run.
DistributedMapConfig: optional settings for distributed map. ItsCompletionConfigdefines item failure thresholds for marking the overall map run failed.DistributedMapSource: factories naming where map run items come from.inline,s3JsonLines,s3JsonArray,s3Csv,s3Objects,s3FlattenedJsonLines,s3FlattenedJsonArray,s3FlattenedCsvandreader.DistributedMapProcessor: describes the Lambda that processes items. ThereportBatchOutcomeandreportItemOutcomesfactories pick how the processor reports outcomes back. The retry option takes aDistributedMapProcessorRetryConfigholdingmaxRetryAttemptsandmaxRetryDuration, withDistributedMapProcessorRetryConfig.UNLIMITEDfor an unbounded attempt count.DistributedMapDestination: thes3Successesands3Failuresfactories for routing item records to S3.UNLIMITED.DurableContext.java,context/DurableContextImpl.javaThe customer-facing entry point on the durable context.
ctx.distributedMap: the method a customer calls to run a distributed map. Overloads that take a result type returnDistributedMapResult, and the others returnDistributedMapSummary.model/The result types a customer receives back from a map run.
DistributedMapSummary: describes the run's overall outcome.DistributedMapResult: returned by the overloads that take a result type. Contains individual map run item outcomes.DistributedMapError: the error on a run or on one item.DistributedMapStatus: the run's terminal status.dmap/Authoring wrappers for the processor Lambda, so a customer writes a plain function rather than the item or batch protocol.
DistributedMapHandlers:createDistributedMapItemHandler,createDistributedMapBatchHandler,createDistributedMapReader, and the durable variantscreateDistributedMapItemHandlerWithDurableExecutionandcreateDistributedMapBatchHandlerWithDurableExecution.ItemContext,BatchContextandReaderContext, passed as the last argument.DurableConfig, so a durable processor can register plugins or supply its own client.ItemHandlerResponse,ItemResult,ItemFailure,ReaderResponse) rather than hand-built maps.operation/DistributedMapOperation.javaThe operation that drives the run against the durable execution runtime.
throwIfError()opts into throwing.execution/CheckpointManager: the checkpoint size estimate counts the distributed map options, so checkpoint batches stay within the limit.DurableExecutor: a processor's invocation input, result and error are read and written with the default JSON serdes, because the service defines their format. Durable operations inside the processor still use the config's serdes.exception/DistributedMapException.javaThe error type a customer catches.
DistributedMapException: thrown bythrowIfError()when a run or an item fails.model/OperationSubType.java,operation/BaseDurableOperation.java,operation/ChildContextOperation.javaOperation type registration.
DISTRIBUTED_MAPtoOperationSubType, and passes a failed run's error to plugins.Future tasks
LocalDurableTestRunner(in the testing package). When this is done, we can add full end to end tests using the runner.Demo/Screenshots
N/A
Design
See Rules for every change.
+2522lines insrc/mainand+3764insrc/test.ctx.distributedMapoverloads, 5 config classes inconfig/with their nested types and factories, 4 result types inmodel/, theDistributedMapHandlerswrappers with their 3 functional interfaces, 11 records indmap/, 1 exception type, and theDISTRIBUTED_MAPvalue ofOperationSubType.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.DistributedMapDetailscarriesSuccessCount,FailureCountandReadCount, carriesTotalCountonce the run succeeded, and reports a run failure asErrorthere rather than as an operation-level error. Unverified.ResultscarriesItemIdand aStatusofSUCCEEDEDorFAILED, with the item's value inOutputas a string the customer's serdes decodes. Unverified.distributedMapRunArnand arecordslist, each record holding a non-empty stringitemIdand abodythe customer's serdes decodes. Unverified.itemIdthe processor echoes, and accepts the batch-failure and item-outcome response shapes the wrappers return. Unverified.distributedMapRunArn, an integermaxItemsPerPage, andstateas the reader last returned it. Unverified.MaxRetryAttemptsof-1meaning unlimited attempts andMaxRetryDurationSecondsa whole number of seconds. Unverified.Decisions not covered by the issue or the design note
One line each, with the reason (rule 7):
IllegalArgumentException, because the other operations' configuration checks throw it.DistributedMapExceptionstays outside theDurableOperationExceptionhierarchy, because it reports a run's aggregate result rather than one operation's failure.DurableExecutorpicks the default JSON serdes when the input type isProcessorEvent, so a customer serdes cannot change the format the service defines, with no new public method orDurableConfigoption.DistributedMapSource, nameds3JsonLinesand so on, so the factory name states the source kind in one call.DurableContextfirst."null", and a non-null value that serializes to null is rejected, because the service requires every item to be a string.Items,Outputand the record body are opaque strings, so a customer serdes other than JSON works without an SDK change.Checklist
Testing
Unit Tests
Have unit tests been written for these changes?
Yes. Tests are split by layer so each sits alongside its class.
config/DistributedMap*Test: config and argument validation.model/DistributedMapSummaryTestandmodel/DistributedMapResultTest: the result types andthrowIfError().operation/DistributedMapOperationTestandoperation/DistributedMapOperationTranslationTest: operation behaviour and the translation to and from the service shapes.context/DurableContextDistributedMapTest: thectx.distributedMapsurface.dmap/DistributedMapHandlersTestanddmap/DistributedMapDurableHandlersTest: authoring wrapper tests, checking that they process items, report failures, pass the run ARN and item ids, and reject bad inputs.execution/CheckpointManagerTest: new tests for the size estimate. No existing test expectation was edited.Integration Tests
Have integration tests been written for these changes?
No.
LocalDurableTestRunnerdoes not support distributed map yet (see Future tasks).Examples
Has a new example been added for the change? (if applicable)
No. Examples will follow with runner support (see Future tasks).