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

remove_remote_layer: uninteresting refactorings #4936

Merged
merged 9 commits into from
Aug 9, 2023
Merged

Conversation

koivunej
Copy link
Member

@koivunej koivunej commented Aug 9, 2023

In the quest to solve #4745 by moving the download/evictedness to be internally mutable factor of a Layer and get rid of trait PersistentLayer at least for prod usage, layer_removal_cs, we present some misc cleanups.

@koivunej koivunej requested review from a team as code owners August 9, 2023 07:26
@koivunej koivunej requested review from knizhnik and hlinnaka and removed request for a team August 9, 2023 07:26
@koivunej koivunej marked this pull request as draft August 9, 2023 07:26
@koivunej
Copy link
Member Author

koivunej commented Aug 9, 2023

Drafting while we see "uninteresting refactorings" produce a new personal record of broken tests.

Narrator: it never did have test failures, only compilation errors, messed up fixups.

@koivunej
Copy link
Member Author

koivunej commented Aug 9, 2023

I'll fix the fixup mistake noted above, and split away the preparatory refactorings from these more unrelated fixes/refactorings.

Done in latest force-push, split to #4937.

@github-actions
Copy link

github-actions bot commented Aug 9, 2023

1264 tests run: 1212 passed, 0 failed, 52 skipped (full report)


Flaky tests (1)

Postgres 15

  • test_branching_with_pgbench[cascade-1-10]: release
The comment gets automatically updated with the latest test results
2f37588 at 2023-08-09T10:33:11.268Z :recycle:

Copy link
Contributor

@LizardWizzard LizardWizzard left a comment

Choose a reason for hiding this comment

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

Nice! LGTM

Small diff to reduce number of LayerDesc clones a bit:

diff --git a/pageserver/src/tenant/layer_map.rs b/pageserver/src/tenant/layer_map.rs
index c4b894fcf..59813b19d 100644
--- a/pageserver/src/tenant/layer_map.rs
+++ b/pageserver/src/tenant/layer_map.rs
@@ -121,7 +121,7 @@ impl BatchedUpdates<'_> {
     ///
     /// This should be called when the corresponding file on disk has been deleted.
     ///
-    pub fn remove_historic(&mut self, layer_desc: PersistentLayerDesc) {
+    pub fn remove_historic(&mut self, layer_desc: &PersistentLayerDesc) {
         self.layer_map.remove_historic_noflush(layer_desc)
     }
 
@@ -253,11 +253,11 @@ impl LayerMap {
     ///
     /// Helper function for BatchedUpdates::remove_historic
     ///
-    pub fn remove_historic_noflush(&mut self, layer_desc: PersistentLayerDesc) {
+    pub fn remove_historic_noflush(&mut self, layer_desc: &PersistentLayerDesc) {
         self.historic
-            .remove(historic_layer_coverage::LayerKey::from(&layer_desc));
+            .remove(historic_layer_coverage::LayerKey::from(layer_desc));
         let layer_key = layer_desc.key();
-        if Self::is_l0(&layer_desc) {
+        if Self::is_l0(layer_desc) {
             let len_before = self.l0_delta_layers.len();
             let mut l0_delta_layers = std::mem::take(&mut self.l0_delta_layers);
             l0_delta_layers.retain(|other| other.key() != layer_key);
@@ -766,8 +766,7 @@ mod tests {
                 expected_in_counts
             );
 
-            map.batch_update()
-                .remove_historic(downloaded.layer_desc().clone());
+            map.batch_update().remove_historic(downloaded.layer_desc());
             assert_eq!(count_layer_in(&map, downloaded.layer_desc()), (0, 0));
         }
 
diff --git a/pageserver/src/tenant/timeline/layer_manager.rs b/pageserver/src/tenant/timeline/layer_manager.rs
index e2f1634ad..824d869be 100644
--- a/pageserver/src/tenant/timeline/layer_manager.rs
+++ b/pageserver/src/tenant/timeline/layer_manager.rs
@@ -277,7 +277,7 @@ impl LayerManager {
         updates: &mut BatchedUpdates<'_>,
         mapping: &mut LayerFileManager,
     ) {
-        updates.remove_historic(layer.layer_desc().clone());
+        updates.remove_historic(layer.layer_desc());
         mapping.remove(layer);
     }
 
@@ -291,7 +291,7 @@ impl LayerManager {
         metrics: &TimelineMetrics,
         mapping: &mut LayerFileManager,
     ) -> anyhow::Result<()> {
-        let desc = layer.layer_desc().to_owned();
+        let desc = layer.layer_desc();
         if !layer.is_remote_layer() {
             layer.delete_resident_layer_file()?;
             metrics.resident_physical_size_gauge.sub(desc.file_size);

@koivunej
Copy link
Member Author

koivunej commented Aug 9, 2023

Above in 2f37588.

@koivunej
Copy link
Member Author

koivunej commented Aug 9, 2023

test_branching_with_pgbench[cascade-1-10] pg15, release:

stderr: command failed: compute startup timed out; still in Init state

@@ -304,17 +304,18 @@ pub async fn disk_usage_eviction_task_iteration_impl<U: Usage>(
// Debug-log the list of candidates
let now = SystemTime::now();
for (i, (partition, candidate)) in candidates.iter().enumerate() {
let desc = candidate.layer.layer_desc();
Copy link
Member

Choose a reason for hiding this comment

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

Very nice 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Sad this is that this is basically dead code... and it might be now more expensive than doing this in a debug! because on prod debug is never enabled so the formatting would had never been done, but let's hope rustc/llvm decide to move this method call after the debug interest check :)

Copy link
Member

Choose a reason for hiding this comment

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

Good point. It's a virtual call, as the layer is a Arc<dyn PersistentLayer>, which can have arbitrary side effects, so I think the optimizer will not move after the check for debug, However, it should be a cheap operation so fine to do.

@koivunej koivunej merged commit cbd04f5 into main Aug 9, 2023
29 checks passed
@koivunej koivunej deleted the remove_remote_layer_1 branch August 9, 2023 11:35
koivunej added a commit that referenced this pull request Oct 26, 2023
…#4938)

Implement a new `struct Layer` abstraction which manages downloadness
internally, requiring no LayerMap locking or rewriting to download or
evict providing a property "you have a layer, you can read it". The new
`struct Layer` provides ability to keep the file resident via a RAII
structure for new layers which still need to be uploaded. Previous
solution solved this `RemoteTimelineClient::wait_completion` which lead
to bugs like #5639. Evicting or the final local deletion after garbage
collection is done using Arc'd value `Drop`.

With a single `struct Layer` the closed open ended `trait Layer`, `trait
PersistentLayer` and `struct RemoteLayer` are removed following noting
that compaction could be simplified by simply not using any of the
traits in between: #4839.

The new `struct Layer` is a preliminary to remove
`Timeline::layer_removal_cs` documented in #4745.

Preliminaries: #4936, #4937, #5013, #5014, #5022, #5033, #5044, #5058,
#5059, #5061, #5074, #5103, epic #5172, #5645, #5649. Related split off:
#5057, #5134.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants