@@ -13,40 +13,98 @@ pub struct KvRequest {
1313 pub action : KvAction ,
1414}
1515
16+ /// IPC Action format, representing operations that can be performed on the key-value runtime module.
17+ /// These actions are included in a KvRequest sent to the kv:distro:sys runtime module.
1618#[ derive( Debug , Serialize , Deserialize , Clone ) ]
1719pub enum KvAction {
20+ /// Opens an existing key-value database or creates a new one if it doesn't exist.
1821 Open ,
22+ /// Permanently deletes the entire key-value database.
1923 RemoveDb ,
24+ /// Sets a value for the specified key in the database.
25+ ///
26+ /// # Parameters
27+ /// * `key` - The key as a byte vector
28+ /// * `tx_id` - Optional transaction ID if this operation is part of a transaction
2029 Set { key : Vec < u8 > , tx_id : Option < u64 > } ,
30+ /// Deletes a key-value pair from the database.
31+ ///
32+ /// # Parameters
33+ /// * `key` - The key to delete as a byte vector
34+ /// * `tx_id` - Optional transaction ID if this operation is part of a transaction
2135 Delete { key : Vec < u8 > , tx_id : Option < u64 > } ,
36+ /// Retrieves the value associated with the specified key.
37+ ///
38+ /// # Parameters
39+ /// * `key` - The key to look up as a byte vector
2240 Get { key : Vec < u8 > } ,
41+ /// Begins a new transaction for atomic operations.
2342 BeginTx ,
43+ /// Commits all operations in the specified transaction.
44+ ///
45+ /// # Parameters
46+ /// * `tx_id` - The ID of the transaction to commit
2447 Commit { tx_id : u64 } ,
48+ /// Creates a backup of the database.
2549 Backup ,
2650}
2751
52+ /// Response types for key-value store operations.
53+ /// These responses are returned after processing a KvAction request.
2854#[ derive( Debug , Serialize , Deserialize ) ]
2955pub enum KvResponse {
56+ /// Indicates successful completion of an operation.
3057 Ok ,
58+ /// Returns the transaction ID for a newly created transaction.
59+ ///
60+ /// # Fields
61+ /// * `tx_id` - The ID of the newly created transaction
3162 BeginTx { tx_id : u64 } ,
63+ /// Returns the key that was retrieved from the database.
64+ ///
65+ /// # Fields
66+ /// * `key` - The retrieved key as a byte vector
3267 Get { key : Vec < u8 > } ,
68+ /// Indicates an error occurred during the operation.
3369 Err ( KvError ) ,
3470}
3571
72+ /// Errors that can occur during key-value store operations.
73+ /// These errors are returned as part of `KvResponse::Err` when an operation fails.
3674#[ derive( Debug , Serialize , Deserialize , Error ) ]
3775pub enum KvError {
76+ /// The requested database does not exist.
3877 #[ error( "kv: DbDoesNotExist" ) ]
3978 NoDb ,
79+ /// The requested key was not found in the database.
4080 #[ error( "kv: KeyNotFound" ) ]
4181 KeyNotFound ,
82+ /// No active transaction found for the given transaction ID.
4283 #[ error( "kv: no Tx found" ) ]
4384 NoTx ,
85+ /// The operation requires capabilities that the caller doesn't have.
86+ ///
87+ /// # Fields
88+ /// * `error` - Description of the missing capability or permission
4489 #[ error( "kv: No capability: {error}" ) ]
4590 NoCap { error : String } ,
91+ /// An internal RocksDB error occurred during the operation.
92+ ///
93+ /// # Fields
94+ /// * `action` - The operation that was being performed
95+ /// * `error` - The specific error message from RocksDB
4696 #[ error( "kv: rocksdb internal error: {error}" ) ]
4797 RocksDBError { action : String , error : String } ,
98+ /// Error parsing or processing input data.
99+ ///
100+ /// # Fields
101+ /// * `error` - Description of what was invalid about the input
48102 #[ error( "kv: input bytes/json/key error: {error}" ) ]
49103 InputError { error : String } ,
104+ /// An I/O error occurred during the operation.
105+ ///
106+ /// # Fields
107+ /// * `error` - Description of the I/O error
50108 #[ error( "kv: IO error: {error}" ) ]
51109 IOError { error : String } ,
52110}
0 commit comments