From b5fcdae01d8b239827bb691fb56cc4c681fb5ada Mon Sep 17 00:00:00 2001 From: "Lei, Huang" <6406592+v0y4g3r@users.noreply.github.com> Date: Tue, 2 Aug 2022 12:59:08 +0800 Subject: [PATCH] LogStore::read takes a reference to namespace (#126) --- src/log-store/src/fs/log.rs | 11 ++++++----- src/log-store/src/fs/noop.rs | 8 ++++---- src/storage/src/wal.rs | 2 +- src/store-api/src/logstore.rs | 8 ++++---- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/log-store/src/fs/log.rs b/src/log-store/src/fs/log.rs index 39bdbd0ce4..6bee0f80a0 100644 --- a/src/log-store/src/fs/log.rs +++ b/src/log-store/src/fs/log.rs @@ -206,17 +206,18 @@ impl LogStore for LocalFileLogStore { .fail(); } - async fn append_batch(&self, _ns: Self::Namespace, _e: Vec) -> Result { + async fn append_batch(&self, _ns: &Self::Namespace, _e: Vec) -> Result { todo!() } async fn read( &self, - ns: Self::Namespace, + ns: &Self::Namespace, id: Id, ) -> Result> { let files = self.files.read().await; + let ns = ns.clone(); let s = stream!({ for (start_id, file) in files.iter() { if *start_id >= id { @@ -232,11 +233,11 @@ impl LogStore for LocalFileLogStore { Ok(Box::pin(s)) } - async fn create_namespace(&mut self, _ns: Self::Namespace) -> Result<()> { + async fn create_namespace(&mut self, _ns: &Self::Namespace) -> Result<()> { todo!() } - async fn delete_namespace(&mut self, _ns: Self::Namespace) -> Result<()> { + async fn delete_namespace(&mut self, _ns: &Self::Namespace) -> Result<()> { todo!() } @@ -316,7 +317,7 @@ mod tests { .entry_id; assert_eq!(0, id); - let stream = logstore.read(ns, 0).await.unwrap(); + let stream = logstore.read(&ns, 0).await.unwrap(); tokio::pin!(stream); let entries = stream.next().await.unwrap().unwrap(); diff --git a/src/log-store/src/fs/noop.rs b/src/log-store/src/fs/noop.rs index 1204792352..bcacbc87cc 100644 --- a/src/log-store/src/fs/noop.rs +++ b/src/log-store/src/fs/noop.rs @@ -26,24 +26,24 @@ impl LogStore for NoopLogStore { }) } - async fn append_batch(&self, _ns: Self::Namespace, _e: Vec) -> Result { + async fn append_batch(&self, _ns: &Self::Namespace, _e: Vec) -> Result { todo!() } async fn read( &self, - _ns: Self::Namespace, + _ns: &Self::Namespace, _id: Id, ) -> Result> { todo!() } - async fn create_namespace(&mut self, _ns: Self::Namespace) -> Result<()> { + async fn create_namespace(&mut self, _ns: &Self::Namespace) -> Result<()> { todo!() } - async fn delete_namespace(&mut self, _ns: Self::Namespace) -> Result<()> { + async fn delete_namespace(&mut self, _ns: &Self::Namespace) -> Result<()> { todo!() } diff --git a/src/storage/src/wal.rs b/src/storage/src/wal.rs index 048a8821b0..e9cb8d6c58 100644 --- a/src/storage/src/wal.rs +++ b/src/storage/src/wal.rs @@ -102,7 +102,7 @@ impl Wal { pub async fn read_from_wal(&self, start_seq: SequenceNumber) -> Result> { let stream = self .store - .read(self.namespace.clone(), start_seq) + .read(&self.namespace, start_seq) .await .map_err(BoxedError::new) .context(error::ReadWalSnafu { name: self.name() })? diff --git a/src/store-api/src/logstore.rs b/src/store-api/src/logstore.rs index 737e0f0a61..255220b894 100644 --- a/src/store-api/src/logstore.rs +++ b/src/store-api/src/logstore.rs @@ -28,22 +28,22 @@ pub trait LogStore: Send + Sync + 'static + std::fmt::Debug { // Append a batch of entries atomically and return the offset of first entry. async fn append_batch( &self, - ns: Self::Namespace, + ns: &Self::Namespace, e: Vec, ) -> Result; // Create a new `EntryStream` to asynchronously generates `Entry` with ids starting from `id`. async fn read( &self, - ns: Self::Namespace, + ns: &Self::Namespace, id: Id, ) -> Result, Self::Error>; // Create a new `Namespace`. - async fn create_namespace(&mut self, ns: Self::Namespace) -> Result<(), Self::Error>; + async fn create_namespace(&mut self, ns: &Self::Namespace) -> Result<(), Self::Error>; // Delete an existing `Namespace` with given ref. - async fn delete_namespace(&mut self, ns: Self::Namespace) -> Result<(), Self::Error>; + async fn delete_namespace(&mut self, ns: &Self::Namespace) -> Result<(), Self::Error>; // List all existing namespaces. async fn list_namespaces(&self) -> Result, Self::Error>;