This commit is contained in:
abbycin 2025-09-22 09:40:28 +08:00
commit f001180f62
Signed by: abby
GPG Key ID: B636E0F0307EF8EB
4 changed files with 13482 additions and 0 deletions

8
.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
/target
*.bak
*.~
*.swp
.idea
.vscode
.cache
Cargo.lock

7
Cargo.toml Normal file
View File

@ -0,0 +1,7 @@
[package]
name = "sample_test"
version = "0.1.0"
edition = "2024"
[dependencies]
mace = { git = "https://git.o2c.fun/abby/mace" }

13419
sample Normal file

File diff suppressed because it is too large Load Diff

48
src/main.rs Normal file
View File

@ -0,0 +1,48 @@
use std::{
fs::File,
io::{BufRead, BufReader, Read},
path::Path,
};
use mace::{Mace, OpCode, Options};
fn main() -> Result<(), OpCode> {
let sample_file = Path::new(env!("CARGO_MANIFEST_DIR")).join("sample");
let mut opt = Options::new("/tmp/sample");
opt.gc_ratio = 10;
opt.gc_eager = true;
opt.gc_timeout = 10000; // 10s
opt.tmp_store = true;
let db = Mace::new(opt.validate()?)?;
let f = File::open(sample_file).map_err(|_| OpCode::IoError)?;
let mut r = BufReader::new(f);
let mut data = Vec::new();
let mut line = String::new();
let mut nr_key = 0;
while let Ok(n) = r.read_line(&mut line)
&& n > 0
{
line.pop(); // remove \n
let rsz = line.split("_").last().unwrap();
let sz = rsz.parse::<u32>().expect("can't parse") as usize;
let v = vec![b'x'; sz];
data.push((line.clone(), v));
line.clear();
nr_key += 1;
}
for (k, v) in &data {
let kv = db.begin()?;
kv.upsert(k.as_bytes(), v)?;
kv.commit()?;
}
println!("insert {nr_key} keys");
println!("press any key to exit...");
let mut k = [0u8; 1];
let _ = std::io::stdin().read(&mut k);
Ok(())
}