Skip to content

Commit

Permalink
comment out block_on
Browse files Browse the repository at this point in the history
Signed-off-by: Ping Yu <[email protected]>
  • Loading branch information
pingyu committed Oct 30, 2023
1 parent 56e8f4d commit 75ecb2c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/transaction/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::Value;
///
/// See the [Transaction](struct@crate::Transaction) docs for more information on the methods.
#[derive(new)]
pub struct Snapshot<Cod: Codec = ApiV1TxnCodec, PdC: PdClient = PdRpcClient<Cod>> {
pub struct Snapshot<Cod: Codec = ApiV1TxnCodec, PdC: PdClient<Codec = Cod> = PdRpcClient<Cod>> {
transaction: Transaction<Cod, PdC>,
phantom: PhantomData<Cod>,
}
Expand Down
45 changes: 23 additions & 22 deletions src/transaction/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use tokio::sync::RwLock;
use tokio::time::Duration;
use tracing::debug;
use tracing::instrument;
use tracing::warn;
use tracing::Span;

use crate::backoff::Backoff;
Expand Down Expand Up @@ -79,7 +78,7 @@ use crate::Value;
/// txn.commit().await.unwrap();
/// # });
/// ```
pub struct Transaction<Cod: Codec = ApiV1TxnCodec, PdC: PdClient = PdRpcClient<Cod>> {
pub struct Transaction<Cod: Codec = ApiV1TxnCodec, PdC: PdClient<Codec = Cod> = PdRpcClient<Cod>> {
status: Arc<RwLock<TransactionStatus>>,
timestamp: Timestamp,
buffer: Buffer,
Expand Down Expand Up @@ -1002,28 +1001,29 @@ impl<Cod: Codec, PdC: PdClient<Codec = Cod>> Transaction<Cod, PdC> {
}
}

impl<Cod: Codec, PdC: PdClient> Drop for Transaction<Cod, PdC> {
impl<Cod: Codec, PdC: PdClient<Codec = Cod>> Drop for Transaction<Cod, PdC> {
#[instrument(skip_all, fields(version=self.timestamp.version()))]
fn drop(&mut self) {
debug!("dropping transaction");
if std::thread::panicking() {
return;
}
// Don't use `futures::executor::block_on`.
// See https://github.com/tokio-rs/tokio/issues/2376.
let mut status = self.status.blocking_write();
if *status == TransactionStatus::Active {
match self.options.check_level {
CheckLevel::Panic => {
panic!("Dropping an active transaction. Consider commit or rollback it.")
}
CheckLevel::Warn => {
warn!("Dropping an active transaction. Consider commit or rollback it.")
}

CheckLevel::None => {}
}
}
*status = TransactionStatus::Dropped;
// if std::thread::panicking() {
// return;
// }
// // Don't use `futures::executor::block_on`.
// // See https://github.com/tokio-rs/tokio/issues/2376.
// let mut status = tokio::task::spawn_blocking(self.status.write());
// if *status == TransactionStatus::Active {
// match self.options.check_level {
// CheckLevel::Panic => {
// panic!("Dropping an active transaction. Consider commit or rollback it.")
// }
// CheckLevel::Warn => {
// warn!("Dropping an active transaction. Consider commit or rollback it.")
// }
//
// CheckLevel::None => {}
// }
// }
// *status = TransactionStatus::Dropped;
}
}

Expand Down Expand Up @@ -1472,6 +1472,7 @@ enum TransactionStatus {
/// The transaction has tried to rollback. Only `rollback` is allowed.
StartedRollback,
/// The transaction has been dropped.
#[allow(dead_code)]
Dropped,
}

Expand Down

0 comments on commit 75ecb2c

Please sign in to comment.