External Storage Integration: WorkflowWorker, replay, history - #3017
External Storage Integration: WorkflowWorker, replay, history#3017cconstable wants to merge 16 commits into
Conversation
dff9b7f to
3a20dcf
Compare
831c284 to
460bfbf
Compare
3a20dcf to
0e37f9d
Compare
0e37f9d to
c67e0f0
Compare
460bfbf to
b3804da
Compare
c67e0f0 to
e292757
Compare
b3804da to
ca09b50
Compare
e292757 to
cb05443
Compare
6d90f7e to
1538817
Compare
2d2d90e to
504467c
Compare
1538817 to
d7b9a62
Compare
…nal payloads after fetching history.
…ng command.getAttributesCase() + switch for exhaustiveness checking.
d7b9a62 to
8062db7
Compare
| Duration stickyTaskQueueScheduleToStartTimeout, | ||
| WorkflowServiceStubs service, | ||
| LocalActivityDispatcher localActivityDispatcher, | ||
| CancellationToken<CancellationException> storageCancellation) { |
There was a problem hiding this comment.
Instead of passing in a cancellation token to each handler type, can we update ExternalStorageRunner to have a shutdown method (or something similar) and have the owner of the runner shut it down from one place?
There was a problem hiding this comment.
Hmm yea I think this would simplify this. Will update unless I can think of a reason why we would need the token
There was a problem hiding this comment.
Thought about this a bit and I don't think we could add a shutdown method. A shutdown method would cancel everything and external storage is shared by across clients and workers (that is how we will eventually get our concurrency controls). One worker shutting down shouldn't cause external storage to shutdown in the others.
There was a problem hiding this comment.
We could potentially put a token on the worker options that can be used to then cancel all inflight extstore operations and get rid of the threading.
There was a problem hiding this comment.
We also still need to retain the ability to cancel individual extstore operations for things like heartbeats (they can be canceled)
| return current; | ||
| case ATTRIBUTES_NOT_SET: | ||
| case START_TIMER_COMMAND_ATTRIBUTES: | ||
| case COMPLETE_WORKFLOW_EXECUTION_COMMAND_ATTRIBUTES: |
There was a problem hiding this comment.
This one should be retargeting to the parent if (1) the parent is known, and (2) is not a CaN'd workflow. Just like the other SDKs already do.
There was a problem hiding this comment.
This is going to require some plumbing. I don't think we have access to that information here
| CommandOrBuilder command = (CommandOrBuilder) message; | ||
| // Keep this exhaustive so new command attributes require an explicit target decision. | ||
| switch (command.getAttributesCase()) { | ||
| case SCHEDULE_ACTIVITY_TASK_COMMAND_ATTRIBUTES: |
There was a problem hiding this comment.
This should not be retargeted to the activity and should remain as the workflow. The external storage is tied to the lifetime of the workflow, not the activity.
| String workflowType = workflowTask.getWorkflowType().getName(); | ||
| Scope metricsScope = | ||
| options.getMetricsScope().tagged(ImmutableMap.of(MetricsTag.WORKFLOW_TYPE, workflowType)); | ||
| ExternalStorageRunner externalStorageRunner = options.getExternalStorageRunner(); |
There was a problem hiding this comment.
These are executed outside of the try-catch that would proactively fail the workflow task; otherwise, an external storage failure is going to just end task processing and wait for the server to timeout.
| } | ||
| try { | ||
| externalStorageRunner.store(builder, target, targetVisitor, storageCancellation); | ||
| } catch (Throwable e) { |
There was a problem hiding this comment.
Ignore the catch if it's cancelled?
There was a problem hiding this comment.
Yes, should be checking if it's a cancellation here.
There was a problem hiding this comment.
Ok I think we do need to check for cancellation here but we also need we also need to throw the cancellation and then check it somewhere up the chain (sendTaskCompleted) and explicitly handle cancellation there (e.g. if the worker is shutting down we want to ignore the error). This was not very easy to understand.
There was a problem hiding this comment.
We can't just ignore it here because that would cause the completion event to be sent in sendTaskCompleted.
There was a problem hiding this comment.
Another issue: when the task fails from this it just says Failed to send workflow task completion: External storage store failed even if it was cancellation. That seems misleading.
| grpcRetryOptions); | ||
| } | ||
|
|
||
| private void sendDirectQueryCompletedResponse( |
There was a problem hiding this comment.
Should have test coverage for this.
| workflowTypeScope, | ||
| workflowStorageTarget(workflowExecution, workflowType)); | ||
| } catch (ExternalStorageTaskFailure e) { | ||
| if (currentTask.getAttempt() > 1) { |
There was a problem hiding this comment.
This is behaviorally different than the other SDKs. I think this came from duplicating the gRPC response path. However, they are different causes, where too large gRPC is not fixable but external storage failures likely are (missing replicated payloads, service temporarily faulted, etc).
There was a problem hiding this comment.
That makes sense. Will remove this check.
| WorkflowServiceStubs service, | ||
| LocalActivityDispatcher localActivityDispatcher, | ||
| CancellationToken<CancellationException> storageCancellation) { | ||
| this.storageCancellation = storageCancellation; |
There was a problem hiding this comment.
I don't think there is test coverage for the shutdown / cancellation behavior.
| } | ||
|
|
||
| @Test | ||
| public void resolvesExternalStorageReferencesInFetchedFullHistory() throws Throwable { |
There was a problem hiding this comment.
This test probably passed even if external storage just passed the payload through without modification. So the test isn't demonstrating any capability of external storage.
| return mockFactory; | ||
| } | ||
|
|
||
| private static final class InMemoryStorageDriver implements StorageDriver { |
There was a problem hiding this comment.
There are several test driver implementations that nearly do the same thing. Can we make one and alter the behavior via parameters / options?
…ellation gracefully during shutdown
…retarget to parent for storage target.
What was changed
WorkflowWorkerhandle + send response now use external storage.Why
Checklist