Skip to content

Commit

Permalink
Removes parking lot dependency
Browse files Browse the repository at this point in the history
There is some circumventions around the absence of upgradable read locks. Not sure if they are valid...
  • Loading branch information
Tpt committed Sep 28, 2022
1 parent 8ed1bbe commit f72ff20
Show file tree
Hide file tree
Showing 9 changed files with 187 additions and 187 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ libc = "0.2"
log = "0.4.8"
lz4 = "1.24.0"
memmap2 = "0.5"
parking_lot = "0.12.0"
rand = "0.8.4"
snap = "1"

Expand Down
12 changes: 6 additions & 6 deletions src/btree/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use super::*;
use crate::{
btree::BTreeTable, db::CommitOverlay, error::Result, log::LogQuery, table::key::TableKeyQuery,
};
use parking_lot::RwLock;
use std::sync::RwLock;

#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum SeekTo<'a> {
Expand Down Expand Up @@ -75,7 +75,7 @@ impl<'a> BTreeIterator<'a> {
log: &'a RwLock<crate::log::LogOverlays>,
commit_overlay: &'a RwLock<Vec<CommitOverlay>>,
) -> Result<Self> {
let record_id = log.read().last_record_id(col);
let record_id = log.read().unwrap().last_record_id(col);
let tree = table.with_locked(|btree| BTree::open(btree, log, record_id))?;
let iter = BTreeIterState::new(tree.record_id);
Ok(BTreeIterator {
Expand All @@ -91,7 +91,7 @@ impl<'a> BTreeIterator<'a> {

pub fn seek(&mut self, key: &[u8]) -> Result<()> {
// seek require log do not change
let log = self.log.read();
let log = self.log.read().unwrap();
let record_id = log.last_record_id(self.col);
self.last_key = LastKey::Seeked(key.to_vec());
self.pending_backend = None;
Expand All @@ -103,7 +103,7 @@ impl<'a> BTreeIterator<'a> {
}

pub fn seek_to_last(&mut self) -> Result<()> {
let log = self.log.read();
let log = self.log.read().unwrap();
let record_id = log.last_record_id(self.col);
self.last_key = LastKey::End;
self.seek_backend_to_last(record_id, self.table, &*log)
Expand All @@ -123,13 +123,13 @@ impl<'a> BTreeIterator<'a> {

loop {
// Lock log over function call (no btree struct change).
let commit_overlay = self.commit_overlay.read();
let commit_overlay = self.commit_overlay.read().unwrap();
let next_commit_overlay =
commit_overlay.get(col as usize).and_then(|o| match direction {
IterDirection::Forward => o.btree_next(&self.last_key),
IterDirection::Backward => o.btree_prev(&self.last_key),
});
let log = self.log.read();
let log = self.log.read().unwrap();
let record_id = log.last_record_id(self.col);
// No consistency over iteration, allows dropping lock to overlay.
drop(commit_overlay);
Expand Down
18 changes: 9 additions & 9 deletions src/btree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
};
pub use iter::{BTreeIterator, LastIndex, LastKey};
use node::SeparatorInner;
use parking_lot::RwLock;
use std::sync::RwLock;

#[allow(clippy::module_inception)]
mod btree;
Expand Down Expand Up @@ -172,13 +172,13 @@ impl BTreeTable {
address: Address,
log: &impl LogQuery,
) -> Result<Option<(u8, Value)>> {
let tables = self.tables.read();
let tables = self.tables.read().unwrap();
let btree = self.locked(&tables);
Column::get_value(key, address, btree, log)
}

pub fn flush(&self) -> Result<()> {
let tables = self.tables.read();
let tables = self.tables.read().unwrap();
for t in tables.iter() {
t.flush()?;
}
Expand Down Expand Up @@ -216,13 +216,13 @@ impl BTreeTable {
}

pub fn with_locked<R>(&self, mut apply: impl FnMut(TablesRef) -> Result<R>) -> Result<R> {
let locked_tables = &*self.tables.read();
let locked_tables = &*self.tables.read().unwrap();
let locked = self.locked(locked_tables);
apply(locked)
}

pub fn enact_plan(&self, action: LogAction, log: &mut LogReader) -> Result<()> {
let tables = self.tables.read();
let tables = self.tables.read().unwrap();
match action {
LogAction::InsertValue(record) => {
tables[record.table.size_tier() as usize].enact_plan(record.index, log)?;
Expand All @@ -233,7 +233,7 @@ impl BTreeTable {
}

pub fn validate_plan(&self, action: LogAction, log: &mut LogReader) -> Result<()> {
let tables = self.tables.upgradable_read();
let tables = self.tables.write().unwrap();
match action {
LogAction::InsertValue(record) => {
tables[record.table.size_tier() as usize].validate_plan(record.index, log)?;
Expand All @@ -247,15 +247,15 @@ impl BTreeTable {
}

pub fn complete_plan(&self, log: &mut LogWriter) -> Result<()> {
let tables = self.tables.read();
let tables = self.tables.read().unwrap();
for t in tables.iter() {
t.complete_plan(log)?;
}
Ok(())
}

pub fn refresh_metadata(&self) -> Result<()> {
let tables = self.tables.read();
let tables = self.tables.read().unwrap();
for t in tables.iter() {
t.refresh_metadata()?;
}
Expand Down Expand Up @@ -436,7 +436,7 @@ pub mod commit_overlay {
) -> Result<()> {
let record_id = writer.record_id();

let locked_tables = btree.tables.read();
let locked_tables = btree.tables.read().unwrap();
let locked = btree.locked(&locked_tables);
let mut tree = BTree::open(locked, writer, record_id)?;

Expand Down
Loading

0 comments on commit f72ff20

Please sign in to comment.