Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
marvin-j97 committed Jun 11, 2024
1 parent 45dff5d commit c27e314
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Config {
///
/// Default = none
#[must_use]
pub fn compression(mut self, compression: CompressionType) -> Self {
pub fn use_compression(mut self, compression: CompressionType) -> Self {
self.compression = compression;
self
}
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ impl From<DeserializeError> for Error {
}
}

/// Tree result
/// Value log result
pub type Result<T> = std::result::Result<T, Error>;
4 changes: 2 additions & 2 deletions src/index.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::ValueHandle;

/// External index trait
/// Trait that allows reading from an internal index
///
/// An index should point into the value log using [`ValueHandle`].
#[allow(clippy::module_name_repetitions)]
pub trait ExternalIndex {
pub trait Reader {
/// Returns a value handle for a given key.
///
/// This method is used to index back into the index to check for
Expand Down
12 changes: 7 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
//! # Example usage
//!
//! ```
//! # use value_log::{ExternalIndex, IndexWriter, MockIndex};
//! # use value_log::{IndexReader, IndexWriter, MockIndex};
//! use value_log::{Config, ValueHandle, ValueLog};
//!
//! # fn main() -> value_log::Result<()> {
Expand Down Expand Up @@ -110,15 +110,17 @@ pub use {
config::Config,
error::{Error, Result},
handle::ValueHandle,
index::{ExternalIndex, Writer as IndexWriter},
segment::multi_writer::MultiWriter as SegmentWriter,
segment::reader::Reader as SegmentReader,
segment::Segment,
index::{Reader as IndexReader, Writer as IndexWriter},
value::UserValue,
value_log::ValueLog,
version::Version,
};

#[doc(hidden)]
pub use segment::{
multi_writer::MultiWriter as SegmentWriter, reader::Reader as SegmentReader, Segment,
};

#[doc(hidden)]
pub use mock::{MockIndex, MockIndexWriter};

Expand Down
13 changes: 7 additions & 6 deletions src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ impl SegmentManifest {
}

/// Lists all segment IDs
#[doc(hidden)]
#[must_use]
pub fn list_segment_ids(&self) -> Vec<SegmentId> {
self.segments
Expand All @@ -278,12 +279,6 @@ impl SegmentManifest {
.collect()
}

/// Counts segments
#[must_use]
pub fn len(&self) -> usize {
self.segments.read().expect("lock is poisoned").len()
}

/// Lists all segments
#[must_use]
pub fn list_segments(&self) -> Vec<Arc<Segment>> {
Expand All @@ -295,6 +290,12 @@ impl SegmentManifest {
.collect()
}

/// Counts segments
#[must_use]
pub fn len(&self) -> usize {
self.segments.read().expect("lock is poisoned").len()
}

/// Returns the amount of bytes on disk that are occupied by blobs.
#[must_use]
pub fn disk_space_used(&self) -> u64 {
Expand Down
4 changes: 2 additions & 2 deletions src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{ExternalIndex, IndexWriter, ValueHandle};
use crate::{IndexReader, IndexWriter, ValueHandle};
use std::{
collections::BTreeMap,
sync::{Arc, RwLock},
Expand Down Expand Up @@ -35,7 +35,7 @@ impl MockIndex {
}
}

impl ExternalIndex for MockIndex {
impl IndexReader for MockIndex {
fn get(&self, key: &[u8]) -> std::io::Result<Option<ValueHandle>> {
Ok(self
.read()
Expand Down
28 changes: 23 additions & 5 deletions src/value_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
segment::merge::MergeReader,
value::UserValue,
version::Version,
Config, ExternalIndex, SegmentWriter, ValueHandle,
Config, IndexReader, SegmentWriter, ValueHandle,
};
use byteorder::{BigEndian, ReadBytesExt};
use std::{
Expand Down Expand Up @@ -42,20 +42,27 @@ impl std::ops::Deref for ValueLog {

#[allow(clippy::module_name_repetitions)]
pub struct ValueLogInner {
/// Unique value log ID
id: u64,

config: Config,

/// Base folder
path: PathBuf,

/// Value log configuration
config: Config,

/// In-memory blob cache
blob_cache: Arc<BlobCache>,

/// Segment manifest
#[doc(hidden)]
pub manifest: SegmentManifest,

/// Generator to get next segment ID
id_generator: IdGenerator,

/// Guards the rollover (compaction) process to only
/// allow one to happen at a time
rollover_guard: Mutex<()>,
}

Expand Down Expand Up @@ -237,7 +244,7 @@ impl ValueLog {
}

/// Tries to find a least-effort-selection of segments to
/// merge to react a certain space amplification.
/// merge to reach a certain space amplification.
#[must_use]
pub fn select_segments_for_space_amp_reduction(&self, space_amp_target: f32) -> Vec<SegmentId> {
let current_space_amp = self.manifest.space_amp();
Expand All @@ -251,6 +258,7 @@ impl ValueLog {
let lock = self.manifest.segments.read().expect("lock is poisoned");
let mut segments = lock.values().collect::<Vec<_>>();

// Sort by stale ratio descending
segments.sort_by(|a, b| {
b.stale_ratio()
.partial_cmp(&a.stale_ratio())
Expand Down Expand Up @@ -450,13 +458,23 @@ impl ValueLog {
Ok(MergeReader::new(readers))
}

#[doc(hidden)]
pub fn major_compact<R: IndexReader, W: IndexWriter>(
&self,
index_reader: &R,
index_writer: W,
) -> crate::Result<()> {
let ids = self.manifest.list_segment_ids();
self.rollover(&ids, index_reader, index_writer)
}

/// Rewrites some segments into new segment(s), blocking the caller
/// until the operation is completely done.
///
/// # Errors
///
/// Will return `Err` if an IO error occurs.
pub fn rollover<R: ExternalIndex, W: IndexWriter>(
pub fn rollover<R: IndexReader, W: IndexWriter>(
&self,
ids: &[u64],
index_reader: &R,
Expand Down
4 changes: 1 addition & 3 deletions tests/basic_gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ fn basic_gc() -> value_log::Result<()> {
assert_eq!(item, key.repeat(1_000).into());
}

let ids = value_log.manifest.list_segment_ids();

value_log.rollover(&ids, &index, MockIndexWriter(index.clone()))?;
value_log.major_compact(&index, MockIndexWriter(index.clone()))?;
value_log.drop_stale_segments()?;

{
Expand Down
4 changes: 2 additions & 2 deletions tests/rollover_index_fail_finish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{
collections::BTreeMap,
sync::{Arc, RwLock},
};
use value_log::{Config, ExternalIndex, IndexWriter, ValueHandle, ValueLog};
use value_log::{Config, IndexReader, IndexWriter, ValueHandle, ValueLog};

type DebugIndexInner = RwLock<BTreeMap<Arc<[u8]>, (ValueHandle, u32)>>;

Expand All @@ -27,7 +27,7 @@ impl DebugIndex {
}
}

impl ExternalIndex for DebugIndex {
impl IndexReader for DebugIndex {
fn get(&self, key: &[u8]) -> std::io::Result<Option<ValueHandle>> {
Ok(self
.read()
Expand Down

0 comments on commit c27e314

Please sign in to comment.