From 8b258e20a0ea5e7de02e581b6be22cec559da653 Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Fri, 2 Feb 2024 10:03:40 +0000 Subject: [PATCH] move more stuff around --- pageserver/src/walredo.rs | 18 +++--------------- pageserver/src/walredo/process.rs | 7 +++---- .../src/walredo/{process => }/protocol.rs | 16 ++++++++++++++-- 3 files changed, 20 insertions(+), 21 deletions(-) rename pageserver/src/walredo/{process => }/protocol.rs (67%) diff --git a/pageserver/src/walredo.rs b/pageserver/src/walredo.rs index 480c7b6580..35f2d8d8de 100644 --- a/pageserver/src/walredo.rs +++ b/pageserver/src/walredo.rs @@ -24,7 +24,6 @@ use bytes::{Bytes, BytesMut}; use pageserver_api::models::WalRedoManagerStatus; use pageserver_api::shard::TenantShardId; -use serde::Serialize; use std::sync::{Arc, RwLock}; use std::time::Duration; @@ -44,7 +43,7 @@ use crate::repository::Key; use crate::walrecord::NeonWalRecord; use pageserver_api::key::{key_to_rel_block, key_to_slru_block}; -use pageserver_api::reltag::{RelTag, SlruKind}; +use pageserver_api::reltag::SlruKind; use postgres_ffi::pg_constants; use postgres_ffi::relfile_utils::VISIBILITYMAP_FORKNUM; use postgres_ffi::v14::nonrelfile_utils::{ @@ -54,20 +53,9 @@ use postgres_ffi::v14::nonrelfile_utils::{ use postgres_ffi::BLCKSZ; mod process; +mod protocol; use process::WalRedoProcess; -/// -/// `RelTag` + block number (`blknum`) gives us a unique id of the page in the cluster. -/// -/// In Postgres `BufferTag` structure is used for exactly the same purpose. -/// [See more related comments here](https://github.com/postgres/postgres/blob/99c5852e20a0987eca1c38ba0c09329d4076b6a0/src/include/storage/buf_internals.h#L91). -/// -#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Serialize)] -pub(crate) struct BufferTag { - pub rel: RelTag, - pub blknum: u32, -} - /// /// This is the real implementation that uses a Postgres process to /// perform WAL replay. Only one thread can use the process at a time, @@ -272,7 +260,7 @@ impl PostgresRedoManager { let started_at = std::time::Instant::now(); // Relational WAL records are applied using wal-redo-postgres - let buf_tag = BufferTag { rel, blknum }; + let buf_tag = protocol::BufferTag { rel, blknum }; let result = proc .apply_wal_records(buf_tag, &base_img, records, wal_redo_timeout) .context("apply_wal_records"); diff --git a/pageserver/src/walredo/process.rs b/pageserver/src/walredo/process.rs index 0f8a7a3831..3b0545437c 100644 --- a/pageserver/src/walredo/process.rs +++ b/pageserver/src/walredo/process.rs @@ -23,12 +23,11 @@ use self::no_leak_child::NoLeakChild; use utils::{lsn::Lsn, nonblock::set_nonblock}; -use super::BufferTag; - use std::os::fd::AsRawFd; +use super::protocol; + mod no_leak_child; -mod protocol; pub struct WalRedoProcess { #[allow(dead_code)] @@ -184,7 +183,7 @@ impl WalRedoProcess { #[instrument(skip_all, fields(tenant_id=%self.tenant_shard_id.tenant_id, shard_id=%self.tenant_shard_id.shard_slug(), pid=%self.id()))] pub(crate) fn apply_wal_records( &self, - tag: BufferTag, + tag: protocol::BufferTag, base_img: &Option, records: &[(Lsn, NeonWalRecord)], wal_redo_timeout: Duration, diff --git a/pageserver/src/walredo/process/protocol.rs b/pageserver/src/walredo/protocol.rs similarity index 67% rename from pageserver/src/walredo/process/protocol.rs rename to pageserver/src/walredo/protocol.rs index fbe515ba27..b703344cc8 100644 --- a/pageserver/src/walredo/process/protocol.rs +++ b/pageserver/src/walredo/protocol.rs @@ -1,8 +1,20 @@ use bytes::BufMut; +use pageserver_api::reltag::RelTag; +use serde::Serialize; +use utils::bin_ser::BeSer; use utils::lsn::Lsn; -use super::BufferTag; -use utils::bin_ser::BeSer; +/// +/// `RelTag` + block number (`blknum`) gives us a unique id of the page in the cluster. +/// +/// In Postgres `BufferTag` structure is used for exactly the same purpose. +/// [See more related comments here](https://github.com/postgres/postgres/blob/99c5852e20a0987eca1c38ba0c09329d4076b6a0/src/include/storage/buf_internals.h#L91). +/// +#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Serialize)] +pub(crate) struct BufferTag { + pub rel: RelTag, + pub blknum: u32, +} pub(crate) fn build_begin_redo_for_block_msg(tag: BufferTag, buf: &mut Vec) { let len = 4 + 1 + 4 * 4;