surrealcs_kernel/messages/server/
interface.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//! The interface for the server message.
use super::kv_operations::{
	MessageDel, MessageDelc, MessageDelr, MessageExists, MessageGet, MessageKeys, MessagePut,
	MessagePutc, MessageScan, MessageSet, ResponseGet, ResponseKeys, ResponseScan,
};
use nanoservices_utils::errors::NanoServiceError;
use revision::revisioned;
use serde::{Deserialize, Serialize};

/// The wrapper for different key value operations.
///
/// # Variants
/// * `Exists` - Check if a key exists.
/// * `Get` - Get the value of a key.
/// * `Set` - Set the value of a key.
/// * `Put` - Put a key value pair.
/// * `Putc` - Put a key value pair if the value of that key is the same as the one provided.
/// * `Del` - Delete a key.
/// * `Delc` - Delete a key if the value of that key is the same as the one provided.
/// * `Delr` - Delete a key and return the value.
/// * `Keys` - Get all keys within a range with a limit.
/// * `Scan` - Get all keys and values within a range with a limit.
/// * `Commit` - Commits the transaction without any more key value operations.
/// * `SetSavePoint` - Set a save point for the transaction.
/// * `RollbackToSavePoint` - Rollback to the last save point.
/// * `Rollback` - Rollback the transaction.
/// * `ResponseExists` - Response to the `Exists` operation.
/// * `ResponseGet` - Response to the `Get` operation.
/// * `ResponseKeys` - Response to the `Keys` operation.
/// * `ResponseScan` - Response to the `Scan` operation.
/// * `ResponseRolledBack` - Response to the `Rollback` operation.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[revisioned(revision = 1)]
pub enum ServerTransactionMessage {
	Exists(MessageExists),
	Get(MessageGet),
	Set(MessageSet),
	Put(MessagePut),
	Putc(MessagePutc),
	Del(MessageDel),
	Delc(MessageDelc),
	Delr(MessageDelr),
	Keys(MessageKeys),
	Scan(MessageScan),
	Commit,
	SetSavePoint,
	RollbackToSavePoint,
	ReleaseSavePoint,
	// Commit, this is commented out for now but if we need to add it back in, we can as we must
	// workout how to pass a generic message to the server under the `Commit` variant
	Rollback,
	EmptyResponse,
	ResponseExists(bool),
	ResponseGet(ResponseGet),
	ResponseKeys(ResponseKeys),
	ResponseScan(ResponseScan),
	ResponseRolledBack(bool),
}

/// The wrapper for different server messages.
///
/// # Variants
/// * `BeginTransaction` - Begin a transaction creating a new transaction actor and setting the transaction id.
/// * `SendOperation` - Send a single operation to the transaction actor.
/// * `ChainedOperations` - Send a list of operations to the transaction actor.
/// * `CommitTransaction` - Commit the transaction.
/// * `Ping` - Ping the server.
/// * `Error` - An error message.
/// * `RollbackTransaction` - Rollback the transaction.
/// * `Cleanup` - Cleanup the transaction removing all actors associated with the transaction being cleaned up.
/// * `CloseToNewTrancations` - Close the server or the connection to new transactions.
/// * `ClosedToNewTrancations` - Signals that the server or connection is now closed to new transactions.
/// * `SetSavePoint` - Set a save point for the transaction.
/// * `RollbackToSavePoint` - Rollback to the last save point.
/// * `ReleaseLastSavePoint` - Release the last save point (currently does nothing).
/// * `CloseConnection` - Close the connection of the TCP (this will wait and then rollback any dangling transaction after an allotted time)
/// * `HardCloseConnection` - Close the connection of the TCP (this will rollback any dangling transaction immediately)
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[revisioned(revision = 1)]
pub enum ServerMessage {
	BeginTransaction(ServerTransactionMessage),
	SendOperation(ServerTransactionMessage),
	ChainedOperations(Vec<ServerTransactionMessage>),
	CommitTransaction,
	Ping(usize),
	Error(NanoServiceError),
	// ones below have their own logging format with transaction_id
	RollbackTransaction,
	Cleanup,
	CloseToNewTrancations,
	ClosedToNewTrancations,
	// below is for savepoints for transactions
	SetSavePoint,
	RollbackToSavePoint,
	ReleaseLastSavePoint,
	CloseConnection,
	HardCloseConnection,
}