-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Alex Feinberg <alex@strlen.net>
- Loading branch information
Showing
5 changed files
with
52 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2024 TiKV Project Authors. Licensed under Apache-2.0. | ||
|
||
use std::sync::Arc; | ||
|
||
use engine_rocks::{util::new_engine, RocksEngine}; | ||
use engine_traits::{Result, CF_DEFAULT, CF_LOCK, CF_WRITE}; | ||
use region_cache_memory_engine::RangeCacheMemoryEngine; | ||
use tempfile::{Builder, TempDir}; | ||
|
||
use crate::HybridEngine; | ||
|
||
/// Create a [`HybridEngine`] using temporary storage in `prefix`. | ||
/// Once the memory engine is created, runs `configure_memory_engine_fn`. | ||
/// Returns the handle to temporary directory and HybridEngine. | ||
/// | ||
/// # Example | ||
/// | ||
/// ``` | ||
/// use hybrid_engine::util::hybrid_engine_for_tests; | ||
/// let (_path, _hybrid_engine) = hybrid_engine_for_tests("temp", |memory_engine| { | ||
/// let range = engine_traits::CacheRange::new(b"k00".to_vec(), b"k10".to_vec()); | ||
/// memory_engine.new_range(range.clone()); | ||
/// { | ||
/// let mut core = memory_engine.core().lock().unwrap(); | ||
/// core.mut_range_manager().set_range_readable(&range, true); | ||
/// core.mut_range_manager().set_safe_ts(&range, 10); | ||
/// } | ||
/// }) | ||
/// .unwrap(); | ||
/// ``` | ||
pub fn hybrid_engine_for_tests<F>( | ||
prefix: &str, | ||
configure_memory_engine_fn: F, | ||
) -> Result<(TempDir, HybridEngine<RocksEngine, RangeCacheMemoryEngine>)> | ||
where | ||
F: FnOnce(&RangeCacheMemoryEngine), | ||
{ | ||
let path = Builder::new().prefix(prefix).tempdir()?; | ||
let disk_engine = new_engine( | ||
path.path().to_str().unwrap(), | ||
&[CF_DEFAULT, CF_LOCK, CF_WRITE], | ||
)?; | ||
let memory_engine = RangeCacheMemoryEngine::new(Arc::default()); | ||
configure_memory_engine_fn(&memory_engine); | ||
let hybrid_engine = HybridEngine::new(disk_engine, memory_engine); | ||
Ok((path, hybrid_engine)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters