From 87ecb2e6ca6dcb24f9a432a0bb8a04513ed4ea9d Mon Sep 17 00:00:00 2001 From: Joonas Koivunen Date: Tue, 29 Aug 2023 10:49:13 +0300 Subject: [PATCH] reorder: get and get_or_apply_evictedness --- pageserver/src/tenant/storage_layer/layer.rs | 54 ++++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/pageserver/src/tenant/storage_layer/layer.rs b/pageserver/src/tenant/storage_layer/layer.rs index ee90941c14..ac650065ef 100644 --- a/pageserver/src/tenant/storage_layer/layer.rs +++ b/pageserver/src/tenant/storage_layer/layer.rs @@ -516,33 +516,6 @@ impl LayerInner { } } - /// Access the current state without waiting for the file to be downloaded. - /// - /// Used by eviction only. Requires that we've initialized to state which is respective to the - /// actual residency state. - fn get(&self) -> Option> { - let locked = self.inner.get(); - Self::get_or_apply_evictedness(locked, &self.wanted_evicted) - } - - fn get_or_apply_evictedness( - guard: Option>, - wanted_evicted: &AtomicBool, - ) -> Option> { - if let Some(mut x) = guard { - if let Some(won) = x.get() { - // there are no guarantees that we will always get to observe a concurrent call - // to evict - if wanted_evicted.load(Ordering::Acquire) { - x.downgrade(); - } - return Some(won); - } - } - - None - } - /// Should be cancellation safe, but cancellation is troublesome together with the spawned /// download. async fn get_or_maybe_download( @@ -754,6 +727,33 @@ impl LayerInner { } } + /// Access the current state without waiting for the file to be downloaded. + /// + /// Requires that we've initialized to state which is respective to the + /// actual residency state. + fn get(&self) -> Option> { + let locked = self.inner.get(); + Self::get_or_apply_evictedness(locked, &self.wanted_evicted) + } + + fn get_or_apply_evictedness( + guard: Option>, + wanted_evicted: &AtomicBool, + ) -> Option> { + if let Some(mut x) = guard { + if let Some(won) = x.get() { + // there are no guarantees that we will always get to observe a concurrent call + // to evict + if wanted_evicted.load(Ordering::Acquire) { + x.downgrade(); + } + return Some(won); + } + } + + None + } + async fn needs_download(&self) -> Result, std::io::Error> { match tokio::fs::metadata(&self.path).await { Ok(m) => Ok(self.is_file_present_and_good_size(&m).err()),