• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

getdozer / dozer / 4354627675

pending completion
4354627675

push

github

GitHub
chore: Use `LmdbMap` and `LmdbMultimap` instead of raw database in cache (#1156)

754 of 754 new or added lines in 15 files covered. (100.0%)

29895 of 39630 relevant lines covered (75.44%)

38604.24 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

53.57
/dozer-cache/src/cache/lmdb/cache/id_database.rs
1
use dozer_storage::{errors::StorageError, lmdb::RwTransaction, LmdbMap};
2

3
pub fn get_or_generate_id(
4
    map: LmdbMap<[u8], u64>,
5
    txn: &mut RwTransaction,
6
    key: Option<&[u8]>,
7
) -> Result<u64, StorageError> {
8
    if let Some(key) = key {
11,854✔
9
        match map.get(txn, key)? {
11,852✔
10
            Some(id) => Ok(id.into_owned()),
1✔
11
            None => generate_id(map, txn, Some(key)),
11,899✔
12
        }
13
    } else {
×
14
        generate_id(map, txn, None)
2✔
15
    }
×
16
}
11,902✔
17

×
18
fn generate_id(
11,889✔
19
    map: LmdbMap<[u8], u64>,
11,889✔
20
    txn: &mut RwTransaction,
11,889✔
21
    key: Option<&[u8]>,
11,889✔
22
) -> Result<u64, StorageError> {
11,889✔
23
    let id = map.count(txn)? as u64;
11,889✔
24

×
25
    let id_bytes = id.to_be_bytes();
11,889✔
26
    let key = key.unwrap_or(&id_bytes);
11,889✔
27

11,889✔
28
    if !map.insert(txn, key, &id)? {
11,889✔
29
        panic!("Generating id for existing key");
×
30
    }
11,859✔
31

11,859✔
32
    Ok(id)
11,859✔
33
}
11,859✔
34

×
35
#[cfg(test)]
×
36
mod tests {
×
37
    use crate::cache::lmdb::utils::{init_env, CacheOptions};
×
38

39
    use super::*;
40

×
41
    #[test]
1✔
42
    fn test_id_database() {
1✔
43
        let mut env = init_env(&CacheOptions::default()).unwrap().0;
1✔
44
        let name = Some("primary_index");
1✔
45
        let writer = LmdbMap::new_from_env(&mut env, name, true).unwrap();
1✔
46
        let reader = LmdbMap::<[u8], u64>::new_from_env(&mut env, name, false).unwrap();
1✔
47

1✔
48
        let key = b"key";
1✔
49

1✔
50
        let txn = env.create_txn().unwrap();
1✔
51
        let mut txn = txn.write();
1✔
52
        let id = get_or_generate_id(writer, txn.txn_mut(), Some(key)).unwrap();
1✔
53
        get_or_generate_id(writer, txn.txn_mut(), None).unwrap();
1✔
54
        txn.commit_and_renew().unwrap();
1✔
55

1✔
56
        assert_eq!(
1✔
57
            writer.get(txn.txn(), key).unwrap().unwrap().into_owned(),
1✔
58
            id
1✔
59
        );
1✔
60
        assert_eq!(
1✔
61
            reader.get(txn.txn(), key).unwrap().unwrap().into_owned(),
1✔
62
            id
1✔
63
        );
1✔
64
        txn.commit_and_renew().unwrap();
1✔
65
    }
1✔
66
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc