Skip to content

Commit

Permalink
explicit trim
Browse files Browse the repository at this point in the history
Signed-off-by: Vaibhav Rabber <[email protected]>
  • Loading branch information
vrongmeal committed Dec 13, 2024
1 parent 187f524 commit d14a1d7
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions examples/explicit_trim.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use streamstore::{
client::{ClientConfig, StreamClient},
types::{AppendInput, AppendRecordBatch, BasinName, CommandRecord},
};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let token = std::env::var("S2_AUTH_TOKEN")?;
let config = ClientConfig::new(token);
let basin: BasinName = "my-basin".parse()?;
let stream = "my-stream";
let stream_client = StreamClient::new(config, basin, stream);

let tail = stream_client.check_tail().await?;

let latest_seq_num = tail - 1;
let trim_request = CommandRecord::trim(latest_seq_num);

let append_record_batch = AppendRecordBatch::try_from_iter([trim_request])
.expect("valid batch with 1 command record");
let append_input = AppendInput::new(append_record_batch);
let _ = stream_client.append(append_input).await?;

Ok(())
}

0 comments on commit d14a1d7

Please sign in to comment.