Skip to content

Commit

Permalink
bottommost-compaction: remove dead code / rectify cfg!()s (#8884)
Browse files Browse the repository at this point in the history
part of #8002
  • Loading branch information
problame authored Sep 2, 2024
1 parent 9746b6e commit 15e90cc
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 103 deletions.
40 changes: 0 additions & 40 deletions pageserver/src/tenant/storage_layer/delta_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,7 @@ pub struct DeltaLayerInner {
file: VirtualFile,
file_id: FileId,

#[allow(dead_code)]
layer_key_range: Range<Key>,
#[allow(dead_code)]
layer_lsn_range: Range<Lsn>,

max_vectored_read_bytes: Option<MaxVectoredReadBytes>,
Expand Down Expand Up @@ -882,44 +880,6 @@ impl DeltaLayerInner {
Ok(())
}

/// Load all key-values in the delta layer, should be replaced by an iterator-based interface in the future.
pub(super) async fn load_key_values(
&self,
ctx: &RequestContext,
) -> anyhow::Result<Vec<(Key, Lsn, Value)>> {
let block_reader = FileBlockReader::new(&self.file, self.file_id);
let index_reader = DiskBtreeReader::<_, DELTA_KEY_SIZE>::new(
self.index_start_blk,
self.index_root_blk,
block_reader,
);
let mut result = Vec::new();
let mut stream =
Box::pin(self.stream_index_forwards(index_reader, &[0; DELTA_KEY_SIZE], ctx));
let block_reader = FileBlockReader::new(&self.file, self.file_id);
let cursor = block_reader.block_cursor();
let mut buf = Vec::new();
while let Some(item) = stream.next().await {
let (key, lsn, pos) = item?;
// TODO: dedup code with get_reconstruct_value
// TODO: ctx handling and sharding
cursor
.read_blob_into_buf(pos.pos(), &mut buf, ctx)
.await
.with_context(|| {
format!("Failed to read blob from virtual file {}", self.file.path)
})?;
let val = Value::des(&buf).with_context(|| {
format!(
"Failed to deserialize file blob from virtual file {}",
self.file.path
)
})?;
result.push((key, lsn, val));
}
Ok(result)
}

async fn plan_reads<Reader>(
keyspace: &KeySpace,
lsn_range: Range<Lsn>,
Expand Down
32 changes: 3 additions & 29 deletions pageserver/src/tenant/storage_layer/image_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::context::{PageContentKind, RequestContext, RequestContextBuilder};
use crate::page_cache::{self, FileId, PAGE_SZ};
use crate::repository::{Key, Value, KEY_SIZE};
use crate::tenant::blob_io::BlobWriter;
use crate::tenant::block_io::{BlockBuf, BlockReader, FileBlockReader};
use crate::tenant::block_io::{BlockBuf, FileBlockReader};
use crate::tenant::disk_btree::{
DiskBtreeBuilder, DiskBtreeIterator, DiskBtreeReader, VisitDirection,
};
Expand Down Expand Up @@ -453,33 +453,6 @@ impl ImageLayerInner {
Ok(())
}

/// Load all key-values in the delta layer, should be replaced by an iterator-based interface in the future.
pub(super) async fn load_key_values(
&self,
ctx: &RequestContext,
) -> anyhow::Result<Vec<(Key, Lsn, Value)>> {
let block_reader = FileBlockReader::new(&self.file, self.file_id);
let tree_reader =
DiskBtreeReader::new(self.index_start_blk, self.index_root_blk, &block_reader);
let mut result = Vec::new();
let mut stream = Box::pin(tree_reader.into_stream(&[0; KEY_SIZE], ctx));
let block_reader = FileBlockReader::new(&self.file, self.file_id);
let cursor = block_reader.block_cursor();
while let Some(item) = stream.next().await {
// TODO: dedup code with get_reconstruct_value
let (raw_key, offset) = item?;
let key = Key::from_slice(&raw_key[..KEY_SIZE]);
// TODO: ctx handling and sharding
let blob = cursor
.read_blob(offset, ctx)
.await
.with_context(|| format!("failed to read value from offset {}", offset))?;
let value = Bytes::from(blob);
result.push((key, self.lsn, Value::Image(value)));
}
Ok(result)
}

/// Traverse the layer's index to build read operations on the overlap of the input keyspace
/// and the keys in this layer.
///
Expand Down Expand Up @@ -711,7 +684,7 @@ struct ImageLayerWriterInner {
blob_writer: BlobWriter<false>,
tree: DiskBtreeBuilder<BlockBuf, KEY_SIZE>,

#[cfg_attr(not(feature = "testing"), allow(dead_code))]
#[cfg(feature = "testing")]
last_written_key: Key,
}

Expand Down Expand Up @@ -770,6 +743,7 @@ impl ImageLayerWriterInner {
uncompressed_bytes_eligible: 0,
uncompressed_bytes_chosen: 0,
num_keys: 0,
#[cfg(feature = "testing")]
last_written_key: Key::MIN,
};

Expand Down
31 changes: 0 additions & 31 deletions pageserver/src/tenant/storage_layer/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use utils::sync::{gate, heavier_once_cell};

use crate::config::PageServerConf;
use crate::context::{DownloadBehavior, RequestContext};
use crate::repository::Key;
use crate::span::debug_assert_current_span_has_tenant_and_timeline_id;
use crate::task_mgr::TaskKind;
use crate::tenant::timeline::{CompactionError, GetVectoredError};
Expand Down Expand Up @@ -334,23 +333,6 @@ impl Layer {
})
}

/// Get all key/values in the layer. Should be replaced with an iterator-based API in the future.
#[allow(dead_code)]
pub(crate) async fn load_key_values(
&self,
ctx: &RequestContext,
) -> anyhow::Result<Vec<(Key, Lsn, crate::repository::Value)>> {
let layer = self
.0
.get_or_maybe_download(true, Some(ctx))
.await
.map_err(|err| match err {
DownloadError::DownloadCancelled => GetVectoredError::Cancelled,
other => GetVectoredError::Other(anyhow::anyhow!(other)),
})?;
layer.load_key_values(&self.0, ctx).await
}

/// Download the layer if evicted.
///
/// Will not error when the layer is already downloaded.
Expand Down Expand Up @@ -1777,19 +1759,6 @@ impl DownloadedLayer {
}
}

async fn load_key_values(
&self,
owner: &Arc<LayerInner>,
ctx: &RequestContext,
) -> anyhow::Result<Vec<(Key, Lsn, crate::repository::Value)>> {
use LayerKind::*;

match self.get(owner, ctx).await? {
Delta(d) => d.load_key_values(ctx).await,
Image(i) => i.load_key_values(ctx).await,
}
}

async fn dump(&self, owner: &Arc<LayerInner>, ctx: &RequestContext) -> anyhow::Result<()> {
use LayerKind::*;
match self.get(owner, ctx).await? {
Expand Down
2 changes: 1 addition & 1 deletion pageserver/src/tenant/storage_layer/layer/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ async fn eviction_cancellation_on_drop() {
let mut writer = timeline.writer().await;
writer
.put(
Key::from_i128(5),
crate::repository::Key::from_i128(5),
Lsn(0x20),
&Value::Image(Bytes::from_static(b"this does not matter either")),
&ctx,
Expand Down
2 changes: 1 addition & 1 deletion pageserver/src/tenant/storage_layer/split_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ impl SplitDeltaLayerWriter {
Ok(generated_layers)
}

#[allow(dead_code)]
#[cfg(test)]
pub(crate) async fn finish(
self,
tline: &Arc<Timeline>,
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 @@ -4537,7 +4537,6 @@ pub struct DeltaLayerTestDesc {

#[cfg(test)]
impl DeltaLayerTestDesc {
#[allow(dead_code)]
pub fn new(lsn_range: Range<Lsn>, key_range: Range<Key>, data: Vec<(Key, Lsn, Value)>) -> Self {
Self {
lsn_range,
Expand Down

1 comment on commit 15e90cc

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3896 tests run: 3780 passed, 0 failed, 116 skipped (full report)


Flaky tests (3)

Postgres 16

Postgres 15

Postgres 14

  • test_ondemand_wal_download_in_replication_slot_funcs: release-x86-64

Code coverage* (full report)

  • functions: 32.4% (7412 of 22848 functions)
  • lines: 50.6% (60041 of 118676 lines)

* collected from Rust tests only


The comment gets automatically updated with the latest test results
15e90cc at 2024-09-02T15:37:31.700Z :recycle:

Please sign in to comment.