Skip to content

Commit 35c8517

Browse files
committed
fix: absolutify db path
+ add test
1 parent ea01165 commit 35c8517

File tree

4 files changed

+54
-4
lines changed

4 files changed

+54
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ Cargo.lock
2121
.data
2222

2323
/old_*
24+
.test

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "fjall"
33
description = "LSM-based key-value storage engine"
44
license = "MIT OR Apache-2.0"
5-
version = "0.6.1"
5+
version = "0.6.2"
66
edition = "2021"
77
rust-version = "1.74.0"
88
readme = "README.md"
@@ -26,11 +26,12 @@ segment_history = ["lsm-tree/segment_history"]
2626
[dependencies]
2727
byteorder = "1.5.0"
2828
crc32fast = "1.3.2"
29-
lsm-tree = { version = "0.6.1", default-features = false }
29+
lsm-tree = { version = "0.6.2", default-features = false }
3030
log = "0.4.20"
3131
std-semaphore = "0.1.0"
3232
tempfile = "3.9.0"
3333
fs_extra = "1.3.0"
34+
path-absolutize = "3.1.1"
3435

3536
[dev-dependencies]
3637
criterion = { version = "0.5.1", features = ["html_reports"] }

src/config.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
use crate::{journal::shard::RecoveryMode, Keyspace};
22
use lsm_tree::{descriptor_table::FileDescriptorTable, BlockCache};
3+
use path_absolutize::Absolutize;
34
use std::{
45
path::{Path, PathBuf},
56
sync::Arc,
67
};
78

9+
fn absolute_path<P: AsRef<Path>>(path: P) -> PathBuf {
10+
// TODO: replace with https://doc.rust-lang.org/std/path/fn.absolute.html once stable
11+
path.as_ref()
12+
.absolutize()
13+
.expect("should be absolute path")
14+
.into()
15+
}
16+
817
/// Global keyspace configuration
918
#[derive(Clone)]
1019
pub struct Config {
@@ -50,7 +59,7 @@ impl Default for Config {
5059
.max(1);
5160

5261
Self {
53-
path: ".fjall_data".into(),
62+
path: absolute_path (".fjall_data"),
5463
block_cache: Arc::new(BlockCache::with_capacity_bytes(/* 16 MiB */ 16 * 1_024 * 1_024)),
5564
descriptor_table: Arc::new(FileDescriptorTable::new(960, 4)),
5665
max_write_buffer_size_in_bytes: 64 * 1_024 * 1_024,
@@ -67,7 +76,7 @@ impl Config {
6776
/// Creates a new configuration
6877
pub fn new<P: AsRef<Path>>(path: P) -> Self {
6978
Self {
70-
path: path.as_ref().into(),
79+
path: absolute_path(path),
7180
..Default::default()
7281
}
7382
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use fjall::Config;
2+
use std::time::Duration;
3+
use test_log::test;
4+
5+
#[test]
6+
fn recover_from_different_folder() -> fjall::Result<()> {
7+
if std::path::Path::new(".test").try_exists()? {
8+
std::fs::remove_dir_all(".test")?;
9+
}
10+
11+
let folder = ".test/asd";
12+
13+
{
14+
let keyspace = Config::new(folder).open()?;
15+
let partition = keyspace.open_partition("default", Default::default())?;
16+
17+
partition.insert("abc", "def")?;
18+
partition.insert("wqewe", "def")?;
19+
partition.insert("ewewq", "def")?;
20+
partition.insert("asddas", "def")?;
21+
partition.insert("ycxycx", "def")?;
22+
partition.insert("asdsda", "def")?;
23+
partition.insert("wewqe", "def")?;
24+
}
25+
26+
let absolute_folder = std::path::Path::new(folder).canonicalize()?;
27+
28+
std::fs::create_dir_all(".test/def")?;
29+
std::env::set_current_dir(".test/def")?;
30+
31+
for _ in 0..10 {
32+
let _keyspace = Config::new(&absolute_folder)
33+
.max_write_buffer_size(1)
34+
.open()?;
35+
std::thread::sleep(Duration::from_secs(1));
36+
}
37+
38+
Ok(())
39+
}

0 commit comments

Comments
 (0)