Rename things in KeyPartition, per Bojan's suggestions.

This commit is contained in:
Heikki Linnakangas
2022-03-16 19:29:07 +02:00
parent adbbb0a4c8
commit 7560854370
2 changed files with 26 additions and 20 deletions
+15 -10
View File
@@ -8,10 +8,11 @@ pub const TARGET_FILE_SIZE_BYTES: u64 = 128 * 1024 * 1024; // 128 MB
///
/// Represents a set of Keys, in a compact form.
///
#[derive(Clone, Debug)]
pub struct KeySpace {
// Contiguous ranges of keys that belong to the key space. In key order, and
// with no overlap.
ranges: Vec<Range<Key>>,
pub ranges: Vec<Range<Key>>,
}
impl KeySpace {
@@ -23,7 +24,7 @@ impl KeySpace {
// Assume that each value is 8k in size.
let target_nblocks = (target_size / pg_constants::BLCKSZ as u64) as usize;
let mut partitions = Vec::new();
let mut parts = Vec::new();
let mut current_part = Vec::new();
let mut current_part_size: usize = 0;
for range in &self.ranges {
@@ -31,7 +32,9 @@ impl KeySpace {
// partition would cause it to be too large, start a new partition.
let this_size = key_range_size(range) as usize;
if current_part_size + this_size > target_nblocks && !current_part.is_empty() {
partitions.push(current_part);
parts.push(KeySpace {
ranges: current_part,
});
current_part = Vec::new();
current_part_size = 0;
}
@@ -42,7 +45,9 @@ impl KeySpace {
let mut start = range.start;
while remain_size > target_nblocks {
let next = start.add(target_nblocks as u32);
partitions.push(vec![start..next]);
parts.push(KeySpace {
ranges: vec![start..next],
});
start = next;
remain_size -= target_nblocks
}
@@ -52,10 +57,12 @@ impl KeySpace {
// add last partition that wasn't full yet.
if !current_part.is_empty() {
partitions.push(current_part);
parts.push(KeySpace {
ranges: current_part,
});
}
KeyPartitioning { partitions }
KeyPartitioning { parts }
}
}
@@ -68,14 +75,12 @@ impl KeySpace {
///
#[derive(Clone, Debug, Default)]
pub struct KeyPartitioning {
pub partitions: Vec<Vec<Range<Key>>>,
pub parts: Vec<KeySpace>,
}
impl KeyPartitioning {
pub fn new() -> Self {
KeyPartitioning {
partitions: Vec::new(),
}
KeyPartitioning { parts: Vec::new() }
}
}
+11 -10
View File
@@ -34,7 +34,7 @@ use std::time::Instant;
use self::metadata::{metadata_path, TimelineMetadata, METADATA_FILE_NAME};
use crate::config::PageServerConf;
use crate::keyspace::KeyPartitioning;
use crate::keyspace::{KeyPartitioning, KeySpace};
use crate::remote_storage::{schedule_timeline_checkpoint_upload, schedule_timeline_download};
use crate::repository::{
GcResult, Repository, RepositoryTimeline, Timeline, TimelineSyncState, TimelineWriter,
@@ -1569,14 +1569,14 @@ impl LayeredTimeline {
// Make a copy of the partitioning, so that we can release
// the lock. Otherwise we could block the WAL receiver.
let lsn = *lsn;
let partitions = partitioning.partitions.clone();
let parts = partitioning.parts.clone();
drop(partitioning_guard);
// 2. Create new image layers for partitions that have been modified
// "enough".
for partition in partitions.iter() {
if self.time_for_new_image_layer(partition, lsn, 3)? {
self.create_image_layer(partition, lsn)?;
for part in parts.iter() {
if self.time_for_new_image_layer(part, lsn, 3)? {
self.create_image_layer(part, lsn)?;
}
}
timer.stop_and_record();
@@ -1604,13 +1604,13 @@ impl LayeredTimeline {
// Is it time to create a new image layer for the given partition?
fn time_for_new_image_layer(
&self,
partition: &[Range<Key>],
partition: &KeySpace,
lsn: Lsn,
threshold: usize,
) -> Result<bool> {
let layers = self.layers.lock().unwrap();
for part_range in partition {
for part_range in &partition.ranges {
let image_coverage = layers.image_coverage(part_range, lsn)?;
for (img_range, last_img) in image_coverage {
let img_lsn = if let Some(ref last_img) = last_img {
@@ -1634,12 +1634,13 @@ impl LayeredTimeline {
Ok(false)
}
fn create_image_layer(&self, partition: &[Range<Key>], lsn: Lsn) -> Result<()> {
let img_range = partition.first().unwrap().start..partition.last().unwrap().end;
fn create_image_layer(&self, partition: &KeySpace, lsn: Lsn) -> Result<()> {
let img_range =
partition.ranges.first().unwrap().start..partition.ranges.last().unwrap().end;
let mut image_layer_writer =
ImageLayerWriter::new(self.conf, self.timelineid, self.tenantid, &img_range, lsn)?;
for range in partition {
for range in &partition.ranges {
let mut key = range.start;
while key < range.end {
let img = self.get(key, lsn)?;