diff --git a/src/rdbc/embedded.rs b/src/rdbc/embedded.rs index 54703d8a..0ced2a19 100644 --- a/src/rdbc/embedded.rs +++ b/src/rdbc/embedded.rs @@ -20,6 +20,7 @@ mod tests { }, driver::EmbeddedDriver, }; + use crate::server::config::{self, SimpleDBConfig}; #[test] fn unit_test() -> Result<()> { @@ -74,7 +75,13 @@ mod tests { ]; // driver - let d = EmbeddedDriver::new(); + let db_config = SimpleDBConfig { + block_size: 400, + num_of_buffers: 8, + buffer_manager: config::BufferMgr::LRU, + query_planner: config::QueryPlanner::Heuristic, + }; + let d = EmbeddedDriver::new(db_config); // connect database let mut conn = d.connect("_test/rdbc")?; // init database diff --git a/src/server/simpledb.rs b/src/server/simpledb.rs index 40d645fd..83f90859 100644 --- a/src/server/simpledb.rs +++ b/src/server/simpledb.rs @@ -70,7 +70,7 @@ pub struct SimpleDB { // managers fm: Arc>, lm: Arc>, - bm: Arc>, + bm: Arc>, mdm: Option>>, qp: Option>>, up: Option>>, @@ -132,7 +132,7 @@ impl SimpleDB { pub fn log_mgr(&self) -> Arc> { Arc::clone(&self.lm) } - pub fn buffer_mgr(&self) -> Arc> { + pub fn buffer_mgr(&self) -> Arc> { Arc::clone(&self.bm) } pub fn metadata_mgr(&self) -> Option>> { @@ -166,7 +166,7 @@ impl SimpleDB { )); let lm = Arc::new(Mutex::new(LogMgr::new(Arc::clone(&fm), LOG_FILE).unwrap())); let (bm_fm, bm_lm, numsbuff) = (Arc::clone(&fm), Arc::clone(&lm), cfg.num_of_buffers); - let bm: Arc> = match cfg.buffer_manager { + let bm: Arc> = match cfg.buffer_manager { config::BufferMgr::Naive => { Arc::new(Mutex::new(NaiveBufferMgr::new(bm_fm, bm_lm, numsbuff))) } diff --git a/src/tx/bufferlist.rs b/src/tx/bufferlist.rs index e4d7e133..408b6828 100644 --- a/src/tx/bufferlist.rs +++ b/src/tx/bufferlist.rs @@ -1,6 +1,7 @@ use anyhow::Result; use std::{ collections::HashMap, + fmt, sync::{Arc, Mutex}, }; @@ -9,15 +10,21 @@ use crate::{ file::block_id::BlockId, }; -#[derive(Debug, Clone)] +#[derive(Clone)] pub struct BufferList { buffers: HashMap>>, pins: Vec, - bm: Arc>, + bm: Arc>, +} + +impl fmt::Debug for BufferList { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "BufferList") + } } impl BufferList { - pub fn new(bm: Arc>) -> Self { + pub fn new(bm: Arc>) -> Self { Self { buffers: HashMap::new(), pins: vec![], diff --git a/src/tx/recovery/manager.rs b/src/tx/recovery/manager.rs index 25b395ed..0f765f2f 100644 --- a/src/tx/recovery/manager.rs +++ b/src/tx/recovery/manager.rs @@ -1,7 +1,10 @@ use anyhow::Result; use chrono::NaiveDate; use core::fmt; -use std::sync::{Arc, Mutex}; +use std::{ + fmt::Debug, + sync::{Arc, Mutex}, +}; use super::logrecord::{ self, checkpoint_record::CheckpointRecord, commit_record::CommitRecord, @@ -32,20 +35,26 @@ impl fmt::Display for RecoveryMgrError { } } -#[derive(Debug, Clone)] +#[derive(Clone)] pub struct RecoveryMgr { lm: Arc>, - bm: Arc>, + bm: Arc>, tx: Arc>, txnum: i32, } +impl fmt::Debug for RecoveryMgr { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "RecoveryMgr(Tx = {})", self.txnum) + } +} + impl RecoveryMgr { pub fn new( tx: Arc>, txnum: i32, lm: Arc>, - bm: Arc>, + bm: Arc>, ) -> Result { StartRecord::write_to_log(Arc::clone(&lm), txnum)?; diff --git a/src/tx/transaction.rs b/src/tx/transaction.rs index dfb0ea94..24f1023c 100644 --- a/src/tx/transaction.rs +++ b/src/tx/transaction.rs @@ -1,6 +1,7 @@ use anyhow::Result; use chrono::NaiveDate; use std::{ + fmt, sync::{Arc, Mutex}, usize, }; @@ -18,19 +19,25 @@ use crate::{ static END_OF_FILE: i32 = -1; -#[derive(Debug, Clone)] +#[derive(Clone)] pub struct Transaction { // static member (shared by all Transaction) next_tx_num: Arc>, recovery_mgr: Option>>, concur_mgr: ConcurrencyMgr, - bm: Arc>, + bm: Arc>, fm: Arc>, txnum: i32, mybuffers: BufferList, } +impl fmt::Debug for Transaction { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "Tx: {}", self.txnum) + } +} + impl Transaction { pub fn new( next_tx_num: Arc>, @@ -38,7 +45,7 @@ impl Transaction { fm: Arc>, lm: Arc>, - bm: Arc>, + bm: Arc>, ) -> Result { let mut tran = Self { next_tx_num,