mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-10 06:52:55 +00:00
code cleanup for XLogRecord decoding
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use crate::pg_constants;
|
||||
use bytes::{Buf, BufMut, Bytes, BytesMut};
|
||||
use log::*;
|
||||
use postgres_ffi::xlog_utils;
|
||||
use postgres_ffi::xlog_utils::XLogRecord;
|
||||
use std::cmp::min;
|
||||
use std::str;
|
||||
use thiserror::Error;
|
||||
@@ -337,7 +337,7 @@ pub struct DecodedWALRecord {
|
||||
fn is_xlog_switch_record(rec: &Bytes) -> bool {
|
||||
let mut buf = rec.clone();
|
||||
|
||||
let xlogrec = xlog_utils::parse_xlog_record(&mut buf);
|
||||
let xlogrec = XLogRecord::from_bytes(&mut buf);
|
||||
xlogrec.xl_info == pg_constants::XLOG_SWITCH && xlogrec.xl_rmid == pg_constants::RM_XLOG_ID
|
||||
}
|
||||
|
||||
@@ -431,7 +431,7 @@ pub fn decode_wal_record(record: Bytes) -> DecodedWALRecord {
|
||||
// 1. Parse XLogRecord struct
|
||||
|
||||
// FIXME: assume little-endian here
|
||||
let xlogrec = xlog_utils::parse_xlog_record(&mut buf);
|
||||
let xlogrec = XLogRecord::from_bytes(&mut buf);
|
||||
|
||||
trace!(
|
||||
"decode_wal_record xl_rmid = {} xl_info = {}",
|
||||
|
||||
@@ -38,7 +38,7 @@ use crate::page_cache::BufferTag;
|
||||
use crate::page_cache::WALRecord;
|
||||
use crate::ZTimelineId;
|
||||
use crate::{pg_constants, PageServerConf};
|
||||
use postgres_ffi::xlog_utils;
|
||||
use postgres_ffi::xlog_utils::{XLogRecord};
|
||||
|
||||
static TIMEOUT: Duration = Duration::from_secs(20);
|
||||
|
||||
@@ -243,7 +243,7 @@ impl WalRedoManagerInternal {
|
||||
|
||||
// 1. Parse XLogRecord struct
|
||||
// FIXME: refactor to avoid code duplication.
|
||||
let xlogrec = xlog_utils::parse_xlog_record(&mut buf);
|
||||
let xlogrec = XLogRecord::from_bytes(&mut buf);
|
||||
|
||||
//move to main data
|
||||
// TODO probably, we should store some records in our special format
|
||||
|
||||
@@ -281,16 +281,18 @@ pub struct XLogRecord {
|
||||
pub xl_crc: u32,
|
||||
}
|
||||
|
||||
pub fn parse_xlog_record(buf: &mut Bytes) -> XLogRecord {
|
||||
XLogRecord {
|
||||
xl_tot_len: buf.get_u32_le(),
|
||||
xl_xid: buf.get_u32_le(),
|
||||
xl_prev: buf.get_u64_le(),
|
||||
xl_info: buf.get_u8(),
|
||||
xl_rmid: buf.get_u8(),
|
||||
xl_crc: {
|
||||
buf.advance(2);
|
||||
buf.get_u32_le()
|
||||
},
|
||||
impl XLogRecord {
|
||||
pub fn from_bytes(buf: &mut Bytes) -> XLogRecord {
|
||||
XLogRecord {
|
||||
xl_tot_len: buf.get_u32_le(),
|
||||
xl_xid: buf.get_u32_le(),
|
||||
xl_prev: buf.get_u64_le(),
|
||||
xl_info: buf.get_u8(),
|
||||
xl_rmid: buf.get_u8(),
|
||||
xl_crc: {
|
||||
buf.advance(2);
|
||||
buf.get_u32_le()
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user