crafty_proto/actor_store.rs
1//! Actor workflow store wire types ([actor-state-store](../../../docs/decisions/actor-state-store.md)).
2
3use serde::{Deserialize, Serialize};
4
5/// Set a workflow key on the leader (`POST /raft/v1/actor-store/set`).
6#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
7pub struct StoreSetRequest {
8 /// UTF-8 key.
9 pub key: String,
10 /// Opaque value bytes.
11 pub value: Vec<u8>,
12 /// TTL in seconds (`0` = no expiry).
13 #[serde(default)]
14 pub ttl_secs: u64,
15}
16
17/// Response to [`StoreSetRequest`].
18#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
19pub struct StoreSetReply {
20 /// Set when the mutation failed.
21 pub error: Option<String>,
22}
23
24/// Delete a workflow key on the leader (`POST /raft/v1/actor-store/delete`).
25#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
26pub struct StoreDeleteRequest {
27 /// Key to remove.
28 pub key: String,
29}
30
31/// Response to [`StoreDeleteRequest`].
32#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
33pub struct StoreDeleteReply {
34 /// Set when the mutation failed.
35 pub error: Option<String>,
36}
37
38/// Compare-and-set on the leader (`POST /raft/v1/actor-store/compare-and-set`).
39#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
40pub struct StoreCompareAndSetRequest {
41 /// Key to update.
42 pub key: String,
43 /// Expected current value (`None` = key must be absent).
44 pub expected: Option<Vec<u8>>,
45 /// New value when the precondition holds.
46 pub value: Vec<u8>,
47 /// TTL in seconds for the new value (`0` = no expiry).
48 #[serde(default)]
49 pub ttl_secs: u64,
50}
51
52/// Response to [`StoreCompareAndSetRequest`].
53#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
54pub struct StoreCompareAndSetReply {
55 /// Whether the swap happened.
56 pub applied: bool,
57 /// Set when the RPC failed (not when the precondition did not hold).
58 pub error: Option<String>,
59}
60
61/// Idempotent mutation replicated from the store leader to every voter.
62#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
63pub enum StoreReplicateOp {
64 /// Upsert a key.
65 Set {
66 /// Key.
67 key: String,
68 /// Value bytes.
69 value: Vec<u8>,
70 /// Expiry unix ms (`0` = never).
71 #[serde(default)]
72 expires_at_ms: u64,
73 },
74 /// Remove a key (no-op when absent).
75 Delete {
76 /// Key.
77 key: String,
78 },
79}
80
81/// Batch of store replication ops from the leader (`POST /raft/v1/actor-store/replicate`).
82#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
83pub struct StoreReplicateRequest {
84 /// Idempotent mutations to apply in order.
85 pub ops: Vec<StoreReplicateOp>,
86}
87
88/// Response to [`StoreReplicateRequest`].
89#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
90pub struct StoreReplicateReply {
91 /// Set when replication apply failed.
92 pub error: Option<String>,
93}