Add comments and make changes suggested by reviewers

refer #1133
This commit is contained in:
Konstantin Knizhnik
2022-01-16 23:04:39 +03:00
parent 5c33095918
commit 79ade52535
4 changed files with 7 additions and 2 deletions

View File

@@ -1612,6 +1612,7 @@ impl LayeredTimeline {
let global_layer_map = GLOBAL_LAYER_MAP.read().unwrap();
if let Some(oldest_layer) = global_layer_map.get(&layer_id) {
let last_lsn = self.get_last_record_lsn();
// Count number of layers only if we nned this information: when creation of image layer was not prohibited
let n_delta_layers = if reconstruct_pages {
layers.count_delta_layers(oldest_layer.get_seg_tag(), last_lsn)
} else {

View File

@@ -28,6 +28,8 @@ use zenith_utils::vec_map::VecMap;
use super::page_versions::PageVersions;
// The garbage collector needs image layers in order to delete files.
// If this number is too large it can result in too many small files on disk.
const MAX_DELTA_LAYERS: usize = 10;
pub struct InMemoryLayer {
@@ -626,7 +628,7 @@ impl InMemoryLayer {
> inner.page_versions.size() * 2
&& n_delta_layers < MAX_DELTA_LAYERS)
{
// The segment was dropped. Create just a delta layer containing all the
// Create just a delta layer containing all the
// changes up to and including the drop.
delta_end_lsn = Some(end_lsn_exclusive);
image_lsn = None;

View File

@@ -249,7 +249,7 @@ where
loop {
// Return next remaining element from the current point
if let Some((point_key, elem_iter)) = &mut self.elem_iter {
for elem in elem_iter {
while let Some(elem) = elem_iter.next_back() {
if elem.start_key() == *point_key {
return Some(Arc::clone(elem));
}

View File

@@ -328,6 +328,8 @@ impl SegEntry {
.any(|layer| !layer.is_incremental())
}
// Count number of delta layers preceeding specified `lsn`.
// Perform backward iteration from exclusive upper bound until image layer is reached.
pub fn count_delta_layers(&self, lsn: Lsn) -> usize {
let mut count: usize = 0;
let mut iter = self.historic.iter_older(lsn);