surrealcs_kernel/messages/server/
interface.rs

1//! The interface for the server message.
2use super::kv_operations::{
3	MessageDel, MessageDelc, MessageDelr, MessageExists, MessageGet, MessageKeys, MessagePut,
4	MessagePutc, MessageScan, MessageSet, ResponseGet, ResponseKeys, ResponseScan,
5};
6use nanoservices_utils::errors::NanoServiceError;
7use revision::revisioned;
8use serde::{Deserialize, Serialize};
9
10/// The wrapper for different key value operations.
11///
12/// # Variants
13/// * `Exists` - Check if a key exists.
14/// * `Get` - Get the value of a key.
15/// * `Set` - Set the value of a key.
16/// * `Put` - Put a key value pair.
17/// * `Putc` - Put a key value pair if the value of that key is the same as the one provided.
18/// * `Del` - Delete a key.
19/// * `Delc` - Delete a key if the value of that key is the same as the one provided.
20/// * `Delr` - Delete a key and return the value.
21/// * `Keys` - Get all keys within a range with a limit.
22/// * `Scan` - Get all keys and values within a range with a limit.
23/// * `Commit` - Commits the transaction without any more key value operations.
24/// * `SetSavePoint` - Set a save point for the transaction.
25/// * `RollbackToSavePoint` - Rollback to the last save point.
26/// * `Rollback` - Rollback the transaction.
27/// * `ResponseExists` - Response to the `Exists` operation.
28/// * `ResponseGet` - Response to the `Get` operation.
29/// * `ResponseKeys` - Response to the `Keys` operation.
30/// * `ResponseScan` - Response to the `Scan` operation.
31/// * `ResponseRolledBack` - Response to the `Rollback` operation.
32#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
33#[revisioned(revision = 1)]
34pub enum ServerTransactionMessage {
35	Exists(MessageExists),
36	Get(MessageGet),
37	Set(MessageSet),
38	Put(MessagePut),
39	Putc(MessagePutc),
40	Del(MessageDel),
41	Delc(MessageDelc),
42	Delr(MessageDelr),
43	Keys(MessageKeys),
44	Scan(MessageScan),
45	Commit,
46	SetSavePoint,
47	RollbackToSavePoint,
48	ReleaseSavePoint,
49	// Commit, this is commented out for now but if we need to add it back in, we can as we must
50	// workout how to pass a generic message to the server under the `Commit` variant
51	Rollback,
52	EmptyResponse,
53	ResponseExists(bool),
54	ResponseGet(ResponseGet),
55	ResponseKeys(ResponseKeys),
56	ResponseScan(ResponseScan),
57	ResponseRolledBack(bool),
58}
59
60/// The wrapper for different server messages.
61///
62/// # Variants
63/// * `BeginTransaction` - Begin a transaction creating a new transaction actor and setting the transaction id.
64/// * `SendOperation` - Send a single operation to the transaction actor.
65/// * `ChainedOperations` - Send a list of operations to the transaction actor.
66/// * `CommitTransaction` - Commit the transaction.
67/// * `Ping` - Ping the server.
68/// * `Error` - An error message.
69/// * `RollbackTransaction` - Rollback the transaction.
70/// * `Cleanup` - Cleanup the transaction removing all actors associated with the transaction being cleaned up.
71/// * `CloseToNewTrancations` - Close the server or the connection to new transactions.
72/// * `ClosedToNewTrancations` - Signals that the server or connection is now closed to new transactions.
73/// * `SetSavePoint` - Set a save point for the transaction.
74/// * `RollbackToSavePoint` - Rollback to the last save point.
75/// * `ReleaseLastSavePoint` - Release the last save point (currently does nothing).
76/// * `CloseConnection` - Close the connection of the TCP (this will wait and then rollback any dangling transaction after an allotted time)
77/// * `HardCloseConnection` - Close the connection of the TCP (this will rollback any dangling transaction immediately)
78#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
79#[revisioned(revision = 1)]
80pub enum ServerMessage {
81	BeginTransaction(ServerTransactionMessage),
82	SendOperation(ServerTransactionMessage),
83	ChainedOperations(Vec<ServerTransactionMessage>),
84	CommitTransaction,
85	Ping(usize),
86	Error(NanoServiceError),
87	// ones below have their own logging format with transaction_id
88	RollbackTransaction,
89	Cleanup,
90	CloseToNewTrancations,
91	ClosedToNewTrancations,
92	// below is for savepoints for transactions
93	SetSavePoint,
94	RollbackToSavePoint,
95	ReleaseLastSavePoint,
96	CloseConnection,
97	HardCloseConnection,
98}