Mercurial > hg
diff rust/hg-core/src/dirstate_tree/dirstate_map.rs @ 47678:065e61628980
dirstate-v2: Support appending to the same data file
For now we’re still writing the entire data every time, so appending is not
useful yet. Later we’ll have new nodes pointing to some existing data for
nodes and paths that haven’t changed.
The decision whether to append is pseudo-random in order to make tests exercise
both code paths. This will be replaced by a heuristic based on the amount
of unused existing data.
Differential Revision: https://phab.mercurial-scm.org/D11094
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Tue, 13 Jul 2021 17:18:23 +0200 |
parents | 48aec076b8fb |
children | d94118365ec5 |
line wrap: on
line diff
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs Tue Jul 13 09:44:44 2021 +0200 +++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs Tue Jul 13 17:18:23 2021 +0200 @@ -468,6 +468,24 @@ Ok((map, parents)) } + /// Assuming dirstate-v2 format, returns whether the next write should + /// append to the existing data file that contains `self.on_disk` (true), + /// or create a new data file from scratch (false). + pub(super) fn write_should_append(&self) -> bool { + // Soon this will be a heuristic based on the amount of unreachable + // data. For now it’s pseudo-random in order to make tests exercise + // both code paths. + + fn bad_rng() -> u32 { + std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .unwrap() + .subsec_millis() + } + + bad_rng() % 2 == 0 + } + fn get_node<'tree>( &'tree self, path: &HgPath, @@ -1043,8 +1061,15 @@ Ok(packed) } + /// Returns new data together with whether that data should be appended to + /// the existing data file whose content is at `self.on_disk` (true), + /// instead of written to a new data file (false). #[timed] - fn pack_v2(&mut self, now: Timestamp) -> Result<Vec<u8>, DirstateError> { + fn pack_v2( + &mut self, + now: Timestamp, + can_append: bool, + ) -> Result<(Vec<u8>, bool), DirstateError> { // TODO: how do we want to handle this in 2038? let now: i32 = now.0.try_into().expect("time overflow"); let mut paths = Vec::new(); @@ -1063,7 +1088,7 @@ self.clear_known_ambiguous_mtimes(&paths)?; - on_disk::write(self) + on_disk::write(self, can_append) } fn status<'a>(