Skip to content

Commit

Permalink
Great renaming/restructuring in the db/ crate
Browse files Browse the repository at this point in the history
Rename "tuplebox" to "rdb", and move a bunch of object-related stuff into "odb"

Rename existing "SlotBox" thing into "TupleBox", to clarify it's the thing that stores tuples.
  • Loading branch information
rdaum committed Jan 9, 2024
1 parent 23ece76 commit 586d925
Show file tree
Hide file tree
Showing 32 changed files with 409 additions and 398 deletions.
8 changes: 4 additions & 4 deletions crates/daemon/src/connections_tb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// this program. If not, see <https://www.gnu.org/licenses/>.
//

//! An implementation of the connections db that uses tuplebox.
//! An implementation of the connections db that uses rdb.
use std::collections::HashSet;
use std::path::PathBuf;
Expand All @@ -25,7 +25,7 @@ use strum::{Display, EnumCount, EnumIter, IntoEnumIterator};
use tracing::{debug, error, warn};
use uuid::Uuid;

use moor_db::tuplebox::{RelationId, RelationInfo, Transaction, TupleBox};
use moor_db::rdb::{RelBox, RelationId, RelationInfo, Transaction};
use moor_kernel::tasks::sessions::SessionError;
use moor_values::util::slice_ref::SliceRef;
use moor_values::var::objid::Objid;
Expand All @@ -36,7 +36,7 @@ use crate::connections::{ConnectionsDB, CONNECTION_TIMEOUT_DURATION};

const CONNECTIONS_DB_MEM_SIZE: usize = 1 << 26;
pub struct ConnectionsTb {
tb: Arc<TupleBox>,
tb: Arc<RelBox>,
}

impl ConnectionsTb {
Expand All @@ -53,7 +53,7 @@ impl ConnectionsTb {
.collect();
relations[ConnectionRelation::ClientConnection as usize].secondary_indexed = true;

let tb = TupleBox::new(CONNECTIONS_DB_MEM_SIZE, path, &relations, 1).await;
let tb = RelBox::new(CONNECTIONS_DB_MEM_SIZE, path, &relations, 1).await;
Self { tb }
}
}
Expand Down
18 changes: 10 additions & 8 deletions crates/db/benches/tb_single_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@
//! Does not measure single-item reads, deletes, or updates, or concurrent access.
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use moor_db::rdb::{RelBox, RelationInfo};
use moor_db::testing::jepsen::{History, Type, Value};
use moor_db::tuplebox::{RelationInfo, TupleBox};
use moor_values::util::slice_ref::SliceRef;
use std::sync::Arc;
use std::time::{Duration, Instant};

// This is a struct that tells Criterion.rs to use the "futures" crate's current-thread executor
use moor_db::tuplebox::RelationId;
use moor_db::rdb::RelationId;
use moor_values::util::{BitArray, Bitset64};
use tokio::runtime::Runtime;

/// Build a test database with a bunch of relations
async fn test_db() -> Arc<TupleBox> {
async fn test_db() -> Arc<RelBox> {
// Generate 10 test relations that we'll use for testing.
let relations = (0..63)
.map(|i| RelationInfo {
Expand All @@ -39,7 +39,7 @@ async fn test_db() -> Arc<TupleBox> {
})
.collect::<Vec<_>>();

TupleBox::new(1 << 24, None, &relations, 0).await
RelBox::new(1 << 24, None, &relations, 0).await
}

fn from_val(value: i64) -> SliceRef {
Expand Down Expand Up @@ -68,7 +68,7 @@ async fn list_append_scan_workload(iters: u64, events: &Vec<History>) -> Duratio

let start = Instant::now();

black_box(for e in events {
for e in events {
match e.r#type {
Type::invoke => {
// Start a transaction.
Expand Down Expand Up @@ -114,7 +114,8 @@ async fn list_append_scan_workload(iters: u64, events: &Vec<History>) -> Duratio
tx.rollback().await.unwrap();
}
}
});
}
black_box(());
cumulative += start.elapsed();
}
cumulative
Expand All @@ -131,7 +132,7 @@ async fn list_append_seek_workload(iters: u64, events: &Vec<History>) -> Duratio
let mut processes: BitArray<_, 256, Bitset64<8>> = BitArray::new();
let start = Instant::now();

black_box(for e in events {
for e in events {
match e.r#type {
Type::invoke => {
// Start a transaction.
Expand Down Expand Up @@ -181,7 +182,8 @@ async fn list_append_seek_workload(iters: u64, events: &Vec<History>) -> Duratio
tx.rollback().await.unwrap();
}
}
});
}
black_box(());
cumulative += start.elapsed();
}
cumulative
Expand Down
10 changes: 4 additions & 6 deletions crates/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@ use moor_values::model::world_state::WorldStateSource;
use moor_values::model::WorldStateError;

use crate::loader::LoaderInterface;
use crate::tb_worldstate::TupleBoxWorldStateSource;
use crate::odb::RelBoxWorldState;

mod db_loader_client;
pub mod db_tx;
mod db_worldstate;
pub mod loader;
pub mod object_relations;
pub mod tb_worldstate;
pub mod tuplebox;
pub mod rdb;

pub mod odb;
#[doc(hidden)]
pub mod testing;

Expand Down Expand Up @@ -63,8 +62,7 @@ impl DatabaseBuilder {
/// database was newly created, and false if it was already present.
pub async fn open_db(&self) -> Result<(Box<dyn Database>, bool), String> {
let (db, fresh) =
TupleBoxWorldStateSource::open(self.path.clone(), self.memory_size.unwrap_or(1 << 40))
.await;
RelBoxWorldState::open(self.path.clone(), self.memory_size.unwrap_or(1 << 40)).await;
Ok((Box::new(db), fresh))
}
}
Expand Down
19 changes: 19 additions & 0 deletions crates/db/src/odb/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (C) 2024 Ryan Daum <[email protected]>
//
// This program is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation, version 3.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with
// this program. If not, see <https://www.gnu.org/licenses/>.
//

mod object_relations;
mod rb_worldstate;

pub use object_relations::{WorldStateRelation, WorldStateSequences};
pub use rb_worldstate::{RelBoxTransaction, RelBoxWorldState};
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use moor_values::util::slice_ref::SliceRef;
use moor_values::var::objid::Objid;
use moor_values::AsByteBuffer;

use crate::tuplebox::TupleError;
use crate::tuplebox::{RelationId, Transaction};
use crate::rdb::TupleError;
use crate::rdb::{RelationId, Transaction};

/// The set of binary relations that are used to represent the world state in the moor system.
#[repr(usize)]
Expand Down Expand Up @@ -204,7 +204,7 @@ async fn delete_if_exists(
}
}

pub async fn delete_composite_if_exists<Codomain: Clone + Eq + PartialEq + AsByteBuffer>(
pub async fn delete_composite_if_exists(
tx: &Transaction,
rel: WorldStateRelation,
oid: Objid,
Expand Down Expand Up @@ -243,14 +243,14 @@ mod tests {
use moor_values::model::objset::ObjSet;
use moor_values::var::objid::Objid;

use crate::object_relations::WorldStateRelation::ObjectParent;
use crate::object_relations::{
use crate::odb::object_relations::WorldStateRelation::ObjectParent;
use crate::odb::object_relations::{
get_object_by_codomain, get_object_value, insert_object_value, upsert_object_value,
WorldStateRelation, WorldStateSequences,
};
use crate::tuplebox::{RelationInfo, TupleBox};
use crate::rdb::{RelBox, RelationInfo};

async fn test_db() -> Arc<TupleBox> {
async fn test_db() -> Arc<RelBox> {
let mut relations: Vec<RelationInfo> = WorldStateRelation::iter()
.map(|wsr| {
RelationInfo {
Expand All @@ -264,7 +264,7 @@ mod tests {
relations[ObjectParent as usize].secondary_indexed = true;
relations[WorldStateRelation::ObjectLocation as usize].secondary_indexed = true;

TupleBox::new(1 << 24, None, &relations, WorldStateSequences::COUNT).await
RelBox::new(1 << 24, None, &relations, WorldStateSequences::COUNT).await
}

/// Test simple relations mapping oid->oid (with secondary index), independent of all other
Expand Down
Loading

0 comments on commit 586d925

Please sign in to comment.