Skip to content

Commit c76b74c

Browse files
skyzhproblame
andauthored
semantic layer map operations (#4618)
## Problem ref #4373 ## Summary of changes A step towards immutable layer map. I decided to finish the refactor with this new approach and apply #4455 on this patch later. In this PR, we moved all modifications of the layer map to one place with semantic operations like `initialize_local_layers`, `finish_compact_l0`, `finish_gc_timeline`, etc, which is now part of `LayerManager`. This makes it easier to build new features upon this PR: * For immutable storage state refactor, we can simply replace the layer map with `ArcSwap<LayerMap>` and remove the `layers` lock. Moving towards it requires us to put all layer map changes in a single place as in #4455. * For manifest, we can write to manifest in each of the semantic functions. --------- Signed-off-by: Alex Chi Z <[email protected]> Co-authored-by: Christian Schwarz <[email protected]>
1 parent ed93888 commit c76b74c

File tree

7 files changed

+468
-309
lines changed

7 files changed

+468
-309
lines changed

pageserver/src/tenant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ impl Tenant {
429429
.layers
430430
.read()
431431
.await
432-
.0
432+
.layer_map()
433433
.iter_historic_layers()
434434
.next()
435435
.is_some(),

pageserver/src/tenant/layer_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ mod tests {
659659

660660
use crate::tenant::{
661661
storage_layer::{AsLayerDesc, PersistentLayerDesc},
662-
timeline::LayerFileManager,
662+
timeline::layer_manager::LayerFileManager,
663663
};
664664

665665
use super::*;

pageserver/src/tenant/storage_layer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub use inmemory_layer::InMemoryLayer;
4141
pub use layer_desc::{PersistentLayerDesc, PersistentLayerKey};
4242
pub use remote_layer::RemoteLayer;
4343

44-
use super::layer_map::BatchedUpdates;
44+
use super::timeline::layer_manager::LayerManager;
4545

4646
pub fn range_overlaps<T>(a: &Range<T>, b: &Range<T>) -> bool
4747
where
@@ -170,7 +170,7 @@ impl LayerAccessStats {
170170
///
171171
/// See [`record_residence_event`] for why you need to do this while holding the layer map lock.
172172
pub(crate) fn for_loading_layer(
173-
layer_map_lock_held_witness: &BatchedUpdates<'_>,
173+
layer_map_lock_held_witness: &LayerManager,
174174
status: LayerResidenceStatus,
175175
) -> Self {
176176
let new = LayerAccessStats(Mutex::new(LayerAccessStatsLocked::default()));
@@ -189,7 +189,7 @@ impl LayerAccessStats {
189189
/// See [`record_residence_event`] for why you need to do this while holding the layer map lock.
190190
pub(crate) fn clone_for_residence_change(
191191
&self,
192-
layer_map_lock_held_witness: &BatchedUpdates<'_>,
192+
layer_map_lock_held_witness: &LayerManager,
193193
new_status: LayerResidenceStatus,
194194
) -> LayerAccessStats {
195195
let clone = {
@@ -221,7 +221,7 @@ impl LayerAccessStats {
221221
///
222222
pub(crate) fn record_residence_event(
223223
&self,
224-
_layer_map_lock_held_witness: &BatchedUpdates<'_>,
224+
_layer_map_lock_held_witness: &LayerManager,
225225
status: LayerResidenceStatus,
226226
reason: LayerResidenceEventReason,
227227
) {

pageserver/src/tenant/storage_layer/remote_layer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
use crate::config::PageServerConf;
55
use crate::context::RequestContext;
66
use crate::repository::Key;
7-
use crate::tenant::layer_map::BatchedUpdates;
87
use crate::tenant::remote_timeline_client::index::LayerFileMetadata;
98
use crate::tenant::storage_layer::{Layer, ValueReconstructResult, ValueReconstructState};
9+
use crate::tenant::timeline::layer_manager::LayerManager;
1010
use anyhow::{bail, Result};
1111
use pageserver_api::models::HistoricLayerInfo;
1212
use std::ops::Range;
@@ -224,7 +224,7 @@ impl RemoteLayer {
224224
/// Create a Layer struct representing this layer, after it has been downloaded.
225225
pub fn create_downloaded_layer(
226226
&self,
227-
layer_map_lock_held_witness: &BatchedUpdates<'_>,
227+
layer_map_lock_held_witness: &LayerManager,
228228
conf: &'static PageServerConf,
229229
file_size: u64,
230230
) -> Arc<dyn PersistentLayer> {

0 commit comments

Comments
 (0)