Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,11 @@ repository = "https://github.com/pathscale/DataBucket"
description = "DataBucket is container for WorkTable's data"

[dependencies]
data_bucket_derive = {path = "codegen" , version = "0.1.0"}
data_bucket_derive = { path = "codegen", version = "0.1.0" }

eyre = "0.6.12"
derive_more = { version = "1.0.0", features = ["from", "error", "display", "into"] }
rkyv = { version = "0.8.9", features = ["uuid-1"]}
scc = "2.1.16"
rkyv = { version = "0.8.9", features = ["uuid-1"] }
lockfree = "0.5.1"
serde = { version = "1.0.215", features = ["derive"] }
uuid = { version = "1.11.0", features = ["v4"] }
bitcode = "0.6.3"

[dev-dependencies]
mktemp = "0.4.0"
indexset = { version = "0.11.1", features = ["concurrent", "cdc", "multimap"] }
15 changes: 9 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
extern crate core;

pub mod link;
pub mod page;
pub mod persistence;
Expand All @@ -8,11 +10,12 @@ pub use link::Link;

pub use data_bucket_codegen::SizeMeasure;
pub use page::{
map_data_pages_to_general, map_index_pages_to_general, map_tree_index,
parse_data_page, parse_index_page, parse_page, persist_page, read_data_pages, read_index_pages,
read_rows_schema, seek_by_link, seek_to_page_start, update_at, Data as DataPage,
General as GeneralPage, GeneralHeader, IndexPage as IndexData, IndexValue, Interval, PageType,
SpaceInfo as SpaceInfoData, DATA_VERSION, GENERAL_HEADER_SIZE, INNER_PAGE_SIZE, PAGE_SIZE,
get_index_page_size_from_data_length, map_data_pages_to_general, map_index_pages_to_general,
parse_data_page, parse_index_page, parse_page, persist_page, seek_by_link, seek_to_page_start,
update_at, DataPage, GeneralHeader, GeneralPage, IndexPage, IndexValue, Interval, PageType,
SpaceInfoPage, TableOfContentsPage, DATA_VERSION, GENERAL_HEADER_SIZE, INNER_PAGE_SIZE,
PAGE_SIZE,
};
pub use persistence::{PersistableIndex, PersistableTable};
pub use util::{align, Persistable, SizeMeasurable};
pub use space::Id as SpaceId;
pub use util::{align, align8, align_vec, Persistable, SizeMeasurable};
26 changes: 17 additions & 9 deletions src/page/data.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use eyre::{eyre, Result};

use crate::Link;
use crate::Persistable;
use eyre::{eyre, Result};

#[derive(Debug)]
pub struct Data<const DATA_LENGTH: usize> {
pub struct DataPage<const DATA_LENGTH: usize> {
pub length: u32,
pub data: [u8; DATA_LENGTH],
}

impl<const DATA_LENGTH: usize> Data<DATA_LENGTH> {
impl<const DATA_LENGTH: usize> DataPage<DATA_LENGTH> {
pub fn update_at(&mut self, link: Link, new_data: &[u8]) -> Result<()> {
if new_data.len() as u32 != link.length {
return Err(eyre!(
Expand Down Expand Up @@ -52,10 +51,19 @@ impl<const DATA_LENGTH: usize> Data<DATA_LENGTH> {
}
}

impl<const DATA_LENGTH: usize> Persistable for Data<DATA_LENGTH> {
impl<const DATA_LENGTH: usize> Persistable for DataPage<DATA_LENGTH> {
fn as_bytes(&self) -> impl AsRef<[u8]> {
&self.data[..self.length as usize]
}

fn from_bytes(bytes: &[u8]) -> Self {
let mut data = [0; DATA_LENGTH];
data.copy_from_slice(bytes);
Self {
length: bytes.len() as u32,
data,
}
}
}

#[cfg(test)]
Expand All @@ -64,7 +72,7 @@ mod tests {

#[test]
fn test_update_at_success() {
let mut data = Data {
let mut data = DataPage {
length: 0,
data: [0; 100],
};
Expand All @@ -82,7 +90,7 @@ mod tests {

#[test]
fn test_update_at_wrong_length() {
let mut data = Data {
let mut data = DataPage {
length: 0,
data: [0; 100],
};
Expand All @@ -101,7 +109,7 @@ mod tests {

#[test]
fn test_update_at_out_of_bounds() {
let mut data = Data {
let mut data = DataPage {
length: 0,
data: [0; 100],
};
Expand All @@ -120,7 +128,7 @@ mod tests {

#[test]
fn test_get_at_out_of_bounds() {
let data = Data {
let data = DataPage {
length: 0,
data: [0; 100],
};
Expand Down
36 changes: 29 additions & 7 deletions src/page/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
use rkyv::{Archive, Deserialize, Serialize};

use crate::page::ty::PageType;
use crate::page::PageId;
use crate::space;
use crate::util::Persistable;
use crate::{page, PAGE_SIZE};
use crate::PAGE_SIZE;

pub const DATA_VERSION: u32 = 1u32;

Expand All @@ -16,15 +17,15 @@ pub const DATA_VERSION: u32 = 1u32;
pub struct GeneralHeader {
pub data_version: u32,
pub space_id: space::Id,
pub page_id: page::PageId,
pub previous_id: page::PageId,
pub next_id: page::PageId,
pub page_id: PageId,
pub previous_id: PageId,
pub next_id: PageId,
pub page_type: PageType,
pub data_length: u32,
}

impl GeneralHeader {
pub fn new(page_id: page::PageId, type_: PageType, space_id: space::Id) -> Self {
pub fn new(page_id: PageId, type_: PageType, space_id: space::Id) -> Self {
Self {
data_version: DATA_VERSION,
page_id,
Expand All @@ -38,7 +39,7 @@ impl GeneralHeader {

/// Creates a new [`GeneralHeader`] for a page that follows page with given
/// header. It means that [`PageType`] and [`space::Id`] are same and
/// old [`page::PageId`] will be `previous_id`.
/// old [`PageId`] will be `previous_id`.
pub fn follow(&mut self) -> Self {
self.next_id = self.page_id.next();
Self {
Expand All @@ -54,7 +55,7 @@ impl GeneralHeader {

/// Creates a new [`GeneralHeader`] for a page that follows page with given
/// header but with different [`PageType`]. [`space::Id`] is same and old
/// [`page::PageId`] will be `previous_id`.
/// [`PageId`] will be `previous_id`.
pub fn follow_with(&mut self, page_type: PageType) -> Self {
self.next_id = self.page_id.next();
Self {
Expand All @@ -67,12 +68,33 @@ impl GeneralHeader {
data_length: PAGE_SIZE as u32,
}
}

/// Creates a new [`GeneralHeader`] for a page that follows page with given
/// header with provided [`PageId`], but with different [`PageType`].
/// [`space::Id`] is same and old [`PageId`] will be `previous_id`.
pub fn follow_with_page_id(&mut self, page_id: PageId) -> Self {
self.next_id = page_id;
Self {
data_version: DATA_VERSION,
page_id,
previous_id: self.page_id,
next_id: 0.into(),
page_type: self.page_type,
space_id: self.space_id,
data_length: PAGE_SIZE as u32,
}
}
}

impl Persistable for GeneralHeader {
fn as_bytes(&self) -> impl AsRef<[u8]> {
rkyv::to_bytes::<rkyv::rancor::Error>(self).unwrap()
}

fn from_bytes(bytes: &[u8]) -> Self {
let archived = unsafe { rkyv::access_unchecked::<<Self as Archive>::Archived>(bytes) };
rkyv::deserialize::<_, rkyv::rancor::Error>(archived).expect("data should be valid")
}
}

#[cfg(test)]
Expand Down
Loading
Loading