global: snapshot

This commit is contained in:
nym21
2025-03-11 17:55:14 +01:00
parent b9e679a514
commit b4fbcf6bee
5 changed files with 26 additions and 35 deletions

5
Cargo.lock generated
View File

@@ -535,7 +535,6 @@ dependencies = [
"brk_logger", "brk_logger",
"brk_parser", "brk_parser",
"brk_query", "brk_query",
"brk_vec",
"clap", "clap",
"color-eyre", "color-eyre",
"jiff", "jiff",
@@ -543,7 +542,6 @@ dependencies = [
"minreq", "minreq",
"oxc", "oxc",
"serde", "serde",
"serde_json",
"tokio", "tokio",
"tower-http", "tower-http",
"zip", "zip",
@@ -553,14 +551,11 @@ dependencies = [
name = "brk_vec" name = "brk_vec"
version = "0.0.8" version = "0.0.8"
dependencies = [ dependencies = [
"brk_core",
"brk_exit",
"memmap2", "memmap2",
"rayon", "rayon",
"serde", "serde",
"serde_json", "serde_json",
"zerocopy", "zerocopy",
"zstd",
] ]
[[package]] [[package]]

View File

@@ -2,6 +2,7 @@ use core::error;
use std::{ use std::{
cmp::Ordering, cmp::Ordering,
fmt::Debug, fmt::Debug,
io,
ops::{Add, Deref, DerefMut, Sub}, ops::{Add, Deref, DerefMut, Sub},
path::{Path, PathBuf}, path::{Path, PathBuf},
}; };
@@ -37,6 +38,16 @@ where
index.try_into().map_err(|_| Error::FailedKeyTryIntoUsize) index.try_into().map_err(|_| Error::FailedKeyTryIntoUsize)
} }
fn safe_truncate_if_needed(&mut self, index: I, exit: &Exit) -> Result<()> {
if exit.triggered() {
return Ok(());
}
exit.block();
self.truncate_if_needed(index)?;
exit.release();
Ok(())
}
#[inline] #[inline]
fn push_and_flush_if_needed(&mut self, index: I, value: T, exit: &Exit) -> Result<()> { fn push_and_flush_if_needed(&mut self, index: I, value: T, exit: &Exit) -> Result<()> {
match self.len().cmp(&Self::i_to_usize(index)?) { match self.len().cmp(&Self::i_to_usize(index)?) {
@@ -58,6 +69,16 @@ where
} }
} }
pub fn safe_flush(&mut self, exit: &Exit) -> io::Result<()> {
if exit.triggered() {
return Ok(());
}
exit.block();
self.flush()?;
exit.release();
Ok(())
}
#[inline] #[inline]
fn path_computed_version(&self) -> PathBuf { fn path_computed_version(&self) -> PathBuf {
self.path().join("computed_version") self.path().join("computed_version")

View File

@@ -16,7 +16,6 @@ brk_indexer = { workspace = true }
brk_logger = { workspace = true } brk_logger = { workspace = true }
brk_parser = { workspace = true } brk_parser = { workspace = true }
brk_query = { workspace = true } brk_query = { workspace = true }
brk_vec = { workspace = true }
clap = { workspace = true } clap = { workspace = true }
color-eyre = { workspace = true } color-eyre = { workspace = true }
jiff = { workspace = true } jiff = { workspace = true }
@@ -24,7 +23,6 @@ log = { workspace = true }
minreq = { workspace = true } minreq = { workspace = true }
oxc = { version = "0.57.0", features = ["codegen", "minifier"] } oxc = { version = "0.57.0", features = ["codegen", "minifier"] }
serde = { workspace = true } serde = { workspace = true }
serde_json = { workspace = true }
tokio = { version = "1.44.0", features = ["full"] } tokio = { version = "1.44.0", features = ["full"] }
tower-http = { version = "0.6.2", features = ["compression-full"] } tower-http = { version = "0.6.2", features = ["compression-full"] }
zip = "2.2.3" zip = "2.2.3"

View File

@@ -9,11 +9,8 @@ license.workspace = true
repository.workspace = true repository.workspace = true
[dependencies] [dependencies]
brk_core = { workspace = true }
brk_exit = { workspace = true }
memmap2 = "0.9.5" memmap2 = "0.9.5"
rayon = { workspace = true } rayon = { workspace = true }
serde = { workspace = true } serde = { workspace = true }
serde_json = { workspace = true } serde_json = { workspace = true }
zerocopy = { workspace = true } zerocopy = { workspace = true }
zstd = "0.13.3"

View File

@@ -15,7 +15,6 @@ use std::{
sync::OnceLock, sync::OnceLock,
}; };
use brk_exit::Exit;
pub use memmap2; pub use memmap2;
use rayon::prelude::*; use rayon::prelude::*;
pub use zerocopy; pub use zerocopy;
@@ -28,6 +27,11 @@ pub use enums::*;
pub use structs::*; pub use structs::*;
pub use traits::*; pub use traits::*;
/// In bytes
const MAX_PAGE_SIZE: usize = 4 * 4096;
const ONE_MIB: usize = 1024 * 1024;
const MAX_CACHE_SIZE: usize = 100 * ONE_MIB;
/// ///
/// A very small, fast, efficient and simple storable Vec /// A very small, fast, efficient and simple storable Vec
/// ///
@@ -53,11 +57,6 @@ pub struct StorableVec<I, T> {
phantom: PhantomData<I>, phantom: PhantomData<I>,
} }
/// In bytes
const MAX_PAGE_SIZE: usize = 4 * 4096;
const ONE_MB: usize = 1024 * 1024;
const MAX_CACHE_SIZE: usize = 100 * ONE_MB;
impl<I, T> StorableVec<I, T> impl<I, T> StorableVec<I, T>
where where
I: StoredIndex, I: StoredIndex,
@@ -423,16 +422,6 @@ where
Ok(()) Ok(())
} }
pub fn safe_flush(&mut self, exit: &Exit) -> io::Result<()> {
if exit.triggered() {
return Ok(());
}
exit.block();
self.flush()?;
exit.release();
Ok(())
}
pub fn reset_file(&mut self) -> Result<()> { pub fn reset_file(&mut self) -> Result<()> {
self.truncate_if_needed(I::from(0))?; self.truncate_if_needed(I::from(0))?;
Ok(()) Ok(())
@@ -453,15 +442,6 @@ where
Ok(value_at_index) Ok(value_at_index)
} }
pub fn safe_truncate_if_needed(&mut self, index: I, exit: &Exit) -> Result<()> {
if exit.triggered() {
return Ok(());
}
exit.block();
self.truncate_if_needed(index)?;
exit.release();
Ok(())
}
#[inline] #[inline]
pub fn i_to_usize(index: I) -> Result<usize> { pub fn i_to_usize(index: I) -> Result<usize> {