mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-15 17:32:56 +00:00
provide and use LayerE::for_evicted
This commit is contained in:
@@ -521,11 +521,49 @@ impl LayerE {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn for_evicted(
|
||||
conf: &'static PageServerConf,
|
||||
timeline: &Arc<Timeline>,
|
||||
file_name: LayerFileName,
|
||||
metadata: LayerFileMetadata,
|
||||
) -> Arc<LayerE> {
|
||||
let path = conf
|
||||
.timeline_path(&timeline.tenant_id, &timeline.timeline_id)
|
||||
.join(file_name.file_name());
|
||||
|
||||
let desc = PersistentLayerDesc::from_filename(
|
||||
timeline.tenant_id,
|
||||
timeline.timeline_id,
|
||||
file_name,
|
||||
metadata.file_size(),
|
||||
);
|
||||
|
||||
let access_stats = LayerAccessStats::for_loading_layer(LayerResidenceStatus::Evicted);
|
||||
|
||||
let outer = Arc::new(LayerE {
|
||||
conf,
|
||||
path,
|
||||
desc,
|
||||
timeline: Arc::downgrade(timeline),
|
||||
access_stats,
|
||||
inner: heavier_once_cell::OnceCell::default(),
|
||||
wanted_garbage_collected: AtomicBool::default(),
|
||||
wanted_evicted: AtomicBool::default(),
|
||||
version: AtomicUsize::default(),
|
||||
have_remote_client: timeline.remote_client.is_some(),
|
||||
status: tokio::sync::broadcast::channel(1).0,
|
||||
});
|
||||
|
||||
debug_assert!(outer.needs_download_blocking().unwrap().is_some());
|
||||
|
||||
outer
|
||||
}
|
||||
|
||||
pub(crate) fn for_resident(
|
||||
conf: &'static PageServerConf,
|
||||
timeline: &Arc<Timeline>,
|
||||
file_name: LayerFileName,
|
||||
metadata: &LayerFileMetadata,
|
||||
metadata: LayerFileMetadata,
|
||||
) -> ResidentLayer {
|
||||
let path = conf
|
||||
.timeline_path(&timeline.tenant_id, &timeline.timeline_id)
|
||||
@@ -538,6 +576,8 @@ impl LayerE {
|
||||
metadata.file_size(),
|
||||
);
|
||||
|
||||
let access_stats = LayerAccessStats::for_loading_layer(LayerResidenceStatus::Resident);
|
||||
|
||||
let mut resident = None;
|
||||
|
||||
let outer = Arc::new_cyclic(|owner| {
|
||||
@@ -552,7 +592,7 @@ impl LayerE {
|
||||
desc,
|
||||
timeline: Arc::downgrade(timeline),
|
||||
have_remote_client: timeline.remote_client.is_some(),
|
||||
access_stats: LayerAccessStats::empty_will_record_residence_event_later(),
|
||||
access_stats,
|
||||
wanted_garbage_collected: AtomicBool::new(false),
|
||||
wanted_evicted: AtomicBool::new(false),
|
||||
inner: heavier_once_cell::OnceCell::new(ResidentOrWantedEvicted::Resident(inner)),
|
||||
|
||||
@@ -1509,30 +1509,20 @@ impl Timeline {
|
||||
Image(i) => assert!(i.lsn <= disk_consistent_lsn),
|
||||
}
|
||||
|
||||
let status = match &decision {
|
||||
UseLocal(_) | NeedsUpload(_) => LayerResidenceStatus::Resident,
|
||||
Evicted(_) | UseRemote { .. } => LayerResidenceStatus::Evicted,
|
||||
};
|
||||
|
||||
let stats = LayerAccessStats::for_loading_layer(status);
|
||||
|
||||
let layer = match decision {
|
||||
NeedsUpload(m) => {
|
||||
total_physical_size += m.file_size();
|
||||
let resident = LayerE::for_resident(conf, &this, name, &m);
|
||||
let resident = LayerE::for_resident(conf, &this, name, m.clone());
|
||||
let layer = resident.as_ref().clone();
|
||||
needs_upload.push((resident, m));
|
||||
layer
|
||||
}
|
||||
UseLocal(m) => {
|
||||
total_physical_size += m.file_size();
|
||||
let resident = LayerE::for_resident(conf, &this, name, &m);
|
||||
resident.drop_eviction_guard()
|
||||
LayerE::for_resident(conf, &this, name, m).drop_eviction_guard()
|
||||
}
|
||||
Evicted(remote) | UseRemote { remote, .. } => {
|
||||
// FIXME: there ought to be a known evicted factory instead of generic
|
||||
// new
|
||||
Arc::new(LayerE::new(conf, &this, &name, remote.file_size(), stats))
|
||||
LayerE::for_evicted(conf, &this, name, remote)
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user