2021-12-25 07:58:27 +00:00
|
|
|
use rand::prelude::*;
|
|
|
|
|
use rand_chacha::ChaCha8Rng;
|
2021-11-22 08:04:50 +00:00
|
|
|
use crate::*;
|
2021-12-25 07:58:27 +00:00
|
|
|
use core::sync::atomic::{AtomicU64, Ordering};
|
2021-12-25 17:42:36 +00:00
|
|
|
use std::collections::BTreeSet;
|
2021-11-22 08:04:50 +00:00
|
|
|
|
2021-11-23 15:33:06 +00:00
|
|
|
const UPPER_BOUND: usize = 9000;
|
small keys had their data missing because i deleted it :-/
it's one of those bugs where you're like oh...right. it's doing
exactly what i told it to. I just told it to do the wrong thing.
Right. If you're updating data at the end of a file, you kind of
don't want to delete the file entirely then do the update.
Fix the code so that in the case of a file extension of a small
key, you're re-inserting the key in its entirety (not just the
updated portion) on the extension case.
Also handled an issue with large files where key extension
should not lead to overwrite of the neighboring data, and put
a cap of the large file limit of 32GiB. See comments for thoughts
on the trade-off of the large file limit versus the allocation
limit of the number of files and the physically realistic
outcomes for the PDDB. Basically as written the PDDB can handle
32GiB files (big enough to hold a blu-ray movie, but not a 4k/8k
movie, uncompressed movies, and/or large virtual machine images),
and can handle creation of files at an average rate of one per
second for 10 years without stop before running out of virtual
memory space.
This isn't "Web scale" as large servers will
definitely require files bigger than 32GiB these days, and
can easily create files at a rate of thousands per second. But,
the PDDB isn't performant enough nor targeted toward large
scale server applications. It should, however, be adequate for
pretty much any user data on a mobile phone if it were recompiled
for a 64-bit target. And, if you needed to scale up to bigger
files and/or more write cycles, the problem can be solved
with some simple memory allocation tricks on the large pool,
but because Precursor only has 16MiB of its own RAM to play
with, we don't implement that as the RAM overhead is both
detrimental and unnecessary at our scale of operation.
2021-11-25 09:56:39 +00:00
|
|
|
const LOWER_BOUND: usize = 12; // needs to be big enough to compute murmur3 hash + hold checksum
|
2021-11-23 15:33:06 +00:00
|
|
|
|
2021-12-25 07:58:27 +00:00
|
|
|
static RNG_LOCAL_STATE: AtomicU64 = AtomicU64::new(xous::TESTING_RNG_SEED);
|
|
|
|
|
|
2021-11-22 18:57:13 +00:00
|
|
|
fn gen_key(dictname: &str, keynum: usize, lower_size_bound: usize, upper_size_bound: usize) -> (String, Vec::<u8>) {
|
2021-12-25 07:58:27 +00:00
|
|
|
let mut rng = ChaCha8Rng::seed_from_u64(RNG_LOCAL_STATE.load(Ordering::SeqCst));
|
2021-11-22 18:57:13 +00:00
|
|
|
// we want roughly half our keys to be in the small bin, and half in the large bin
|
|
|
|
|
let keylen = if rng.gen_bool(0.5) {
|
|
|
|
|
rng.gen_range(lower_size_bound..VPAGE_SIZE)
|
|
|
|
|
} else {
|
|
|
|
|
rng.gen_range(VPAGE_SIZE..upper_size_bound)
|
|
|
|
|
};
|
|
|
|
|
// record the owning dictionary name & length with the key. This isn't mandatory for a key name,
|
|
|
|
|
// but it helps the test checking program check things.
|
|
|
|
|
let keyname = format!("sanitycheck|{}|key{}|len{}", dictname, keynum, keylen);
|
|
|
|
|
let mut keydata = Vec::<u8>::new();
|
|
|
|
|
for i in 0..keylen-4 {
|
|
|
|
|
// the data starts with a number equal to the key number, and increments from there
|
|
|
|
|
keydata.push((keynum + i) as u8);
|
|
|
|
|
}
|
|
|
|
|
// a checksum is appended to each run of data
|
|
|
|
|
// copy the stored data, and pad it out to a multiple of word lengths with 0's so we can compute the checksum
|
|
|
|
|
let mut checkdata = Vec::<u8>::new();
|
|
|
|
|
for &b in &keydata {
|
|
|
|
|
checkdata.push(b);
|
|
|
|
|
}
|
|
|
|
|
while checkdata.len() % 4 != 0 {
|
|
|
|
|
checkdata.push(0);
|
|
|
|
|
}
|
|
|
|
|
let checksum = murmur3_32(&checkdata, 0);
|
|
|
|
|
keydata.append(&mut checksum.to_le_bytes().to_vec());
|
2021-12-25 07:58:27 +00:00
|
|
|
RNG_LOCAL_STATE.store(rng.next_u64(), Ordering::SeqCst);
|
2021-11-22 18:57:13 +00:00
|
|
|
(keyname, keydata)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) fn create_basis_testcase(hw: &mut PddbOs, basis_cache: &mut BasisCache,
|
2021-11-23 19:57:50 +00:00
|
|
|
maybe_num_dicts: Option<usize>, maybe_num_keys: Option<usize>, maybe_key_sizes: Option<(usize, usize)>,
|
|
|
|
|
maybe_extra_reserved: Option<usize>,
|
|
|
|
|
) {
|
2021-11-22 08:04:50 +00:00
|
|
|
|
2021-11-22 20:36:58 +00:00
|
|
|
hw.pddb_format(false).unwrap();
|
2021-11-22 08:04:50 +00:00
|
|
|
let sys_basis = hw.pddb_mount().expect("couldn't mount system basis");
|
2021-11-28 15:54:58 +00:00
|
|
|
basis_cache.basis_add(sys_basis);
|
2021-11-22 08:04:50 +00:00
|
|
|
|
|
|
|
|
let num_dicts = maybe_num_dicts.unwrap_or(4);
|
|
|
|
|
let num_keys = maybe_num_keys.unwrap_or(34);
|
small keys had their data missing because i deleted it :-/
it's one of those bugs where you're like oh...right. it's doing
exactly what i told it to. I just told it to do the wrong thing.
Right. If you're updating data at the end of a file, you kind of
don't want to delete the file entirely then do the update.
Fix the code so that in the case of a file extension of a small
key, you're re-inserting the key in its entirety (not just the
updated portion) on the extension case.
Also handled an issue with large files where key extension
should not lead to overwrite of the neighboring data, and put
a cap of the large file limit of 32GiB. See comments for thoughts
on the trade-off of the large file limit versus the allocation
limit of the number of files and the physically realistic
outcomes for the PDDB. Basically as written the PDDB can handle
32GiB files (big enough to hold a blu-ray movie, but not a 4k/8k
movie, uncompressed movies, and/or large virtual machine images),
and can handle creation of files at an average rate of one per
second for 10 years without stop before running out of virtual
memory space.
This isn't "Web scale" as large servers will
definitely require files bigger than 32GiB these days, and
can easily create files at a rate of thousands per second. But,
the PDDB isn't performant enough nor targeted toward large
scale server applications. It should, however, be adequate for
pretty much any user data on a mobile phone if it were recompiled
for a 64-bit target. And, if you needed to scale up to bigger
files and/or more write cycles, the problem can be solved
with some simple memory allocation tricks on the large pool,
but because Precursor only has 16MiB of its own RAM to play
with, we don't implement that as the RAM overhead is both
detrimental and unnecessary at our scale of operation.
2021-11-25 09:56:39 +00:00
|
|
|
let (key_lower_bound, key_upper_bound) = maybe_key_sizes.unwrap_or((LOWER_BOUND, UPPER_BOUND - 4)); // 4 bytes for the CI checksum
|
2021-11-23 19:57:50 +00:00
|
|
|
let extra_reserved = maybe_extra_reserved.unwrap_or(0);
|
2021-11-22 08:04:50 +00:00
|
|
|
|
|
|
|
|
// make all the directories first
|
|
|
|
|
for dictnum in 1..=num_dicts {
|
|
|
|
|
let dictname = format!("dict{}", dictnum);
|
|
|
|
|
basis_cache.dict_add(hw, &dictname, None).unwrap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// now add keys of various sizes, striping through each dictionary. Adding the keys cross-dictionary
|
|
|
|
|
// exercises the large pool allocator, as it is shared across multiple dictionaries.
|
|
|
|
|
for keynum in 1..=num_keys {
|
|
|
|
|
for dictnum in 1..=num_dicts {
|
|
|
|
|
let dictname = format!("dict{}", dictnum);
|
2021-11-22 18:57:13 +00:00
|
|
|
let (keyname, keydata) = gen_key(&dictname, keynum, key_lower_bound, key_upper_bound);
|
|
|
|
|
// now we're ready to write it out
|
2021-11-23 19:57:50 +00:00
|
|
|
if maybe_extra_reserved.is_none() {
|
|
|
|
|
// we do this slightly funky way instead of just passing Some(0) because we want to test the "None" path explicitly
|
|
|
|
|
basis_cache.key_update(hw, &dictname, &keyname, &keydata, None,
|
|
|
|
|
None,
|
|
|
|
|
None, false).unwrap();
|
|
|
|
|
} else {
|
|
|
|
|
basis_cache.key_update(hw, &dictname, &keyname, &keydata, None,
|
|
|
|
|
Some(keydata.len() + extra_reserved),
|
|
|
|
|
None, false).unwrap();
|
|
|
|
|
}
|
2021-11-22 18:57:13 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Delete & add dictionary consistency check
|
|
|
|
|
pub(crate) fn delete_add_dict_consistency(hw: &mut PddbOs, basis_cache: &mut BasisCache,
|
small keys had their data missing because i deleted it :-/
it's one of those bugs where you're like oh...right. it's doing
exactly what i told it to. I just told it to do the wrong thing.
Right. If you're updating data at the end of a file, you kind of
don't want to delete the file entirely then do the update.
Fix the code so that in the case of a file extension of a small
key, you're re-inserting the key in its entirety (not just the
updated portion) on the extension case.
Also handled an issue with large files where key extension
should not lead to overwrite of the neighboring data, and put
a cap of the large file limit of 32GiB. See comments for thoughts
on the trade-off of the large file limit versus the allocation
limit of the number of files and the physically realistic
outcomes for the PDDB. Basically as written the PDDB can handle
32GiB files (big enough to hold a blu-ray movie, but not a 4k/8k
movie, uncompressed movies, and/or large virtual machine images),
and can handle creation of files at an average rate of one per
second for 10 years without stop before running out of virtual
memory space.
This isn't "Web scale" as large servers will
definitely require files bigger than 32GiB these days, and
can easily create files at a rate of thousands per second. But,
the PDDB isn't performant enough nor targeted toward large
scale server applications. It should, however, be adequate for
pretty much any user data on a mobile phone if it were recompiled
for a 64-bit target. And, if you needed to scale up to bigger
files and/or more write cycles, the problem can be solved
with some simple memory allocation tricks on the large pool,
but because Precursor only has 16MiB of its own RAM to play
with, we don't implement that as the RAM overhead is both
detrimental and unnecessary at our scale of operation.
2021-11-25 09:56:39 +00:00
|
|
|
maybe_num_dicts: Option<usize>, maybe_num_keys: Option<usize>, maybe_key_sizes: Option<(usize, usize)>,
|
2021-11-28 15:54:58 +00:00
|
|
|
maybe_extra_reserved: Option<usize>, basis_name: Option<&str>
|
small keys had their data missing because i deleted it :-/
it's one of those bugs where you're like oh...right. it's doing
exactly what i told it to. I just told it to do the wrong thing.
Right. If you're updating data at the end of a file, you kind of
don't want to delete the file entirely then do the update.
Fix the code so that in the case of a file extension of a small
key, you're re-inserting the key in its entirety (not just the
updated portion) on the extension case.
Also handled an issue with large files where key extension
should not lead to overwrite of the neighboring data, and put
a cap of the large file limit of 32GiB. See comments for thoughts
on the trade-off of the large file limit versus the allocation
limit of the number of files and the physically realistic
outcomes for the PDDB. Basically as written the PDDB can handle
32GiB files (big enough to hold a blu-ray movie, but not a 4k/8k
movie, uncompressed movies, and/or large virtual machine images),
and can handle creation of files at an average rate of one per
second for 10 years without stop before running out of virtual
memory space.
This isn't "Web scale" as large servers will
definitely require files bigger than 32GiB these days, and
can easily create files at a rate of thousands per second. But,
the PDDB isn't performant enough nor targeted toward large
scale server applications. It should, however, be adequate for
pretty much any user data on a mobile phone if it were recompiled
for a 64-bit target. And, if you needed to scale up to bigger
files and/or more write cycles, the problem can be solved
with some simple memory allocation tricks on the large pool,
but because Precursor only has 16MiB of its own RAM to play
with, we don't implement that as the RAM overhead is both
detrimental and unnecessary at our scale of operation.
2021-11-25 09:56:39 +00:00
|
|
|
) {
|
2021-11-22 18:57:13 +00:00
|
|
|
let evict_count = maybe_num_dicts.unwrap_or(1);
|
|
|
|
|
let num_keys = maybe_num_keys.unwrap_or(36);
|
small keys had their data missing because i deleted it :-/
it's one of those bugs where you're like oh...right. it's doing
exactly what i told it to. I just told it to do the wrong thing.
Right. If you're updating data at the end of a file, you kind of
don't want to delete the file entirely then do the update.
Fix the code so that in the case of a file extension of a small
key, you're re-inserting the key in its entirety (not just the
updated portion) on the extension case.
Also handled an issue with large files where key extension
should not lead to overwrite of the neighboring data, and put
a cap of the large file limit of 32GiB. See comments for thoughts
on the trade-off of the large file limit versus the allocation
limit of the number of files and the physically realistic
outcomes for the PDDB. Basically as written the PDDB can handle
32GiB files (big enough to hold a blu-ray movie, but not a 4k/8k
movie, uncompressed movies, and/or large virtual machine images),
and can handle creation of files at an average rate of one per
second for 10 years without stop before running out of virtual
memory space.
This isn't "Web scale" as large servers will
definitely require files bigger than 32GiB these days, and
can easily create files at a rate of thousands per second. But,
the PDDB isn't performant enough nor targeted toward large
scale server applications. It should, however, be adequate for
pretty much any user data on a mobile phone if it were recompiled
for a 64-bit target. And, if you needed to scale up to bigger
files and/or more write cycles, the problem can be solved
with some simple memory allocation tricks on the large pool,
but because Precursor only has 16MiB of its own RAM to play
with, we don't implement that as the RAM overhead is both
detrimental and unnecessary at our scale of operation.
2021-11-25 09:56:39 +00:00
|
|
|
let (key_lower_bound, key_upper_bound) = maybe_key_sizes.unwrap_or((LOWER_BOUND, UPPER_BOUND - 4));
|
|
|
|
|
let extra_reserved = maybe_extra_reserved.unwrap_or(0);
|
2021-11-22 18:57:13 +00:00
|
|
|
|
2021-12-25 17:42:36 +00:00
|
|
|
#[cfg(feature = "deterministic")]
|
2021-12-25 08:44:24 +00:00
|
|
|
let mut dict_list = BTreeSet::<String>::new();
|
2021-12-25 17:42:36 +00:00
|
|
|
#[cfg(feature = "deterministic")]
|
|
|
|
|
{
|
|
|
|
|
let dict_list_unord = basis_cache.dict_list(hw, None);
|
|
|
|
|
for s in dict_list_unord {
|
|
|
|
|
dict_list.insert(s);
|
|
|
|
|
}
|
2021-12-25 08:44:24 +00:00
|
|
|
}
|
2021-12-25 17:42:36 +00:00
|
|
|
#[cfg(not(feature = "deterministic"))]
|
|
|
|
|
let dict_list = basis_cache.dict_list(hw, None);
|
|
|
|
|
|
2021-11-22 18:57:13 +00:00
|
|
|
let dict_start_index = dict_list.len();
|
|
|
|
|
for (evicted, evict_dict) in dict_list.iter().enumerate() {
|
|
|
|
|
if evicted < evict_count {
|
2021-11-28 15:54:58 +00:00
|
|
|
match basis_cache.dict_remove(hw, evict_dict, basis_name, false) {
|
2021-11-22 18:57:13 +00:00
|
|
|
Ok(_) => {},
|
|
|
|
|
Err(e) => log::error!("Error evicting dictionary {}: {:?}", evict_dict, e),
|
2021-11-22 08:04:50 +00:00
|
|
|
}
|
2021-11-22 18:57:13 +00:00
|
|
|
} else {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for keynum in 1..=num_keys {
|
|
|
|
|
for dictnum in 1..=evict_count {
|
|
|
|
|
let dictname = format!("dict{}", dictnum + dict_start_index);
|
|
|
|
|
let (keyname, keydata) = gen_key(&dictname, keynum, key_lower_bound, key_upper_bound);
|
2021-11-22 08:04:50 +00:00
|
|
|
// now we're ready to write it out
|
small keys had their data missing because i deleted it :-/
it's one of those bugs where you're like oh...right. it's doing
exactly what i told it to. I just told it to do the wrong thing.
Right. If you're updating data at the end of a file, you kind of
don't want to delete the file entirely then do the update.
Fix the code so that in the case of a file extension of a small
key, you're re-inserting the key in its entirety (not just the
updated portion) on the extension case.
Also handled an issue with large files where key extension
should not lead to overwrite of the neighboring data, and put
a cap of the large file limit of 32GiB. See comments for thoughts
on the trade-off of the large file limit versus the allocation
limit of the number of files and the physically realistic
outcomes for the PDDB. Basically as written the PDDB can handle
32GiB files (big enough to hold a blu-ray movie, but not a 4k/8k
movie, uncompressed movies, and/or large virtual machine images),
and can handle creation of files at an average rate of one per
second for 10 years without stop before running out of virtual
memory space.
This isn't "Web scale" as large servers will
definitely require files bigger than 32GiB these days, and
can easily create files at a rate of thousands per second. But,
the PDDB isn't performant enough nor targeted toward large
scale server applications. It should, however, be adequate for
pretty much any user data on a mobile phone if it were recompiled
for a 64-bit target. And, if you needed to scale up to bigger
files and/or more write cycles, the problem can be solved
with some simple memory allocation tricks on the large pool,
but because Precursor only has 16MiB of its own RAM to play
with, we don't implement that as the RAM overhead is both
detrimental and unnecessary at our scale of operation.
2021-11-25 09:56:39 +00:00
|
|
|
if maybe_extra_reserved.is_none() {
|
|
|
|
|
// we do this slightly funky way instead of just passing Some(0) because we want to test the "None" path explicitly
|
|
|
|
|
basis_cache.key_update(hw, &dictname, &keyname, &keydata, None,
|
|
|
|
|
None,
|
2021-11-28 15:54:58 +00:00
|
|
|
basis_name, false).unwrap();
|
small keys had their data missing because i deleted it :-/
it's one of those bugs where you're like oh...right. it's doing
exactly what i told it to. I just told it to do the wrong thing.
Right. If you're updating data at the end of a file, you kind of
don't want to delete the file entirely then do the update.
Fix the code so that in the case of a file extension of a small
key, you're re-inserting the key in its entirety (not just the
updated portion) on the extension case.
Also handled an issue with large files where key extension
should not lead to overwrite of the neighboring data, and put
a cap of the large file limit of 32GiB. See comments for thoughts
on the trade-off of the large file limit versus the allocation
limit of the number of files and the physically realistic
outcomes for the PDDB. Basically as written the PDDB can handle
32GiB files (big enough to hold a blu-ray movie, but not a 4k/8k
movie, uncompressed movies, and/or large virtual machine images),
and can handle creation of files at an average rate of one per
second for 10 years without stop before running out of virtual
memory space.
This isn't "Web scale" as large servers will
definitely require files bigger than 32GiB these days, and
can easily create files at a rate of thousands per second. But,
the PDDB isn't performant enough nor targeted toward large
scale server applications. It should, however, be adequate for
pretty much any user data on a mobile phone if it were recompiled
for a 64-bit target. And, if you needed to scale up to bigger
files and/or more write cycles, the problem can be solved
with some simple memory allocation tricks on the large pool,
but because Precursor only has 16MiB of its own RAM to play
with, we don't implement that as the RAM overhead is both
detrimental and unnecessary at our scale of operation.
2021-11-25 09:56:39 +00:00
|
|
|
} else {
|
|
|
|
|
basis_cache.key_update(hw, &dictname, &keyname, &keydata, None,
|
|
|
|
|
Some(keydata.len() + extra_reserved),
|
2021-11-28 15:54:58 +00:00
|
|
|
basis_name, false).unwrap();
|
small keys had their data missing because i deleted it :-/
it's one of those bugs where you're like oh...right. it's doing
exactly what i told it to. I just told it to do the wrong thing.
Right. If you're updating data at the end of a file, you kind of
don't want to delete the file entirely then do the update.
Fix the code so that in the case of a file extension of a small
key, you're re-inserting the key in its entirety (not just the
updated portion) on the extension case.
Also handled an issue with large files where key extension
should not lead to overwrite of the neighboring data, and put
a cap of the large file limit of 32GiB. See comments for thoughts
on the trade-off of the large file limit versus the allocation
limit of the number of files and the physically realistic
outcomes for the PDDB. Basically as written the PDDB can handle
32GiB files (big enough to hold a blu-ray movie, but not a 4k/8k
movie, uncompressed movies, and/or large virtual machine images),
and can handle creation of files at an average rate of one per
second for 10 years without stop before running out of virtual
memory space.
This isn't "Web scale" as large servers will
definitely require files bigger than 32GiB these days, and
can easily create files at a rate of thousands per second. But,
the PDDB isn't performant enough nor targeted toward large
scale server applications. It should, however, be adequate for
pretty much any user data on a mobile phone if it were recompiled
for a 64-bit target. And, if you needed to scale up to bigger
files and/or more write cycles, the problem can be solved
with some simple memory allocation tricks on the large pool,
but because Precursor only has 16MiB of its own RAM to play
with, we don't implement that as the RAM overhead is both
detrimental and unnecessary at our scale of operation.
2021-11-25 09:56:39 +00:00
|
|
|
}
|
2021-11-22 08:04:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
2021-11-22 08:28:26 +00:00
|
|
|
}
|
|
|
|
|
|
2021-11-22 20:36:58 +00:00
|
|
|
/// patch data check
|
|
|
|
|
pub(crate) fn patch_test(hw: &mut PddbOs, basis_cache: &mut BasisCache,
|
2021-11-23 19:57:50 +00:00
|
|
|
maybe_patch_offset: Option<usize>, maybe_patch_data: Option<String>, extend: bool) {
|
2021-11-22 08:28:26 +00:00
|
|
|
|
2021-11-22 20:36:58 +00:00
|
|
|
let patch_offset = maybe_patch_offset.unwrap_or(5);
|
|
|
|
|
let patch_data = maybe_patch_data.unwrap_or("patched!".to_string());
|
2021-11-22 08:28:26 +00:00
|
|
|
|
2021-12-25 17:42:36 +00:00
|
|
|
#[cfg(feature = "deterministic")]
|
2021-12-25 08:44:24 +00:00
|
|
|
let mut dict_list = BTreeSet::<String>::new();
|
2021-12-25 17:42:36 +00:00
|
|
|
#[cfg(feature = "deterministic")]
|
|
|
|
|
{
|
|
|
|
|
let dict_list_unord = basis_cache.dict_list(hw, None);
|
|
|
|
|
for s in dict_list_unord {
|
|
|
|
|
dict_list.insert(s);
|
|
|
|
|
}
|
2021-12-25 08:44:24 +00:00
|
|
|
}
|
2021-12-25 17:42:36 +00:00
|
|
|
#[cfg(not(feature = "deterministic"))]
|
|
|
|
|
let dict_list = basis_cache.dict_list(hw, None);
|
2021-11-22 20:36:58 +00:00
|
|
|
for dict in dict_list.iter() {
|
2021-12-25 08:44:24 +00:00
|
|
|
if let Ok(key_list_unord) = basis_cache.key_list(hw, dict, None) {
|
2021-12-25 17:42:36 +00:00
|
|
|
#[cfg(feature = "deterministic")]
|
2021-12-25 08:44:24 +00:00
|
|
|
let mut key_list = BTreeSet::<String>::new();
|
2021-12-25 17:42:36 +00:00
|
|
|
#[cfg(feature = "deterministic")]
|
2021-12-25 08:44:24 +00:00
|
|
|
for s in key_list_unord {
|
|
|
|
|
key_list.insert(s);
|
|
|
|
|
}
|
2021-12-25 17:42:36 +00:00
|
|
|
#[cfg(not(feature = "deterministic"))]
|
|
|
|
|
let key_list = key_list_unord;
|
2021-11-22 20:36:58 +00:00
|
|
|
for key in key_list.iter() {
|
|
|
|
|
// this actually does something a bit more complicated on a multi-basis system than you'd think:
|
|
|
|
|
// it will get the union of all key names, and then patch the *latest open basis* only with new data.
|
|
|
|
|
// note: if the key didn't already exist in the latest open basis, it's added, with just that patch data in it.
|
|
|
|
|
// to override this behavior, you'd want to specify a _specific_ basis, but for testing purposes, we only have one
|
|
|
|
|
// so we're doing this way that would lead to surprising results if it were copied as template code elsewhere.
|
2021-11-24 19:14:29 +00:00
|
|
|
match basis_cache.key_update(hw, dict, key, patch_data.as_bytes(), Some(patch_offset), None, None, false) {
|
|
|
|
|
Ok(_) => (),
|
|
|
|
|
Err(e) => {
|
|
|
|
|
log::error!("couldn't update key {}:{} with {} bytes data offset {}: {:?}", dict, key, patch_data.as_bytes().len(), patch_offset, e);
|
|
|
|
|
panic!("error updating patch key");
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-11-23 15:33:06 +00:00
|
|
|
|
|
|
|
|
// now fix the CI checksum. structured as two separate patches. not because it's efficient,
|
|
|
|
|
// but because it exercises the code harder.
|
2021-11-24 06:50:44 +00:00
|
|
|
let mut patchbuf = [0u8; UPPER_BOUND];
|
2021-11-23 15:33:06 +00:00
|
|
|
let readlen = basis_cache.key_read(hw, dict, key, &mut patchbuf, Some(0), None).unwrap();
|
2021-11-23 19:57:50 +00:00
|
|
|
if !extend {
|
|
|
|
|
// now re-compute the checksum
|
|
|
|
|
let mut checkdata = Vec::<u8>::new();
|
|
|
|
|
for &b in &patchbuf[..readlen-4] {
|
|
|
|
|
checkdata.push(b);
|
|
|
|
|
}
|
|
|
|
|
log::trace!("checkdata len: {}", checkdata.len());
|
|
|
|
|
while checkdata.len() % 4 != 0 {
|
|
|
|
|
checkdata.push(0);
|
|
|
|
|
}
|
|
|
|
|
let checksum = murmur3_32(&checkdata, 0);
|
|
|
|
|
basis_cache.key_update(hw, dict, key, &checksum.to_le_bytes(), Some(readlen-4), None, None, false).unwrap();
|
|
|
|
|
} else {
|
|
|
|
|
// this gloms a new checksum onto the existing record, adding 4 new bytes.
|
|
|
|
|
let mut checkdata = Vec::<u8>::new();
|
2021-11-24 19:14:29 +00:00
|
|
|
for &b in &patchbuf[..readlen] {
|
2021-11-23 19:57:50 +00:00
|
|
|
checkdata.push(b);
|
|
|
|
|
}
|
2021-11-25 19:08:08 +00:00
|
|
|
log::trace!("checkdata len: {}", checkdata.len());
|
2021-11-23 19:57:50 +00:00
|
|
|
while checkdata.len() % 4 != 0 {
|
|
|
|
|
checkdata.push(0);
|
|
|
|
|
}
|
|
|
|
|
let checksum = murmur3_32(&checkdata, 0);
|
|
|
|
|
basis_cache.key_update(hw, dict, key, &checksum.to_le_bytes(), Some(readlen), None, None, false).unwrap();
|
2021-11-23 15:33:06 +00:00
|
|
|
}
|
2021-11-22 20:36:58 +00:00
|
|
|
}
|
2021-11-22 08:28:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
2021-11-23 19:57:50 +00:00
|
|
|
}
|
2021-11-25 19:08:08 +00:00
|
|
|
|
|
|
|
|
pub(crate) fn delete_pattern(hw: &mut PddbOs, basis_cache: &mut BasisCache,
|
|
|
|
|
maybe_num_dicts: Option<usize>, maybe_num_keys: Option<usize>, maybe_key_sizes: Option<(usize, usize)>,
|
|
|
|
|
maybe_extra_reserved: Option<usize>,
|
|
|
|
|
) {
|
|
|
|
|
let evict_count = maybe_num_dicts.unwrap_or(2);
|
|
|
|
|
let num_keys = maybe_num_keys.unwrap_or(36);
|
|
|
|
|
let (key_lower_bound, key_upper_bound) = maybe_key_sizes.unwrap_or((LOWER_BOUND, UPPER_BOUND - 4));
|
|
|
|
|
let extra_reserved = maybe_extra_reserved.unwrap_or(0);
|
|
|
|
|
|
|
|
|
|
let mut evicted_dicts = Vec::<String>::new();
|
2021-12-25 17:42:36 +00:00
|
|
|
#[cfg(feature = "deterministic")]
|
2021-12-25 08:44:24 +00:00
|
|
|
let mut dict_list = BTreeSet::<String>::new();
|
2021-12-25 17:42:36 +00:00
|
|
|
#[cfg(feature = "deterministic")]
|
|
|
|
|
{
|
|
|
|
|
let dict_list_unord = basis_cache.dict_list(hw, None);
|
|
|
|
|
for s in dict_list_unord {
|
|
|
|
|
dict_list.insert(s);
|
|
|
|
|
}
|
2021-12-25 08:44:24 +00:00
|
|
|
}
|
2021-12-25 17:42:36 +00:00
|
|
|
#[cfg(not(feature = "deterministic"))]
|
|
|
|
|
let dict_list = basis_cache.dict_list(hw, None);
|
2021-11-25 19:08:08 +00:00
|
|
|
let mut evict_iter = 0;
|
|
|
|
|
for (evicted, evict_dict) in dict_list.iter().enumerate() {
|
|
|
|
|
if evicted < evict_count {
|
2021-12-25 08:44:24 +00:00
|
|
|
let key_list_unord = basis_cache.key_list(hw, evict_dict, None).unwrap();
|
|
|
|
|
let mut key_list = BTreeSet::<String>::new();
|
|
|
|
|
for s in key_list_unord {
|
|
|
|
|
key_list.insert(s);
|
|
|
|
|
}
|
|
|
|
|
for (index, key) in key_list.iter().enumerate() {
|
2021-11-25 19:08:08 +00:00
|
|
|
if index % 2 == (evict_iter % 2) { // exercise odd/even patterns
|
|
|
|
|
log::info!("deleting {}:{}", evict_dict, key);
|
|
|
|
|
basis_cache.key_remove(hw, evict_dict, key,None, false).unwrap();
|
|
|
|
|
let da = basis_cache.dict_attributes(hw, evict_dict, None).unwrap();
|
|
|
|
|
log::info!("{:?}", da);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
evicted_dicts.push(evict_dict.to_string());
|
|
|
|
|
evict_iter += 1;
|
|
|
|
|
}
|
2021-12-25 17:42:36 +00:00
|
|
|
#[cfg(feature = "deterministic")]
|
2021-12-25 08:44:24 +00:00
|
|
|
let mut dict_list = BTreeSet::<String>::new();
|
2021-12-25 17:42:36 +00:00
|
|
|
#[cfg(feature = "deterministic")]
|
|
|
|
|
{
|
|
|
|
|
let dict_list_unord = basis_cache.dict_list(hw, None);
|
|
|
|
|
for s in dict_list_unord {
|
|
|
|
|
dict_list.insert(s);
|
|
|
|
|
}
|
2021-12-25 08:44:24 +00:00
|
|
|
}
|
2021-12-25 17:42:36 +00:00
|
|
|
#[cfg(not(feature = "deterministic"))]
|
|
|
|
|
let dict_list = basis_cache.dict_list(hw, None);
|
2021-12-25 08:44:24 +00:00
|
|
|
for dict in dict_list.iter() {
|
2021-11-25 19:08:08 +00:00
|
|
|
let da = basis_cache.dict_attributes(hw, dict, None).unwrap();
|
2021-12-21 23:09:30 +00:00
|
|
|
log::debug!("{:?}", da);
|
2021-11-25 19:08:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for keynum in 1..=num_keys {
|
|
|
|
|
for dictname in evicted_dicts.iter() {
|
|
|
|
|
let (keyname, keydata) = gen_key(dictname, keynum, key_lower_bound, key_upper_bound);
|
|
|
|
|
// now we're ready to write it out
|
|
|
|
|
if maybe_extra_reserved.is_none() {
|
|
|
|
|
// we do this slightly funky way instead of just passing Some(0) because we want to test the "None" path explicitly
|
|
|
|
|
basis_cache.key_update(hw, dictname, &keyname, &keydata, None,
|
|
|
|
|
None,
|
|
|
|
|
None, false).unwrap();
|
|
|
|
|
} else {
|
|
|
|
|
basis_cache.key_update(hw, dictname, &keyname, &keydata, None,
|
|
|
|
|
Some(keydata.len() + extra_reserved),
|
|
|
|
|
None, false).unwrap();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-25 17:42:36 +00:00
|
|
|
#[cfg(feature = "deterministic")]
|
2021-12-25 08:44:24 +00:00
|
|
|
let mut dict_list = BTreeSet::<String>::new();
|
2021-12-25 17:42:36 +00:00
|
|
|
#[cfg(feature = "deterministic")]
|
|
|
|
|
{
|
|
|
|
|
let dict_list_unord = basis_cache.dict_list(hw, None);
|
|
|
|
|
for s in dict_list_unord {
|
|
|
|
|
dict_list.insert(s);
|
|
|
|
|
}
|
2021-12-25 08:44:24 +00:00
|
|
|
}
|
2021-12-25 17:42:36 +00:00
|
|
|
#[cfg(not(feature = "deterministic"))]
|
|
|
|
|
let dict_list = basis_cache.dict_list(hw, None);
|
2021-12-25 08:44:24 +00:00
|
|
|
for dict in dict_list.iter() {
|
2021-11-25 19:36:36 +00:00
|
|
|
let da = basis_cache.dict_attributes(hw, dict, None).unwrap();
|
2021-12-21 23:09:30 +00:00
|
|
|
log::debug!("{:?}", da);
|
2021-11-25 19:36:36 +00:00
|
|
|
}
|
2021-11-25 19:08:08 +00:00
|
|
|
|
|
|
|
|
log::info!("doing all-basis sync");
|
|
|
|
|
basis_cache.sync(hw, None).unwrap();
|
|
|
|
|
log::info!("all-basis sync done");
|
|
|
|
|
|
2021-11-25 19:36:36 +00:00
|
|
|
list_all(hw, basis_cache);
|
2021-12-25 17:42:36 +00:00
|
|
|
#[cfg(feature = "deterministic")]
|
2021-12-25 08:44:24 +00:00
|
|
|
let mut dict_list = BTreeSet::<String>::new();
|
2021-12-25 17:42:36 +00:00
|
|
|
#[cfg(feature = "deterministic")]
|
|
|
|
|
{
|
|
|
|
|
let dict_list_unord = basis_cache.dict_list(hw, None);
|
|
|
|
|
for s in dict_list_unord {
|
|
|
|
|
dict_list.insert(s);
|
|
|
|
|
}
|
2021-12-25 08:44:24 +00:00
|
|
|
}
|
2021-12-25 17:42:36 +00:00
|
|
|
#[cfg(not(feature = "deterministic"))]
|
|
|
|
|
let dict_list = basis_cache.dict_list(hw, None);
|
2021-12-25 08:44:24 +00:00
|
|
|
for dict in dict_list.iter() {
|
2021-11-25 19:36:36 +00:00
|
|
|
let da = basis_cache.dict_attributes(hw, dict, None).unwrap();
|
|
|
|
|
log::info!("{:?}", da);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) fn list_all(hw: &mut PddbOs, basis_cache: &mut BasisCache) {
|
2021-12-25 17:42:36 +00:00
|
|
|
#[cfg(feature = "deterministic")]
|
2021-12-25 08:44:24 +00:00
|
|
|
let mut dict_list = BTreeSet::<String>::new();
|
2021-12-25 17:42:36 +00:00
|
|
|
#[cfg(feature = "deterministic")]
|
|
|
|
|
{
|
|
|
|
|
let dict_list_unord = basis_cache.dict_list(hw, None);
|
|
|
|
|
for s in dict_list_unord {
|
|
|
|
|
dict_list.insert(s);
|
|
|
|
|
}
|
2021-12-25 08:44:24 +00:00
|
|
|
}
|
2021-12-25 17:42:36 +00:00
|
|
|
#[cfg(not(feature = "deterministic"))]
|
|
|
|
|
let dict_list = basis_cache.dict_list(hw, None);
|
2021-12-25 08:44:24 +00:00
|
|
|
|
2021-11-25 19:08:08 +00:00
|
|
|
// now list all the attributes of the basis
|
2021-12-25 08:44:24 +00:00
|
|
|
for dict in dict_list.iter() {
|
2021-11-29 16:38:29 +00:00
|
|
|
let da = match basis_cache.dict_attributes(hw, &dict, None) {
|
|
|
|
|
Ok(da) => da,
|
|
|
|
|
Err(e) => {
|
|
|
|
|
log::warn!("dictionary {} not in sub-basis (this is normal for multi-basis systems, {:?}", dict, e);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
};
|
2021-12-21 23:09:30 +00:00
|
|
|
log::debug!("{:?}", da);
|
2021-11-25 19:08:08 +00:00
|
|
|
let mut sanity_count = 0;
|
2021-11-29 16:38:29 +00:00
|
|
|
for key in basis_cache.key_list(hw, dict, None).unwrap().iter() {
|
|
|
|
|
let attrs = match basis_cache.key_attributes(hw, dict, key, None) {
|
|
|
|
|
Ok(a) => a,
|
|
|
|
|
Err(e) => {log::debug!("key not in basis, searching another basis, {:?}", e); continue},
|
|
|
|
|
};
|
2021-12-21 23:09:30 +00:00
|
|
|
log::debug!("{}:{}=>{:?}", dict, key, attrs);
|
2021-11-25 19:08:08 +00:00
|
|
|
sanity_count += 1;
|
|
|
|
|
}
|
|
|
|
|
log::info!("sanity check count: {}", sanity_count);
|
|
|
|
|
}
|
|
|
|
|
}
|