From 99d9c23df5d81667b351973907e26405f8adcff6 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Tue, 22 Nov 2022 11:01:02 +0200 Subject: [PATCH] Gather path-related consts and functions to one place. Feels more organized this way. --- pageserver/src/config.rs | 6 +---- pageserver/src/lib.rs | 37 ++++++++++++++++++++++++++++--- pageserver/src/tenant.rs | 2 +- pageserver/src/tenant/timeline.rs | 3 ++- pageserver/src/tenant_mgr.rs | 20 ++--------------- 5 files changed, 40 insertions(+), 28 deletions(-) diff --git a/pageserver/src/config.rs b/pageserver/src/config.rs index 71ba6fc67a..66a14b64f1 100644 --- a/pageserver/src/config.rs +++ b/pageserver/src/config.rs @@ -25,11 +25,7 @@ use utils::{ use crate::tenant::TIMELINES_SEGMENT_NAME; use crate::tenant_config::{TenantConf, TenantConfOpt}; - -/// The name of the metadata file pageserver creates per timeline. -pub const METADATA_FILE_NAME: &str = "metadata"; -pub const TIMELINE_UNINIT_MARK_SUFFIX: &str = "___uninit"; -const TENANT_CONFIG_NAME: &str = "config"; +use crate::{METADATA_FILE_NAME, TENANT_CONFIG_NAME, TIMELINE_UNINIT_MARK_SUFFIX}; pub mod defaults { use crate::tenant_config::defaults::*; diff --git a/pageserver/src/lib.rs b/pageserver/src/lib.rs index b62143f650..c0c167c2ac 100644 --- a/pageserver/src/lib.rs +++ b/pageserver/src/lib.rs @@ -23,6 +23,7 @@ pub mod walrecord; pub mod walredo; use std::collections::HashMap; +use std::path::Path; use tracing::info; use utils::id::{TenantId, TimelineId}; @@ -120,9 +121,39 @@ impl TenantTimelineValues { } } -/// A suffix to be used during file sync from the remote storage, -/// to ensure that we do not leave corrupted files that pretend to be layers. -const TEMP_FILE_SUFFIX: &str = "___temp"; +/// The name of the metadata file pageserver creates per timeline. +/// Full path: `tenants//timelines//metadata`. +pub const METADATA_FILE_NAME: &str = "metadata"; + +/// Per-tenant configuration file. +/// Full path: `tenants//config`. +pub const TENANT_CONFIG_NAME: &str = "config"; + +/// A suffix used for various temporary files. Any temporary files found in the +/// data directory at pageserver startup can be automatically removed. +pub const TEMP_FILE_SUFFIX: &str = "___temp"; + +/// A marker file to mark that a timeline directory was not fully initialized. +/// If a timeline directory with this marker is encountered at pageserver startup, +/// the timeline directory and the marker file are both removed. +/// Full path: `tenants//timelines/___uninit`. +pub const TIMELINE_UNINIT_MARK_SUFFIX: &str = "___uninit"; + +pub fn is_temporary(path: &Path) -> bool { + match path.file_name() { + Some(name) => name.to_string_lossy().ends_with(TEMP_FILE_SUFFIX), + None => false, + } +} + +pub fn is_uninit_mark(path: &Path) -> bool { + match path.file_name() { + Some(name) => name + .to_string_lossy() + .ends_with(TIMELINE_UNINIT_MARK_SUFFIX), + None => false, + } +} #[cfg(test)] mod backoff_defaults_tests { diff --git a/pageserver/src/tenant.rs b/pageserver/src/tenant.rs index 4405e0b236..1ec9b0dbc7 100644 --- a/pageserver/src/tenant.rs +++ b/pageserver/src/tenant.rs @@ -1828,11 +1828,11 @@ pub mod harness { #[cfg(test)] mod tests { use super::*; - use crate::config::METADATA_FILE_NAME; use crate::keyspace::KeySpaceAccum; use crate::repository::{Key, Value}; use crate::tenant::harness::*; use crate::DEFAULT_PG_VERSION; + use crate::METADATA_FILE_NAME; use bytes::BytesMut; use hex_literal::hex; use once_cell::sync::Lazy; diff --git a/pageserver/src/tenant/timeline.rs b/pageserver/src/tenant/timeline.rs index 63ba4c10e6..b6eb488020 100644 --- a/pageserver/src/tenant/timeline.rs +++ b/pageserver/src/tenant/timeline.rs @@ -31,7 +31,7 @@ use crate::tenant::{ storage_layer::{Layer, ValueReconstructResult, ValueReconstructState}, }; -use crate::config::{PageServerConf, METADATA_FILE_NAME}; +use crate::config::PageServerConf; use crate::keyspace::{KeyPartitioning, KeySpace}; use crate::metrics::TimelineMetrics; use crate::pgdatadir_mapping::BlockNumber; @@ -55,6 +55,7 @@ use crate::task_mgr::TaskKind; use crate::walreceiver::{is_etcd_client_initialized, spawn_connection_manager_task}; use crate::walredo::WalRedoManager; use crate::CheckpointConfig; +use crate::METADATA_FILE_NAME; use crate::ZERO_PAGE; use crate::{ page_cache, diff --git a/pageserver/src/tenant_mgr.rs b/pageserver/src/tenant_mgr.rs index 3766bc5cb3..061d7fa195 100644 --- a/pageserver/src/tenant_mgr.rs +++ b/pageserver/src/tenant_mgr.rs @@ -12,7 +12,7 @@ use tracing::*; use remote_storage::GenericRemoteStorage; -use crate::config::{PageServerConf, METADATA_FILE_NAME, TIMELINE_UNINIT_MARK_SUFFIX}; +use crate::config::PageServerConf; use crate::http::models::TenantInfo; use crate::storage_sync::index::{LayerFileMetadata, RemoteIndex, RemoteTimelineIndex}; use crate::storage_sync::{self, LocalTimelineInitStatus, SyncStartupData, TimelineLocalFiles}; @@ -22,7 +22,7 @@ use crate::tenant::{ }; use crate::tenant_config::TenantConfOpt; use crate::walredo::PostgresRedoManager; -use crate::TEMP_FILE_SUFFIX; +use crate::{is_temporary, is_uninit_mark, METADATA_FILE_NAME, TEMP_FILE_SUFFIX}; use utils::crashsafe::{self, path_with_suffix_extension}; use utils::id::{TenantId, TimelineId}; @@ -635,22 +635,6 @@ fn remove_if_empty(tenant_dir_path: &Path) -> anyhow::Result { } } -fn is_temporary(path: &Path) -> bool { - match path.file_name() { - Some(name) => name.to_string_lossy().ends_with(TEMP_FILE_SUFFIX), - None => false, - } -} - -fn is_uninit_mark(path: &Path) -> bool { - match path.file_name() { - Some(name) => name - .to_string_lossy() - .ends_with(TIMELINE_UNINIT_MARK_SUFFIX), - None => false, - } -} - fn collect_timelines_for_tenant( config: &'static PageServerConf, tenant_path: &Path,