Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Awakeable id format changes #47

Merged
merged 2 commits into from
Aug 18, 2023
Merged
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
24 changes: 9 additions & 15 deletions dev/restate/service/protocol.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ message StartMessage {
bytes value = 2;
}

bytes invocation_id = 1;
bytes instance_key = 2;
// Unique id of the invocation. This id is unique across invocations and won't change when replaying the journal.
bytes id = 1;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This id in the runtime world is partition_key + invocation_id, but in sdk terms it doesn't really matter, this is just what you need to concatenate with the awakeable index.


// Invocation id that can be used for logging.
// The user can use this id to address this invocation in admin and status introspection apis.
string debug_id = 2;

uint32 known_entries = 3;

Expand Down Expand Up @@ -162,6 +166,7 @@ message BackgroundInvokeEntryMessage {

// Kind: Completable JournalEntry
// Type: 0x0C00 + 3
// Awakeables are addressed by an identifier exposed to the user. See the spec for more details.
message AwakeableEntryMessage {
oneof result {
bytes value = 14;
Expand All @@ -172,10 +177,8 @@ message AwakeableEntryMessage {
// Kind: Non-Completable JournalEntry
// Type: 0x0C00 + 4
message CompleteAwakeableEntryMessage {
string service_name = 1;
bytes instance_key = 2;
bytes invocation_id = 3;
uint32 entry_index = 4;
// Identifier of the awakeable. See the spec for more details.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe say that this is the base64 encoded form of the awakeable identifier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this adds more than what is already described in the spec.

string id = 1;

oneof result {
bytes value = 5;
Expand All @@ -196,12 +199,3 @@ message Failure {
// Contains a concise error message, e.g. Throwable#getMessage() in Java.
string message = 2;
}

// --- Other types

message AwakeableIdentifier {
string service_name = 1;
bytes instance_key = 2;
bytes invocation_id = 3;
uint32 entry_index = 4;
}
27 changes: 19 additions & 8 deletions service-invocation-protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,13 @@ descriptions in [`protocol.proto`](dev/restate/service/protocol.proto).

**Completable journal entries**

| Message | Type | Description |
| ----------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `PollInputStreamEntryMessage` | `0x0400` | Carries the service method input message(s) of the invocation. Note: currently the runtime always sends this entry completed, but this may change in future. |
| `GetStateEntryMessage` | `0x0800` | Get the value of a service instance state key. |
| `SleepEntryMessage` | `0x0C00` | Initiate a timer that completes after the given time. |
| `InvokeEntryMessage` | `0x0C01` | Invoke another Restate service. |
| `AwakeableEntryMessage` | `0x0C03` | Arbitrary result container which can be completed from another service, given a specific id. The id MUST be exposed to the user code serializing the `AwakeableIdentifier` message as [Base64 URL Safe string](https://datatracker.ietf.org/doc/html/rfc4648#section-5) |
| Message | Type | Description |
| ----------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `PollInputStreamEntryMessage` | `0x0400` | Carries the service method input message(s) of the invocation. Note: currently the runtime always sends this entry completed, but this may change in future. |
| `GetStateEntryMessage` | `0x0800` | Get the value of a service instance state key. |
| `SleepEntryMessage` | `0x0C00` | Initiate a timer that completes after the given time. |
| `InvokeEntryMessage` | `0x0C01` | Invoke another Restate service. |
| `AwakeableEntryMessage` | `0x0C03` | Arbitrary result container which can be completed from another service, given a specific id. See [Awakeable identifier](#awakeable-identifier) for more details. |

**Non-Completable journal entries**

Expand All @@ -264,7 +264,18 @@ descriptions in [`protocol.proto`](dev/restate/service/protocol.proto).
| `SetStateEntryMessage` | `0x0800` | Set the value of a service instance state key. |
| `ClearStateEntryMessage` | `0x0801` | Clear the value of a service instance state key. |
| `BackgroundInvokeEntryMessage` | `0x0C02` | Invoke another Restate service at the given time, without waiting for the response. |
| `CompleteAwakeableEntryMessage` | `0x0C04` | Complete an `Awakeable`, given its id (see `AwakeableEntryMessage`). |
| `CompleteAwakeableEntryMessage` | `0x0C04` | Complete an `Awakeable`, given its id. See [Awakeable identifier](#awakeable-identifier) for more details. |

#### Awakeable identifier

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

The id format is a [Base64 URL Safe string](https://datatracker.ietf.org/doc/html/rfc4648#section-5) encoding a byte
array that concatenates:

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

## Suspension

Expand Down