Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
cutsea110 committed Jun 24, 2022
1 parent e29e227 commit 3193a47
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/server/simpledb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub struct SimpleDB {
// managers
fm: Arc<Mutex<FileMgr>>,
lm: Arc<Mutex<LogMgr>>,
bm: Arc<Mutex<dyn BufferMgr>>,
bm: Arc<Mutex<dyn BufferMgr + Send>>,
mdm: Option<Arc<Mutex<MetadataMgr>>>,
qp: Option<Arc<Mutex<dyn QueryPlanner>>>,
up: Option<Arc<Mutex<dyn UpdatePlanner>>>,
Expand Down Expand Up @@ -125,7 +125,7 @@ impl SimpleDB {
pub fn log_mgr(&self) -> Arc<Mutex<LogMgr>> {
Arc::clone(&self.lm)
}
pub fn buffer_mgr(&self) -> Arc<Mutex<dyn BufferMgr>> {
pub fn buffer_mgr(&self) -> Arc<Mutex<dyn BufferMgr + Send>> {
Arc::clone(&self.bm)
}
pub fn metadata_mgr(&self) -> Option<Arc<Mutex<MetadataMgr>>> {
Expand Down
13 changes: 10 additions & 3 deletions src/tx/bufferlist.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::Result;
use std::{
collections::HashMap,
fmt,
sync::{Arc, Mutex},
};

Expand All @@ -9,15 +10,21 @@ use crate::{
file::block_id::BlockId,
};

#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct BufferList {
buffers: HashMap<BlockId, Arc<Mutex<Buffer>>>,
pins: Vec<BlockId>,
bm: Arc<Mutex<dyn BufferMgr>>,
bm: Arc<Mutex<dyn BufferMgr + Send>>,
}

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<Mutex<dyn BufferMgr>>) -> Self {
pub fn new(bm: Arc<Mutex<dyn BufferMgr + Send>>) -> Self {
Self {
buffers: HashMap::new(),
pins: vec![],
Expand Down
17 changes: 13 additions & 4 deletions src/tx/recovery/manager.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -32,20 +35,26 @@ impl fmt::Display for RecoveryMgrError {
}
}

#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct RecoveryMgr {
lm: Arc<Mutex<LogMgr>>,
bm: Arc<Mutex<dyn BufferMgr>>,
bm: Arc<Mutex<dyn BufferMgr + Send>>,
tx: Arc<Mutex<Transaction>>,
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<Mutex<Transaction>>,
txnum: i32,
lm: Arc<Mutex<LogMgr>>,
bm: Arc<Mutex<dyn BufferMgr>>,
bm: Arc<Mutex<dyn BufferMgr + Send>>,
) -> Result<Self> {
StartRecord::write_to_log(Arc::clone(&lm), txnum)?;

Expand Down
13 changes: 10 additions & 3 deletions src/tx/transaction.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::Result;
use chrono::NaiveDate;
use std::{
fmt,
sync::{Arc, Mutex},
usize,
};
Expand All @@ -18,27 +19,33 @@ 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<Mutex<i32>>,

recovery_mgr: Option<Arc<Mutex<RecoveryMgr>>>,
concur_mgr: ConcurrencyMgr,
bm: Arc<Mutex<dyn BufferMgr>>,
bm: Arc<Mutex<dyn BufferMgr + Send>>,
fm: Arc<Mutex<FileMgr>>,
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<Mutex<i32>>,
locktbl: Arc<Mutex<LockTable>>,

fm: Arc<Mutex<FileMgr>>,
lm: Arc<Mutex<LogMgr>>,
bm: Arc<Mutex<dyn BufferMgr>>,
bm: Arc<Mutex<dyn BufferMgr + Send>>,
) -> Result<Self> {
let mut tran = Self {
next_tx_num,
Expand Down

0 comments on commit 3193a47

Please sign in to comment.