disk bucket: new_map takes bytes (#31020)
This commit is contained in:
parent
8051aea88e
commit
9219a16c42
|
@ -93,7 +93,8 @@ impl<O: BucketOccupied> BucketStorage<O> {
|
||||||
"header size must be a multiple of u64"
|
"header size must be a multiple of u64"
|
||||||
);
|
);
|
||||||
let cell_size = elem_size * num_elems + offset as u64;
|
let cell_size = elem_size * num_elems + offset as u64;
|
||||||
let (mmap, path) = Self::new_map(&drives, cell_size as usize, capacity_pow2, &stats);
|
let bytes = (1u64 << capacity_pow2) * cell_size;
|
||||||
|
let (mmap, path) = Self::new_map(&drives, bytes, &stats);
|
||||||
Self {
|
Self {
|
||||||
path,
|
path,
|
||||||
mmap,
|
mmap,
|
||||||
|
@ -234,14 +235,9 @@ impl<O: BucketOccupied> BucketStorage<O> {
|
||||||
unsafe { std::slice::from_raw_parts_mut(ptr, len as usize) }
|
unsafe { std::slice::from_raw_parts_mut(ptr, len as usize) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_map(
|
/// allocate a new memory mapped file of size `bytes` on one of `drives`
|
||||||
drives: &[PathBuf],
|
fn new_map(drives: &[PathBuf], bytes: u64, stats: &BucketStats) -> (MmapMut, PathBuf) {
|
||||||
cell_size: usize,
|
|
||||||
capacity_pow2: u8,
|
|
||||||
stats: &BucketStats,
|
|
||||||
) -> (MmapMut, PathBuf) {
|
|
||||||
let mut measure_new_file = Measure::start("measure_new_file");
|
let mut measure_new_file = Measure::start("measure_new_file");
|
||||||
let capacity = 1u64 << capacity_pow2;
|
|
||||||
let r = thread_rng().gen_range(0, drives.len());
|
let r = thread_rng().gen_range(0, drives.len());
|
||||||
let drive = &drives[r];
|
let drive = &drives[r];
|
||||||
let pos = format!("{}", thread_rng().gen_range(0, u128::MAX),);
|
let pos = format!("{}", thread_rng().gen_range(0, u128::MAX),);
|
||||||
|
@ -265,8 +261,7 @@ impl<O: BucketOccupied> BucketStorage<O> {
|
||||||
// the file so that we won't have to resize it later, which may be
|
// the file so that we won't have to resize it later, which may be
|
||||||
// expensive.
|
// expensive.
|
||||||
//debug!("GROWING file {}", capacity * cell_size as u64);
|
//debug!("GROWING file {}", capacity * cell_size as u64);
|
||||||
data.seek(SeekFrom::Start(capacity * cell_size as u64 - 1))
|
data.seek(SeekFrom::Start(bytes - 1)).unwrap();
|
||||||
.unwrap();
|
|
||||||
data.write_all(&[0]).unwrap();
|
data.write_all(&[0]).unwrap();
|
||||||
data.rewind().unwrap();
|
data.rewind().unwrap();
|
||||||
measure_new_file.stop();
|
measure_new_file.stop();
|
||||||
|
|
Loading…
Reference in New Issue