mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-08 05:52:55 +00:00
WIP: beginnings of page server page cache
This commit is contained in:
committed by
Stas Kelvich
parent
d6ba1e6b78
commit
3058021ca7
7
Cargo.lock
generated
7
Cargo.lock
generated
@@ -228,6 +228,12 @@ dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.88"
|
||||
@@ -334,6 +340,7 @@ name = "pageserver"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"lazy_static",
|
||||
"postgres-protocol",
|
||||
"tokio",
|
||||
"tokio-postgres",
|
||||
|
||||
@@ -8,6 +8,7 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
bytes = "1.0.1"
|
||||
lazy_static = "1.4.0"
|
||||
tokio = { version = "1.3.0", features = ["full"] }
|
||||
tokio-stream = { version = "0.1.4" }
|
||||
tokio-postgres = { git = "https://github.com/kelvich/rust-postgres", branch = "replication_rebase" }
|
||||
|
||||
@@ -6,6 +6,9 @@ mod walreceiver;
|
||||
|
||||
use std::io::Error;
|
||||
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
|
||||
fn main() -> Result<(), Error> {
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use bytes::Bytes;
|
||||
|
||||
#[derive(PartialEq, Eq, Hash)]
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct BufferTag {
|
||||
pub spcnode: u32,
|
||||
pub dbnode: u32,
|
||||
@@ -10,38 +10,79 @@ pub struct BufferTag {
|
||||
pub blknum: u32,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct CacheKey {
|
||||
pub tag: BufferTag,
|
||||
pub lsn: u64
|
||||
|
||||
}
|
||||
|
||||
pub struct WALRecord {
|
||||
pub lsn: u64,
|
||||
pub rec: Bytes
|
||||
}
|
||||
|
||||
// FIXME: dead code, but I left this here to remind how lazy_static works.
|
||||
/*
|
||||
struct CacheEntry {
|
||||
//
|
||||
// We store two kinds of entries in the page cache:
|
||||
//
|
||||
// 1. Ready-made images of the block
|
||||
// 2. WAL records, to be applied on top of the "previous" entry
|
||||
//
|
||||
// Some WAL records will initialize the page from scratch. For such records,
|
||||
// the 'will_init' flag is set. They don't need the previous page image before
|
||||
// applying. The 'will_init' flag is set for records containing a full-page image,
|
||||
// and for records with the BKPBLOCK_WILL_INIT flag. These differ from PageImages
|
||||
// stored directly in the cache entry in that you still need to run the WAL redo
|
||||
// routine to generate the page image.
|
||||
//
|
||||
enum CacheEntry {
|
||||
|
||||
_records: VecDeque<WALRecord>,
|
||||
|
||||
// Oldest base image of the page, and its LSN
|
||||
_lsn: u64,
|
||||
_base: [u8; 8192] // the first 8 bytes of the page are actually the lsn, too
|
||||
PageImage {
|
||||
img: Bytes
|
||||
}
|
||||
|
||||
WALRecord {
|
||||
will_init: bool,
|
||||
rec: Bytes
|
||||
},
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref PAGECACHE: CHashMap<BufferTag, CacheEntry> = CHashMap::new();
|
||||
static ref PAGECACHE: BTreeMap<CacheKey, CacheEntry> = BTreeMap::new();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Public interface functions
|
||||
|
||||
//
|
||||
// GetPage@LSN
|
||||
//
|
||||
#[allow(dead_code)]
|
||||
pub fn lookup_page(key: BufferTag, _lsn: u64) {
|
||||
#[allow(unused_variables)]
|
||||
pub fn get_page_at_lsn(tag: BufferTag, lsn: u64)
|
||||
{
|
||||
// TODO:
|
||||
//
|
||||
// Look up cache entry
|
||||
// If it's a page image, return that. If it's a WAL record, walk backwards
|
||||
// to the latest page image. Then apply all the WAL records up until the
|
||||
// given LSN.
|
||||
//
|
||||
|
||||
PAGECACHE.get(&key);
|
||||
}
|
||||
|
||||
pub fn _append_record(_key: BufferTag, _lsn: u64) { // and wal record in some form
|
||||
|
||||
// PAGECACHE.get(&tag);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Add WAL record
|
||||
//
|
||||
#[allow(dead_code)]
|
||||
#[allow(unused_variables)]
|
||||
pub fn put_wal_record(tag: BufferTag, lsn: u64, rec: Bytes)
|
||||
{
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user