mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
feat(lambda): durable function chained invokes (#5164)
* feat(lambda): durable function chained invokes
A CHAINED_INVOKE operation runs another function. A durable target
needs a version or alias and runs as its own durable execution with a
random name; its close completes the operation as SUCCEEDED, FAILED,
TIMED_OUT ("CHAINED_INVOKE timed out after N seconds.") or STOPPED. Any
other function is invoked once, and an output over 1 MB fails the
operation. A missing function or an unqualified durable one fails the
operation at once. Stopping the parent leaves the child running.
A plain chained invoke lost with the process runs again after a restart,
and a durable child that closed before its report reaches the parent
reports then.
* fix(lambda): close the gaps in durable chained invokes
A durable child that closes during a restart reports to its parent
under its own lock, and recovery triggers an execution once. A durable
target invoked without Payload starts its child with no input, while a
plain target gets {}. A target started in the batch that closes the
execution still runs and its result is ignored, as on AWS.
* fix(lambda): reject a chained invoke of another account or region
AWS rejects the checkpoint with InvalidParameterValueException "Cannot
start a CHAINED_INVOKE on a function in another account." or "... in
another region." Cross-account chained invocations are not supported.
* fix(lambda): keep durable chained invokes across a crash
The parent is saved before the child it starts, so a crash in between
leaves no child the parent does not know. On restart a child the parent
recorded but the store lost is started again under the same ARN, and a
plain target started by the checkpoint that closed the execution runs
again until its result is recorded. A child reports only to the
operation that started it.
* fix(lambda): recreate a lost durable child on the version its ARN names
An alias the chained invoke named may point to another version after a
restart, and a child recreated there would not match the ARN the parent
saved.
This commit is contained in:
1 parent
be668acefd
commit
6e6ce61eea
13 files changed
+921
-37
No files matched your search
+48
-4
@@ -1,6 +1,7 @@
|
||||
package io.github.hectorvent.floci.services.lambda.durable;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.services.lambda.LambdaArnUtils;
|
||||
import io.github.hectorvent.floci.services.lambda.durable.model.DurableErrorObject;
|
||||
import io.github.hectorvent.floci.services.lambda.durable.model.DurableExecution;
|
||||
import io.github.hectorvent.floci.services.lambda.durable.model.DurableExecutionStatus;
|
||||
@@ -30,12 +31,14 @@ final class DurableCheckpointApplier {
|
||||
|
||||
static final int MAX_OPERATION_PAYLOAD_BYTES = 256 * 1024;
|
||||
static final int MAX_ERROR_BYTES = 32 * 1024;
|
||||
static final int MAX_CHAINED_INVOKE_PAYLOAD_BYTES = 1024 * 1024;
|
||||
private static final Pattern OPERATION_ID = Pattern.compile("[a-zA-Z0-9-_]{1,64}");
|
||||
|
||||
private DurableCheckpointApplier() {
|
||||
}
|
||||
|
||||
record Outcome(boolean closed) {
|
||||
/** {@code chainedInvokes} names the CHAINED_INVOKE operations this batch started, for the service to run. */
|
||||
record Outcome(boolean closed, List<String> chainedInvokes) {
|
||||
}
|
||||
|
||||
static Outcome apply(DurableExecution execution, List<DurableOperationUpdate> updates, long now) {
|
||||
@@ -45,7 +48,7 @@ final class DurableCheckpointApplier {
|
||||
draft.apply(update);
|
||||
}
|
||||
draft.commit();
|
||||
return new Outcome(draft.closingStatus != null);
|
||||
return new Outcome(draft.closingStatus != null, List.copyOf(draft.chainedInvokes));
|
||||
}
|
||||
|
||||
/** Completes waits, step retries and callback timeouts whose time has come. The sweeper and every checkpoint call it. */
|
||||
@@ -156,6 +159,7 @@ final class DurableCheckpointApplier {
|
||||
private final long now;
|
||||
private final LinkedHashMap<String, DurableOperation> operations = new LinkedHashMap<>();
|
||||
private final List<Consumer<DurableExecution>> events = new ArrayList<>();
|
||||
private final List<String> chainedInvokes = new ArrayList<>();
|
||||
private long changeSequence;
|
||||
private DurableExecutionStatus closingStatus;
|
||||
private String closingResult;
|
||||
@@ -189,7 +193,12 @@ final class DurableCheckpointApplier {
|
||||
}
|
||||
}
|
||||
requireErrorSize(update);
|
||||
if (utf8Length(update.payload()) > MAX_OPERATION_PAYLOAD_BYTES) {
|
||||
if (update.type() == DurableOperationType.CHAINED_INVOKE) {
|
||||
if (utf8Length(update.payload()) > MAX_CHAINED_INVOKE_PAYLOAD_BYTES) {
|
||||
throw invalid("CHAINED_INVOKE input payload size must be less than or equal to "
|
||||
+ MAX_CHAINED_INVOKE_PAYLOAD_BYTES + " bytes.");
|
||||
}
|
||||
} else if (utf8Length(update.payload()) > MAX_OPERATION_PAYLOAD_BYTES) {
|
||||
throw invalid(update.type() + " payload size must be less than or equal to "
|
||||
+ MAX_OPERATION_PAYLOAD_BYTES + " bytes.");
|
||||
}
|
||||
@@ -198,7 +207,7 @@ final class DurableCheckpointApplier {
|
||||
case STEP -> applyStep(update, existing);
|
||||
case WAIT -> applyWait(update, existing);
|
||||
case CALLBACK -> applyCallback(update, existing);
|
||||
case CHAINED_INVOKE -> throw invalid(update.type() + " operations are not supported yet");
|
||||
case CHAINED_INVOKE -> applyChainedInvoke(update, existing);
|
||||
default -> throw invalid("Unknown operation type.");
|
||||
}
|
||||
}
|
||||
@@ -368,6 +377,41 @@ final class DurableCheckpointApplier {
|
||||
}
|
||||
}
|
||||
|
||||
/** The service resolves and runs the target, and records ChainedInvokeStarted with what it found. */
|
||||
private void applyChainedInvoke(DurableOperationUpdate update, DurableOperation existing) {
|
||||
if (update.action() != DurableOperationAction.START) {
|
||||
throw invalid("Invalid action for the given operation type.");
|
||||
}
|
||||
if (update.chainedFunctionName() == null) {
|
||||
throw invalid("Update for CHAINED_INVOKE operation requires ChainedInvokeOptions.");
|
||||
}
|
||||
if (existing != null) {
|
||||
throw invalid("Cannot start a CHAINED_INVOKE that already exist.");
|
||||
}
|
||||
requireSameAccountAndRegion(update.chainedFunctionName());
|
||||
DurableOperation operation = create(update);
|
||||
operation.setChainedFunctionName(update.chainedFunctionName());
|
||||
operation.setChainedTenantId(update.chainedTenantId());
|
||||
operation.setInputPayload(update.payload());
|
||||
chainedInvokes.add(update.id());
|
||||
}
|
||||
|
||||
/** A name that does not parse is left to the target lookup, which fails the operation. */
|
||||
private void requireSameAccountAndRegion(String functionName) {
|
||||
LambdaArnUtils.ResolvedFunctionRef ref;
|
||||
try {
|
||||
ref = LambdaArnUtils.resolve(functionName);
|
||||
} catch (AwsException e) {
|
||||
return;
|
||||
}
|
||||
if (ref.account() != null && !ref.account().equals(execution.getAccountId())) {
|
||||
throw invalid("Cannot start a CHAINED_INVOKE on a function in another account.");
|
||||
}
|
||||
if (ref.region() != null && !ref.region().equals(execution.getRegion())) {
|
||||
throw invalid("Cannot start a CHAINED_INVOKE on a function in another region.");
|
||||
}
|
||||
}
|
||||
|
||||
/** Only the function starts a callback. SendDurableExecutionCallback* completes it. */
|
||||
private void applyCallback(DurableOperationUpdate update, DurableOperation existing) {
|
||||
if (update.action() != DurableOperationAction.START) {
|
||||
|
||||
+252
-3
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.lambda.durable;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.Pagination;
|
||||
import io.github.hectorvent.floci.core.common.PaginatedResult;
|
||||
@@ -247,6 +248,11 @@ public class DurableExecutionService implements Resettable {
|
||||
DurableExecution execution = loadWithCurrentToken(arn, checkpointToken);
|
||||
long now = clock.millis();
|
||||
DurableCheckpointApplier.Outcome outcome = DurableCheckpointApplier.apply(execution, updates, now);
|
||||
// AWS runs a target started in the batch that closes the execution, and ignores its result.
|
||||
List<DurableExecution> children = new ArrayList<>();
|
||||
for (String operationId : outcome.chainedInvokes()) {
|
||||
startChainedInvoke(execution, execution.getOperations().get(operationId), now, children, effects);
|
||||
}
|
||||
if (!outcome.closed()) {
|
||||
DurableCheckpointApplier.fireDueTimers(execution, now);
|
||||
}
|
||||
@@ -264,6 +270,10 @@ public class DurableExecutionService implements Resettable {
|
||||
: new DurableCheckpointReplay(checkpointToken, clientToken, nextToken, changed));
|
||||
execution.setSeenSequence(execution.getChangeSequence());
|
||||
save(execution);
|
||||
// After the parent, so a crash in between leaves no child the parent does not know.
|
||||
for (DurableExecution child : children) {
|
||||
save(child);
|
||||
}
|
||||
result = new CheckpointResult(nextToken, changed);
|
||||
}
|
||||
runEffects(effects);
|
||||
@@ -446,17 +456,27 @@ public class DurableExecutionService implements Resettable {
|
||||
*/
|
||||
public void recoverAfterRestart() {
|
||||
int recovered = 0;
|
||||
List<Runnable> lateReports = new ArrayList<>();
|
||||
for (AccountEntry<DurableExecution> entry : store.scanAllAccountEntries(key -> true)) {
|
||||
List<Runnable> effects = new ArrayList<>();
|
||||
synchronized (lockFor(entry.accountId(), entry.key())) {
|
||||
DurableExecution execution = store.getForAccount(entry.accountId(), entry.key()).orElse(null);
|
||||
if (execution == null || execution.isClosed()) {
|
||||
if (execution == null) {
|
||||
continue;
|
||||
}
|
||||
if (execution.isClosed()) {
|
||||
// A child that closed just before the restart may not have reached its parent.
|
||||
reportToParent(execution, lateReports);
|
||||
resumeChainedInvokes(execution, effects);
|
||||
save(execution);
|
||||
runEffects(effects);
|
||||
continue;
|
||||
}
|
||||
execution.setCurrentInvocationId(null);
|
||||
execution.setReinvokeRequested(false);
|
||||
resumeChainedInvokes(execution, effects);
|
||||
// A crash retry keeps its backoff, and the sweeper relaunches it when it is due.
|
||||
if (execution.getNextInvocationAttemptAt() == null) {
|
||||
if (execution.getCurrentInvocationId() == null && execution.getNextInvocationAttemptAt() == null) {
|
||||
trigger(execution, effects);
|
||||
}
|
||||
save(execution);
|
||||
@@ -464,6 +484,7 @@ public class DurableExecutionService implements Resettable {
|
||||
}
|
||||
runEffects(effects);
|
||||
}
|
||||
runEffects(lateReports);
|
||||
if (recovered > 0) {
|
||||
LOG.infov("Resumed {0} durable execution(s) after restart", recovered);
|
||||
}
|
||||
@@ -647,8 +668,12 @@ public class DurableExecutionService implements Resettable {
|
||||
// ──────────────────────────── state changes ────────────────────────────
|
||||
|
||||
private DurableExecution newExecution(StartRequest request, ResolvedDurableTarget target, String name, long now) {
|
||||
return newExecution(request, target, name, UUID.randomUUID().toString(), now);
|
||||
}
|
||||
|
||||
private DurableExecution newExecution(StartRequest request, ResolvedDurableTarget target, String name,
|
||||
String executionId, long now) {
|
||||
DurableExecution execution = new DurableExecution();
|
||||
String executionId = UUID.randomUUID().toString();
|
||||
execution.setExecutionId(executionId);
|
||||
execution.setName(name);
|
||||
execution.setAccountId(request.accountId());
|
||||
@@ -715,6 +740,230 @@ public class DurableExecutionService implements Resettable {
|
||||
waiter.complete(execution);
|
||||
}
|
||||
});
|
||||
reportToParent(execution, effects);
|
||||
}
|
||||
|
||||
// ──────────────────────────── chained invoke ────────────────────────────
|
||||
|
||||
private record ChainedOutcome(DurableOperationStatus status, String result, DurableErrorObject error) {
|
||||
|
||||
static ChainedOutcome failed(AwsException e) {
|
||||
return new ChainedOutcome(DurableOperationStatus.FAILED, null,
|
||||
DurableErrorObject.of(e.getMessage(), e.getErrorCode()));
|
||||
}
|
||||
}
|
||||
|
||||
/** Call it under the child's lock. The parent is only touched under its own lock, in the effect. */
|
||||
private void reportToParent(DurableExecution child, List<Runnable> effects) {
|
||||
if (child.getParentExecutionArn() == null) {
|
||||
return;
|
||||
}
|
||||
ArnParts parent = parseArn(child.getParentExecutionArn());
|
||||
ChainedOutcome outcome = chainedOutcome(child);
|
||||
String operationId = child.getParentOperationId();
|
||||
String childArn = child.getExecutionArn();
|
||||
effects.add(() -> finishChainedInvoke(parent.accountId(), parent.storeKey(), operationId, childArn, outcome));
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the target of a CHAINED_INVOKE this checkpoint started. A target that cannot be
|
||||
* invoked fails the operation at once, and ChainedInvokeStarted then names only the function.
|
||||
*/
|
||||
private void startChainedInvoke(DurableExecution execution, DurableOperation operation, long now,
|
||||
List<DurableExecution> children, List<Runnable> effects) {
|
||||
Map<String, Object> details = new LinkedHashMap<>();
|
||||
details.put("FunctionName", operation.getChainedFunctionName());
|
||||
if (operation.getChainedTenantId() != null) {
|
||||
details.put("TenantId", operation.getChainedTenantId());
|
||||
}
|
||||
ResolvedDurableTarget target;
|
||||
try {
|
||||
target = resolveChainedTarget(execution, operation.getChainedFunctionName());
|
||||
} catch (AwsException e) {
|
||||
DurableHistory.operationEvent(execution, operation, "ChainedInvokeStarted", now, details);
|
||||
completeChainedInvoke(execution, operation, ChainedOutcome.failed(e), now, effects);
|
||||
return;
|
||||
}
|
||||
details.put("Input", DurableHistory.payloadWrapper(operation.getInputPayload()));
|
||||
details.put("ExecutedVersion", target.version());
|
||||
if (target.durable()) {
|
||||
DurableExecution child = newChildExecution(execution, operation, target, UUID.randomUUID().toString(),
|
||||
UUID.randomUUID().toString(), now, effects);
|
||||
operation.setChildExecutionArn(child.getExecutionArn());
|
||||
children.add(child);
|
||||
details.put("DurableExecutionArn", child.getExecutionArn());
|
||||
} else {
|
||||
effects.add(plainChainedInvoke(execution, operation, target));
|
||||
}
|
||||
DurableHistory.operationEvent(execution, operation, "ChainedInvokeStarted", now, details);
|
||||
}
|
||||
|
||||
/** The checkpoint already rejected a target in another account or region. */
|
||||
private ResolvedDurableTarget resolveChainedTarget(DurableExecution execution, String functionName) {
|
||||
LambdaArnUtils.ResolvedFunctionRef ref = LambdaArnUtils.resolve(functionName);
|
||||
String accountId = execution.getAccountId();
|
||||
String region = execution.getRegion();
|
||||
ResolvedDurableTarget target;
|
||||
try {
|
||||
target = invoker.resolve(accountId, region, ref.name(), ref.qualifier());
|
||||
} catch (AwsException e) {
|
||||
if (!"ResourceNotFoundException".equals(e.getErrorCode())) {
|
||||
throw e;
|
||||
}
|
||||
String qualifier = ref.qualifier() != null ? ref.qualifier() : "$LATEST";
|
||||
throw new AwsException("ResourceNotFoundException", "Function not found: "
|
||||
+ AwsArnUtils.Arn.of("lambda", region, accountId, "function:" + ref.name() + ":" + qualifier), 404);
|
||||
}
|
||||
if (target.durable() && ref.qualifier() == null) {
|
||||
throw new AwsException("InvalidParameterValueException",
|
||||
"You cannot invoke a durable function using an unqualified ARN.", 400);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
/** The child gets a random name, as on AWS, and reports its close back to the parent operation. */
|
||||
private DurableExecution newChildExecution(DurableExecution parent, DurableOperation operation,
|
||||
ResolvedDurableTarget target, String name, String executionId, long now,
|
||||
List<Runnable> effects) {
|
||||
StartRequest request = new StartRequest(target.accountId(), target.region(), target.functionName(),
|
||||
target.version(), name, operation.getInputPayload(), false);
|
||||
DurableExecution child = newExecution(request, target, name, executionId, now);
|
||||
child.setParentExecutionArn(parent.getExecutionArn());
|
||||
child.setParentOperationId(operation.getId());
|
||||
trigger(child, effects);
|
||||
return child;
|
||||
}
|
||||
|
||||
private Runnable plainChainedInvoke(DurableExecution parent, DurableOperation operation,
|
||||
ResolvedDurableTarget target) {
|
||||
String accountId = parent.getAccountId();
|
||||
String key = storeKey(parent);
|
||||
String operationId = operation.getId();
|
||||
// A plain target gets {} when the update has no Payload. A durable child starts with no input.
|
||||
byte[] payload = (operation.getInputPayload() != null ? operation.getInputPayload() : "{}")
|
||||
.getBytes(StandardCharsets.UTF_8);
|
||||
long launchGeneration = generation.get();
|
||||
return () -> launchExecutor.execute(() -> {
|
||||
ChainedOutcome outcome = invokePlainFunction(target, payload);
|
||||
if (launchGeneration == generation.get()) {
|
||||
finishChainedInvoke(accountId, key, operationId, null, outcome);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private ChainedOutcome invokePlainFunction(ResolvedDurableTarget target, byte[] payload) {
|
||||
DurableInvocationResult result;
|
||||
try {
|
||||
result = invoker.invoke(target, payload);
|
||||
} catch (AwsException e) {
|
||||
return ChainedOutcome.failed(e);
|
||||
} catch (RuntimeException e) {
|
||||
LOG.warnv("Chained invoke of {0} failed: {1}", target.functionArn(), e.getMessage());
|
||||
return new ChainedOutcome(DurableOperationStatus.FAILED, null,
|
||||
DurableErrorObject.of(e.getMessage(), "InvocationError"));
|
||||
}
|
||||
if (result.functionError() != null) {
|
||||
return new ChainedOutcome(DurableOperationStatus.FAILED, null,
|
||||
errorFromLambdaPayload(result.payload(), result.functionError()));
|
||||
}
|
||||
if (result.payload() != null && DurableCheckpointApplier.MAX_CHAINED_INVOKE_PAYLOAD_BYTES < result.payload().length) {
|
||||
return new ChainedOutcome(DurableOperationStatus.FAILED, null, DurableErrorObject.of(
|
||||
"CHAINED_INVOKE output payload size must be less than or equal to "
|
||||
+ DurableCheckpointApplier.MAX_CHAINED_INVOKE_PAYLOAD_BYTES + " bytes.", null));
|
||||
}
|
||||
String output = result.payload() == null || result.payload().length == 0 ? null
|
||||
: new String(result.payload(), StandardCharsets.UTF_8);
|
||||
return new ChainedOutcome(DurableOperationStatus.SUCCEEDED, output, null);
|
||||
}
|
||||
|
||||
/** A child's close maps onto the parent operation. A timeout reports the child's ExecutionTimeout. */
|
||||
private static ChainedOutcome chainedOutcome(DurableExecution child) {
|
||||
return switch (child.getStatus()) {
|
||||
case SUCCEEDED -> new ChainedOutcome(DurableOperationStatus.SUCCEEDED, child.getResult(), null);
|
||||
case TIMED_OUT -> new ChainedOutcome(DurableOperationStatus.TIMED_OUT, null, DurableErrorObject.of(
|
||||
"CHAINED_INVOKE timed out after " + child.getExecutionTimeoutSeconds() + " seconds.",
|
||||
"ChainedInvoke.Timeout"));
|
||||
case STOPPED -> new ChainedOutcome(DurableOperationStatus.STOPPED, null, child.getError());
|
||||
default -> new ChainedOutcome(DurableOperationStatus.FAILED, null, child.getError());
|
||||
};
|
||||
}
|
||||
|
||||
/** {@code childArn} is the reporting child, which must be the one the operation started. */
|
||||
private void finishChainedInvoke(String accountId, String key, String operationId, String childArn,
|
||||
ChainedOutcome outcome) {
|
||||
List<Runnable> effects = new ArrayList<>();
|
||||
synchronized (lockFor(accountId, key)) {
|
||||
DurableExecution execution = store.getForAccount(accountId, key).orElse(null);
|
||||
DurableOperation operation = execution == null ? null : execution.getOperations().get(operationId);
|
||||
if (operation == null || operation.getStatus() != DurableOperationStatus.STARTED
|
||||
|| !Objects.equals(childArn, operation.getChildExecutionArn())) {
|
||||
return;
|
||||
}
|
||||
completeChainedInvoke(execution, operation, outcome, clock.millis(), effects);
|
||||
save(execution);
|
||||
}
|
||||
runEffects(effects);
|
||||
}
|
||||
|
||||
/** A closed execution records the outcome without an event, so a restart does not run the target again. */
|
||||
private void completeChainedInvoke(DurableExecution execution, DurableOperation operation, ChainedOutcome outcome,
|
||||
long now, List<Runnable> effects) {
|
||||
operation.setStatus(outcome.status());
|
||||
operation.setResult(outcome.result());
|
||||
operation.setError(outcome.error());
|
||||
operation.setEndTimestamp(now);
|
||||
if (execution.isClosed()) {
|
||||
return;
|
||||
}
|
||||
operation.setChangeSequence(execution.nextChangeSequence());
|
||||
Map<String, Object> details = new LinkedHashMap<>();
|
||||
if (outcome.status() == DurableOperationStatus.SUCCEEDED) {
|
||||
details.put("Result", DurableHistory.payloadWrapper(outcome.result()));
|
||||
} else {
|
||||
details.put("Error", DurableHistory.errorWrapper(outcome.error()));
|
||||
}
|
||||
String eventType = switch (outcome.status()) {
|
||||
case SUCCEEDED -> "ChainedInvokeSucceeded";
|
||||
case TIMED_OUT -> "ChainedInvokeTimedOut";
|
||||
case STOPPED -> "ChainedInvokeStopped";
|
||||
default -> "ChainedInvokeFailed";
|
||||
};
|
||||
DurableHistory.operationEvent(execution, operation, eventType, now, details);
|
||||
trigger(execution, effects);
|
||||
}
|
||||
|
||||
/**
|
||||
* A plain chained invoke in flight was lost with the process, so it runs again. A durable child
|
||||
* the parent recorded but the store lost is started again under the same ARN.
|
||||
*/
|
||||
private void resumeChainedInvokes(DurableExecution execution, List<Runnable> effects) {
|
||||
for (DurableOperation operation : execution.getOperations().values()) {
|
||||
if (operation.getType() != DurableOperationType.CHAINED_INVOKE
|
||||
|| operation.getStatus() != DurableOperationStatus.STARTED) {
|
||||
continue;
|
||||
}
|
||||
ArnParts childArn = operation.getChildExecutionArn() == null ? null
|
||||
: parseArn(operation.getChildExecutionArn());
|
||||
if (childArn != null && store.getForAccount(childArn.accountId(), childArn.storeKey()).isPresent()) {
|
||||
continue;
|
||||
}
|
||||
ResolvedDurableTarget target;
|
||||
try {
|
||||
// The version in the saved ARN, since an alias may point elsewhere by now.
|
||||
target = childArn == null ? resolveChainedTarget(execution, operation.getChainedFunctionName())
|
||||
: invoker.resolve(childArn.accountId(), childArn.region(), childArn.functionName(),
|
||||
childArn.version());
|
||||
} catch (AwsException e) {
|
||||
completeChainedInvoke(execution, operation, ChainedOutcome.failed(e), clock.millis(), effects);
|
||||
continue;
|
||||
}
|
||||
if (childArn == null) {
|
||||
effects.add(plainChainedInvoke(execution, operation, target));
|
||||
} else {
|
||||
save(newChildExecution(execution, operation, target, childArn.name(), childArn.executionId(),
|
||||
clock.millis(), effects));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Null unless this is the last checkpoint again, with the same ClientToken, and its token is still current. */
|
||||
|
||||
@@ -119,6 +119,7 @@ public final class DurableWire {
|
||||
putTimestamp(details, "ScheduledEndTimestamp", operation.getScheduledEndTimestamp(), millis);
|
||||
}
|
||||
}
|
||||
case CHAINED_INVOKE -> putResultAndError(node.putObject("ChainedInvokeDetails"), operation);
|
||||
case CALLBACK -> {
|
||||
ObjectNode details = node.putObject("CallbackDetails");
|
||||
putIfPresent(details, "CallbackId", operation.getCallbackId());
|
||||
@@ -264,6 +265,7 @@ public final class DurableWire {
|
||||
Map<?, ?> waitOptions = structure(map, "WaitOptions");
|
||||
Map<?, ?> contextOptions = structure(map, "ContextOptions");
|
||||
Map<?, ?> callbackOptions = structure(map, "CallbackOptions");
|
||||
Map<?, ?> chainedInvokeOptions = structure(map, "ChainedInvokeOptions");
|
||||
return new DurableOperationUpdate(
|
||||
string(map, "Id"),
|
||||
string(map, "ParentId"),
|
||||
@@ -278,7 +280,9 @@ public final class DurableWire {
|
||||
contextOptions == null ? null : bool(contextOptions, "ReplayChildren"),
|
||||
integer(callbackOptions, "TimeoutSeconds", path + "callbackOptions", 0, MAX_CALLBACK_TIMEOUT_SECONDS),
|
||||
integer(callbackOptions, "HeartbeatTimeoutSeconds", path + "callbackOptions", 0,
|
||||
MAX_CALLBACK_TIMEOUT_SECONDS));
|
||||
MAX_CALLBACK_TIMEOUT_SECONDS),
|
||||
chainedInvokeOptions == null ? null : string(chainedInvokeOptions, "FunctionName"),
|
||||
chainedInvokeOptions == null ? null : string(chainedInvokeOptions, "TenantId"));
|
||||
}
|
||||
|
||||
private static <E extends Enum<E>> E enumMember(Map<?, ?> map, String member, Class<E> type) {
|
||||
|
||||
+11
-2
@@ -52,6 +52,9 @@ public class DurableExecution {
|
||||
private int consecutiveInvocationFailures;
|
||||
private Long nextInvocationAttemptAt;
|
||||
private DurableCheckpointReplay lastCheckpoint;
|
||||
/** Set on an execution a chained invoke started. Its close completes that operation of the parent. */
|
||||
private String parentExecutionArn;
|
||||
private String parentOperationId;
|
||||
|
||||
public DurableExecution() {
|
||||
}
|
||||
@@ -66,7 +69,7 @@ public class DurableExecution {
|
||||
return changeSequence > seenSequence;
|
||||
}
|
||||
|
||||
/** True while a wait, a step retry or a callback is still pending. */
|
||||
/** True while a wait, a step retry, a callback or a chained invoke is still pending. */
|
||||
@JsonIgnore
|
||||
public boolean hasPendingOperations() {
|
||||
for (DurableOperation operation : operations.values()) {
|
||||
@@ -83,7 +86,7 @@ public class DurableExecution {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
case CALLBACK -> {
|
||||
case CALLBACK, CHAINED_INVOKE -> {
|
||||
if (operationStatus == DurableOperationStatus.STARTED) {
|
||||
return true;
|
||||
}
|
||||
@@ -199,6 +202,12 @@ public class DurableExecution {
|
||||
this.nextInvocationAttemptAt = nextInvocationAttemptAt;
|
||||
}
|
||||
|
||||
public String getParentExecutionArn() { return parentExecutionArn; }
|
||||
public void setParentExecutionArn(String parentExecutionArn) { this.parentExecutionArn = parentExecutionArn; }
|
||||
|
||||
public String getParentOperationId() { return parentOperationId; }
|
||||
public void setParentOperationId(String parentOperationId) { this.parentOperationId = parentOperationId; }
|
||||
|
||||
public DurableCheckpointReplay getLastCheckpoint() { return lastCheckpoint; }
|
||||
public void setLastCheckpoint(DurableCheckpointReplay lastCheckpoint) { this.lastCheckpoint = lastCheckpoint; }
|
||||
}
|
||||
+17
@@ -34,6 +34,11 @@ public class DurableOperation {
|
||||
private Long callbackDeadline;
|
||||
/** Moves forward on every SendDurableExecutionCallbackHeartbeat. */
|
||||
private Long heartbeatDeadline;
|
||||
/** The FunctionName of a chained invoke, as the function sent it. */
|
||||
private String chainedFunctionName;
|
||||
private String chainedTenantId;
|
||||
/** Set when a chained invoke runs a durable function. Unset, the function runs as a plain invocation. */
|
||||
private String childExecutionArn;
|
||||
/** Position in the execution's change log. The handler is only shown operations newer than it has seen. */
|
||||
private long changeSequence;
|
||||
|
||||
@@ -61,6 +66,9 @@ public class DurableOperation {
|
||||
copy.heartbeatTimeoutSeconds = heartbeatTimeoutSeconds;
|
||||
copy.callbackDeadline = callbackDeadline;
|
||||
copy.heartbeatDeadline = heartbeatDeadline;
|
||||
copy.chainedFunctionName = chainedFunctionName;
|
||||
copy.chainedTenantId = chainedTenantId;
|
||||
copy.childExecutionArn = childExecutionArn;
|
||||
copy.changeSequence = changeSequence;
|
||||
return copy;
|
||||
}
|
||||
@@ -124,6 +132,15 @@ public class DurableOperation {
|
||||
public Long getHeartbeatDeadline() { return heartbeatDeadline; }
|
||||
public void setHeartbeatDeadline(Long heartbeatDeadline) { this.heartbeatDeadline = heartbeatDeadline; }
|
||||
|
||||
public String getChainedFunctionName() { return chainedFunctionName; }
|
||||
public void setChainedFunctionName(String chainedFunctionName) { this.chainedFunctionName = chainedFunctionName; }
|
||||
|
||||
public String getChainedTenantId() { return chainedTenantId; }
|
||||
public void setChainedTenantId(String chainedTenantId) { this.chainedTenantId = chainedTenantId; }
|
||||
|
||||
public String getChildExecutionArn() { return childExecutionArn; }
|
||||
public void setChildExecutionArn(String childExecutionArn) { this.childExecutionArn = childExecutionArn; }
|
||||
|
||||
public long getChangeSequence() { return changeSequence; }
|
||||
public void setChangeSequence(long changeSequence) { this.changeSequence = changeSequence; }
|
||||
}
|
||||
+3
-1
@@ -16,5 +16,7 @@ public record DurableOperationUpdate(String id,
|
||||
Integer waitSeconds,
|
||||
Boolean replayChildren,
|
||||
Integer callbackTimeoutSeconds,
|
||||
Integer callbackHeartbeatTimeoutSeconds) {
|
||||
Integer callbackHeartbeatTimeoutSeconds,
|
||||
String chainedFunctionName,
|
||||
String chainedTenantId) {
|
||||
}
|
||||
Reference in new issue
Block a user