code cleanup for XLogRecord decoding

This commit is contained in:
anastasia
2021-04-28 12:57:52 +03:00
committed by lubennikovaav
parent ef37eb96b9
commit 421d586953
3 changed files with 18 additions and 16 deletions

View File

@@ -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 = {}",

View File

@@ -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

View File

@@ -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()
},
}
}
}