-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
75 additions
and
2 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
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,60 @@ | ||
// 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 tonic::codec::CompressionEncoding; | ||
|
||
use restate_admin::cluster_controller::protobuf::cluster_ctrl_svc_client::ClusterCtrlSvcClient; | ||
use restate_admin::cluster_controller::protobuf::TrimLogRequest; | ||
use restate_cli_util::c_println; | ||
|
||
use crate::app::ConnectionInfo; | ||
use crate::util::grpc_connect; | ||
|
||
#[derive(Run, Parser, Collect, Clone, Debug)] | ||
#[clap()] | ||
#[cling(run = "trim_log")] | ||
pub struct TrimLogOpts { | ||
/// The log to trim | ||
#[arg(short, long)] | ||
log_id: u32, | ||
|
||
/// The Log Sequence Number (LSN) to trim the log to, inclusive | ||
#[arg(short, long)] | ||
trim_point: u64, | ||
} | ||
|
||
async fn trim_log(connection: &ConnectionInfo, opts: &TrimLogOpts) -> 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 trim_request = TrimLogRequest { | ||
log_id: opts.log_id, | ||
trim_point: opts.trim_point, | ||
}; | ||
client | ||
.trim_log(trim_request) | ||
.await | ||
.with_context(|| "failed to submit trim request")? | ||
.into_inner(); | ||
|
||
c_println!("Submitted"); | ||
|
||
Ok(()) | ||
} |