Skip to content

Commit 2635559

Browse files
Merge commit '85c812484be6e8fd186aa4ee23674051e18d048c'
2 parents f870d57 + 85c8124 commit 2635559

File tree

2 files changed

+47
-22
lines changed

2 files changed

+47
-22
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,26 @@ message ClearStateEntryMessage {
151151
bytes key = 1;
152152
}
153153

154+
// Completable: No
155+
// Fallible: No
156+
// Type: 0x0800 + 3
157+
message ClearAllStateEntryMessage {
158+
}
159+
160+
// Completable: Yes
161+
// Fallible: No
162+
// Type: 0x0800 + 4
163+
message GetStateKeysEntryMessage {
164+
message StateKeys {
165+
repeated bytes keys = 1;
166+
}
167+
168+
oneof result {
169+
StateKeys value = 14;
170+
Failure failure = 15;
171+
};
172+
}
173+
154174
// ------ Syscalls ------
155175

156176
// Completable: Yes

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

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ The following specification describes the protocol used by Restate to invoke rem
77
The system is composed of two actors:
88

99
- Restate Runtime
10-
- Service endpoint, which is split into:
10+
- Service deployment, which is split into:
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

@@ -16,15 +16,15 @@ either by user code 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
19-
tracked both by Restate's runtime and the service endpoint.
19+
tracked both by Restate's runtime and the service deployment.
2020

21-
Runtime and service endpoint exchange _Messages_ containing the invocation journal and runtime events through an HTTP
21+
Runtime and service deployment exchange _Messages_ containing the invocation journal and runtime events through an HTTP
2222
message stream.
2323

2424
## State machine and journal
2525

2626
Every invocation state machine begins when the stream is opened and ends when the stream is closed. In the middle,
27-
arbitrary interaction can be performed from the Service endpoint to the Runtime and vice versa via well-defined
27+
arbitrary interaction can be performed from the Service deployment to the Runtime and vice versa via well-defined
2828
messages.
2929

3030
The state machine is summarized in the following diagram:
@@ -63,14 +63,14 @@ Both runtime and SDKs transition the message stream through 2 states:
6363

6464
There are a couple of properties that we enforce through the design of the protocol:
6565

66-
- Runtime and service endpoint both have their view of the journal
66+
- Runtime and service deployment both have their view of the journal
6767
- The source of truth of the journal and its ordering is:
6868
- The runtime, when the invocation is not in _processing_ state
69-
- The service endpoint, when the invocation is in _processing_ state
70-
- When in _replaying_ state, the service endpoint cannot create new journal entries.
71-
- When in _processing_ state, only the service endpoint can create new journal entries, picking their order.
69+
- The service deployment, when the invocation is in _processing_ state
70+
- When in _replaying_ state, the service deployment cannot create new journal entries.
71+
- When in _processing_ state, only the service deployment can create new journal entries, picking their order.
7272
Consequently, it might have newer entries that the runtime is not aware of. It’s also the responsibility of the
73-
service endpoint to make sure the runtime has the same ordered view of the journal it has.
73+
service deployment to make sure the runtime has the same ordered view of the journal it has.
7474
- Only in processing state the runtime can send
7575
[`CompletionMessage`](#completable-journal-entries-and-completionmessage)
7676

@@ -90,8 +90,8 @@ Each syscall defines a priori whether it replies with an ack or a completion, or
9090

9191
## Messages
9292

93-
The protocol is composed by messages that are sent back and forth between runtime and service Endpoint. The protocol
94-
mandates the following messages:
93+
The protocol is composed by messages that are sent back and forth between runtime and the service deployment. The
94+
protocol mandates the following messages:
9595

9696
- `StartMessage`
9797
- `[..]EntryMessage`
@@ -102,8 +102,8 @@ mandates the following messages:
102102

103103
### Message stream
104104

105-
In order to execute a service method invocation, service endpoint and restate Runtime open a single stream between the
106-
runtime and the service endpoint. Given 10 concurrent service method invocations to a service endpoint, there are 10
105+
In order to execute a service method invocation, service deployment and restate Runtime open a single stream between the
106+
runtime and the service deployment. Given 10 concurrent service method invocations to a service deployment, there are 10
107107
concurrent streams, each of them mapping to a specific invocation.
108108

109109
Every unit of the stream contains a Message serialized using the
@@ -115,9 +115,9 @@ in two modes:
115115

116116
- Full duplex (bidirectional) stream: Messages are sent back and forth on the same stream at the same time. This option
117117
is supported only when using HTTP/2.
118-
- Request/Response stream: Messages are sent from runtime to service endpoint, and later from service endpoint to
119-
runtime. Once the service endpoint starts sending messages to the runtime, the runtime cannot send messages anymore
120-
back to the service endpoint.
118+
- Request/Response stream: Messages are sent from runtime to service deployment, and later from service deployment to
119+
runtime. Once the service deployment starts sending messages to the runtime, the runtime cannot send messages anymore
120+
back to the service deployment.
121121

122122
When opening the stream, the request method MUST be `POST` and the request path MUST have the following format:
123123

@@ -284,6 +284,7 @@ descriptions in [`protocol.proto`](dev/restate/service/protocol.proto).
284284
| ------------------------------- | -------- | ----------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
285285
| `PollInputStreamEntryMessage` | `0x0400` | Yes | No | Carries the invocation input message(s) of the invocation. Note: currently the runtime always sends this entry completed, but this may change in future. |
286286
| `GetStateEntryMessage` | `0x0800` | Yes | No | Get the value of a service instance state key. |
287+
| `GetStateKeysEntryMessage` | `0x0804` | Yes | No | Get all the known state keys for this service instance. Note: the completion value for this message is a protobuf of type `GetStateKeysEntryMessage.StateKeys`. |
287288
| `SleepEntryMessage` | `0x0C00` | Yes | No | Initiate a timer that completes after the given time. |
288289
| `InvokeEntryMessage` | `0x0C01` | Yes | Yes | Invoke another Restate service. |
289290
| `AwakeableEntryMessage` | `0x0C03` | Yes | No | Arbitrary result container which can be completed from another service, given a specific id. See [Awakeable identifier](#awakeable-identifier) for more details. |
@@ -292,18 +293,22 @@ descriptions in [`protocol.proto`](dev/restate/service/protocol.proto).
292293
| `OutputStreamEntryMessage` | `0x0401` | No | No | Carries the invocation output message(s) or terminal failure of the invocation. |
293294
| `SetStateEntryMessage` | `0x0800` | No | No | Set the value of a service instance state key. |
294295
| `ClearStateEntryMessage` | `0x0801` | No | No | Clear the value of a service instance state key. |
296+
| `ClearAllStateEntryMessage` | `0x0802` | No | No | Clear all the values of the service instance state. |
295297

296298
#### Awakeable identifier
297299

298300
When creating an `AwakeableEntryMessage`, the SDK MUST expose to the user code an id, required to later complete the
299301
entry, using either `CompleteAwakeableEntryMessage` or some other mechanism provided by the runtime.
300302

301-
The id format is a [Base64 URL Safe string](https://datatracker.ietf.org/doc/html/rfc4648#section-5) encoding a byte
302-
array that concatenates:
303+
The id format is a string starts with `prom_1` concatenated with a
304+
[Base64 URL Safe string](https://datatracker.ietf.org/doc/html/rfc4648#section-5) encoding of a byte array that
305+
concatenates:
303306

304307
- `StartMessage.id`
305308
- The index of the Awakeable entry, encoded as unsigned 32 bit integer big endian.
306309

310+
An example of a valid identifier would look like `prom_1NMyOAvDK2CcBjUH4Rmb7eGBp0DNNDnmsAAAAAQ`
311+
307312
## Suspension
308313

309314
As mentioned in [Replaying and processing](#replaying-and-processing), an invocation can be suspended while waiting for
@@ -329,8 +334,8 @@ To notify a failure, the SDK can either:
329334

330335
- Close the stream with `ErrorMessage` as last message. This message is used by the runtime for accurate reporting to
331336
the user.
332-
- Close the stream without `EndMessage` or `SuspensionMessage` or `ErrorMessage`. This is equivalent to sending
333-
an `ErrorMessage` with unknown reason.
337+
- Close the stream without `EndMessage` or `SuspensionMessage` or `ErrorMessage`. This is equivalent to sending an
338+
`ErrorMessage` with unknown reason.
334339

335340
The runtime takes care of retrying to execute the invocation after such failures occur, following a defined set of
336341
policies. When retrying, the previous stored journal will be reused. Moreover, the SDK MUST NOT assume that every
@@ -398,5 +403,5 @@ A possible implementation could be the following. Given a user requests a state
398403
- If `partial_state` is set, generate a `GetStateEntryMessage` without a `result`, and wait for the runtime to send a
399404
`Completion` back (same logic as without eager state)
400405

401-
In order for the aforementioned algorithm to work, set and clear state operations must be reflected on the local
402-
`state_map` as well.
406+
In order for the aforementioned algorithm to work, set, clear and clear all state operations must be reflected on the
407+
local `state_map` as well.

0 commit comments

Comments
 (0)