Skip to content

Commit ce0bd7a

Browse files
committed
retry tx lock on shared wal shutdown on error
1 parent c1ebf3f commit ce0bd7a

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

libsql-wal/src/shared_wal.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,20 @@ pub struct SharedWal<IO: Io> {
5757
}
5858

5959
impl<IO: Io> SharedWal<IO> {
60+
#[tracing::instrument(skip(self), fields(namespace = self.namespace.as_str()))]
6061
pub fn shutdown(&self) -> Result<()> {
62+
tracing::info!("started namespace shutdown");
6163
self.shutdown.store(true, Ordering::SeqCst);
62-
let mut tx = Transaction::Read(self.begin_read(u64::MAX));
63-
self.upgrade(&mut tx)?;
64+
// fixme: for infinite loop
65+
let mut tx = loop {
66+
let mut tx = Transaction::Read(self.begin_read(u64::MAX));
67+
match self.upgrade(&mut tx) {
68+
Ok(_) => break tx,
69+
Err(Error::BusySnapshot) => continue,
70+
Err(e) => return Err(e),
71+
}
72+
};
73+
6474
{
6575
let mut tx = tx.as_write_mut().unwrap().lock();
6676
tx.commit();
@@ -69,6 +79,7 @@ impl<IO: Io> SharedWal<IO> {
6979
// The current segment will not be used anymore. It's empty, but we still seal it so that
7080
// the next startup doesn't find an unsealed segment.
7181
self.current.load().seal()?;
82+
tracing::info!("namespace shutdown");
7283
Ok(())
7384
}
7485

0 commit comments

Comments
 (0)