mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-15 09:22:55 +00:00
This moves things around: - The PageCache is split into two structs: Repository and Timeline. A Repository holds multiple Timelines. In order to get a page version, you must first get a reference to the Repository, then the Timeline in the repository, and finally call the get_page_at_lsn() function on the Timeline object. This sounds complicated, but because each connection from a compute node, and each WAL receiver, only deals with one timeline at a time, the callers can get the reference to the Timeline object once and hold onto it. The Timeline corresponds most closely to the old PageCache object. - Repository and Timeline are now abstract traits, so that we can support multiple implementations. I don't actually expect us to have multiple implementations for long. We have the RocksDB implementation now, but as soon as we have a different implementation that's usable, I expect that we will retire the RocksDB implementation. But I think this abstraction works as good documentation in any case: it's now easier to see what the interface for storing and loading pages from the repository is, by looking at the Repository/Timeline traits. They abstract traits are in repository.rs, and the RocksDB implementation of them is in repository/rocksdb.rs. - page_cache.rs is now a "switchboard" to get a handle to the repository. Currently, the page server can only handle one repository at a time, so there isn't much there, but in the future we might do multi-tenancy there.
26 lines
843 B
Rust
26 lines
843 B
Rust
//! This module acts as a switchboard to access different repositories managed by this
|
|
//! page server. Currently, a Page Server can only manage one repository, so there
|
|
//! isn't much here. If we implement multi-tenancy, this will probably be changed into
|
|
//! a hash map, keyed by the tenant ID.
|
|
|
|
use crate::PageServerConf;
|
|
//use crate::repository::Repository;
|
|
use crate::repository::rocksdb::RocksRepository;
|
|
use lazy_static::lazy_static;
|
|
use std::sync::{Arc, Mutex};
|
|
|
|
lazy_static! {
|
|
pub static ref REPOSITORY: Mutex<Option<Arc<RocksRepository>>> = Mutex::new(None);
|
|
}
|
|
|
|
pub fn init(conf: &PageServerConf) {
|
|
let mut m = REPOSITORY.lock().unwrap();
|
|
|
|
*m = Some(Arc::new(RocksRepository::new(conf)));
|
|
}
|
|
|
|
pub fn get_repository() -> Arc<RocksRepository> {
|
|
let o = &REPOSITORY.lock().unwrap();
|
|
Arc::clone(o.as_ref().unwrap())
|
|
}
|