Skip to content

Commit 3a3500b

Browse files
committed
add destroy method to segment
1 parent ec4b2eb commit 3a3500b

3 files changed

Lines changed: 19 additions & 0 deletions

File tree

libsql-wal/src/segment/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use zerocopy::AsBytes;
2121
use crate::error::{Error, Result};
2222
use crate::io::buf::IoBufMut;
2323
use crate::io::FileExt;
24+
use crate::io::Io;
2425
use crate::LIBSQL_MAGIC;
2526
use crate::LIBSQL_PAGE_SIZE;
2627

@@ -167,6 +168,8 @@ pub trait Segment: Send + Sync + 'static {
167168
async fn read_frame_offset_async<B>(&self, offset: u32, buf: B) -> (B, Result<()>)
168169
where
169170
B: IoBufMut + Send + 'static;
171+
172+
fn destroy<IO: Io>(&self, io: &IO) -> impl Future<Output = ()>;
170173
}
171174

172175
impl<T: Segment> Segment for Arc<T> {
@@ -208,6 +211,10 @@ impl<T: Segment> Segment for Arc<T> {
208211
fn size_after(&self) -> u32 {
209212
self.as_ref().size_after()
210213
}
214+
215+
fn destroy<IO: Io>(&self, io: &IO) -> impl Future<Output = ()> {
216+
self.as_ref().destroy(io)
217+
}
211218
}
212219

213220
#[repr(C)]

libsql-wal/src/segment/sealed.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,14 @@ where
183183
fn size_after(&self) -> u32 {
184184
self.header().size_after()
185185
}
186+
187+
fn destroy<IO: crate::io::Io>(&self, io: &IO) -> impl std::future::Future<Output = ()> {
188+
async move {
189+
if let Err(e) = io.remove_file_async(&self.path).await {
190+
tracing::error!("failed to remove segment file {:?}: {e}", self.path);
191+
}
192+
}
193+
}
186194
}
187195

188196
impl<F: FileExt> SealedSegment<F> {

libsql-wal/src/storage/job.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,10 @@ mod test {
421421
{
422422
todo!()
423423
}
424+
425+
fn destroy<IO: Io>(&self, _io: &IO) -> impl std::future::Future<Output = ()> {
426+
async move { todo!() }
427+
}
424428
}
425429

426430
struct TestBackend;

0 commit comments

Comments
 (0)