mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-09 14:32:57 +00:00
Misc page server cleanup
- reduce println chatter - improve error handling in the GetPage@LSN function
This commit is contained in:
committed by
Stas Kelvich
parent
af7ebb6395
commit
3de0148232
@@ -1,5 +1,6 @@
|
||||
use std::collections::BTreeMap;
|
||||
use std::sync::Mutex;
|
||||
use std::error::Error;
|
||||
use bytes::Bytes;
|
||||
use lazy_static::lazy_static;
|
||||
use rand::Rng;
|
||||
@@ -93,19 +94,26 @@ pub fn test_get_page_at_lsn()
|
||||
}
|
||||
}
|
||||
|
||||
println!("testing GetPage@LSN: {}", tag.unwrap().blknum);
|
||||
|
||||
get_page_at_lsn(tag.unwrap(), 0xffff_ffff_ffff_eeee);
|
||||
|
||||
println!("testing GetPage@LSN for block {}", tag.unwrap().blknum);
|
||||
match get_page_at_lsn(tag.unwrap(), 0xffff_ffff_ffff_eeee) {
|
||||
Ok(img) => {
|
||||
println!("{:X?}", img);
|
||||
},
|
||||
Err(error) => {
|
||||
println!("GetPage@LSN failed: {}", error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// GetPage@LSN
|
||||
//
|
||||
// Returns an 8k page image
|
||||
//
|
||||
#[allow(dead_code)]
|
||||
#[allow(unused_variables)]
|
||||
pub fn get_page_at_lsn(tag: BufferTag, lsn: u64)
|
||||
pub fn get_page_at_lsn(tag: BufferTag, lsn: u64) -> Result<Bytes, Box<dyn Error>>
|
||||
{
|
||||
// TODO:
|
||||
//
|
||||
@@ -149,13 +157,25 @@ pub fn get_page_at_lsn(tag: BufferTag, lsn: u64)
|
||||
}
|
||||
}
|
||||
|
||||
let page_img: Bytes;
|
||||
|
||||
if !records.is_empty() {
|
||||
records.reverse();
|
||||
|
||||
walredo::apply_wal_records(tag, base_img, &records).expect("could not apply WAL records");
|
||||
page_img = walredo::apply_wal_records(tag, base_img, &records)?;
|
||||
|
||||
println!("applied {} WAL records to produce page image at LSN {}", records.len(), lsn);
|
||||
|
||||
// Here, we could put the new page image back to the page cache, to save effort if the
|
||||
// same (or later) page version is requested again. It's a tradeoff though, as each
|
||||
// page image consumes some memory
|
||||
} else if base_img.is_some() {
|
||||
page_img = base_img.unwrap();
|
||||
} else {
|
||||
return Err("could not find page image")?;
|
||||
}
|
||||
|
||||
return Ok(page_img);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -76,7 +76,6 @@ impl WalStreamDecoder {
|
||||
}
|
||||
|
||||
pub fn feed_bytes(&mut self, buf: &[u8]) {
|
||||
println!("feed_bytes called: {}", buf.len());
|
||||
self.inputbuf.extend_from_slice(buf);
|
||||
}
|
||||
|
||||
@@ -84,8 +83,6 @@ impl WalStreamDecoder {
|
||||
|
||||
loop {
|
||||
// parse and verify page boundaries as we go
|
||||
println!("parsing at {} {} (cont {} pad {})", self.lsn, self.lsn % 8192,
|
||||
self.contlen, self.padlen);
|
||||
if self.lsn % WAL_SEGMENT_SIZE == 0 {
|
||||
// parse long header
|
||||
|
||||
@@ -138,8 +135,6 @@ impl WalStreamDecoder {
|
||||
let xl_tot_len = self.inputbuf.get_u32_le();
|
||||
self.lsn += 4;
|
||||
|
||||
println!("reading record with len {}", xl_tot_len);
|
||||
|
||||
self.recordbuf.clear();
|
||||
self.recordbuf.reserve(xl_tot_len as usize);
|
||||
self.recordbuf.put_u32_le(xl_tot_len);
|
||||
@@ -311,8 +306,6 @@ pub fn decode_wal_record(lsn: u64, rec: Bytes) -> DecodedWALRecord {
|
||||
//TODO error
|
||||
}
|
||||
|
||||
println!("rmgrid {}", _xl_rmid);
|
||||
|
||||
let mut rnode_spcnode: u32 = 0;
|
||||
let mut rnode_dbnode: u32 = 0;
|
||||
let mut rnode_relnode: u32 = 0;
|
||||
@@ -538,7 +531,7 @@ pub fn decode_wal_record(lsn: u64, rec: Bytes) -> DecodedWALRecord {
|
||||
|
||||
blk.blkno = buf.get_u32_le();
|
||||
|
||||
println!("this record affects {}/{}/{} blk {}",rnode_spcnode, rnode_dbnode, rnode_relnode, blk.blkno);
|
||||
//println!("this record affects {}/{}/{} blk {}",rnode_spcnode, rnode_dbnode, rnode_relnode, blk.blkno);
|
||||
|
||||
blocks.push(blk);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user