Skip to content

Commit

Permalink
Delay block in place (#454)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkuris authored Jan 2, 2024
1 parent 36a562c commit fab15d7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
11 changes: 5 additions & 6 deletions firewood/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ pub struct DbRev<S> {
#[async_trait]
impl<S: ShaleStore<Node> + Send + Sync> api::DbView for DbRev<S> {
async fn root_hash(&self) -> Result<api::HashKey, api::Error> {
block_in_place(|| self.merkle.root_hash(self.header.kv_root))
self.merkle
.root_hash(self.header.kv_root)
.map(|h| *h)
.map_err(|e| api::Error::IO(std::io::Error::new(ErrorKind::Other, e)))
}
Expand Down Expand Up @@ -414,7 +415,7 @@ impl api::Db for Db {
type Proposal = proposal::Proposal;

async fn revision(&self, root_hash: HashKey) -> Result<Arc<Self::Historical>, api::Error> {
let rev = block_in_place(|| self.get_revision(&TrieHash(root_hash)));
let rev = self.get_revision(&TrieHash(root_hash));
if let Some(rev) = rev {
Ok(Arc::new(rev.rev))
} else {
Expand All @@ -425,16 +426,14 @@ impl api::Db for Db {
}

async fn root_hash(&self) -> Result<HashKey, api::Error> {
block_in_place(|| self.kv_root_hash())
.map(|hash| hash.0)
.map_err(Into::into)
self.kv_root_hash().map(|hash| hash.0).map_err(Into::into)
}

async fn propose<K: KeyType, V: ValueType>(
&self,
batch: api::Batch<K, V>,
) -> Result<Self::Proposal, api::Error> {
block_in_place(|| self.new_proposal(batch)).map_err(Into::into)
self.new_proposal(batch).map_err(Into::into)
}
}

Expand Down
2 changes: 1 addition & 1 deletion firewood/src/db/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl crate::v2::api::Proposal for Proposal {
self: Arc<Self>,
data: api::Batch<K, V>,
) -> Result<Self::Proposal, api::Error> {
block_in_place(|| self.propose_sync(data)).map_err(Into::into)
self.propose_sync(data).map_err(Into::into)
}
}

Expand Down
5 changes: 3 additions & 2 deletions firewood/src/storage/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use growthring::{
walerror::WalError,
WalFileImpl, WalStoreImpl,
};
use tokio::task::block_in_place;
use tokio::{
sync::{
mpsc,
Expand Down Expand Up @@ -588,7 +589,7 @@ impl DiskBufferRequester {
.map_err(StoreError::Send)
.ok();
#[allow(clippy::unwrap_used)]
resp_rx.blocking_recv().unwrap()
block_in_place(move || resp_rx.blocking_recv().unwrap())
}

/// Sends a batch of writes to the buffer.
Expand Down Expand Up @@ -622,7 +623,7 @@ impl DiskBufferRequester {
.send(BufferCmd::CollectAsh(nrecords, resp_tx))
.map_err(StoreError::Send)
.ok();
resp_rx.blocking_recv().map_err(StoreError::Receive)
block_in_place(|| resp_rx.blocking_recv().map_err(StoreError::Receive))
}

/// Register a cached space to the buffer.
Expand Down

0 comments on commit fab15d7

Please sign in to comment.