Skip to content

Commit 22bbc48

Browse files
committed
get txn out of owned txn guard
1 parent 4bf5f75 commit 22bbc48

1 file changed

Lines changed: 13 additions & 14 deletions

File tree

libsql-wal/src/transaction.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,23 @@ pub struct WriteTransaction<F> {
155155
}
156156

157157
pub struct TxGuardOwned<F> {
158-
_lock: Option<async_lock::MutexGuardArc<Option<u64>>>,
158+
lock: Option<async_lock::MutexGuardArc<Option<u64>>>,
159159
inner: Option<WriteTransaction<F>>,
160160
}
161161

162+
impl<F> TxGuardOwned<F> {
163+
pub(crate) fn into_inner(mut self) -> WriteTransaction<F> {
164+
self.lock.take();
165+
self.inner.take().unwrap()
166+
}
167+
}
168+
162169
impl<F> Drop for TxGuardOwned<F> {
163170
fn drop(&mut self) {
164-
let _ = self._lock.take();
165-
self.inner.take().expect("already dropped").downgrade();
171+
let _ = self.lock.take();
172+
if let Some(inner) = self.inner.take() {
173+
inner.downgrade();
174+
}
166175
}
167176
}
168177

@@ -217,11 +226,6 @@ impl<F> WriteTransaction<F> {
217226
}
218227

219228
pub fn lock(&mut self) -> TxGuard<F> {
220-
if self.is_commited {
221-
tracing::error!("transaction already commited");
222-
todo!("txn has already been commited");
223-
}
224-
225229
let g = self.wal_lock.tx_id.lock_arc_blocking();
226230
match *g {
227231
// we still hold the lock, we can proceed
@@ -236,16 +240,11 @@ impl<F> WriteTransaction<F> {
236240
}
237241

238242
pub fn into_lock_owned(self) -> TxGuardOwned<F> {
239-
if self.is_commited {
240-
tracing::error!("transaction already commited");
241-
todo!("txn has already been commited");
242-
}
243-
244243
let g = self.wal_lock.tx_id.lock_arc_blocking();
245244
match *g {
246245
// we still hold the lock, we can proceed
247246
Some(id) if self.id == id => TxGuardOwned {
248-
_lock: Some(g),
247+
lock: Some(g),
249248
inner: Some(self),
250249
},
251250
// Somebody took the lock from us

0 commit comments

Comments
 (0)