Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay block in place #454

Merged
merged 6 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just guessing that you don't need this here because you're not in an async function

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 will it work if not in an async call?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this, all the tests fail. This code does nothing if you're not in an async context. If you are, then it moves you to a blockable thread to prevent interference with the async runtime.

}

/// 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
Loading