-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[restatectl] Introduces replicated-loglet top-level command
Currently this only implements a very basic `info`. Note that the command is built merely as an example, it's UI/UX and behaviour will change by follow-ups. Pass by stringified log_id (`<log_id>_<segment>`) ``` cargo run -q --bin restatectl -- replicated-loglet info 1_0 ✘ 1 Log Configuration (v1) Loglet Referenced in: - LogId=1, Segment=0 Loglet Parameters: Loglet Id: 1_0 (4294967296) Sequencer: N1:1 Replication: {node: 2} Node Set: [N3, N2, N1] ``` Or raw loglet id (`<loglet_id>`) ``` cargo run -q --bin restatectl -- replicated-loglet info 1_0 ✘ 1 Log Configuration (v1) Loglet Referenced in: - LogId=1, Segment=0 Loglet Parameters: Loglet Id: 1_0 (4294967296) Sequencer: N1:1 Replication: {node: 2} Node Set: [N3, N2, N1] ```
- Loading branch information
1 parent
58afe5c
commit f063825
Showing
5 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,5 @@ pub mod log; | |
pub mod metadata; | ||
pub mod node; | ||
pub mod partition; | ||
pub mod replicated_loglet; | ||
pub mod snapshot; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright (c) 2024 - Restate Software, Inc., Restate GmbH. | ||
// All rights reserved. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the LICENSE file. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0. | ||
|
||
use anyhow::Context; | ||
use cling::prelude::*; | ||
|
||
use restate_admin::cluster_controller::protobuf::cluster_ctrl_svc_client::ClusterCtrlSvcClient; | ||
use restate_admin::cluster_controller::protobuf::ListLogsRequest; | ||
use restate_cli_util::{c_indentln, c_println}; | ||
use restate_types::logs::metadata::Logs; | ||
use restate_types::replicated_loglet::ReplicatedLogletId; | ||
use restate_types::storage::StorageCodec; | ||
use restate_types::Versioned; | ||
use tonic::codec::CompressionEncoding; | ||
|
||
use crate::app::ConnectionInfo; | ||
use crate::util::grpc_connect; | ||
|
||
#[derive(Run, Parser, Collect, Clone, Debug)] | ||
#[cling(run = "get_info")] | ||
pub struct InfoOpts { | ||
/// The replicated loglet id | ||
loglet_id: ReplicatedLogletId, | ||
} | ||
|
||
async fn get_info(connection: &ConnectionInfo, opts: &InfoOpts) -> anyhow::Result<()> { | ||
let channel = grpc_connect(connection.cluster_controller.clone()) | ||
.await | ||
.with_context(|| { | ||
format!( | ||
"cannot connect to cluster controller at {}", | ||
connection.cluster_controller | ||
) | ||
})?; | ||
let mut client = | ||
ClusterCtrlSvcClient::new(channel).accept_compressed(CompressionEncoding::Gzip); | ||
|
||
let req = ListLogsRequest::default(); | ||
let response = client.list_logs(req).await?.into_inner(); | ||
|
||
let mut buf = response.logs; | ||
let logs = StorageCodec::decode::<Logs, _>(&mut buf)?; | ||
c_println!("Log Configuration ({})", logs.version()); | ||
|
||
let Some(loglet_ref) = logs.get_replicated_loglet(&opts.loglet_id) else { | ||
return Err(anyhow::anyhow!("loglet {} not found", opts.loglet_id)); | ||
}; | ||
|
||
c_println!("Loglet Referenced in: "); | ||
for (log_id, segment) in &loglet_ref.references { | ||
c_indentln!(2, "- LogId={}, Segment={}", log_id, segment); | ||
} | ||
c_println!(); | ||
c_println!("Loglet Parameters:"); | ||
c_indentln!( | ||
2, | ||
"Loglet Id: {} ({})", | ||
loglet_ref.params.loglet_id, | ||
*loglet_ref.params.loglet_id | ||
); | ||
c_indentln!(2, "Sequencer: {}", loglet_ref.params.sequencer); | ||
c_indentln!(2, "Replication: {}", loglet_ref.params.replication); | ||
c_indentln!(2, "Node Set: {}", loglet_ref.params.nodeset); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (c) 2024 - Restate Software, Inc., Restate GmbH. | ||
// All rights reserved. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the LICENSE file. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0. | ||
|
||
mod info; | ||
|
||
use cling::prelude::*; | ||
|
||
#[derive(Run, Subcommand, Clone)] | ||
pub enum ReplicatedLoglet { | ||
/// View loglet info | ||
Info(info::InfoOpts), | ||
} |