From 1b9b9d60d462afd893cf989ca6a6cc55039b7e15 Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Wed, 1 Mar 2023 13:06:43 +0100 Subject: [PATCH] eviction: add comment explaining resident size decrement on error https://github.com/neondatabase/neon/issues/3722 --- pageserver/src/tenant/timeline.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pageserver/src/tenant/timeline.rs b/pageserver/src/tenant/timeline.rs index 3926249572..ca0cd04bd0 100644 --- a/pageserver/src/tenant/timeline.rs +++ b/pageserver/src/tenant/timeline.rs @@ -1079,7 +1079,16 @@ impl Timeline { if let Err(e) = local_layer.delete() { error!("failed to remove layer file on evict after replacement: {e:#?}"); } - + // Always decrement the physical size gauge, even if we failed to delete the file. + // Rationale: we already replaced the layer with a remote layer in the layer map, + // and any subsequent download_remote_layer will + // 1. overwrite the file on disk and + // 2. add the downloaded size to the resident size gauge. + // + // If there is no re-download, and we restart the pageserver, then load_layer_map + // will treat the file as a local layer again, count it towards resident size, + // and it'll be like the layer removal never happened. + // The bump in resident size is perhaps unexpected but overall a robust behavior. self.metrics .resident_physical_size_gauge .sub(layer_file_size);