@@ -25,6 +25,16 @@ use crate::{
2525 transaction_repl, ConsoleContext ,
2626} ;
2727
28+ pub ( crate ) fn server_version ( context : & mut ConsoleContext , _input : & [ String ] ) -> CommandResult {
29+ let driver = context. driver . clone ( ) ;
30+ let server_version = context
31+ . background_runtime
32+ . run ( async move { driver. server_version ( ) . await } )
33+ . map_err ( |err| Box :: new ( err) as Box < dyn Error + Send > ) ?;
34+ println ! ( "{}" , server_version) ;
35+ Ok ( ( ) )
36+ }
37+
2838pub ( crate ) fn database_list ( context : & mut ConsoleContext , _input : & [ String ] ) -> CommandResult {
2939 let driver = context. driver . clone ( ) ;
3040 let databases = context
@@ -186,6 +196,55 @@ pub(crate) fn user_update_password(context: &mut ConsoleContext, input: &[String
186196 Ok ( ( ) )
187197}
188198
199+ pub ( crate ) fn replica_list ( context : & mut ConsoleContext , _input : & [ String ] ) -> CommandResult {
200+ let driver = context. driver . clone ( ) ;
201+ let replicas = driver. replicas ( ) ;
202+ if replicas. is_empty ( ) {
203+ println ! ( "No replicas are present." ) ;
204+ } else {
205+ for replica in replicas {
206+ println ! ( "{}" , replica. address( ) ) ;
207+ }
208+ }
209+ Ok ( ( ) )
210+ }
211+
212+ pub ( crate ) fn replica_primary ( context : & mut ConsoleContext , _input : & [ String ] ) -> CommandResult {
213+ let driver = context. driver . clone ( ) ;
214+ let primary_replica = driver. primary_replica ( ) ;
215+ if let Some ( primary_replica) = primary_replica {
216+ println ! ( "{}" , primary_replica. address( ) ) ;
217+ } else {
218+ println ! ( "No primary replica is present." ) ;
219+ }
220+ Ok ( ( ) )
221+ }
222+
223+ pub ( crate ) fn replica_register ( context : & mut ConsoleContext , input : & [ String ] ) -> CommandResult {
224+ let driver = context. driver . clone ( ) ;
225+ let replica_id: u64 = input[ 0 ] . parse ( ) . map_err ( |_| Box :: new ( ReplError { message : format ! ( "Replica id '{}' must be a number." , input[ 0 ] ) } )
226+ as Box < dyn Error + Send > ) ?;
227+ let address = input[ 1 ] . clone ( ) ;
228+ context
229+ . background_runtime
230+ . run ( async move { driver. register_replica ( replica_id, address) . await } )
231+ . map_err ( |err| Box :: new ( err) as Box < dyn Error + Send > ) ?;
232+ println ! ( "Successfully registered replica." ) ;
233+ Ok ( ( ) )
234+ }
235+
236+ pub ( crate ) fn replica_deregister ( context : & mut ConsoleContext , input : & [ String ] ) -> CommandResult {
237+ let driver = context. driver . clone ( ) ;
238+ let replica_id: u64 = input[ 0 ] . parse ( ) . map_err ( |_| Box :: new ( ReplError { message : format ! ( "Replica id '{}' must be a number." , input[ 0 ] ) } )
239+ as Box < dyn Error + Send > ) ?;
240+ context
241+ . background_runtime
242+ . run ( async move { driver. deregister_replica ( replica_id) . await } )
243+ . map_err ( |err| Box :: new ( err) as Box < dyn Error + Send > ) ?;
244+ println ! ( "Successfully deregistered replica." ) ;
245+ Ok ( ( ) )
246+ }
247+
189248pub ( crate ) fn transaction_read ( context : & mut ConsoleContext , input : & [ String ] ) -> CommandResult {
190249 let driver = context. driver . clone ( ) ;
191250 let db_name = & input[ 0 ] ;
0 commit comments