@@ -21,6 +21,16 @@ use crate::{
2121 transaction_repl, ConsoleContext ,
2222} ;
2323
24+ pub ( crate ) fn server_version ( context : & mut ConsoleContext , _input : & [ String ] ) -> CommandResult {
25+ let driver = context. driver . clone ( ) ;
26+ let server_version = context
27+ . background_runtime
28+ . run ( async move { driver. server_version ( ) . await } )
29+ . map_err ( |err| Box :: new ( err) as Box < dyn Error + Send > ) ?;
30+ println ! ( "{}" , server_version) ;
31+ Ok ( ( ) )
32+ }
33+
2434pub ( crate ) fn database_list ( context : & mut ConsoleContext , _input : & [ String ] ) -> CommandResult {
2535 let driver = context. driver . clone ( ) ;
2636 let databases = context
@@ -201,6 +211,55 @@ pub(crate) fn user_update_password(context: &mut ConsoleContext, input: &[String
201211 Ok ( ( ) )
202212}
203213
214+ pub ( crate ) fn replica_list ( context : & mut ConsoleContext , _input : & [ String ] ) -> CommandResult {
215+ let driver = context. driver . clone ( ) ;
216+ let replicas = driver. replicas ( ) ;
217+ if replicas. is_empty ( ) {
218+ println ! ( "No replicas are present." ) ;
219+ } else {
220+ for replica in replicas {
221+ println ! ( "{}" , replica. address( ) ) ;
222+ }
223+ }
224+ Ok ( ( ) )
225+ }
226+
227+ pub ( crate ) fn replica_primary ( context : & mut ConsoleContext , _input : & [ String ] ) -> CommandResult {
228+ let driver = context. driver . clone ( ) ;
229+ let primary_replica = driver. primary_replica ( ) ;
230+ if let Some ( primary_replica) = primary_replica {
231+ println ! ( "{}" , primary_replica. address( ) ) ;
232+ } else {
233+ println ! ( "No primary replica is present." ) ;
234+ }
235+ Ok ( ( ) )
236+ }
237+
238+ pub ( crate ) fn replica_register ( context : & mut ConsoleContext , input : & [ String ] ) -> CommandResult {
239+ let driver = context. driver . clone ( ) ;
240+ let replica_id: u64 = input[ 0 ] . parse ( ) . map_err ( |_| Box :: new ( ReplError { message : format ! ( "Replica id '{}' must be a number." , input[ 0 ] ) } )
241+ as Box < dyn Error + Send > ) ?;
242+ let address = input[ 1 ] . clone ( ) ;
243+ context
244+ . background_runtime
245+ . run ( async move { driver. register_replica ( replica_id, address) . await } )
246+ . map_err ( |err| Box :: new ( err) as Box < dyn Error + Send > ) ?;
247+ println ! ( "Successfully registered replica." ) ;
248+ Ok ( ( ) )
249+ }
250+
251+ pub ( crate ) fn replica_deregister ( context : & mut ConsoleContext , input : & [ String ] ) -> CommandResult {
252+ let driver = context. driver . clone ( ) ;
253+ let replica_id: u64 = input[ 0 ] . parse ( ) . map_err ( |_| Box :: new ( ReplError { message : format ! ( "Replica id '{}' must be a number." , input[ 0 ] ) } )
254+ as Box < dyn Error + Send > ) ?;
255+ context
256+ . background_runtime
257+ . run ( async move { driver. deregister_replica ( replica_id) . await } )
258+ . map_err ( |err| Box :: new ( err) as Box < dyn Error + Send > ) ?;
259+ println ! ( "Successfully deregistered replica." ) ;
260+ Ok ( ( ) )
261+ }
262+
204263pub ( crate ) fn transaction_read ( context : & mut ConsoleContext , input : & [ String ] ) -> CommandResult {
205264 let driver = context. driver . clone ( ) ;
206265 let db_name = & input[ 0 ] ;
0 commit comments