Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove one slice copy in wal encoding #3861

Merged
merged 2 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/log-store/src/kafka/log_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,9 @@ impl LogStore for KafkaLogStore {
type Namespace = NamespaceImpl;

/// Creates an entry of the associated Entry type.
fn entry<D: AsRef<[u8]>>(
&self,
data: D,
entry_id: EntryId,
ns: Self::Namespace,
) -> Self::Entry {
fn entry(&self, data: &mut Vec<u8>, entry_id: EntryId, ns: Self::Namespace) -> Self::Entry {
EntryImpl {
data: data.as_ref().to_vec(),
data: std::mem::take(data),
id: entry_id,
ns,
}
Expand Down
9 changes: 2 additions & 7 deletions src/log-store/src/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,7 @@ impl LogStore for NoopLogStore {
Ok(vec![])
}

fn entry<D: AsRef<[u8]>>(
&self,
data: D,
entry_id: EntryId,
ns: Self::Namespace,
) -> Self::Entry {
fn entry(&self, data: &mut Vec<u8>, entry_id: EntryId, ns: Self::Namespace) -> Self::Entry {
let _ = data;
let _ = entry_id;
let _ = ns;
Expand Down Expand Up @@ -140,7 +135,7 @@ mod tests {
#[tokio::test]
async fn test_noop_logstore() {
let store = NoopLogStore;
let e = store.entry("".as_bytes(), 1, NamespaceImpl);
let e = store.entry(&mut vec![], 1, NamespaceImpl);
let _ = store.append(e.clone()).await.unwrap();
assert!(store.append_batch(vec![e]).await.is_ok());
store.create_namespace(&NamespaceImpl).await.unwrap();
Expand Down
9 changes: 2 additions & 7 deletions src/log-store/src/raft_engine/log_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,15 +402,10 @@ impl LogStore for RaftEngineLogStore {
Ok(namespaces)
}

fn entry<D: AsRef<[u8]>>(
&self,
data: D,
entry_id: EntryId,
ns: Self::Namespace,
) -> Self::Entry {
fn entry(&self, data: &mut Vec<u8>, entry_id: EntryId, ns: Self::Namespace) -> Self::Entry {
EntryImpl {
id: entry_id,
data: data.as_ref().to_vec(),
data: std::mem::take(data),
namespace_id: ns.id(),
..Default::default()
}
Expand Down
4 changes: 2 additions & 2 deletions src/mito2/src/wal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub struct WalWriter<S: LogStore> {
}

impl<S: LogStore> WalWriter<S> {
/// Add an wal entry for specific region to the writer's buffer.
/// Add a wal entry for specific region to the writer's buffer.
pub fn add_entry(
&mut self,
region_id: RegionId,
Expand All @@ -157,7 +157,7 @@ impl<S: LogStore> WalWriter<S> {
.context(EncodeWalSnafu { region_id })?;
let entry = self
.store
.entry(&self.entry_encode_buf, entry_id, namespace);
.entry(&mut self.entry_encode_buf, entry_id, namespace);

self.entries.push(entry);

Expand Down
3 changes: 1 addition & 2 deletions src/store-api/src/logstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ pub trait LogStore: Send + Sync + 'static + std::fmt::Debug {
async fn obsolete(&self, ns: Self::Namespace, entry_id: EntryId) -> Result<(), Self::Error>;

/// Makes an entry instance of the associated Entry type
fn entry<D: AsRef<[u8]>>(&self, data: D, entry_id: EntryId, ns: Self::Namespace)
-> Self::Entry;
fn entry(&self, data: &mut Vec<u8>, entry_id: EntryId, ns: Self::Namespace) -> Self::Entry;

/// Makes a namespace instance of the associated Namespace type
fn namespace(&self, ns_id: NamespaceId, wal_options: &WalOptions) -> Self::Namespace;
Expand Down
Loading