Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch to immutable layer map implementation #4766

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 27 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ license = "Apache-2.0"
## All dependency versions, used in the project
[workspace.dependencies]
anyhow = { version = "1.0", features = ["backtrace"] }
arc-swap = "1.6"
async-compression = { version = "0.4.0", features = ["tokio", "gzip"] }
flate2 = "1.0.26"
async-stream = "0.3"
Expand All @@ -54,6 +55,7 @@ comfy-table = "6.1"
const_format = "0.2"
crc32c = "0.6"
crossbeam-utils = "0.8.5"
dashmap = "5.5"
either = "1.8"
enum-map = "2.4.2"
enumset = "1.0.12"
Expand Down
2 changes: 2 additions & 0 deletions pageserver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ testing = ["fail/failpoints"]

[dependencies]
anyhow.workspace = true
arc-swap.workspace = true
async-compression.workspace = true
async-stream.workspace = true
async-trait.workspace = true
Expand All @@ -24,6 +25,7 @@ const_format.workspace = true
consumption_metrics.workspace = true
crc32c.workspace = true
crossbeam-utils.workspace = true
dashmap.workspace = true
either.workspace = true
flate2.workspace = true
fail.workspace = true
Expand Down
6 changes: 3 additions & 3 deletions pageserver/src/tenant/layer_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ use super::storage_layer::PersistentLayerDesc;
///
/// LayerMap tracks what layers exist on a timeline.
///
#[derive(Default)]
#[derive(Default, Clone)]
pub struct LayerMap {
//
// 'open_layer' holds the current InMemoryLayer that is accepting new
Expand Down Expand Up @@ -727,7 +727,7 @@ mod tests {
// and can remove it in the future.
let _map = LayerMap::default();

let mut mapping = TestLayerFileManager::new();
let mapping = TestLayerFileManager::new();

mapping
.replace_and_verify(not_found, new_version)
Expand All @@ -742,7 +742,7 @@ mod tests {
let downloaded = Arc::new(LayerObject::new(skeleton));

let mut map = LayerMap::default();
let mut mapping = LayerFileManager::new();
let mapping = LayerFileManager::new();

// two disjoint Arcs in different lifecycle phases. even if it seems they must be the
// same layer, we use LayerMap::compare_arced_layers as the identity of layers.
Expand Down
2 changes: 2 additions & 0 deletions pageserver/src/tenant/layer_map/historic_layer_coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ impl From<&PersistentLayerDesc> for LayerKey {
/// Allows answering layer map queries very efficiently,
/// but doesn't allow retroactive insertion, which is
/// sometimes necessary. See BufferedHistoricLayerCoverage.
#[derive(Clone)]
pub struct HistoricLayerCoverage<Value> {
/// The latest state
head: LayerCoverageTuple<Value>,
Expand Down Expand Up @@ -412,6 +413,7 @@ fn test_persistent_overlapping() {
///
/// See this for more on persistent and retroactive techniques:
/// <https://www.youtube.com/watch?v=WqCWghETNDc&t=581s>
#[derive(Clone)]
pub struct BufferedHistoricLayerCoverage<Value> {
/// A persistent layer map that we rebuild when we need to retroactively update
historic_coverage: HistoricLayerCoverage<Value>,
Expand Down
2 changes: 2 additions & 0 deletions pageserver/src/tenant/layer_map/layer_coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use rpds::RedBlackTreeMapSync;
///
/// NOTE The struct is parameterized over Value for easier
/// testing, but in practice it's some sort of layer.
#[derive(Clone)]
pub struct LayerCoverage<Value> {
/// For every change in coverage (as we sweep the key space)
/// we store (lsn.end, value).
Expand Down Expand Up @@ -138,6 +139,7 @@ impl<Value: Clone> LayerCoverage<Value> {
}

/// Image and delta coverage at a specific LSN.
#[derive(Clone)]
pub struct LayerCoverageTuple<Value> {
pub image_coverage: LayerCoverage<Value>,
pub delta_coverage: LayerCoverage<Value>,
Expand Down
8 changes: 4 additions & 4 deletions pageserver/src/tenant/storage_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub use inmemory_layer::InMemoryLayer;
pub use layer_desc::{PersistentLayerDesc, PersistentLayerKey};
pub use remote_layer::RemoteLayer;

use super::timeline::layer_manager::LayerManager;
use super::timeline::layer_manager::LayerManagerWriteGuard;

pub fn range_overlaps<T>(a: &Range<T>, b: &Range<T>) -> bool
where
Expand Down Expand Up @@ -176,7 +176,7 @@ impl LayerAccessStats {
/// [`LayerLoad`]: LayerResidenceEventReason::LayerLoad
/// [`record_residence_event`]: Self::record_residence_event
pub(crate) fn for_loading_layer(
layer_map_lock_held_witness: &LayerManager,
layer_map_lock_held_witness: &LayerManagerWriteGuard,
status: LayerResidenceStatus,
) -> Self {
let new = LayerAccessStats(Mutex::new(LayerAccessStatsLocked::default()));
Expand All @@ -197,7 +197,7 @@ impl LayerAccessStats {
/// [`record_residence_event`]: Self::record_residence_event
pub(crate) fn clone_for_residence_change(
&self,
layer_map_lock_held_witness: &LayerManager,
layer_map_lock_held_witness: &LayerManagerWriteGuard,
new_status: LayerResidenceStatus,
) -> LayerAccessStats {
let clone = {
Expand Down Expand Up @@ -229,7 +229,7 @@ impl LayerAccessStats {
///
pub(crate) fn record_residence_event(
&self,
_layer_map_lock_held_witness: &LayerManager,
_layer_map_lock_held_witness: &LayerManagerWriteGuard,
status: LayerResidenceStatus,
reason: LayerResidenceEventReason,
) {
Expand Down
4 changes: 2 additions & 2 deletions pageserver/src/tenant/storage_layer/remote_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::context::RequestContext;
use crate::repository::Key;
use crate::tenant::remote_timeline_client::index::LayerFileMetadata;
use crate::tenant::storage_layer::{Layer, ValueReconstructResult, ValueReconstructState};
use crate::tenant::timeline::layer_manager::LayerManager;
use crate::tenant::timeline::layer_manager::LayerManagerWriteGuard;
use anyhow::{bail, Result};
use pageserver_api::models::HistoricLayerInfo;
use std::ops::Range;
Expand Down Expand Up @@ -226,7 +226,7 @@ impl RemoteLayer {
/// Create a Layer struct representing this layer, after it has been downloaded.
pub fn create_downloaded_layer(
&self,
layer_map_lock_held_witness: &LayerManager,
layer_map_lock_held_witness: &LayerManagerWriteGuard,
conf: &'static PageServerConf,
file_size: u64,
) -> Arc<dyn PersistentLayer> {
Expand Down
Loading