Line data Source code
1 : //! This module implements Timeline lifecycle management and has all necessary code
2 : //! to glue together SafeKeeper and all other background services.
3 :
4 : use anyhow::{anyhow, bail, Result};
5 : use camino::Utf8PathBuf;
6 : use remote_storage::RemotePath;
7 : use safekeeper_api::models::TimelineTermBumpResponse;
8 : use serde::{Deserialize, Serialize};
9 : use tokio::fs::{self};
10 : use tokio_util::sync::CancellationToken;
11 : use utils::id::TenantId;
12 :
13 : use std::cmp::max;
14 : use std::ops::{Deref, DerefMut};
15 : use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
16 : use std::sync::Arc;
17 : use std::time::Duration;
18 : use tokio::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard};
19 : use tokio::{sync::watch, time::Instant};
20 : use tracing::*;
21 : use utils::http::error::ApiError;
22 : use utils::{
23 : id::{NodeId, TenantTimelineId},
24 : lsn::Lsn,
25 : };
26 :
27 : use storage_broker::proto::SafekeeperTimelineInfo;
28 : use storage_broker::proto::TenantTimelineId as ProtoTenantTimelineId;
29 :
30 : use crate::control_file;
31 : use crate::rate_limit::RateLimiter;
32 : use crate::receive_wal::WalReceivers;
33 : use crate::safekeeper::{
34 : AcceptorProposerMessage, ProposerAcceptorMessage, SafeKeeper, Term, TermLsn,
35 : };
36 : use crate::send_wal::WalSenders;
37 : use crate::state::{EvictionState, TimelineMemState, TimelinePersistentState, TimelineState};
38 : use crate::timeline_guard::ResidenceGuard;
39 : use crate::timeline_manager::{AtomicStatus, ManagerCtl};
40 : use crate::timelines_set::TimelinesSet;
41 : use crate::wal_backup::{self, remote_timeline_path};
42 : use crate::wal_backup_partial::PartialRemoteSegment;
43 :
44 : use crate::metrics::{FullTimelineInfo, WalStorageMetrics, MISC_OPERATION_SECONDS};
45 : use crate::wal_storage::{Storage as wal_storage_iface, WalReader};
46 : use crate::{debug_dump, timeline_manager, wal_storage};
47 : use crate::{GlobalTimelines, SafeKeeperConf};
48 :
49 : /// Things safekeeper should know about timeline state on peers.
50 0 : #[derive(Debug, Clone, Serialize, Deserialize)]
51 : pub struct PeerInfo {
52 : pub sk_id: NodeId,
53 : pub term: Term,
54 : /// Term of the last entry.
55 : pub last_log_term: Term,
56 : /// LSN of the last record.
57 : pub flush_lsn: Lsn,
58 : pub commit_lsn: Lsn,
59 : /// Since which LSN safekeeper has WAL.
60 : pub local_start_lsn: Lsn,
61 : /// When info was received. Serde annotations are not very useful but make
62 : /// the code compile -- we don't rely on this field externally.
63 : #[serde(skip)]
64 : #[serde(default = "Instant::now")]
65 : ts: Instant,
66 : pub pg_connstr: String,
67 : pub http_connstr: String,
68 : }
69 :
70 : impl PeerInfo {
71 0 : fn from_sk_info(sk_info: &SafekeeperTimelineInfo, ts: Instant) -> PeerInfo {
72 0 : PeerInfo {
73 0 : sk_id: NodeId(sk_info.safekeeper_id),
74 0 : term: sk_info.term,
75 0 : last_log_term: sk_info.last_log_term,
76 0 : flush_lsn: Lsn(sk_info.flush_lsn),
77 0 : commit_lsn: Lsn(sk_info.commit_lsn),
78 0 : local_start_lsn: Lsn(sk_info.local_start_lsn),
79 0 : pg_connstr: sk_info.safekeeper_connstr.clone(),
80 0 : http_connstr: sk_info.http_connstr.clone(),
81 0 : ts,
82 0 : }
83 0 : }
84 : }
85 :
86 : // vector-based node id -> peer state map with very limited functionality we
87 : // need.
88 : #[derive(Debug, Clone, Default)]
89 : pub struct PeersInfo(pub Vec<PeerInfo>);
90 :
91 : impl PeersInfo {
92 0 : fn get(&mut self, id: NodeId) -> Option<&mut PeerInfo> {
93 0 : self.0.iter_mut().find(|p| p.sk_id == id)
94 0 : }
95 :
96 0 : fn upsert(&mut self, p: &PeerInfo) {
97 0 : match self.get(p.sk_id) {
98 0 : Some(rp) => *rp = p.clone(),
99 0 : None => self.0.push(p.clone()),
100 : }
101 0 : }
102 : }
103 :
104 : pub type ReadGuardSharedState<'a> = RwLockReadGuard<'a, SharedState>;
105 :
106 : /// WriteGuardSharedState is a wrapper around `RwLockWriteGuard<SharedState>` that
107 : /// automatically updates `watch::Sender` channels with state on drop.
108 : pub struct WriteGuardSharedState<'a> {
109 : tli: Arc<Timeline>,
110 : guard: RwLockWriteGuard<'a, SharedState>,
111 : skip_update: bool,
112 : }
113 :
114 : impl<'a> WriteGuardSharedState<'a> {
115 0 : fn new(tli: Arc<Timeline>, guard: RwLockWriteGuard<'a, SharedState>) -> Self {
116 0 : WriteGuardSharedState {
117 0 : tli,
118 0 : guard,
119 0 : skip_update: false,
120 0 : }
121 0 : }
122 : }
123 :
124 : impl Deref for WriteGuardSharedState<'_> {
125 : type Target = SharedState;
126 :
127 0 : fn deref(&self) -> &Self::Target {
128 0 : &self.guard
129 0 : }
130 : }
131 :
132 : impl DerefMut for WriteGuardSharedState<'_> {
133 0 : fn deref_mut(&mut self) -> &mut Self::Target {
134 0 : &mut self.guard
135 0 : }
136 : }
137 :
138 : impl Drop for WriteGuardSharedState<'_> {
139 0 : fn drop(&mut self) {
140 0 : let term_flush_lsn =
141 0 : TermLsn::from((self.guard.sk.last_log_term(), self.guard.sk.flush_lsn()));
142 0 : let commit_lsn = self.guard.sk.state().inmem.commit_lsn;
143 0 :
144 0 : let _ = self.tli.term_flush_lsn_watch_tx.send_if_modified(|old| {
145 0 : if *old != term_flush_lsn {
146 0 : *old = term_flush_lsn;
147 0 : true
148 : } else {
149 0 : false
150 : }
151 0 : });
152 0 :
153 0 : let _ = self.tli.commit_lsn_watch_tx.send_if_modified(|old| {
154 0 : if *old != commit_lsn {
155 0 : *old = commit_lsn;
156 0 : true
157 : } else {
158 0 : false
159 : }
160 0 : });
161 0 :
162 0 : if !self.skip_update {
163 0 : // send notification about shared state update
164 0 : self.tli.shared_state_version_tx.send_modify(|old| {
165 0 : *old += 1;
166 0 : });
167 0 : }
168 0 : }
169 : }
170 :
171 : /// This structure is stored in shared state and represents the state of the timeline.
172 : ///
173 : /// Usually it holds SafeKeeper, but it also supports offloaded timeline state. In this
174 : /// case, SafeKeeper is not available (because WAL is not present on disk) and all
175 : /// operations can be done only with control file.
176 : pub enum StateSK {
177 : Loaded(SafeKeeper<control_file::FileStorage, wal_storage::PhysicalStorage>),
178 : Offloaded(Box<TimelineState<control_file::FileStorage>>),
179 : // Not used, required for moving between states.
180 : Empty,
181 : }
182 :
183 : impl StateSK {
184 0 : pub fn flush_lsn(&self) -> Lsn {
185 0 : match self {
186 0 : StateSK::Loaded(sk) => sk.wal_store.flush_lsn(),
187 0 : StateSK::Offloaded(state) => match state.eviction_state {
188 0 : EvictionState::Offloaded(flush_lsn) => flush_lsn,
189 0 : _ => panic!("StateSK::Offloaded mismatches with eviction_state from control_file"),
190 : },
191 0 : StateSK::Empty => unreachable!(),
192 : }
193 0 : }
194 :
195 : /// Get a reference to the control file's timeline state.
196 0 : pub fn state(&self) -> &TimelineState<control_file::FileStorage> {
197 0 : match self {
198 0 : StateSK::Loaded(sk) => &sk.state,
199 0 : StateSK::Offloaded(ref s) => s,
200 0 : StateSK::Empty => unreachable!(),
201 : }
202 0 : }
203 :
204 0 : pub fn state_mut(&mut self) -> &mut TimelineState<control_file::FileStorage> {
205 0 : match self {
206 0 : StateSK::Loaded(sk) => &mut sk.state,
207 0 : StateSK::Offloaded(ref mut s) => s,
208 0 : StateSK::Empty => unreachable!(),
209 : }
210 0 : }
211 :
212 0 : pub fn last_log_term(&self) -> Term {
213 0 : self.state()
214 0 : .acceptor_state
215 0 : .get_last_log_term(self.flush_lsn())
216 0 : }
217 :
218 0 : pub async fn term_bump(&mut self, to: Option<Term>) -> Result<TimelineTermBumpResponse> {
219 0 : self.state_mut().term_bump(to).await
220 0 : }
221 :
222 : /// Close open WAL files to release FDs.
223 0 : fn close_wal_store(&mut self) {
224 0 : if let StateSK::Loaded(sk) = self {
225 0 : sk.wal_store.close();
226 0 : }
227 0 : }
228 :
229 : /// Update timeline state with peer safekeeper data.
230 0 : pub async fn record_safekeeper_info(&mut self, sk_info: &SafekeeperTimelineInfo) -> Result<()> {
231 0 : // update commit_lsn if safekeeper is loaded
232 0 : match self {
233 0 : StateSK::Loaded(sk) => sk.record_safekeeper_info(sk_info).await?,
234 0 : StateSK::Offloaded(_) => {}
235 0 : StateSK::Empty => unreachable!(),
236 : }
237 :
238 : // update everything else, including remote_consistent_lsn and backup_lsn
239 0 : let mut sync_control_file = false;
240 0 : let state = self.state_mut();
241 0 : let wal_seg_size = state.server.wal_seg_size as u64;
242 0 :
243 0 : state.inmem.backup_lsn = max(Lsn(sk_info.backup_lsn), state.inmem.backup_lsn);
244 0 : sync_control_file |= state.backup_lsn + wal_seg_size < state.inmem.backup_lsn;
245 0 :
246 0 : state.inmem.remote_consistent_lsn = max(
247 0 : Lsn(sk_info.remote_consistent_lsn),
248 0 : state.inmem.remote_consistent_lsn,
249 0 : );
250 0 : sync_control_file |=
251 0 : state.remote_consistent_lsn + wal_seg_size < state.inmem.remote_consistent_lsn;
252 0 :
253 0 : state.inmem.peer_horizon_lsn =
254 0 : max(Lsn(sk_info.peer_horizon_lsn), state.inmem.peer_horizon_lsn);
255 0 : sync_control_file |= state.peer_horizon_lsn + wal_seg_size < state.inmem.peer_horizon_lsn;
256 0 :
257 0 : if sync_control_file {
258 0 : state.flush().await?;
259 0 : }
260 0 : Ok(())
261 0 : }
262 :
263 : /// Previously known as epoch_start_lsn. Needed only for reference in some APIs.
264 0 : pub fn term_start_lsn(&self) -> Lsn {
265 0 : match self {
266 0 : StateSK::Loaded(sk) => sk.term_start_lsn,
267 0 : StateSK::Offloaded(_) => Lsn(0),
268 0 : StateSK::Empty => unreachable!(),
269 : }
270 0 : }
271 :
272 : /// Used for metrics only.
273 0 : pub fn wal_storage_metrics(&self) -> WalStorageMetrics {
274 0 : match self {
275 0 : StateSK::Loaded(sk) => sk.wal_store.get_metrics(),
276 0 : StateSK::Offloaded(_) => WalStorageMetrics::default(),
277 0 : StateSK::Empty => unreachable!(),
278 : }
279 0 : }
280 :
281 : /// Returns WAL storage internal LSNs for debug dump.
282 0 : pub fn wal_storage_internal_state(&self) -> (Lsn, Lsn, Lsn, bool) {
283 0 : match self {
284 0 : StateSK::Loaded(sk) => sk.wal_store.internal_state(),
285 : StateSK::Offloaded(_) => {
286 0 : let flush_lsn = self.flush_lsn();
287 0 : (flush_lsn, flush_lsn, flush_lsn, false)
288 : }
289 0 : StateSK::Empty => unreachable!(),
290 : }
291 0 : }
292 :
293 : /// Access to SafeKeeper object. Panics if offloaded, should be good to use from WalResidentTimeline.
294 0 : pub fn safekeeper(
295 0 : &mut self,
296 0 : ) -> &mut SafeKeeper<control_file::FileStorage, wal_storage::PhysicalStorage> {
297 0 : match self {
298 0 : StateSK::Loaded(sk) => sk,
299 : StateSK::Offloaded(_) => {
300 0 : panic!("safekeeper is offloaded, cannot be used")
301 : }
302 0 : StateSK::Empty => unreachable!(),
303 : }
304 0 : }
305 :
306 : /// Moves control file's state structure out of the enum. Used to switch states.
307 0 : fn take_state(self) -> TimelineState<control_file::FileStorage> {
308 0 : match self {
309 0 : StateSK::Loaded(sk) => sk.state,
310 0 : StateSK::Offloaded(state) => *state,
311 0 : StateSK::Empty => unreachable!(),
312 : }
313 0 : }
314 : }
315 :
316 : /// Shared state associated with database instance
317 : pub struct SharedState {
318 : /// Safekeeper object
319 : pub(crate) sk: StateSK,
320 : /// In memory list containing state of peers sent in latest messages from them.
321 : pub(crate) peers_info: PeersInfo,
322 : // True value hinders old WAL removal; this is used by snapshotting. We
323 : // could make it a counter, but there is no need to.
324 : pub(crate) wal_removal_on_hold: bool,
325 : }
326 :
327 : impl SharedState {
328 : /// Restore SharedState from control file. If file doesn't exist, bails out.
329 0 : fn restore(conf: &SafeKeeperConf, ttid: &TenantTimelineId) -> Result<Self> {
330 0 : let timeline_dir = get_timeline_dir(conf, ttid);
331 0 : let control_store = control_file::FileStorage::restore_new(ttid, conf)?;
332 0 : if control_store.server.wal_seg_size == 0 {
333 0 : bail!(TimelineError::UninitializedWalSegSize(*ttid));
334 0 : }
335 :
336 0 : let sk = match control_store.eviction_state {
337 : EvictionState::Present => {
338 0 : let wal_store =
339 0 : wal_storage::PhysicalStorage::new(ttid, timeline_dir, conf, &control_store)?;
340 0 : StateSK::Loaded(SafeKeeper::new(
341 0 : TimelineState::new(control_store),
342 0 : wal_store,
343 0 : conf.my_id,
344 0 : )?)
345 : }
346 : EvictionState::Offloaded(_) => {
347 0 : StateSK::Offloaded(Box::new(TimelineState::new(control_store)))
348 : }
349 : };
350 :
351 0 : Ok(Self {
352 0 : sk,
353 0 : peers_info: PeersInfo(vec![]),
354 0 : wal_removal_on_hold: false,
355 0 : })
356 0 : }
357 :
358 0 : pub(crate) fn get_wal_seg_size(&self) -> usize {
359 0 : self.sk.state().server.wal_seg_size as usize
360 0 : }
361 :
362 0 : fn get_safekeeper_info(
363 0 : &self,
364 0 : ttid: &TenantTimelineId,
365 0 : conf: &SafeKeeperConf,
366 0 : standby_apply_lsn: Lsn,
367 0 : ) -> SafekeeperTimelineInfo {
368 0 : SafekeeperTimelineInfo {
369 0 : safekeeper_id: conf.my_id.0,
370 0 : tenant_timeline_id: Some(ProtoTenantTimelineId {
371 0 : tenant_id: ttid.tenant_id.as_ref().to_owned(),
372 0 : timeline_id: ttid.timeline_id.as_ref().to_owned(),
373 0 : }),
374 0 : term: self.sk.state().acceptor_state.term,
375 0 : last_log_term: self.sk.last_log_term(),
376 0 : flush_lsn: self.sk.flush_lsn().0,
377 0 : // note: this value is not flushed to control file yet and can be lost
378 0 : commit_lsn: self.sk.state().inmem.commit_lsn.0,
379 0 : remote_consistent_lsn: self.sk.state().inmem.remote_consistent_lsn.0,
380 0 : peer_horizon_lsn: self.sk.state().inmem.peer_horizon_lsn.0,
381 0 : safekeeper_connstr: conf
382 0 : .advertise_pg_addr
383 0 : .to_owned()
384 0 : .unwrap_or(conf.listen_pg_addr.clone()),
385 0 : http_connstr: conf.listen_http_addr.to_owned(),
386 0 : backup_lsn: self.sk.state().inmem.backup_lsn.0,
387 0 : local_start_lsn: self.sk.state().local_start_lsn.0,
388 0 : availability_zone: conf.availability_zone.clone(),
389 0 : standby_horizon: standby_apply_lsn.0,
390 0 : }
391 0 : }
392 :
393 : /// Get our latest view of alive peers status on the timeline.
394 : /// We pass our own info through the broker as well, so when we don't have connection
395 : /// to the broker returned vec is empty.
396 0 : pub(crate) fn get_peers(&self, heartbeat_timeout: Duration) -> Vec<PeerInfo> {
397 0 : let now = Instant::now();
398 0 : self.peers_info
399 0 : .0
400 0 : .iter()
401 0 : // Regard peer as absent if we haven't heard from it within heartbeat_timeout.
402 0 : .filter(|p| now.duration_since(p.ts) <= heartbeat_timeout)
403 0 : .cloned()
404 0 : .collect()
405 0 : }
406 : }
407 :
408 0 : #[derive(Debug, thiserror::Error)]
409 : pub enum TimelineError {
410 : #[error("Timeline {0} was cancelled and cannot be used anymore")]
411 : Cancelled(TenantTimelineId),
412 : #[error("Timeline {0} was not found in global map")]
413 : NotFound(TenantTimelineId),
414 : #[error("Timeline {0} creation is in progress")]
415 : CreationInProgress(TenantTimelineId),
416 : #[error("Timeline {0} exists on disk, but wasn't loaded on startup")]
417 : Invalid(TenantTimelineId),
418 : #[error("Timeline {0} is already exists")]
419 : AlreadyExists(TenantTimelineId),
420 : #[error("Timeline {0} is not initialized, wal_seg_size is zero")]
421 : UninitializedWalSegSize(TenantTimelineId),
422 : #[error("Timeline {0} is not initialized, pg_version is unknown")]
423 : UninitialinzedPgVersion(TenantTimelineId),
424 : }
425 :
426 : // Convert to HTTP API error.
427 : impl From<TimelineError> for ApiError {
428 0 : fn from(te: TimelineError) -> ApiError {
429 0 : match te {
430 0 : TimelineError::NotFound(ttid) => {
431 0 : ApiError::NotFound(anyhow!("timeline {} not found", ttid).into())
432 : }
433 0 : _ => ApiError::InternalServerError(anyhow!("{}", te)),
434 : }
435 0 : }
436 : }
437 :
438 : /// Timeline struct manages lifecycle (creation, deletion, restore) of a safekeeper timeline.
439 : /// It also holds SharedState and provides mutually exclusive access to it.
440 : pub struct Timeline {
441 : pub ttid: TenantTimelineId,
442 : pub remote_path: RemotePath,
443 :
444 : /// Used to broadcast commit_lsn updates to all background jobs.
445 : commit_lsn_watch_tx: watch::Sender<Lsn>,
446 : commit_lsn_watch_rx: watch::Receiver<Lsn>,
447 :
448 : /// Broadcasts (current term, flush_lsn) updates, walsender is interested in
449 : /// them when sending in recovery mode (to walproposer or peers). Note: this
450 : /// is just a notification, WAL reading should always done with lock held as
451 : /// term can change otherwise.
452 : term_flush_lsn_watch_tx: watch::Sender<TermLsn>,
453 : term_flush_lsn_watch_rx: watch::Receiver<TermLsn>,
454 :
455 : /// Broadcasts shared state updates.
456 : shared_state_version_tx: watch::Sender<usize>,
457 : shared_state_version_rx: watch::Receiver<usize>,
458 :
459 : /// Safekeeper and other state, that should remain consistent and
460 : /// synchronized with the disk. This is tokio mutex as we write WAL to disk
461 : /// while holding it, ensuring that consensus checks are in order.
462 : mutex: RwLock<SharedState>,
463 : walsenders: Arc<WalSenders>,
464 : walreceivers: Arc<WalReceivers>,
465 : timeline_dir: Utf8PathBuf,
466 : manager_ctl: ManagerCtl,
467 :
468 : /// Delete/cancel will trigger this, background tasks should drop out as soon as it fires
469 : pub(crate) cancel: CancellationToken,
470 :
471 : // timeline_manager controlled state
472 : pub(crate) broker_active: AtomicBool,
473 : pub(crate) wal_backup_active: AtomicBool,
474 : pub(crate) last_removed_segno: AtomicU64,
475 : pub(crate) mgr_status: AtomicStatus,
476 : }
477 :
478 : impl Timeline {
479 : /// Load existing timeline from disk.
480 0 : pub fn load_timeline(conf: &SafeKeeperConf, ttid: TenantTimelineId) -> Result<Arc<Timeline>> {
481 0 : let _enter = info_span!("load_timeline", timeline = %ttid.timeline_id).entered();
482 :
483 0 : let shared_state = SharedState::restore(conf, &ttid)?;
484 0 : let (commit_lsn_watch_tx, commit_lsn_watch_rx) =
485 0 : watch::channel(shared_state.sk.state().commit_lsn);
486 0 : let (term_flush_lsn_watch_tx, term_flush_lsn_watch_rx) = watch::channel(TermLsn::from((
487 0 : shared_state.sk.last_log_term(),
488 0 : shared_state.sk.flush_lsn(),
489 0 : )));
490 0 : let (shared_state_version_tx, shared_state_version_rx) = watch::channel(0);
491 0 :
492 0 : let walreceivers = WalReceivers::new();
493 0 : let remote_path = remote_timeline_path(&ttid)?;
494 0 : Ok(Arc::new(Timeline {
495 0 : ttid,
496 0 : remote_path,
497 0 : commit_lsn_watch_tx,
498 0 : commit_lsn_watch_rx,
499 0 : term_flush_lsn_watch_tx,
500 0 : term_flush_lsn_watch_rx,
501 0 : shared_state_version_tx,
502 0 : shared_state_version_rx,
503 0 : mutex: RwLock::new(shared_state),
504 0 : walsenders: WalSenders::new(walreceivers.clone()),
505 0 : walreceivers,
506 0 : cancel: CancellationToken::default(),
507 0 : timeline_dir: get_timeline_dir(conf, &ttid),
508 0 : manager_ctl: ManagerCtl::new(),
509 0 : broker_active: AtomicBool::new(false),
510 0 : wal_backup_active: AtomicBool::new(false),
511 0 : last_removed_segno: AtomicU64::new(0),
512 0 : mgr_status: AtomicStatus::new(),
513 0 : }))
514 0 : }
515 :
516 : /// Initialize fresh timeline on disk and start background tasks. If init
517 : /// fails, timeline is cancelled and cannot be used anymore.
518 : ///
519 : /// Init is transactional, so if it fails, created files will be deleted,
520 : /// and state on disk should remain unchanged.
521 0 : pub async fn init_new(
522 0 : self: &Arc<Timeline>,
523 0 : shared_state: &mut WriteGuardSharedState<'_>,
524 0 : conf: &SafeKeeperConf,
525 0 : broker_active_set: Arc<TimelinesSet>,
526 0 : partial_backup_rate_limiter: RateLimiter,
527 0 : ) -> Result<()> {
528 0 : match fs::metadata(&self.timeline_dir).await {
529 : Ok(_) => {
530 : // Timeline directory exists on disk, we should leave state unchanged
531 : // and return error.
532 0 : bail!(TimelineError::Invalid(self.ttid));
533 : }
534 0 : Err(e) if e.kind() == std::io::ErrorKind::NotFound => {}
535 0 : Err(e) => {
536 0 : return Err(e.into());
537 : }
538 : }
539 :
540 : // Create timeline directory.
541 0 : fs::create_dir_all(&self.timeline_dir).await?;
542 :
543 : // Write timeline to disk and start background tasks.
544 0 : if let Err(e) = shared_state.sk.state_mut().flush().await {
545 : // Bootstrap failed, cancel timeline and remove timeline directory.
546 0 : self.cancel(shared_state);
547 :
548 0 : if let Err(fs_err) = fs::remove_dir_all(&self.timeline_dir).await {
549 0 : warn!(
550 0 : "failed to remove timeline {} directory after bootstrap failure: {}",
551 0 : self.ttid, fs_err
552 : );
553 0 : }
554 :
555 0 : return Err(e);
556 0 : }
557 0 : self.bootstrap(
558 0 : shared_state,
559 0 : conf,
560 0 : broker_active_set,
561 0 : partial_backup_rate_limiter,
562 0 : );
563 0 : Ok(())
564 0 : }
565 :
566 : /// Bootstrap new or existing timeline starting background tasks.
567 0 : pub fn bootstrap(
568 0 : self: &Arc<Timeline>,
569 0 : _shared_state: &mut WriteGuardSharedState<'_>,
570 0 : conf: &SafeKeeperConf,
571 0 : broker_active_set: Arc<TimelinesSet>,
572 0 : partial_backup_rate_limiter: RateLimiter,
573 0 : ) {
574 0 : let (tx, rx) = self.manager_ctl.bootstrap_manager();
575 0 :
576 0 : // Start manager task which will monitor timeline state and update
577 0 : // background tasks.
578 0 : tokio::spawn(timeline_manager::main_task(
579 0 : ManagerTimeline { tli: self.clone() },
580 0 : conf.clone(),
581 0 : broker_active_set,
582 0 : tx,
583 0 : rx,
584 0 : partial_backup_rate_limiter,
585 0 : ));
586 0 : }
587 :
588 : /// Delete timeline from disk completely, by removing timeline directory.
589 : /// Background timeline activities will stop eventually.
590 : ///
591 : /// Also deletes WAL in s3. Might fail if e.g. s3 is unavailable, but
592 : /// deletion API endpoint is retriable.
593 0 : pub async fn delete(
594 0 : &self,
595 0 : shared_state: &mut WriteGuardSharedState<'_>,
596 0 : only_local: bool,
597 0 : ) -> Result<bool> {
598 0 : self.cancel(shared_state);
599 0 :
600 0 : // TODO: It's better to wait for s3 offloader termination before
601 0 : // removing data from s3. Though since s3 doesn't have transactions it
602 0 : // still wouldn't guarantee absense of data after removal.
603 0 : let conf = GlobalTimelines::get_global_config();
604 0 : if !only_local && conf.is_wal_backup_enabled() {
605 : // Note: we concurrently delete remote storage data from multiple
606 : // safekeepers. That's ok, s3 replies 200 if object doesn't exist and we
607 : // do some retries anyway.
608 0 : wal_backup::delete_timeline(&self.ttid).await?;
609 0 : }
610 0 : let dir_existed = delete_dir(&self.timeline_dir).await?;
611 0 : Ok(dir_existed)
612 0 : }
613 :
614 : /// Cancel timeline to prevent further usage. Background tasks will stop
615 : /// eventually after receiving cancellation signal.
616 0 : fn cancel(&self, shared_state: &mut WriteGuardSharedState<'_>) {
617 0 : info!("timeline {} is cancelled", self.ttid);
618 0 : self.cancel.cancel();
619 0 : // Close associated FDs. Nobody will be able to touch timeline data once
620 0 : // it is cancelled, so WAL storage won't be opened again.
621 0 : shared_state.sk.close_wal_store();
622 0 : }
623 :
624 : /// Returns if timeline is cancelled.
625 0 : pub fn is_cancelled(&self) -> bool {
626 0 : self.cancel.is_cancelled()
627 0 : }
628 :
629 : /// Take a writing mutual exclusive lock on timeline shared_state.
630 0 : pub async fn write_shared_state<'a>(self: &'a Arc<Self>) -> WriteGuardSharedState<'a> {
631 0 : WriteGuardSharedState::new(self.clone(), self.mutex.write().await)
632 0 : }
633 :
634 0 : pub async fn read_shared_state(&self) -> ReadGuardSharedState {
635 0 : self.mutex.read().await
636 0 : }
637 :
638 : /// Returns commit_lsn watch channel.
639 0 : pub fn get_commit_lsn_watch_rx(&self) -> watch::Receiver<Lsn> {
640 0 : self.commit_lsn_watch_rx.clone()
641 0 : }
642 :
643 : /// Returns term_flush_lsn watch channel.
644 0 : pub fn get_term_flush_lsn_watch_rx(&self) -> watch::Receiver<TermLsn> {
645 0 : self.term_flush_lsn_watch_rx.clone()
646 0 : }
647 :
648 : /// Returns watch channel for SharedState update version.
649 0 : pub fn get_state_version_rx(&self) -> watch::Receiver<usize> {
650 0 : self.shared_state_version_rx.clone()
651 0 : }
652 :
653 : /// Returns wal_seg_size.
654 0 : pub async fn get_wal_seg_size(&self) -> usize {
655 0 : self.read_shared_state().await.get_wal_seg_size()
656 0 : }
657 :
658 : /// Returns state of the timeline.
659 0 : pub async fn get_state(&self) -> (TimelineMemState, TimelinePersistentState) {
660 0 : let state = self.read_shared_state().await;
661 0 : (
662 0 : state.sk.state().inmem.clone(),
663 0 : TimelinePersistentState::clone(state.sk.state()),
664 0 : )
665 0 : }
666 :
667 : /// Returns latest backup_lsn.
668 0 : pub async fn get_wal_backup_lsn(&self) -> Lsn {
669 0 : self.read_shared_state().await.sk.state().inmem.backup_lsn
670 0 : }
671 :
672 : /// Sets backup_lsn to the given value.
673 0 : pub async fn set_wal_backup_lsn(self: &Arc<Self>, backup_lsn: Lsn) -> Result<()> {
674 0 : if self.is_cancelled() {
675 0 : bail!(TimelineError::Cancelled(self.ttid));
676 0 : }
677 :
678 0 : let mut state = self.write_shared_state().await;
679 0 : state.sk.state_mut().inmem.backup_lsn = max(state.sk.state().inmem.backup_lsn, backup_lsn);
680 0 : // we should check whether to shut down offloader, but this will be done
681 0 : // soon by peer communication anyway.
682 0 : Ok(())
683 0 : }
684 :
685 : /// Get safekeeper info for broadcasting to broker and other peers.
686 0 : pub async fn get_safekeeper_info(&self, conf: &SafeKeeperConf) -> SafekeeperTimelineInfo {
687 0 : let standby_apply_lsn = self.walsenders.get_hotstandby().reply.apply_lsn;
688 0 : let shared_state = self.read_shared_state().await;
689 0 : shared_state.get_safekeeper_info(&self.ttid, conf, standby_apply_lsn)
690 0 : }
691 :
692 : /// Update timeline state with peer safekeeper data.
693 0 : pub async fn record_safekeeper_info(
694 0 : self: &Arc<Self>,
695 0 : sk_info: SafekeeperTimelineInfo,
696 0 : ) -> Result<()> {
697 : {
698 0 : let mut shared_state = self.write_shared_state().await;
699 0 : shared_state.sk.record_safekeeper_info(&sk_info).await?;
700 0 : let peer_info = PeerInfo::from_sk_info(&sk_info, Instant::now());
701 0 : shared_state.peers_info.upsert(&peer_info);
702 0 : }
703 0 : Ok(())
704 0 : }
705 :
706 0 : pub async fn get_peers(&self, conf: &SafeKeeperConf) -> Vec<PeerInfo> {
707 0 : let shared_state = self.read_shared_state().await;
708 0 : shared_state.get_peers(conf.heartbeat_timeout)
709 0 : }
710 :
711 0 : pub fn get_walsenders(&self) -> &Arc<WalSenders> {
712 0 : &self.walsenders
713 0 : }
714 :
715 0 : pub fn get_walreceivers(&self) -> &Arc<WalReceivers> {
716 0 : &self.walreceivers
717 0 : }
718 :
719 : /// Returns flush_lsn.
720 0 : pub async fn get_flush_lsn(&self) -> Lsn {
721 0 : self.read_shared_state().await.sk.flush_lsn()
722 0 : }
723 :
724 : /// Gather timeline data for metrics.
725 0 : pub async fn info_for_metrics(&self) -> Option<FullTimelineInfo> {
726 0 : if self.is_cancelled() {
727 0 : return None;
728 0 : }
729 0 :
730 0 : let (ps_feedback_count, last_ps_feedback) = self.walsenders.get_ps_feedback_stats();
731 0 : let state = self.read_shared_state().await;
732 0 : Some(FullTimelineInfo {
733 0 : ttid: self.ttid,
734 0 : ps_feedback_count,
735 0 : last_ps_feedback,
736 0 : wal_backup_active: self.wal_backup_active.load(Ordering::Relaxed),
737 0 : timeline_is_active: self.broker_active.load(Ordering::Relaxed),
738 0 : num_computes: self.walreceivers.get_num() as u32,
739 0 : last_removed_segno: self.last_removed_segno.load(Ordering::Relaxed),
740 0 : epoch_start_lsn: state.sk.term_start_lsn(),
741 0 : mem_state: state.sk.state().inmem.clone(),
742 0 : persisted_state: TimelinePersistentState::clone(state.sk.state()),
743 0 : flush_lsn: state.sk.flush_lsn(),
744 0 : wal_storage: state.sk.wal_storage_metrics(),
745 0 : })
746 0 : }
747 :
748 : /// Returns in-memory timeline state to build a full debug dump.
749 0 : pub async fn memory_dump(&self) -> debug_dump::Memory {
750 0 : let state = self.read_shared_state().await;
751 :
752 0 : let (write_lsn, write_record_lsn, flush_lsn, file_open) =
753 0 : state.sk.wal_storage_internal_state();
754 0 :
755 0 : debug_dump::Memory {
756 0 : is_cancelled: self.is_cancelled(),
757 0 : peers_info_len: state.peers_info.0.len(),
758 0 : walsenders: self.walsenders.get_all(),
759 0 : wal_backup_active: self.wal_backup_active.load(Ordering::Relaxed),
760 0 : active: self.broker_active.load(Ordering::Relaxed),
761 0 : num_computes: self.walreceivers.get_num() as u32,
762 0 : last_removed_segno: self.last_removed_segno.load(Ordering::Relaxed),
763 0 : epoch_start_lsn: state.sk.term_start_lsn(),
764 0 : mem_state: state.sk.state().inmem.clone(),
765 0 : mgr_status: self.mgr_status.get(),
766 0 : write_lsn,
767 0 : write_record_lsn,
768 0 : flush_lsn,
769 0 : file_open,
770 0 : }
771 0 : }
772 :
773 : /// Apply a function to the control file state and persist it.
774 0 : pub async fn map_control_file<T>(
775 0 : self: &Arc<Self>,
776 0 : f: impl FnOnce(&mut TimelinePersistentState) -> Result<T>,
777 0 : ) -> Result<T> {
778 0 : let mut state = self.write_shared_state().await;
779 0 : let mut persistent_state = state.sk.state_mut().start_change();
780 : // If f returns error, we abort the change and don't persist anything.
781 0 : let res = f(&mut persistent_state)?;
782 : // If persisting fails, we abort the change and return error.
783 0 : state
784 0 : .sk
785 0 : .state_mut()
786 0 : .finish_change(&persistent_state)
787 0 : .await?;
788 0 : Ok(res)
789 0 : }
790 :
791 0 : pub async fn term_bump(self: &Arc<Self>, to: Option<Term>) -> Result<TimelineTermBumpResponse> {
792 0 : let mut state = self.write_shared_state().await;
793 0 : state.sk.term_bump(to).await
794 0 : }
795 :
796 : /// Get the timeline guard for reading/writing WAL files.
797 : /// If WAL files are not present on disk (evicted), they will be automatically
798 : /// downloaded from remote storage. This is done in the manager task, which is
799 : /// responsible for issuing all guards.
800 : ///
801 : /// NB: don't use this function from timeline_manager, it will deadlock.
802 : /// NB: don't use this function while holding shared_state lock.
803 0 : pub async fn wal_residence_guard(self: &Arc<Self>) -> Result<WalResidentTimeline> {
804 0 : if self.is_cancelled() {
805 0 : bail!(TimelineError::Cancelled(self.ttid));
806 0 : }
807 0 :
808 0 : debug!("requesting WalResidentTimeline guard");
809 0 : let started_at = Instant::now();
810 0 : let status_before = self.mgr_status.get();
811 :
812 : // Wait 30 seconds for the guard to be acquired. It can time out if someone is
813 : // holding the lock (e.g. during `SafeKeeper::process_msg()`) or manager task
814 : // is stuck.
815 0 : let res = tokio::time::timeout_at(
816 0 : started_at + Duration::from_secs(30),
817 0 : self.manager_ctl.wal_residence_guard(),
818 0 : )
819 0 : .await;
820 :
821 0 : let guard = match res {
822 0 : Ok(Ok(guard)) => {
823 0 : let finished_at = Instant::now();
824 0 : let elapsed = finished_at - started_at;
825 0 : MISC_OPERATION_SECONDS
826 0 : .with_label_values(&["wal_residence_guard"])
827 0 : .observe(elapsed.as_secs_f64());
828 0 :
829 0 : guard
830 : }
831 0 : Ok(Err(e)) => {
832 0 : warn!(
833 0 : "error while acquiring WalResidentTimeline guard, statuses {:?} => {:?}",
834 0 : status_before,
835 0 : self.mgr_status.get()
836 : );
837 0 : return Err(e);
838 : }
839 : Err(_) => {
840 0 : warn!(
841 0 : "timeout while acquiring WalResidentTimeline guard, statuses {:?} => {:?}",
842 0 : status_before,
843 0 : self.mgr_status.get()
844 : );
845 0 : anyhow::bail!("timeout while acquiring WalResidentTimeline guard");
846 : }
847 : };
848 :
849 0 : Ok(WalResidentTimeline::new(self.clone(), guard))
850 0 : }
851 :
852 0 : pub async fn backup_partial_reset(self: &Arc<Self>) -> Result<Vec<String>> {
853 0 : self.manager_ctl.backup_partial_reset().await
854 0 : }
855 : }
856 :
857 : /// This is a guard that allows to read/write disk timeline state.
858 : /// All tasks that are trying to read/write WAL from disk should use this guard.
859 : pub struct WalResidentTimeline {
860 : pub tli: Arc<Timeline>,
861 : _guard: ResidenceGuard,
862 : }
863 :
864 : impl WalResidentTimeline {
865 0 : pub fn new(tli: Arc<Timeline>, _guard: ResidenceGuard) -> Self {
866 0 : WalResidentTimeline { tli, _guard }
867 0 : }
868 : }
869 :
870 : impl Deref for WalResidentTimeline {
871 : type Target = Arc<Timeline>;
872 :
873 0 : fn deref(&self) -> &Self::Target {
874 0 : &self.tli
875 0 : }
876 : }
877 :
878 : impl WalResidentTimeline {
879 : /// Returns true if walsender should stop sending WAL to pageserver. We
880 : /// terminate it if remote_consistent_lsn reached commit_lsn and there is no
881 : /// computes. While there might be nothing to stream already, we learn about
882 : /// remote_consistent_lsn update through replication feedback, and we want
883 : /// to stop pushing to the broker if pageserver is fully caughtup.
884 0 : pub async fn should_walsender_stop(&self, reported_remote_consistent_lsn: Lsn) -> bool {
885 0 : if self.is_cancelled() {
886 0 : return true;
887 0 : }
888 0 : let shared_state = self.read_shared_state().await;
889 0 : if self.walreceivers.get_num() == 0 {
890 0 : return shared_state.sk.state().inmem.commit_lsn == Lsn(0) || // no data at all yet
891 0 : reported_remote_consistent_lsn >= shared_state.sk.state().inmem.commit_lsn;
892 0 : }
893 0 : false
894 0 : }
895 :
896 : /// Ensure that current term is t, erroring otherwise, and lock the state.
897 0 : pub async fn acquire_term(&self, t: Term) -> Result<ReadGuardSharedState> {
898 0 : let ss = self.read_shared_state().await;
899 0 : if ss.sk.state().acceptor_state.term != t {
900 0 : bail!(
901 0 : "failed to acquire term {}, current term {}",
902 0 : t,
903 0 : ss.sk.state().acceptor_state.term
904 0 : );
905 0 : }
906 0 : Ok(ss)
907 0 : }
908 :
909 : /// Pass arrived message to the safekeeper.
910 0 : pub async fn process_msg(
911 0 : &self,
912 0 : msg: &ProposerAcceptorMessage,
913 0 : ) -> Result<Option<AcceptorProposerMessage>> {
914 0 : if self.is_cancelled() {
915 0 : bail!(TimelineError::Cancelled(self.ttid));
916 0 : }
917 :
918 : let mut rmsg: Option<AcceptorProposerMessage>;
919 : {
920 0 : let mut shared_state = self.write_shared_state().await;
921 0 : rmsg = shared_state.sk.safekeeper().process_msg(msg).await?;
922 :
923 : // if this is AppendResponse, fill in proper hot standby feedback.
924 0 : if let Some(AcceptorProposerMessage::AppendResponse(ref mut resp)) = rmsg {
925 0 : resp.hs_feedback = self.walsenders.get_hotstandby().hs_feedback;
926 0 : }
927 : }
928 0 : Ok(rmsg)
929 0 : }
930 :
931 0 : pub async fn get_walreader(&self, start_lsn: Lsn) -> Result<WalReader> {
932 0 : let (_, persisted_state) = self.get_state().await;
933 0 : let enable_remote_read = GlobalTimelines::get_global_config().is_wal_backup_enabled();
934 0 :
935 0 : WalReader::new(
936 0 : &self.ttid,
937 0 : self.timeline_dir.clone(),
938 0 : &persisted_state,
939 0 : start_lsn,
940 0 : enable_remote_read,
941 0 : )
942 0 : }
943 :
944 0 : pub fn get_timeline_dir(&self) -> Utf8PathBuf {
945 0 : self.timeline_dir.clone()
946 0 : }
947 :
948 : /// Update in memory remote consistent lsn.
949 0 : pub async fn update_remote_consistent_lsn(&self, candidate: Lsn) {
950 0 : let mut shared_state = self.write_shared_state().await;
951 0 : shared_state.sk.state_mut().inmem.remote_consistent_lsn = max(
952 0 : shared_state.sk.state().inmem.remote_consistent_lsn,
953 0 : candidate,
954 0 : );
955 0 : }
956 : }
957 :
958 : /// This struct contains methods that are used by timeline manager task.
959 : pub(crate) struct ManagerTimeline {
960 : pub(crate) tli: Arc<Timeline>,
961 : }
962 :
963 : impl Deref for ManagerTimeline {
964 : type Target = Arc<Timeline>;
965 :
966 0 : fn deref(&self) -> &Self::Target {
967 0 : &self.tli
968 0 : }
969 : }
970 :
971 : impl ManagerTimeline {
972 0 : pub(crate) fn timeline_dir(&self) -> &Utf8PathBuf {
973 0 : &self.tli.timeline_dir
974 0 : }
975 :
976 : /// Manager requests this state on startup.
977 0 : pub(crate) async fn bootstrap_mgr(&self) -> (bool, Option<PartialRemoteSegment>) {
978 0 : let shared_state = self.read_shared_state().await;
979 0 : let is_offloaded = matches!(
980 0 : shared_state.sk.state().eviction_state,
981 : EvictionState::Offloaded(_)
982 : );
983 0 : let partial_backup_uploaded = shared_state.sk.state().partial_backup.uploaded_segment();
984 0 :
985 0 : (is_offloaded, partial_backup_uploaded)
986 0 : }
987 :
988 : /// Try to switch state Present->Offloaded.
989 0 : pub(crate) async fn switch_to_offloaded(
990 0 : &self,
991 0 : partial: &PartialRemoteSegment,
992 0 : ) -> anyhow::Result<()> {
993 0 : let mut shared = self.write_shared_state().await;
994 :
995 : // updating control file
996 0 : let mut pstate = shared.sk.state_mut().start_change();
997 :
998 0 : if !matches!(pstate.eviction_state, EvictionState::Present) {
999 0 : bail!(
1000 0 : "cannot switch to offloaded state, current state is {:?}",
1001 0 : pstate.eviction_state
1002 0 : );
1003 0 : }
1004 0 :
1005 0 : if partial.flush_lsn != shared.sk.flush_lsn() {
1006 0 : bail!(
1007 0 : "flush_lsn mismatch in partial backup, expected {}, got {}",
1008 0 : shared.sk.flush_lsn(),
1009 0 : partial.flush_lsn
1010 0 : );
1011 0 : }
1012 0 :
1013 0 : if partial.commit_lsn != pstate.commit_lsn {
1014 0 : bail!(
1015 0 : "commit_lsn mismatch in partial backup, expected {}, got {}",
1016 0 : pstate.commit_lsn,
1017 0 : partial.commit_lsn
1018 0 : );
1019 0 : }
1020 0 :
1021 0 : if partial.term != shared.sk.last_log_term() {
1022 0 : bail!(
1023 0 : "term mismatch in partial backup, expected {}, got {}",
1024 0 : shared.sk.last_log_term(),
1025 0 : partial.term
1026 0 : );
1027 0 : }
1028 0 :
1029 0 : pstate.eviction_state = EvictionState::Offloaded(shared.sk.flush_lsn());
1030 0 : shared.sk.state_mut().finish_change(&pstate).await?;
1031 : // control file is now switched to Offloaded state
1032 :
1033 : // now we can switch shared.sk to Offloaded, shouldn't fail
1034 0 : let prev_sk = std::mem::replace(&mut shared.sk, StateSK::Empty);
1035 0 : let cfile_state = prev_sk.take_state();
1036 0 : shared.sk = StateSK::Offloaded(Box::new(cfile_state));
1037 0 :
1038 0 : Ok(())
1039 0 : }
1040 :
1041 : /// Try to switch state Offloaded->Present.
1042 0 : pub(crate) async fn switch_to_present(&self) -> anyhow::Result<()> {
1043 0 : let conf = GlobalTimelines::get_global_config();
1044 0 : let mut shared = self.write_shared_state().await;
1045 :
1046 : // trying to restore WAL storage
1047 0 : let wal_store = wal_storage::PhysicalStorage::new(
1048 0 : &self.ttid,
1049 0 : self.timeline_dir.clone(),
1050 0 : &conf,
1051 0 : shared.sk.state(),
1052 0 : )?;
1053 :
1054 : // updating control file
1055 0 : let mut pstate = shared.sk.state_mut().start_change();
1056 :
1057 0 : if !matches!(pstate.eviction_state, EvictionState::Offloaded(_)) {
1058 0 : bail!(
1059 0 : "cannot switch to present state, current state is {:?}",
1060 0 : pstate.eviction_state
1061 0 : );
1062 0 : }
1063 0 :
1064 0 : if wal_store.flush_lsn() != shared.sk.flush_lsn() {
1065 0 : bail!(
1066 0 : "flush_lsn mismatch in restored WAL, expected {}, got {}",
1067 0 : shared.sk.flush_lsn(),
1068 0 : wal_store.flush_lsn()
1069 0 : );
1070 0 : }
1071 0 :
1072 0 : pstate.eviction_state = EvictionState::Present;
1073 0 : shared.sk.state_mut().finish_change(&pstate).await?;
1074 :
1075 : // now we can switch shared.sk to Present, shouldn't fail
1076 0 : let prev_sk = std::mem::replace(&mut shared.sk, StateSK::Empty);
1077 0 : let cfile_state = prev_sk.take_state();
1078 0 : shared.sk = StateSK::Loaded(SafeKeeper::new(cfile_state, wal_store, conf.my_id)?);
1079 :
1080 0 : Ok(())
1081 0 : }
1082 :
1083 : /// Update current manager state, useful for debugging manager deadlocks.
1084 0 : pub(crate) fn set_status(&self, status: timeline_manager::Status) {
1085 0 : self.mgr_status.store(status, Ordering::Relaxed);
1086 0 : }
1087 : }
1088 :
1089 : /// Deletes directory and it's contents. Returns false if directory does not exist.
1090 0 : async fn delete_dir(path: &Utf8PathBuf) -> Result<bool> {
1091 0 : match fs::remove_dir_all(path).await {
1092 0 : Ok(_) => Ok(true),
1093 0 : Err(e) if e.kind() == std::io::ErrorKind::NotFound => Ok(false),
1094 0 : Err(e) => Err(e.into()),
1095 : }
1096 0 : }
1097 :
1098 : /// Get a path to the tenant directory. If you just need to get a timeline directory,
1099 : /// use WalResidentTimeline::get_timeline_dir instead.
1100 7 : pub(crate) fn get_tenant_dir(conf: &SafeKeeperConf, tenant_id: &TenantId) -> Utf8PathBuf {
1101 7 : conf.workdir.join(tenant_id.to_string())
1102 7 : }
1103 :
1104 : /// Get a path to the timeline directory. If you need to read WAL files from disk,
1105 : /// use WalResidentTimeline::get_timeline_dir instead. This function does not check
1106 : /// timeline eviction status and WAL files might not be present on disk.
1107 7 : pub(crate) fn get_timeline_dir(conf: &SafeKeeperConf, ttid: &TenantTimelineId) -> Utf8PathBuf {
1108 7 : get_tenant_dir(conf, &ttid.tenant_id).join(ttid.timeline_id.to_string())
1109 7 : }
|