mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-14 00:42:54 +00:00
This includes the following commits:35a1c3d521Specify right LSN in test_createdb.pyd95e1da742Fix issue with propagation of CREATE DATABASE to the branch8465738aa5[refer #167] Fix handling of pg_filenode.map files in page server86056abd0eFix merge conflict: set initial WAL position to second segment because of pg_resetwal2bf2dd1d88Add nonrelfile_utils.rs file20b6279bebFix restoring non-relational data during compute node startup06f96f9600Do not transfer WAL to computation nodes: use pg_resetwal for node startup As well as some older changes related to storing CLOG and MultiXact data as "pseudorelation" in the page server. With this revert, we go back to the situtation that when you create a new compute node, we ship *all* the WAL from the beginning of time to the compute node. Obviously we need a better solution, like the code that this reverts. But per discussion with Konstantin and Stas, this stuff was still half-baked, and it's better for it to live in a branch for now, until it's more complete and has gone through some review.
72 lines
2.2 KiB
Rust
72 lines
2.2 KiB
Rust
#![allow(non_upper_case_globals)]
|
|
#![allow(non_camel_case_types)]
|
|
#![allow(non_snake_case)]
|
|
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
|
|
|
pub mod pg_constants;
|
|
pub mod relfile_utils;
|
|
pub mod xlog_utils;
|
|
|
|
use bytes::{Buf, Bytes, BytesMut};
|
|
|
|
// sizeof(ControlFileData)
|
|
const SIZEOF_CONTROLDATA: usize = std::mem::size_of::<ControlFileData>();
|
|
const OFFSETOF_CRC: usize = PG_CONTROLFILEDATA_OFFSETOF_CRC as usize;
|
|
|
|
impl ControlFileData {
|
|
// Initialize an all-zeros ControlFileData struct
|
|
pub fn new() -> ControlFileData {
|
|
let controlfile: ControlFileData;
|
|
|
|
let b = [0u8; SIZEOF_CONTROLDATA];
|
|
controlfile =
|
|
unsafe { std::mem::transmute::<[u8; SIZEOF_CONTROLDATA], ControlFileData>(b) };
|
|
|
|
controlfile
|
|
}
|
|
}
|
|
|
|
pub fn decode_pg_control(mut buf: Bytes) -> Result<ControlFileData, anyhow::Error> {
|
|
let mut b: [u8; SIZEOF_CONTROLDATA] = [0u8; SIZEOF_CONTROLDATA];
|
|
buf.copy_to_slice(&mut b);
|
|
|
|
let controlfile: ControlFileData;
|
|
|
|
// TODO: verify CRC
|
|
let mut data_without_crc: [u8; OFFSETOF_CRC] = [0u8; OFFSETOF_CRC];
|
|
data_without_crc.copy_from_slice(&b[0..OFFSETOF_CRC]);
|
|
let expectedcrc = crc32c::crc32c(&data_without_crc);
|
|
|
|
controlfile = unsafe { std::mem::transmute::<[u8; SIZEOF_CONTROLDATA], ControlFileData>(b) };
|
|
|
|
if expectedcrc != controlfile.crc {
|
|
anyhow::bail!(
|
|
"invalid CRC in control file: expected {:08X}, was {:08X}",
|
|
expectedcrc,
|
|
controlfile.crc
|
|
);
|
|
}
|
|
|
|
Ok(controlfile)
|
|
}
|
|
|
|
pub fn encode_pg_control(controlfile: ControlFileData) -> Bytes {
|
|
let b: [u8; SIZEOF_CONTROLDATA];
|
|
|
|
b = unsafe { std::mem::transmute::<ControlFileData, [u8; SIZEOF_CONTROLDATA]>(controlfile) };
|
|
|
|
// Recompute the CRC
|
|
let mut data_without_crc: [u8; OFFSETOF_CRC] = [0u8; OFFSETOF_CRC];
|
|
data_without_crc.copy_from_slice(&b[0..OFFSETOF_CRC]);
|
|
let newcrc = crc32c::crc32c(&data_without_crc);
|
|
|
|
let mut buf = BytesMut::with_capacity(PG_CONTROL_FILE_SIZE as usize);
|
|
|
|
buf.extend_from_slice(&b[0..OFFSETOF_CRC]);
|
|
buf.extend_from_slice(&newcrc.to_ne_bytes());
|
|
// Fill the rest of the control file with zeros.
|
|
buf.resize(PG_CONTROL_FILE_SIZE as usize, 0);
|
|
|
|
buf.into()
|
|
}
|