Skip to content

Commit

Permalink
TableFile::open propagates io errors other than NotFound. fmt.
Browse files Browse the repository at this point in the history
  • Loading branch information
MattHalpinParity committed Jul 29, 2024
1 parent 15ddab9 commit b4b7375
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/btree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ impl BTreeTable {
return Ok(None)
}
let record_id = 0; // lifetime of Btree is the query, so no invalidate.
// keeping log locked when parsing tree.
// keeping log locked when parsing tree.
let tree = BTree::new(Some(btree_header.root), btree_header.depth, record_id);
tree.get(key, values, log)
}
Expand Down
17 changes: 13 additions & 4 deletions src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub fn madvise_random(_map: &mut memmap2::MmapMut) {}
fn mmap(file: &std::fs::File, len: usize) -> Result<memmap2::MmapMut> {
#[cfg(not(test))]
const RESERVE_ADDRESS_SPACE: usize = 1024 * 1024 * 1024; // 1 Gb
// Use a different value for tests to work around docker limits on the test machine.
// Use a different value for tests to work around docker limits on the test machine.
#[cfg(test)]
const RESERVE_ADDRESS_SPACE: usize = 64 * 1024 * 1024; // 64 Mb

Expand All @@ -85,6 +85,12 @@ fn mmap(file: &std::fs::File, _len: usize) -> Result<memmap2::MmapMut> {

const GROW_SIZE_BYTES: u64 = 256 * 1024;

fn test_metadata<P: AsRef<std::path::Path>>(path: P) -> std::io::Result<std::fs::Metadata> {
std::fs::metadata(path)
//Err(std::io::Error::new(ErrorKind::NotFound, "Test NotFound error"))
//Err(std::io::Error::new(ErrorKind::PermissionDenied, "Test other error"))
}

#[derive(Debug)]
pub struct TableFile {
pub map: RwLock<Option<(memmap2::MmapMut, std::fs::File)>>,
Expand All @@ -96,7 +102,12 @@ pub struct TableFile {
impl TableFile {
pub fn open(filepath: std::path::PathBuf, entry_size: u16, id: TableId) -> Result<Self> {
let mut capacity = 0u64;
let map = if std::fs::metadata(&filepath).is_ok() {
let map = if let Err(error) = test_metadata(&filepath) {
match error.kind() {
std::io::ErrorKind::NotFound => None,
_ => return try_io!(Err(error)),
}
} else {
let file = try_io!(std::fs::OpenOptions::new()
.read(true)
.write(true)
Expand All @@ -113,8 +124,6 @@ impl TableFile {
}
let map = mmap(&file, len as usize)?;
Some((map, file))
} else {
None
};
Ok(TableFile {
path: filepath,
Expand Down

0 comments on commit b4b7375

Please sign in to comment.