|
| 1 | +// Copyright (c) 2023 - Restate Software, Inc., Restate GmbH |
| 2 | +// |
| 3 | +// This file is part of the Restate service protocol, which is |
| 4 | +// released under the MIT license. |
| 5 | +// |
| 6 | +// You can find a copy of the license in file LICENSE in the root |
| 7 | +// directory of this repository or package, or at |
| 8 | +// https://github.com/restatedev/proto/blob/main/LICENSE |
| 9 | + |
| 10 | +syntax = "proto3"; |
| 11 | + |
| 12 | +/* |
| 13 | + This package contains internal service interfaces |
| 14 | + */ |
| 15 | +package dev.restate.internal; |
| 16 | + |
| 17 | +import "dev/restate/ext.proto"; |
| 18 | +import "google/protobuf/empty.proto"; |
| 19 | +import "google/protobuf/struct.proto"; |
| 20 | + |
| 21 | +service Proxy { |
| 22 | + // Proxy invocation through this service. This service is mostly used for proxying invocations through a specific partition processor, e.g. to reuse the deduplication id map. |
| 23 | + rpc ProxyThrough(ProxyThroughRequest) returns (google.protobuf.Empty); |
| 24 | +} |
| 25 | + |
| 26 | +message ProxyThroughRequest { |
| 27 | + string target_service = 1; |
| 28 | + string target_method = 2; |
| 29 | + bytes target_key = 3; |
| 30 | + bytes target_invocation_uuid = 4; |
| 31 | + |
| 32 | + bytes input = 5; |
| 33 | +} |
| 34 | + |
| 35 | +// RemoteContext service to implement the embedded handler API |
| 36 | +service RemoteContext { |
| 37 | + option (dev.restate.ext.service_type) = KEYED; |
| 38 | + |
| 39 | + // Start a new invocation, or resume a previously existing one. |
| 40 | + // |
| 41 | + // If another client is already executing this invocation, it will be fenced off and this client will take precedence. |
| 42 | + // |
| 43 | + // This method is not idempotent. |
| 44 | + rpc Start(StartRequest) returns (StartResponse); |
| 45 | + |
| 46 | + // Send new messages to append to the message stream. |
| 47 | + // |
| 48 | + // This method is not idempotent, and a request can fail for several reasons, |
| 49 | + // including errors in sent messages, or some other transient error. |
| 50 | + // The client should consider the stream in an unrecoverable error state and it can retry |
| 51 | + // by creating a new stream through Start() with a different stream_id. |
| 52 | + // |
| 53 | + // Once the invocation is completed, subsequent Send fail. |
| 54 | + rpc Send(SendRequest) returns (SendResponse); |
| 55 | + |
| 56 | + // Receive new messages from the message stream. |
| 57 | + // |
| 58 | + // This method is not idempotent, and a request can fail for several reasons, |
| 59 | + // including errors in sent messages, or some other transient error. |
| 60 | + // The client should consider the stream in an unrecoverable error state and it can retry |
| 61 | + // by creating a new stream through Start() with a different stream_id. |
| 62 | + // |
| 63 | + // If the invocation is completed, Recv returns a response with messages field empty. |
| 64 | + rpc Recv(RecvRequest) returns (RecvResponse); |
| 65 | + |
| 66 | + // Get the result of the invocation. |
| 67 | + // |
| 68 | + // In case another client is executing the invocation (through a sequence of Start/Send/Recv), this method will block |
| 69 | + // until a response is computed. |
| 70 | + // In case the response is already available, it will return immediately with the response. |
| 71 | + // In case no client is executing the invocation, that is no client ever invoked Start() for the given operation_id, |
| 72 | + // this method will return response.none. |
| 73 | + // |
| 74 | + // This method can be safely invoked by multiple clients and it's idempotent. |
| 75 | + rpc GetResult(GetResultRequest) returns (GetResultResponse); |
| 76 | + |
| 77 | + // Cleanup all the state of the invocation, excluding the user state. |
| 78 | + // |
| 79 | + // This is automatically executed when retention_period_sec is past, but it can be manually invoked before the expiry time elapsed. |
| 80 | + rpc Cleanup(CleanupRequest) returns (google.protobuf.Empty); |
| 81 | +} |
| 82 | + |
| 83 | +message StartRequest { |
| 84 | + // User provided operation id, this is used as idempotency key. |
| 85 | + string operation_id = 1 [(dev.restate.ext.field) = KEY]; |
| 86 | + |
| 87 | + // Stream id to uniquely identify a open stream between client and Restate. |
| 88 | + // There can be at most one open stream at the same time. |
| 89 | + string stream_id = 2; |
| 90 | + |
| 91 | + // Retention period for the response in seconds. |
| 92 | + // After the invocation completes, the response will be persisted for the given duration. |
| 93 | + // Afterwards, the system will cleanup the response and treats any subsequent invocation with same operation_id as new. |
| 94 | + // |
| 95 | + // If not set, 30 minutes will be used as retention period. |
| 96 | + uint32 retention_period_sec = 3; |
| 97 | + |
| 98 | + // Argument of the invocation |
| 99 | + bytes argument = 4; |
| 100 | +} |
| 101 | + |
| 102 | +message StartResponse { |
| 103 | + oneof invocation_status { |
| 104 | + // Contains the concatenated first messages of the stream, encoded using the same framing used by service-protocol |
| 105 | + bytes executing = 1; |
| 106 | + |
| 107 | + // Contains the result of the invocation |
| 108 | + GetResultResponse completed = 2; |
| 109 | + } |
| 110 | +} |
| 111 | + |
| 112 | +message SendRequest { |
| 113 | + // User provided operation id, this is used as idempotency key. |
| 114 | + string operation_id = 1 [(dev.restate.ext.field) = KEY]; |
| 115 | + |
| 116 | + // Stream id to uniquely identify a open stream between client and Restate. |
| 117 | + // There can be at most one open stream at the same time. |
| 118 | + string stream_id = 2; |
| 119 | + |
| 120 | + // Contains the concatenated messages of the stream, encoded using the same framing used by service-protocol |
| 121 | + bytes messages = 3; |
| 122 | +} |
| 123 | + |
| 124 | +message SendResponse { |
| 125 | + oneof response { |
| 126 | + google.protobuf.Empty ok = 1; |
| 127 | + |
| 128 | + // This means the provided stream_id is invalid, and it should not be reused, |
| 129 | + // nor the client should create a new stream using Start(). |
| 130 | + // The client can instead read the invocation result using GetResult(). |
| 131 | + google.protobuf.Empty invalid_stream = 2; |
| 132 | + } |
| 133 | +} |
| 134 | + |
| 135 | +message RecvRequest { |
| 136 | + // User provided operation id, this is used as idempotency key. |
| 137 | + string operation_id = 1 [(dev.restate.ext.field) = KEY]; |
| 138 | + |
| 139 | + // Stream id to uniquely identify a open stream between client and Restate. |
| 140 | + // There can be at most one open stream at the same time. |
| 141 | + string stream_id = 2; |
| 142 | +} |
| 143 | + |
| 144 | +message RecvResponse { |
| 145 | + oneof response { |
| 146 | + // Contains the concatenated messages of the stream, encoded using the same framing used by service-protocol |
| 147 | + bytes messages = 1; |
| 148 | + |
| 149 | + // This means the provided stream_id is invalid, and it should not be reused, |
| 150 | + // nor the client should create a new stream using Start(). |
| 151 | + // The client can instead read the invocation result using GetResult(). |
| 152 | + google.protobuf.Empty invalid_stream = 2; |
| 153 | + } |
| 154 | +} |
| 155 | + |
| 156 | +message GetResultRequest { |
| 157 | + // User provided operation id, this is used as idempotency key. |
| 158 | + string operation_id = 1 [(dev.restate.ext.field) = KEY]; |
| 159 | +} |
| 160 | + |
| 161 | +message GetResultResponse { |
| 162 | + message InvocationFailure { |
| 163 | + uint32 code = 1; |
| 164 | + string message = 2; |
| 165 | + } |
| 166 | + |
| 167 | + oneof response { |
| 168 | + // See GetResult documentation |
| 169 | + google.protobuf.Empty none = 1; |
| 170 | + bytes success = 2; |
| 171 | + InvocationFailure failure = 3; |
| 172 | + } |
| 173 | + |
| 174 | + // Timestamp of the response expiry time in RFC3339. |
| 175 | + // Empty if response = none |
| 176 | + string expiry_time = 15; |
| 177 | +} |
| 178 | + |
| 179 | +message CleanupRequest { |
| 180 | + // User provided operation id, this is used as idempotency key. |
| 181 | + string operation_id = 1 [(dev.restate.ext.field) = KEY]; |
| 182 | +} |
0 commit comments