Line data Source code
1 : //!
2 : //! WAL redo. This service runs PostgreSQL in a special wal_redo mode
3 : //! to apply given WAL records over an old page image and return new
4 : //! page image.
5 : //!
6 : //! We rely on Postgres to perform WAL redo for us. We launch a
7 : //! postgres process in special "wal redo" mode that's similar to
8 : //! single-user mode. We then pass the previous page image, if any,
9 : //! and all the WAL records we want to apply, to the postgres
10 : //! process. Then we get the page image back. Communication with the
11 : //! postgres process happens via stdin/stdout
12 : //!
13 : //! See pgxn/neon_walredo/walredoproc.c for the other side of
14 : //! this communication.
15 : //!
16 : //! The Postgres process is assumed to be secure against malicious WAL
17 : //! records. It achieves it by dropping privileges before replaying
18 : //! any WAL records, so that even if an attacker hijacks the Postgres
19 : //! process, he cannot escape out of it.
20 :
21 : /// Process lifecycle and abstracction for the IPC protocol.
22 : mod process;
23 :
24 : /// Code to apply [`NeonWalRecord`]s.
25 : pub(crate) mod apply_neon;
26 :
27 : use crate::config::PageServerConf;
28 : use crate::metrics::{
29 : WAL_REDO_BYTES_HISTOGRAM, WAL_REDO_PROCESS_LAUNCH_DURATION_HISTOGRAM,
30 : WAL_REDO_RECORDS_HISTOGRAM, WAL_REDO_TIME,
31 : };
32 : use crate::repository::Key;
33 : use crate::walrecord::NeonWalRecord;
34 : use anyhow::Context;
35 : use bytes::{Bytes, BytesMut};
36 : use pageserver_api::models::{WalRedoManagerProcessStatus, WalRedoManagerStatus};
37 : use pageserver_api::shard::TenantShardId;
38 : use std::sync::Arc;
39 : use std::time::Duration;
40 : use std::time::Instant;
41 : use tracing::*;
42 : use utils::lsn::Lsn;
43 : use utils::sync::heavier_once_cell;
44 :
45 : ///
46 : /// This is the real implementation that uses a Postgres process to
47 : /// perform WAL replay. Only one thread can use the process at a time,
48 : /// that is controlled by the Mutex. In the future, we might want to
49 : /// launch a pool of processes to allow concurrent replay of multiple
50 : /// records.
51 : ///
52 : pub struct PostgresRedoManager {
53 : tenant_shard_id: TenantShardId,
54 : conf: &'static PageServerConf,
55 : last_redo_at: std::sync::Mutex<Option<Instant>>,
56 : /// The current [`process::WalRedoProcess`] that is used by new redo requests.
57 : /// We use [`heavier_once_cell`] for coalescing the spawning, but the redo
58 : /// requests don't use the [`heavier_once_cell::Guard`] to keep ahold of the
59 : /// their process object; we use [`Arc::clone`] for that.
60 : /// This is primarily because earlier implementations that didn't use [`heavier_once_cell`]
61 : /// had that behavior; it's probably unnecessary.
62 : /// The only merit of it is that if one walredo process encounters an error,
63 : /// it can take it out of rotation (= using [`heavier_once_cell::Guard::take_and_deinit`].
64 : /// and retry redo, thereby starting the new process, while other redo tasks might
65 : /// still be using the old redo process. But, those other tasks will most likely
66 : /// encounter an error as well, and errors are an unexpected condition anyway.
67 : /// So, probably we could get rid of the `Arc` in the future.
68 : redo_process: heavier_once_cell::OnceCell<Arc<process::WalRedoProcess>>,
69 : }
70 :
71 : ///
72 : /// Public interface of WAL redo manager
73 : ///
74 : impl PostgresRedoManager {
75 : ///
76 : /// Request the WAL redo manager to apply some WAL records
77 : ///
78 : /// The WAL redo is handled by a separate thread, so this just sends a request
79 : /// to the thread and waits for response.
80 : ///
81 : /// # Cancel-Safety
82 : ///
83 : /// This method is cancellation-safe.
84 6 : pub async fn request_redo(
85 6 : &self,
86 6 : key: Key,
87 6 : lsn: Lsn,
88 6 : base_img: Option<(Lsn, Bytes)>,
89 6 : records: Vec<(Lsn, NeonWalRecord)>,
90 6 : pg_version: u32,
91 6 : ) -> anyhow::Result<Bytes> {
92 6 : if records.is_empty() {
93 0 : anyhow::bail!("invalid WAL redo request with no records");
94 6 : }
95 6 :
96 6 : let base_img_lsn = base_img.as_ref().map(|p| p.0).unwrap_or(Lsn::INVALID);
97 6 : let mut img = base_img.map(|p| p.1);
98 6 : let mut batch_neon = apply_neon::can_apply_in_neon(&records[0].1);
99 6 : let mut batch_start = 0;
100 6 : for (i, record) in records.iter().enumerate().skip(1) {
101 6 : let rec_neon = apply_neon::can_apply_in_neon(&record.1);
102 6 :
103 6 : if rec_neon != batch_neon {
104 0 : let result = if batch_neon {
105 0 : self.apply_batch_neon(key, lsn, img, &records[batch_start..i])
106 : } else {
107 0 : self.apply_batch_postgres(
108 0 : key,
109 0 : lsn,
110 0 : img,
111 0 : base_img_lsn,
112 0 : &records[batch_start..i],
113 0 : self.conf.wal_redo_timeout,
114 0 : pg_version,
115 0 : )
116 0 : .await
117 : };
118 0 : img = Some(result?);
119 :
120 0 : batch_neon = rec_neon;
121 0 : batch_start = i;
122 6 : }
123 : }
124 : // last batch
125 6 : if batch_neon {
126 0 : self.apply_batch_neon(key, lsn, img, &records[batch_start..])
127 : } else {
128 6 : self.apply_batch_postgres(
129 6 : key,
130 6 : lsn,
131 6 : img,
132 6 : base_img_lsn,
133 6 : &records[batch_start..],
134 6 : self.conf.wal_redo_timeout,
135 6 : pg_version,
136 6 : )
137 16 : .await
138 : }
139 6 : }
140 :
141 0 : pub fn status(&self) -> WalRedoManagerStatus {
142 0 : WalRedoManagerStatus {
143 0 : last_redo_at: {
144 0 : let at = *self.last_redo_at.lock().unwrap();
145 0 : at.and_then(|at| {
146 0 : let age = at.elapsed();
147 0 : // map any chrono errors silently to None here
148 0 : chrono::Utc::now().checked_sub_signed(chrono::Duration::from_std(age).ok()?)
149 0 : })
150 0 : },
151 0 : process: self
152 0 : .redo_process
153 0 : .get()
154 0 : .map(|p| WalRedoManagerProcessStatus { pid: p.id() }),
155 0 : }
156 0 : }
157 : }
158 :
159 : impl PostgresRedoManager {
160 : ///
161 : /// Create a new PostgresRedoManager.
162 : ///
163 6 : pub fn new(
164 6 : conf: &'static PageServerConf,
165 6 : tenant_shard_id: TenantShardId,
166 6 : ) -> PostgresRedoManager {
167 6 : // The actual process is launched lazily, on first request.
168 6 : PostgresRedoManager {
169 6 : tenant_shard_id,
170 6 : conf,
171 6 : last_redo_at: std::sync::Mutex::default(),
172 6 : redo_process: heavier_once_cell::OnceCell::default(),
173 6 : }
174 6 : }
175 :
176 : /// This type doesn't have its own background task to check for idleness: we
177 : /// rely on our owner calling this function periodically in its own housekeeping
178 : /// loops.
179 0 : pub(crate) fn maybe_quiesce(&self, idle_timeout: Duration) {
180 0 : if let Ok(g) = self.last_redo_at.try_lock() {
181 0 : if let Some(last_redo_at) = *g {
182 0 : if last_redo_at.elapsed() >= idle_timeout {
183 0 : drop(g);
184 0 : drop(self.redo_process.get().map(|guard| guard.take_and_deinit()));
185 0 : }
186 0 : }
187 0 : }
188 0 : }
189 :
190 : ///
191 : /// Process one request for WAL redo using wal-redo postgres
192 : ///
193 : /// # Cancel-Safety
194 : ///
195 : /// Cancellation safe.
196 : #[allow(clippy::too_many_arguments)]
197 6 : async fn apply_batch_postgres(
198 6 : &self,
199 6 : key: Key,
200 6 : lsn: Lsn,
201 6 : base_img: Option<Bytes>,
202 6 : base_img_lsn: Lsn,
203 6 : records: &[(Lsn, NeonWalRecord)],
204 6 : wal_redo_timeout: Duration,
205 6 : pg_version: u32,
206 6 : ) -> anyhow::Result<Bytes> {
207 6 : *(self.last_redo_at.lock().unwrap()) = Some(Instant::now());
208 :
209 6 : let (rel, blknum) = key.to_rel_block().context("invalid record")?;
210 : const MAX_RETRY_ATTEMPTS: u32 = 1;
211 6 : let mut n_attempts = 0u32;
212 : loop {
213 8 : let proc: Arc<process::WalRedoProcess> =
214 8 : match self.redo_process.get_or_init_detached().await {
215 0 : Ok(guard) => Arc::clone(&guard),
216 8 : Err(permit) => {
217 8 : // don't hold poison_guard, the launch code can bail
218 8 : let start = Instant::now();
219 8 : let proc = Arc::new(
220 8 : process::WalRedoProcess::launch(
221 8 : self.conf,
222 8 : self.tenant_shard_id,
223 8 : pg_version,
224 8 : )
225 8 : .context("launch walredo process")?,
226 : );
227 8 : let duration = start.elapsed();
228 8 : WAL_REDO_PROCESS_LAUNCH_DURATION_HISTOGRAM.observe(duration.as_secs_f64());
229 8 : info!(
230 0 : duration_ms = duration.as_millis(),
231 0 : pid = proc.id(),
232 0 : "launched walredo process"
233 : );
234 8 : self.redo_process.set(Arc::clone(&proc), permit);
235 8 : proc
236 : }
237 : };
238 :
239 8 : let started_at = std::time::Instant::now();
240 :
241 : // Relational WAL records are applied using wal-redo-postgres
242 8 : let result = proc
243 8 : .apply_wal_records(rel, blknum, &base_img, records, wal_redo_timeout)
244 16 : .await
245 8 : .context("apply_wal_records");
246 8 :
247 8 : let duration = started_at.elapsed();
248 8 :
249 8 : let len = records.len();
250 16 : let nbytes = records.iter().fold(0, |acumulator, record| {
251 16 : acumulator
252 16 : + match &record.1 {
253 16 : NeonWalRecord::Postgres { rec, .. } => rec.len(),
254 0 : _ => unreachable!("Only PostgreSQL records are accepted in this batch"),
255 : }
256 16 : });
257 8 :
258 8 : WAL_REDO_TIME.observe(duration.as_secs_f64());
259 8 : WAL_REDO_RECORDS_HISTOGRAM.observe(len as f64);
260 8 : WAL_REDO_BYTES_HISTOGRAM.observe(nbytes as f64);
261 8 :
262 8 : debug!(
263 0 : "postgres applied {} WAL records ({} bytes) in {} us to reconstruct page image at LSN {}",
264 0 : len,
265 0 : nbytes,
266 0 : duration.as_micros(),
267 : lsn
268 : );
269 :
270 : // If something went wrong, don't try to reuse the process. Kill it, and
271 : // next request will launch a new one.
272 8 : if let Err(e) = result.as_ref() {
273 4 : error!(
274 0 : "error applying {} WAL records {}..{} ({} bytes) to key {key}, from base image with LSN {} to reconstruct page image at LSN {} n_attempts={}: {:?}",
275 0 : records.len(),
276 4 : records.first().map(|p| p.0).unwrap_or(Lsn(0)),
277 4 : records.last().map(|p| p.0).unwrap_or(Lsn(0)),
278 : nbytes,
279 : base_img_lsn,
280 : lsn,
281 : n_attempts,
282 : e,
283 : );
284 : // Avoid concurrent callers hitting the same issue by taking `proc` out of the rotation.
285 : // Note that there may be other tasks concurrent with us that also hold `proc`.
286 : // We have to deal with that here.
287 : // Also read the doc comment on field `self.redo_process`.
288 : //
289 : // NB: there may still be other concurrent threads using `proc`.
290 : // The last one will send SIGKILL when the underlying Arc reaches refcount 0.
291 : //
292 : // NB: the drop impl blocks the dropping thread with a wait() system call for
293 : // the child process. In some ways the blocking is actually good: if we
294 : // deferred the waiting into the background / to tokio if we used `tokio::process`,
295 : // it could happen that if walredo always fails immediately, we spawn processes faster
296 : // than we can SIGKILL & `wait` for them to exit. By doing it the way we do here,
297 : // we limit this risk of run-away to at most $num_runtimes * $num_executor_threads.
298 : // This probably needs revisiting at some later point.
299 4 : match self.redo_process.get() {
300 0 : None => (),
301 4 : Some(guard) => {
302 4 : if Arc::ptr_eq(&proc, &*guard) {
303 4 : // We're the first to observe an error from `proc`, it's our job to take it out of rotation.
304 4 : guard.take_and_deinit();
305 4 : } else {
306 0 : // Another task already spawned another redo process (further up in this method)
307 0 : // and put it into `redo_process`. Do nothing, our view of the world is behind.
308 0 : }
309 : }
310 : }
311 : // The last task that does this `drop()` of `proc` will do a blocking `wait()` syscall.
312 4 : drop(proc);
313 4 : } else if n_attempts != 0 {
314 0 : info!(n_attempts, "retried walredo succeeded");
315 4 : }
316 8 : n_attempts += 1;
317 8 : if n_attempts > MAX_RETRY_ATTEMPTS || result.is_ok() {
318 6 : return result;
319 2 : }
320 : }
321 6 : }
322 :
323 : ///
324 : /// Process a batch of WAL records using bespoken Neon code.
325 : ///
326 0 : fn apply_batch_neon(
327 0 : &self,
328 0 : key: Key,
329 0 : lsn: Lsn,
330 0 : base_img: Option<Bytes>,
331 0 : records: &[(Lsn, NeonWalRecord)],
332 0 : ) -> anyhow::Result<Bytes> {
333 0 : let start_time = Instant::now();
334 0 :
335 0 : let mut page = BytesMut::new();
336 0 : if let Some(fpi) = base_img {
337 0 : // If full-page image is provided, then use it...
338 0 : page.extend_from_slice(&fpi[..]);
339 0 : } else {
340 : // All the current WAL record types that we can handle require a base image.
341 0 : anyhow::bail!("invalid neon WAL redo request with no base image");
342 : }
343 :
344 : // Apply all the WAL records in the batch
345 0 : for (record_lsn, record) in records.iter() {
346 0 : self.apply_record_neon(key, &mut page, *record_lsn, record)?;
347 : }
348 : // Success!
349 0 : let duration = start_time.elapsed();
350 0 : // FIXME: using the same metric here creates a bimodal distribution by default, and because
351 0 : // there could be multiple batch sizes this would be N+1 modal.
352 0 : WAL_REDO_TIME.observe(duration.as_secs_f64());
353 0 :
354 0 : debug!(
355 0 : "neon applied {} WAL records in {} us to reconstruct page image at LSN {}",
356 0 : records.len(),
357 0 : duration.as_micros(),
358 : lsn
359 : );
360 :
361 0 : Ok(page.freeze())
362 0 : }
363 :
364 0 : fn apply_record_neon(
365 0 : &self,
366 0 : key: Key,
367 0 : page: &mut BytesMut,
368 0 : record_lsn: Lsn,
369 0 : record: &NeonWalRecord,
370 0 : ) -> anyhow::Result<()> {
371 0 : apply_neon::apply_in_neon(record, record_lsn, key, page)?;
372 :
373 0 : Ok(())
374 0 : }
375 : }
376 :
377 : #[cfg(test)]
378 : mod tests {
379 : use super::PostgresRedoManager;
380 : use crate::repository::Key;
381 : use crate::{config::PageServerConf, walrecord::NeonWalRecord};
382 : use bytes::Bytes;
383 : use pageserver_api::shard::TenantShardId;
384 : use std::str::FromStr;
385 : use tracing::Instrument;
386 : use utils::{id::TenantId, lsn::Lsn};
387 :
388 : #[tokio::test]
389 2 : async fn short_v14_redo() {
390 2 : let expected = std::fs::read("test_data/short_v14_redo.page").unwrap();
391 2 :
392 2 : let h = RedoHarness::new().unwrap();
393 2 :
394 2 : let page = h
395 2 : .manager
396 2 : .request_redo(
397 2 : Key {
398 2 : field1: 0,
399 2 : field2: 1663,
400 2 : field3: 13010,
401 2 : field4: 1259,
402 2 : field5: 0,
403 2 : field6: 0,
404 2 : },
405 2 : Lsn::from_str("0/16E2408").unwrap(),
406 2 : None,
407 2 : short_records(),
408 2 : 14,
409 2 : )
410 2 : .instrument(h.span())
411 4 : .await
412 2 : .unwrap();
413 2 :
414 2 : assert_eq!(&expected, &*page);
415 2 : }
416 :
417 : #[tokio::test]
418 2 : async fn short_v14_fails_for_wrong_key_but_returns_zero_page() {
419 2 : let h = RedoHarness::new().unwrap();
420 2 :
421 2 : let page = h
422 2 : .manager
423 2 : .request_redo(
424 2 : Key {
425 2 : field1: 0,
426 2 : field2: 1663,
427 2 : // key should be 13010
428 2 : field3: 13130,
429 2 : field4: 1259,
430 2 : field5: 0,
431 2 : field6: 0,
432 2 : },
433 2 : Lsn::from_str("0/16E2408").unwrap(),
434 2 : None,
435 2 : short_records(),
436 2 : 14,
437 2 : )
438 2 : .instrument(h.span())
439 4 : .await
440 2 : .unwrap();
441 2 :
442 2 : // TODO: there will be some stderr printout, which is forwarded to tracing that could
443 2 : // perhaps be captured as long as it's in the same thread.
444 2 : assert_eq!(page, crate::ZERO_PAGE);
445 2 : }
446 :
447 : #[tokio::test]
448 2 : async fn test_stderr() {
449 2 : let h = RedoHarness::new().unwrap();
450 2 : h
451 2 : .manager
452 2 : .request_redo(
453 2 : Key::from_i128(0),
454 2 : Lsn::INVALID,
455 2 : None,
456 2 : short_records(),
457 2 : 16, /* 16 currently produces stderr output on startup, which adds a nice extra edge */
458 2 : )
459 2 : .instrument(h.span())
460 8 : .await
461 2 : .unwrap_err();
462 2 : }
463 :
464 : #[allow(clippy::octal_escapes)]
465 6 : fn short_records() -> Vec<(Lsn, NeonWalRecord)> {
466 6 : vec![
467 6 : (
468 6 : Lsn::from_str("0/16A9388").unwrap(),
469 6 : NeonWalRecord::Postgres {
470 6 : will_init: true,
471 6 : rec: Bytes::from_static(b"j\x03\0\0\0\x04\0\0\xe8\x7fj\x01\0\0\0\0\0\n\0\0\xd0\x16\x13Y\0\x10\0\04\x03\xd4\0\x05\x7f\x06\0\0\xd22\0\0\xeb\x04\0\0\0\0\0\0\xff\x03\0\0\0\0\x80\xeca\x01\0\0\x01\0\xd4\0\xa0\x1d\0 \x04 \0\0\0\0/\0\x01\0\xa0\x9dX\x01\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0.\0\x01\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\00\x9f\x9a\x01P\x9e\xb2\x01\0\x04\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x02\0!\0\x01\x08 \xff\xff\xff?\0\0\0\0\0\0@\0\0another_table\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x98\x08\0\0\x02@\0\0\0\0\0\0\n\0\0\0\x02\0\0\0\0@\0\0\0\0\0\0\0\0\0\0\0\0\x80\xbf\0\0\0\0\0\0\0\0\0\0pr\x01\0\0\0\0\0\0\0\0\x01d\0\0\0\0\0\0\x04\0\0\x01\0\0\0\0\0\0\0\x0c\x02\0\0\0\0\0\0\0\0\0\0\0\0\0\0/\0!\x80\x03+ \xff\xff\xff\x7f\0\0\0\0\0\xdf\x04\0\0pg_type\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x0b\0\0\0G\0\0\0\0\0\0\0\n\0\0\0\x02\0\0\0\0\0\0\0\0\0\0\0\x0e\0\0\0\0@\x16D\x0e\0\0\0K\x10\0\0\x01\0pr \0\0\0\0\0\0\0\0\x01n\0\0\0\0\0\xd6\x02\0\0\x01\0\0\0[\x01\0\0\0\0\0\0\0\t\x04\0\0\x02\0\0\0\x01\0\0\0\n\0\0\0\n\0\0\0\x7f\0\0\0\0\0\0\0\n\0\0\0\x02\0\0\0\0\0\0C\x01\0\0\x15\x01\0\0\0\0\0\0\0\0\0\0\0\0\0\0.\0!\x80\x03+ \xff\xff\xff\x7f\0\0\0\0\0;\n\0\0pg_statistic\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x0b\0\0\0\xfd.\0\0\0\0\0\0\n\0\0\0\x02\0\0\0;\n\0\0\0\0\0\0\x13\0\0\0\0\0\xcbC\x13\0\0\0\x18\x0b\0\0\x01\0pr\x1f\0\0\0\0\0\0\0\0\x01n\0\0\0\0\0\xd6\x02\0\0\x01\0\0\0C\x01\0\0\0\0\0\0\0\t\x04\0\0\x01\0\0\0\x01\0\0\0\n\0\0\0\n\0\0\0\x7f\0\0\0\0\0\0\x02\0\x01")
472 6 : }
473 6 : ),
474 6 : (
475 6 : Lsn::from_str("0/16D4080").unwrap(),
476 6 : NeonWalRecord::Postgres {
477 6 : will_init: false,
478 6 : rec: Bytes::from_static(b"\xbc\0\0\0\0\0\0\0h?m\x01\0\0\0\0p\n\0\09\x08\xa3\xea\0 \x8c\0\x7f\x06\0\0\xd22\0\0\xeb\x04\0\0\0\0\0\0\xff\x02\0@\0\0another_table\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x98\x08\0\0\x02@\0\0\0\0\0\0\n\0\0\0\x02\0\0\0\0@\0\0\0\0\0\0\x05\0\0\0\0@zD\x05\0\0\0\0\0\0\0\0\0pr\x01\0\0\0\0\0\0\0\0\x01d\0\0\0\0\0\0\x04\0\0\x01\0\0\0\x02\0")
479 6 : }
480 6 : )
481 6 : ]
482 6 : }
483 :
484 : struct RedoHarness {
485 : // underscored because unused, except for removal at drop
486 : _repo_dir: camino_tempfile::Utf8TempDir,
487 : manager: PostgresRedoManager,
488 : tenant_shard_id: TenantShardId,
489 : }
490 :
491 : impl RedoHarness {
492 6 : fn new() -> anyhow::Result<Self> {
493 6 : crate::tenant::harness::setup_logging();
494 :
495 6 : let repo_dir = camino_tempfile::tempdir()?;
496 6 : let conf = PageServerConf::dummy_conf(repo_dir.path().to_path_buf());
497 6 : let conf = Box::leak(Box::new(conf));
498 6 : let tenant_shard_id = TenantShardId::unsharded(TenantId::generate());
499 6 :
500 6 : let manager = PostgresRedoManager::new(conf, tenant_shard_id);
501 6 :
502 6 : Ok(RedoHarness {
503 6 : _repo_dir: repo_dir,
504 6 : manager,
505 6 : tenant_shard_id,
506 6 : })
507 6 : }
508 6 : fn span(&self) -> tracing::Span {
509 6 : tracing::info_span!("RedoHarness", tenant_id=%self.tenant_shard_id.tenant_id, shard_id=%self.tenant_shard_id.shard_slug())
510 6 : }
511 : }
512 : }
|