Skip to content
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
21 changes: 12 additions & 9 deletions storage/src/compaction/compact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ use std::{
use anyhow::{Ok, Result};

use crate::{
SSTableBuilder, SSTableIterator, Storage, common::iterator::StorageIterator,
iterators::merged_iterator::MergedIterator, lsm_storage::StorageState,
manifest::ManifestRecord::Compaction,
SSTableBuilder, SSTableIterator, common::iterator::StorageIterator,
iterators::merged_iterator::MergedIterator, lsm_storage_inner::StorageInner,
lsm_storage_inner::StorageState, manifest::ManifestRecord::Compaction,
};

const COMPACT_INTERVAL: Duration = Duration::from_secs(60);

impl Storage {
impl StorageInner {
pub fn trigger_compaction(&self) -> Result<()> {
let state = {
let guard = self.state.read().unwrap();
Expand Down Expand Up @@ -101,7 +102,9 @@ mod tests {
use bytes::Bytes;
use tempfile::tempdir;

use crate::{Config, common::iterator::StorageIterator, lsm_util::get_entries, new};
use crate::{
Config, common::iterator::StorageIterator, lsm_storage_inner::new, lsm_util::get_entries,
};

#[test]
fn test_compaction() {
Expand All @@ -113,7 +116,7 @@ mod tests {
num_memtable_limit: 5,
enable_wal: true,
};
let storage = new(config);
let storage = new(config).unwrap();

for (key, value) in get_entries() {
storage.put(key, value).unwrap();
Expand Down Expand Up @@ -148,7 +151,7 @@ mod tests {
num_memtable_limit: 5,
enable_wal: true,
};
let storage = new(config);
let storage = new(config).unwrap();

for (key, value) in get_entries() {
storage.put(key, value).unwrap();
Expand Down Expand Up @@ -211,7 +214,7 @@ mod tests {
num_memtable_limit: 5,
enable_wal: true,
};
let storage = new(config);
let storage = new(config).unwrap();
let mut entries = get_entries();

// adds a new version of key a=3
Expand Down Expand Up @@ -268,7 +271,7 @@ mod tests {
num_memtable_limit: 5,
enable_wal: true,
};
let storage = new(config);
let storage = new(config).unwrap();

for (key, value) in get_entries() {
storage.put(key, value).unwrap();
Expand Down
7 changes: 5 additions & 2 deletions storage/src/compaction/flush.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ use std::{
time::Duration,
};

use crate::{SSTableBuilder, Storage, lsm_storage::StorageState, manifest::ManifestRecord::Flush};
use crate::{
SSTableBuilder, lsm_storage_inner::StorageInner, lsm_storage_inner::StorageState,
manifest::ManifestRecord::Flush,
};

const FLUSH_INTERVAL: Duration = Duration::from_millis(50);

impl Storage {
impl StorageInner {
pub(crate) fn flush_frozen_memtable(&self) -> Result<()> {
let sst_id = {
let mut sst_builder = SSTableBuilder::new(self.config.block_size);
Expand Down
6 changes: 4 additions & 2 deletions storage/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
pub mod common;
pub mod compaction;
pub mod iterators;
pub mod lsm_storage;
mod lsm_storage;
mod lsm_storage_inner;
mod lsm_util;
mod manifest;
pub mod memtable;
mod wal;

mod block;
mod sst;
pub use lsm_storage::{Config, Storage, new};
pub use lsm_storage::new;
pub use lsm_storage_inner::Config;
pub use sst::{FileObject, SSTable, SSTableBuilder, SSTableIterator};
Loading
Loading