Skip to content

Commit 705b78e

Browse files
committed
Progress with todos, review me
1 parent abb1fbb commit 705b78e

File tree

3 files changed

+33
-30
lines changed

3 files changed

+33
-30
lines changed

src/cli.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ pub struct Args {
4646
#[arg(long = "replication-disabled", default_value = "false")]
4747
pub replication_disabled: bool,
4848

49+
// TODO: Add cluster-related retries/attempts flags from Driver Options?
50+
4951
/// Username for authentication
5052
#[arg(long, value_name = USERNAME_VALUE_NAME)]
5153
pub username: Option<String>,

src/main.rs

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,26 @@ fn execute_commands(context: &mut ConsoleContext, mut input: &str, must_log_comm
329329
fn entry_repl(driver: Arc<TypeDBDriver>, runtime: BackgroundRuntime) -> Repl<ConsoleContext> {
330330
let server_commands = Subcommand::new("server")
331331
.add(CommandLeaf::new("version", "Retrieve server version.", server_version));
332-
332+
333+
let replica_commands = Subcommand::new("replica")
334+
.add(CommandLeaf::new("list", "List replicas.", replica_list))
335+
.add(CommandLeaf::new("primary", "Get current primary replica.", replica_primary))
336+
.add(CommandLeaf::new_with_inputs(
337+
"register",
338+
"Register new replica. Requires a clustering address, not a connection address.",
339+
vec![
340+
CommandInput::new("replica id", get_word, None, None),
341+
CommandInput::new("clustering address", get_word, None, None),
342+
],
343+
replica_register,
344+
))
345+
.add(CommandLeaf::new_with_input(
346+
"deregister",
347+
"Deregister existing replica.",
348+
CommandInput::new("replica id", get_word, None, None),
349+
replica_deregister,
350+
));
351+
333352
let database_commands = Subcommand::new("database")
334353
.add(CommandLeaf::new("list", "List databases on the server.", database_list))
335354
.add(CommandLeaf::new_with_input(
@@ -414,25 +433,6 @@ fn entry_repl(driver: Arc<TypeDBDriver>, runtime: BackgroundRuntime) -> Repl<Con
414433
user_update_password,
415434
));
416435

417-
let replica_commands = Subcommand::new("replica")
418-
.add(CommandLeaf::new("list", "List replicas.", replica_list))
419-
.add(CommandLeaf::new("primary", "Get current primary replica.", replica_primary))
420-
.add(CommandLeaf::new_with_inputs(
421-
"register",
422-
"Register new replica.",
423-
vec![
424-
CommandInput::new("replica id", get_word, None, None),
425-
CommandInput::new("address", get_word, None, None),
426-
],
427-
replica_register,
428-
))
429-
.add(CommandLeaf::new_with_input(
430-
"deregister",
431-
"Deregister existing replica.",
432-
CommandInput::new("replica id", get_word, None, None),
433-
replica_deregister,
434-
));
435-
436436
let transaction_commands = Subcommand::new("transaction")
437437
.add(CommandLeaf::new_with_input(
438438
"read",
@@ -537,7 +537,6 @@ fn parse_addresses(args: &Args) -> AddressInfo {
537537
AddressInfo {only_https: is_https_address(address), addresses: Addresses::try_from_address_str(address).unwrap() }
538538
} else if let Some(addresses) = &args.addresses {
539539
let split = addresses.split(',').map(str::to_string).collect::<Vec<_>>();
540-
println!("Split: {split:?}");
541540
let only_https = split.iter().all(|address| is_https_address(address));
542541
AddressInfo {only_https, addresses: Addresses::try_from_addresses_str(split).unwrap() }
543542
} else if let Some(translation) = &args.address_translation {
@@ -550,7 +549,7 @@ fn parse_addresses(args: &Args) -> AddressInfo {
550549
only_https = only_https && is_https_address(public_address);
551550
map.insert(public_address.to_string(), private_address.to_string());
552551
}
553-
println!("Translation map:: {map:?}");
552+
println!("Translation map:: {map:?}"); // TODO: Remove
554553
AddressInfo {only_https, addresses: Addresses::try_from_translation_str(map).unwrap() }
555554
} else {
556555
panic!("At least one of --address, --addresses, or --address-translation must be provided.");

src/operations.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,17 @@ pub(crate) fn user_update_password(context: &mut ConsoleContext, input: &[String
213213

214214
pub(crate) fn replica_list(context: &mut ConsoleContext, _input: &[String]) -> CommandResult {
215215
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());
216+
context.background_runtime.run(async move {
217+
let replicas = driver.replicas().await.map_err(|err| Box::new(err) as Box<dyn Error + Send>)?;
218+
if replicas.is_empty() {
219+
println!("No replicas are present.");
220+
} else {
221+
for replica in replicas {
222+
println!("{}", replica.address());
223+
}
222224
}
223-
}
224-
Ok(())
225+
Ok(())
226+
})
225227
}
226228

227229
pub(crate) fn replica_primary(context: &mut ConsoleContext, _input: &[String]) -> CommandResult {

0 commit comments

Comments
 (0)