From 9bf2db776bf677312a6f7dc7fca8fece71754047 Mon Sep 17 00:00:00 2001 From: Simon Mo Date: Tue, 18 Apr 2023 16:11:26 -0700 Subject: [PATCH] Implement `list` for snapshotter request This PR follows up on @wedsonaf's #126 and pass the filters through the list input. Note that this is not backward compatible but this is a step closer to the protocol conformance. --- crates/snapshots/examples/snapshotter.rs | 7 ++++++- crates/snapshots/src/lib.rs | 6 +++++- crates/snapshots/src/wrap.rs | 5 +++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/crates/snapshots/examples/snapshotter.rs b/crates/snapshots/examples/snapshotter.rs index d8d7ba3..1bfd510 100644 --- a/crates/snapshots/examples/snapshotter.rs +++ b/crates/snapshots/examples/snapshotter.rs @@ -100,7 +100,12 @@ impl snapshots::Snapshotter for Example { } type InfoStream = EmptyStream; - async fn list(&self) -> Result { + async fn list( + &self, + snapshotter: String, + filters: Vec, + ) -> Result { + info!("List: snapshotter={}, filters={:?}", snapshotter, filters); // Returns no snapshots. Ok(EmptyStream) } diff --git a/crates/snapshots/src/lib.rs b/crates/snapshots/src/lib.rs index f03fb9d..23261de 100644 --- a/crates/snapshots/src/lib.rs +++ b/crates/snapshots/src/lib.rs @@ -283,5 +283,9 @@ pub trait Snapshotter: Send + Sync + 'static { /// }) /// } /// ``` - async fn list(&self) -> Result; + async fn list( + &self, + snapshotter: String, + filters: Vec, + ) -> Result; } diff --git a/crates/snapshots/src/wrap.rs b/crates/snapshots/src/wrap.rs index 07101a7..aa4d69a 100644 --- a/crates/snapshots/src/wrap.rs +++ b/crates/snapshots/src/wrap.rs @@ -158,11 +158,12 @@ impl Snapshots for Wrapper { async fn list( &self, - _request: tonic::Request, + request: tonic::Request, ) -> Result, tonic::Status> { + let request = request.into_inner(); let sn = self.snapshotter.clone(); let output = async_stream::try_stream! { - let walk_stream = sn.list().await?; + let walk_stream = sn.list(request.snapshotter, request.filters).await?; pin_utils::pin_mut!(walk_stream); let mut infos = Vec::::new(); while let Some(info) = walk_stream.next().await {