Skip to content

Commit bc2c40f

Browse files
committed
Avoid block_in_place in the common case for local durability as well
1 parent eea36a4 commit bc2c40f

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

crates/durability/src/imp/local.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,13 +330,21 @@ impl<T: Send + Sync + 'static> Durability for Local<T> {
330330
type TxData = Txdata<T>;
331331

332332
fn append_tx(&self, tx: Transaction<Self::TxData>) {
333-
let send = || self.queue.blocking_send(tx);
334-
if tokio::runtime::Handle::try_current().is_ok() {
335-
tokio::task::block_in_place(send)
336-
} else {
337-
send()
333+
match self.queue.try_reserve() {
334+
Ok(permit) => permit.send(tx),
335+
Err(mpsc::error::TrySendError::Closed(_)) => {
336+
panic!("durability actor crashed");
337+
}
338+
Err(mpsc::error::TrySendError::Full(_)) => {
339+
let send = || self.queue.blocking_send(tx);
340+
if tokio::runtime::Handle::try_current().is_ok() {
341+
tokio::task::block_in_place(send)
342+
} else {
343+
send()
344+
}
345+
.expect("durability actor crashed");
346+
}
338347
}
339-
.expect("durability actor crashed");
340348

341349
self.queue_depth.fetch_add(1, Relaxed);
342350
}

0 commit comments

Comments
 (0)