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

feat: Implement the Buf to avoid extra memory allocation #4585

Merged
merged 11 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions src/mito2/src/wal/entry_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ pub(crate) fn decode_raw_entry(raw_entry: Entry) -> Result<(EntryId, WalEntry)>
let region_id = raw_entry.region_id();
ensure!(raw_entry.is_complete(), CorruptedEntrySnafu { region_id });
// TODO(weny): implement the [Buf] for return value, avoid extra memory allocation.
WenyXu marked this conversation as resolved.
Show resolved Hide resolved
let bytes = raw_entry.into_bytes();
let wal_entry = WalEntry::decode(bytes.as_slice()).context(DecodeWalSnafu { region_id })?;

let buffer = raw_entry.into_buffer();
let wal_entry = WalEntry::decode(buffer).context(DecodeWalSnafu { region_id })?;
Ok((entry_id, wal_entry))
}

Expand Down
1 change: 1 addition & 0 deletions src/object-store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ pub mod manager;
mod metrics;
pub mod test_util;
pub mod util;
pub use opendal;
WenyXu marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions src/store-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ serde_json.workspace = true
snafu.workspace = true
strum.workspace = true
tokio.workspace = true
object-store.workspace = true
bytes.workspace = true

[dev-dependencies]
async-stream.workspace = true
Expand Down
10 changes: 10 additions & 0 deletions src/store-api/src/logstore/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::mem::size_of;

use crate::logstore::provider::Provider;
use crate::storage::RegionId;
use object_store::opendal::Buffer;

/// An entry's id.
/// Different log store implementations may interpret the id to different meanings.
Expand Down Expand Up @@ -143,6 +144,15 @@ impl Entry {
}
}

pub fn into_buffer(self) -> Buffer {
WenyXu marked this conversation as resolved.
Show resolved Hide resolved
match self {
Entry::Naive(entry) => Buffer::from(entry.data),
Entry::MultiplePart(entry) => Buffer::from(bytes::Bytes::from_iter(entry.parts.into_iter().flatten())),

}
WenyXu marked this conversation as resolved.
Show resolved Hide resolved
}


pub fn estimated_size(&self) -> usize {
match self {
Entry::Naive(entry) => entry.estimated_size(),
Expand Down
Loading