aboutsummaryrefslogtreecommitdiffstats
path: root/log_db/benches/utils.rs
diff options
context:
space:
mode:
authorJan Tuomi <jan@jantuomi.fi>2025-01-08 10:13:00 +0200
committerJan Tuomi <jan@jantuomi.fi>2025-01-10 19:48:50 +0200
commit3ffa6702cdb39c21a26ddc434f46d17d0104cb7b (patch)
treeb0d8e4dcbb967d90b90a338eb0cb50fc0f10c518 /log_db/benches/utils.rs
parentf19c7e6a41768e73a0f727deb22d65f1646a0777 (diff)
Fix compaction issue where get of valid logkey produced unset metadata row (len = 0)
Diffstat (limited to 'log_db/benches/utils.rs')
-rw-r--r--log_db/benches/utils.rs22
1 files changed, 16 insertions, 6 deletions
diff --git a/log_db/benches/utils.rs b/log_db/benches/utils.rs
index 05ea30f..0f9c620 100644
--- a/log_db/benches/utils.rs
+++ b/log_db/benches/utils.rs
@@ -12,9 +12,9 @@ pub enum Field {
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct Inst {
- id: i64,
- name: String,
- data: Vec<u8>,
+ pub id: i64,
+ pub name: String,
+ pub data: Vec<u8>,
}
impl Recordable for Inst {
type Field = Field;
@@ -28,6 +28,10 @@ impl Recordable for Inst {
fn primary_key() -> Self::Field {
Field::Id
}
+ fn secondary_keys() -> Vec<Self::Field> {
+ vec![Field::Name]
+ }
+
fn into_record(self) -> Vec<Value> {
vec![
Value::Int(self.id),
@@ -81,11 +85,17 @@ pub fn random_inst(from_id: i64, to_id: i64) -> Inst {
}
}
-pub fn prefill_db(db: &mut DB<Inst>, n_records: usize, compact: bool) -> Result<(), DBError> {
- for _ in 0..n_records {
+pub fn prefill_db(
+ db: &mut DB<Inst>,
+ insts: &mut Vec<Inst>,
+ n_records: usize,
+ compact: bool,
+) -> Result<(), DBError> {
+ for i in 0..(n_records - insts.len()) {
let inst = random_inst(0, n_records as i64);
+ insts.push(inst.clone());
db.upsert(inst)?;
- if compact {
+ if i % 1000 == 0 && compact {
db.do_maintenance_tasks()?;
}
}