Skip to main content

bonsai/storage/
mod.rs

1//! Pages and the files they live in.
2//!
3//! See [Database File Layout](https://www.postgresql.org/docs/current/storage-file-layout.html).
4
5use std::fmt;
6
7pub mod checksum;
8pub mod page;
9pub mod manager;
10
11/// Size of a page, and of every block in a relation file. Postgres's `BLCKSZ`.
12pub const BLCKSZ: usize = 8192;
13
14/// Position of a block within one fork of a relation, counting from 0.
15#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
16pub struct BlockNumber(pub u32);
17
18impl fmt::Display for BlockNumber {
19    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20        write!(f, "{:#x}", self.0)
21    }
22}
23
24/// How many blocks a fork or a segment holds: blocks `0` to `count - 1`.
25#[derive(Clone, Copy, Debug, PartialEq, Eq)]
26pub struct BlockCount(pub u32);
27
28impl BlockCount {
29    pub fn contains(self, block: BlockNumber) -> bool {
30        block.0 < self.0
31    }
32}