Skip to content

Commit

Permalink
infer prewarm_on_write from PageServerConf; #8190 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
problame committed Jul 1, 2024
1 parent ad004b7 commit 511d664
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 27 deletions.
9 changes: 6 additions & 3 deletions pageserver/src/l0_flush.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ impl L0FlushGlobalState {
pub(crate) fn inner(&self) -> &Arc<Inner> {
&self.0
}
}

impl L0FlushConfig {
pub(crate) fn prewarm_on_write(&self) -> ephemeral_file::PrewarmPageCacheOnWrite {
match &*self.0 {
Inner::PageCached => ephemeral_file::PrewarmPageCacheOnWrite::Yes,
Inner::Direct { .. } => ephemeral_file::PrewarmPageCacheOnWrite::No,
use L0FlushConfig::*;
match self {
PageCached => ephemeral_file::PrewarmPageCacheOnWrite::Yes,
Direct { .. } => ephemeral_file::PrewarmPageCacheOnWrite::No,
}
}
}
9 changes: 2 additions & 7 deletions pageserver/src/tenant/ephemeral_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ impl EphemeralFile {
conf: &PageServerConf,
tenant_shard_id: TenantShardId,
timeline_id: TimelineId,
prewarm_on_write: page_caching::PrewarmOnWrite,
ctx: &RequestContext,
) -> Result<EphemeralFile, io::Error> {
static NEXT_FILENAME: AtomicU64 = AtomicU64::new(1);
Expand All @@ -55,7 +54,7 @@ impl EphemeralFile {
Ok(EphemeralFile {
_tenant_shard_id: tenant_shard_id,
_timeline_id: timeline_id,
rw: page_caching::RW::new(file, prewarm_on_write),
rw: page_caching::RW::new(file, conf.l0_flush.prewarm_on_write()),
})
}

Expand Down Expand Up @@ -162,11 +161,7 @@ mod tests {
async fn test_ephemeral_blobs() -> Result<(), io::Error> {
let (conf, tenant_id, timeline_id, ctx) = harness("ephemeral_blobs")?;

let prewarm_on_write =
crate::l0_flush::L0FlushGlobalState::new(crate::l0_flush::L0FlushConfig::default())
.prewarm_on_write();
let mut file =
EphemeralFile::create(conf, tenant_id, timeline_id, prewarm_on_write, &ctx).await?;
let mut file = EphemeralFile::create(conf, tenant_id, timeline_id, &ctx).await?;

let pos_foo = file.write_blob(b"foo", &ctx).await?;
assert_eq!(
Expand Down
6 changes: 2 additions & 4 deletions pageserver/src/tenant/storage_layer/inmemory_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::context::{PageContentKind, RequestContext, RequestContextBuilder};
use crate::page_cache::PAGE_SZ;
use crate::repository::{Key, Value};
use crate::tenant::block_io::{BlockCursor, BlockReader, BlockReaderRef};
use crate::tenant::ephemeral_file::{self, EphemeralFile};
use crate::tenant::ephemeral_file::EphemeralFile;
use crate::tenant::storage_layer::ValueReconstructResult;
use crate::tenant::timeline::GetVectoredError;
use crate::tenant::{PageReconstructError, Timeline};
Expand Down Expand Up @@ -475,13 +475,11 @@ impl InMemoryLayer {
timeline_id: TimelineId,
tenant_shard_id: TenantShardId,
start_lsn: Lsn,
prewarm_on_write: ephemeral_file::PrewarmPageCacheOnWrite,
ctx: &RequestContext,
) -> Result<InMemoryLayer> {
trace!("initializing new empty InMemoryLayer for writing on timeline {timeline_id} at {start_lsn}");

let file = EphemeralFile::create(conf, tenant_shard_id, timeline_id, prewarm_on_write, ctx)
.await?;
let file = EphemeralFile::create(conf, tenant_shard_id, timeline_id, ctx).await?;
let key = InMemoryLayerFileId(file.page_cache_file_id());

Ok(InMemoryLayer {
Expand Down
1 change: 0 additions & 1 deletion pageserver/src/tenant/timeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3671,7 +3671,6 @@ impl Timeline {
self.conf,
self.timeline_id,
self.tenant_shard_id,
self.l0_flush_global_state.prewarm_on_write(),
ctx,
)
.await?;
Expand Down
14 changes: 2 additions & 12 deletions pageserver/src/tenant/timeline/layer_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use crate::{
context::RequestContext,
metrics::TimelineMetrics,
tenant::{
ephemeral_file,
layer_map::{BatchedUpdates, LayerMap},
storage_layer::{
AsLayerDesc, InMemoryLayer, Layer, PersistentLayerDesc, PersistentLayerKey,
Expand Down Expand Up @@ -67,15 +66,13 @@ impl LayerManager {

/// Open a new writable layer to append data if there is no open layer, otherwise return the current open layer,
/// called within `get_layer_for_write`.
#[allow(clippy::too_many_arguments)]
pub(crate) async fn get_layer_for_write(
&mut self,
lsn: Lsn,
last_record_lsn: Lsn,
conf: &'static PageServerConf,
timeline_id: TimelineId,
tenant_shard_id: TenantShardId,
prewarm_on_write: ephemeral_file::PrewarmPageCacheOnWrite,
ctx: &RequestContext,
) -> Result<Arc<InMemoryLayer>> {
ensure!(lsn.is_aligned());
Expand Down Expand Up @@ -112,15 +109,8 @@ impl LayerManager {
lsn
);

let new_layer = InMemoryLayer::create(
conf,
timeline_id,
tenant_shard_id,
start_lsn,
prewarm_on_write,
ctx,
)
.await?;
let new_layer =
InMemoryLayer::create(conf, timeline_id, tenant_shard_id, start_lsn, ctx).await?;
let layer = Arc::new(new_layer);

self.layer_map.open_layer = Some(layer.clone());
Expand Down

0 comments on commit 511d664

Please sign in to comment.