Skip to content

Commit eaf2eb9

Browse files
Merge commit 'e47aadba3ed95651b748b6356e139edbf3ead30c' into side-effects-core
2 parents 4657365 + e47aadb commit eaf2eb9

File tree

2 files changed

+33
-30
lines changed

2 files changed

+33
-30
lines changed

sdk-core/src/main/service-protocol/dev/restate/service/protocol.proto

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,16 @@ message EndMessage {
9898
// --- Journal Entries ---
9999

100100
// Every Completable JournalEntry has a result field, filled only and only if the entry is in DONE state.
101-
// Depending on the semantics of the corresponding syscall, the entry can represent the result field with any of these three types:
101+
//
102+
// For every journal entry, fields 12, 13, 14 and 15 are reserved.
103+
//
104+
// The field 12 is used for name. The name is used by introspection/observability tools.
105+
//
106+
// Depending on the semantics of the corresponding syscall, the entry can represent the completion result field with any of these three types:
102107
//
103108
// * google.protobuf.Empty empty = 13 for cases when we need to propagate to user code the distinction between default value or no value.
104109
// * bytes value = 14 for carrying the result value
105110
// * Failure failure = 15 for carrying a failure
106-
//
107-
// The tag numbers 12, 13, 14 and 15 are reserved and shouldn't be used for other fields.
108111

109112
// ------ Input and output ------
110113

@@ -285,8 +288,22 @@ message CompleteAwakeableEntryMessage {
285288
string id = 1;
286289

287290
oneof result {
288-
bytes value = 5;
289-
Failure failure = 6;
291+
bytes value = 14;
292+
Failure failure = 15;
293+
};
294+
295+
// Entry name
296+
string name = 12;
297+
}
298+
299+
// Completable: No
300+
// Fallible: No
301+
// Type: 0x0C00 + 5
302+
// Flag: RequiresRuntimeAck
303+
message SideEffectEntryMessage {
304+
oneof result {
305+
bytes value = 14;
306+
dev.restate.service.protocol.Failure failure = 15;
290307
};
291308

292309
// Entry name

sdk-core/src/main/service-protocol/service-invocation-protocol.md

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ The system is composed of two actors:
1111
- SDK, which contains the implementation of the Restate Protocol
1212
- User business logic, which interacts with the SDK to access Restate system calls (or syscalls)
1313

14-
Each invocation is modeled by the protocol as a state machine, where state transitions can be caused
15-
either by user code or by _Runtime events_.
14+
Each invocation is modeled by the protocol as a state machine, where state transitions can be caused either by user code
15+
or by _Runtime events_.
1616

1717
Every state transition is logged in the _Invocation journal_, used to implement Restate's durable execution model. The
1818
journal is also used to suspend an invocation and resume it at a later point in time. The _Invocation journal_ is
@@ -103,7 +103,9 @@ protocol mandates the following messages:
103103

104104
### Message stream
105105

106-
In order to execute an invocation, service deployment and restate Runtime open a single stream between the runtime and the service deployment. Given 10 concurrent invocations to a service deployment, there are 10 concurrent streams, each of them mapping to a specific invocation.
106+
In order to execute an invocation, service deployment and restate Runtime open a single stream between the runtime and
107+
the service deployment. Given 10 concurrent invocations to a service deployment, there are 10 concurrent streams, each
108+
of them mapping to a specific invocation.
107109

108110
Every unit of the stream contains a Message serialized using the
109111
[Protobuf encoding](https://protobuf.dev/programming-guides/encoding/), using the definitions in
@@ -145,26 +147,21 @@ For example:
145147

146148
An arbitrary path MAY prepend the aforementioned path format.
147149

148-
In case the path format is not respected, or `serviceName` or `handlerName` is unknown, the SDK MUST close the stream replying back with a `404` status code.
150+
In case the path format is not respected, or `serviceName` or `handlerName` is unknown, the SDK MUST close the stream
151+
replying back with a `404` status code.
149152

150153
In case the invocation is accepted, `200` status code MUST be returned.
151154

152-
Additionally, the header `x-restate-user-agent` MAY be sent back, with the following format:
155+
Additionally, the header `x-restate-server` MAY be sent back, with the following format:
153156

154157
```http request
155-
x-restate-user-agent: <sdk-name> / <sdk-version>; <additional-metadata?>
158+
x-restate-server: <sdk-name> / <sdk-version>
156159
```
157160

158161
E.g.:
159162

160163
```http request
161-
x-restate-user-agent: restate-sdk-java/0.8.0
162-
```
163-
164-
Or:
165-
166-
```http request
167-
x-restate-user-agent: restate-sdk-java/0.8.0; gitHash=0c5917b
164+
x-restate-server: restate-sdk-java/0.8.0
168165
```
169166

170167
This header is used for observability purposes by the Restate observability tools.
@@ -321,6 +318,7 @@ descriptions in [`protocol.proto`](dev/restate/service/protocol.proto).
321318
| `SetStateEntryMessage` | `0x0800` | No | No | Set the value of a service instance state key. |
322319
| `ClearStateEntryMessage` | `0x0801` | No | No | Clear the value of a service instance state key. |
323320
| `ClearAllStateEntryMessage` | `0x0802` | No | No | Clear all the values of the service instance state. |
321+
| `SideEffectEntryMessage` | `0x0C05` | No | No | Run non-deterministic user provided code and persist the result. |
324322

325323
#### Awakeable identifier
326324

@@ -437,15 +435,3 @@ A possible implementation could be the following. Given a user requests a state
437435

438436
In order for the aforementioned algorithm to work, set, clear and clear all state operations must be reflected on the
439437
local `state_map` as well.
440-
441-
### Side effect/Run
442-
443-
The side effect/run feature allows users to execute arbitrary non-deterministic code within their service and record the
444-
result, such that on re-executions the stored value will be used instead of replaying the given code.
445-
446-
SDKs MAY implement the side effect feature by storing the result using a custom entry message, as described in
447-
[Custom entry](#custom-entry-messages). By convention, the SDKs SHOULD use the entry type `FC01` for side effects.
448-
449-
When storing side effects, SDKs MAY need to wait for the
450-
[acknowledgment of the stored entry](#acknowledgment-of-stored-entries) before continuing the execution of the
451-
invocation.

0 commit comments

Comments
 (0)