Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/added/steady-stream-heron.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add experimental Stream reads in Workflows with replay checks for changed or missing Records.
63 changes: 63 additions & 0 deletions temporalio/bridge/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 24 additions & 6 deletions temporalio/bridge/_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,26 @@ async def _visit_coresdk_workflow_activation_ResolveStreamAppend(
if o.HasField("failed"):
await self._visit_temporal_api_failure_v1_Failure(fs, o.failed)

async def _visit_temporal_api_stream_v1_StreamRecord(
self, fs: VisitorFunctions, o: Any
):
if o.HasField("body"):
await self._visit_temporal_api_common_v1_Payload(fs, o.body)

async def _visit_coresdk_workflow_activation_StreamPage(
self, fs: VisitorFunctions, o: Any
):
for v in o.records:
await self._visit_temporal_api_stream_v1_StreamRecord(fs, v)

async def _visit_coresdk_workflow_activation_ResolveStreamRead(
self, fs: VisitorFunctions, o: Any
):
if o.HasField("page"):
await self._visit_coresdk_workflow_activation_StreamPage(fs, o.page)
elif o.HasField("failed"):
await self._visit_temporal_api_failure_v1_Failure(fs, o.failed)

async def _visit_coresdk_workflow_activation_WorkflowActivationJob(
self, fs: VisitorFunctions, o: Any
):
Expand Down Expand Up @@ -363,6 +383,10 @@ async def _visit_coresdk_workflow_activation_WorkflowActivationJob(
await self._visit_coresdk_workflow_activation_ResolveStreamAppend(
fs, o.resolve_stream_append
)
elif o.HasField("resolve_stream_read"):
await self._visit_coresdk_workflow_activation_ResolveStreamRead(
fs, o.resolve_stream_read
)

async def _visit_coresdk_workflow_activation_WorkflowActivation(
self, fs: VisitorFunctions, o: Any
Expand Down Expand Up @@ -690,12 +714,6 @@ async def _visit_temporal_api_sdk_v1_ReadRecordsRequest(
) -> None:
pass

async def _visit_temporal_api_stream_v1_StreamRecord(
self, fs: VisitorFunctions, o: Any
):
if o.HasField("body"):
await self._visit_temporal_api_common_v1_Payload(fs, o.body)

async def _visit_temporal_api_streamservice_v1_ReadRecordsResponse(
self, fs: VisitorFunctions, o: Any
):
Expand Down
6 changes: 6 additions & 0 deletions temporalio/bridge/proto/external_data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
StreamAppendOrigin,
StreamAppendResult,
StreamFailure,
StreamReadMarkerData,
StreamReadPage,
StreamReadResult,
)

__all__ = [
Expand All @@ -16,4 +19,7 @@
"StreamAppendOrigin",
"StreamAppendResult",
"StreamFailure",
"StreamReadMarkerData",
"StreamReadPage",
"StreamReadResult",
]

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

153 changes: 153 additions & 0 deletions temporalio/bridge/proto/external_data/external_data_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,156 @@ class StreamFailure(google.protobuf.message.Message):
) -> None: ...

global___StreamFailure = StreamFailure

@typing.final
class StreamReadMarkerData(google.protobuf.message.Message):
"""The JSON data of a `core_stream_read` marker. Core records one marker for each activation that
gives Workflow code the result of a read. The marker doesn't hold the Records of a page. It
holds the offset that the page starts after, the number of its Records and a digest of them. A
replay reads the Records from the Store again and checks them against the digest. The `bytes`
fields are Base64 in the JSON.

A marker can have no result. Core records one when a Workflow Task completes with no other
event while Workflow code waits for a read. Without an event, a replay can't see where that
task ended.
"""

DESCRIPTOR: google.protobuf.descriptor.Descriptor

READS_FIELD_NUMBER: builtins.int
@property
def reads(
self,
) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[
global___StreamReadResult
]:
"""The results that Workflow code got in the activation."""

def __init__(
self,
*,
reads: collections.abc.Iterable[global___StreamReadResult] | None = ...,
) -> None: ...
def ClearField(self, field_name: typing.Literal["reads", b"reads"]) -> None: ...

global___StreamReadMarkerData = StreamReadMarkerData

@typing.final
class StreamReadResult(google.protobuf.message.Message):
"""The result of one read, as Workflow code got it, without the Records."""

DESCRIPTOR: google.protobuf.descriptor.Descriptor

SEQ_FIELD_NUMBER: builtins.int
STREAM_ID_FIELD_NUMBER: builtins.int
STORE_FIELD_NUMBER: builtins.int
ACTIVATION_INDEX_FIELD_NUMBER: builtins.int
AFTER_OFFSET_FIELD_NUMBER: builtins.int
PAGE_FIELD_NUMBER: builtins.int
FAILURE_FIELD_NUMBER: builtins.int
seq: builtins.int
"""The `seq` of the `ReadStream` command."""
stream_id: builtins.str
store: builtins.str
"""The name of the Store that the read used. For a command with no Store name, it's the name
that Core chose (see `AppendToStream`).
"""
activation_index: builtins.int
"""The activation that gave Workflow code the result. Activations count from 0 in each Workflow
Task.
"""
after_offset: builtins.bytes
"""The `after_offset` of the command. A replay reads the Records of the page after it."""
@property
def page(self) -> global___StreamReadPage: ...
@property
def failure(self) -> global___StreamFailure: ...
def __init__(
self,
*,
seq: builtins.int = ...,
stream_id: builtins.str = ...,
store: builtins.str = ...,
activation_index: builtins.int = ...,
after_offset: builtins.bytes = ...,
page: global___StreamReadPage | None = ...,
failure: global___StreamFailure | None = ...,
) -> None: ...
def HasField(
self,
field_name: typing.Literal[
"failure", b"failure", "page", b"page", "result", b"result"
],
) -> builtins.bool: ...
def ClearField(
self,
field_name: typing.Literal[
"activation_index",
b"activation_index",
"after_offset",
b"after_offset",
"failure",
b"failure",
"page",
b"page",
"result",
b"result",
"seq",
b"seq",
"store",
b"store",
"stream_id",
b"stream_id",
],
) -> None: ...
def WhichOneof(
self, oneof_group: typing.Literal["result", b"result"]
) -> typing.Literal["page", "failure"] | None: ...

global___StreamReadResult = StreamReadResult

@typing.final
class StreamReadPage(google.protobuf.message.Message):
"""A page that a read gave Workflow code, without its Records."""

DESCRIPTOR: google.protobuf.descriptor.Descriptor

RECORD_COUNT_FIELD_NUMBER: builtins.int
DIGEST_FIELD_NUMBER: builtins.int
RECORD_BYTES_FIELD_NUMBER: builtins.int
WAIT_CUT_FIELD_NUMBER: builtins.int
record_count: builtins.int
"""The number of Records in the page."""
digest: builtins.bytes
"""A digest of the Records. It's a version byte, which is 1, and the first 16 bytes of a SHA-256
hash of the Records in an encoding that Core owns. It's empty for a page with no Record.
"""
record_bytes: builtins.int
"""The size of the Records in bytes, counted as the `max_bytes` of a read counts them. A replay
asks the Store for that many bytes.
"""
wait_cut: builtins.bool
"""The `wait_cut` that Workflow code got with the page."""
def __init__(
self,
*,
record_count: builtins.int = ...,
digest: builtins.bytes = ...,
record_bytes: builtins.int = ...,
wait_cut: builtins.bool = ...,
) -> None: ...
def ClearField(
self,
field_name: typing.Literal[
"digest",
b"digest",
"record_bytes",
b"record_bytes",
"record_count",
b"record_count",
"wait_cut",
b"wait_cut",
],
) -> None: ...

global___StreamReadPage = StreamReadPage
4 changes: 4 additions & 0 deletions temporalio/bridge/proto/workflow_activation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
ResolveRequestCancelExternalWorkflow,
ResolveSignalExternalWorkflow,
ResolveStreamAppend,
ResolveStreamRead,
SignalWorkflow,
StreamAppended,
StreamPage,
UpdateRandomSeed,
WorkflowActivation,
WorkflowActivationJob,
Expand All @@ -43,8 +45,10 @@
"ResolveRequestCancelExternalWorkflow",
"ResolveSignalExternalWorkflow",
"ResolveStreamAppend",
"ResolveStreamRead",
"SignalWorkflow",
"StreamAppended",
"StreamPage",
"UpdateRandomSeed",
"WorkflowActivation",
"WorkflowActivationJob",
Expand Down
Loading
Loading