Merge branch 'redesign-tables' into redesign-indexes
This commit is contained in:
commit
dae012daa7
6 changed files with 358 additions and 138 deletions
|
|
@ -1,7 +1,7 @@
|
|||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
use tokio::fs::{File, OpenOptions, DirBuilder};
|
||||
use tokio::fs;
|
||||
use std::path::Path;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::marker::PhantomData;
|
||||
use async_trait::async_trait;
|
||||
|
||||
|
|
@ -28,7 +28,6 @@ pub struct Store<T> {
|
|||
// {write: 0, read: n + 1} ~> {write:0, read: n} // destroy read
|
||||
// {write: 0, read: 0} ~> {write: 1, read: 0} // create write
|
||||
// {write: 1, read: 0} ~> {write: 0, read: 0} // destroy write
|
||||
pub table_folder: String,
|
||||
// primary_index: Vec<Index<T, FilePosition>>>,
|
||||
// indexes: Vec<Option<Index<T, HashSet<FilePosition>>>>,
|
||||
// primary_index: Index<PositionOfValue, PositionOfRow>,
|
||||
|
|
@ -54,6 +53,7 @@ pub async fn less_than_eq<T>(store: &mut Store<T>, file_position0: FilePosition,
|
|||
}
|
||||
|
||||
pub const ROWS_FILE_NAME: &'static str = "rows";
|
||||
pub const GARBAGE_COLLECTION_INTERMEDIATE_ROWS_FILE_NAME: &'static str = "rows_intermediate";
|
||||
|
||||
impl <T>Store<T> {
|
||||
// ===Creation===
|
||||
|
|
@ -63,6 +63,31 @@ impl <T>Store<T> {
|
|||
DirBuilder::new()
|
||||
.create(path_to_table).await?;
|
||||
|
||||
let header = StoreHeader {
|
||||
table_folder: table_folder.to_string(),
|
||||
number_of_columns,
|
||||
deleted_count: 0,
|
||||
total_count: 0,
|
||||
primary_column,
|
||||
};
|
||||
|
||||
// We don't need the file right now. Only cursors will later open it.
|
||||
Self::create_empty_rows_file(path_to_rows, &header).await?;
|
||||
|
||||
// TODO: indexes
|
||||
// let index: Index<PositionOfValue, PositionOfRow> = Index::new(
|
||||
// &format!("rows_{}", primary_column.to_string()),
|
||||
// ).await?;
|
||||
|
||||
let store = Self {
|
||||
header,
|
||||
data_type: PhantomData::<T>,
|
||||
};
|
||||
|
||||
Ok(store)
|
||||
}
|
||||
|
||||
pub async fn create_empty_rows_file(path_to_rows: PathBuf, header: &StoreHeader) -> Result<File> {
|
||||
let mut file: File =
|
||||
OpenOptions::new()
|
||||
.write(true)
|
||||
|
|
@ -71,28 +96,10 @@ impl <T>Store<T> {
|
|||
.open(path_to_rows)
|
||||
.await?;
|
||||
|
||||
let header = StoreHeader {
|
||||
number_of_columns,
|
||||
deleted_count: 0,
|
||||
total_count: 0,
|
||||
primary_column,
|
||||
};
|
||||
let encoded_header: Vec<u8> = header.encode()?;
|
||||
file.write(&encoded_header).await?;
|
||||
|
||||
|
||||
// TODO: indexes
|
||||
// let index: Index<PositionOfValue, PositionOfRow> = Index::new(
|
||||
// &format!("rows_{}", primary_column.to_string()),
|
||||
// ).await?;
|
||||
|
||||
let store = Self {
|
||||
table_folder: table_folder.to_string(),
|
||||
header,
|
||||
data_type: PhantomData::<T>,
|
||||
};
|
||||
|
||||
Ok(store)
|
||||
Ok(file)
|
||||
}
|
||||
|
||||
pub async fn connect(table_folder: &str) -> Result<Self>
|
||||
|
|
@ -112,10 +119,9 @@ impl <T>Store<T> {
|
|||
// header.
|
||||
let mut header_bytes = StoreHeader::decode_buffer();
|
||||
file.read_exact(&mut header_bytes).await?;
|
||||
let header = StoreHeader::decode(&mut header_bytes).await?;
|
||||
let header = StoreHeader::decode(table_folder, &mut header_bytes).await?;
|
||||
|
||||
let store = Self {
|
||||
table_folder: table_folder.to_string(),
|
||||
header,
|
||||
data_type: PhantomData::<T>,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue