diff options
Diffstat (limited to 'import/src/db.rs')
-rw-r--r-- | import/src/db.rs | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/import/src/db.rs b/import/src/db.rs index e6174e4..87350ac 100644 --- a/import/src/db.rs +++ b/import/src/db.rs @@ -1,6 +1,6 @@ use anyhow::{anyhow, Context}; use jellybase::database::{ - redb::ReadableTable, + redb::{ReadableTable, ReadableTableMetadata}, tantivy::{doc, DateTime}, DataAcid, Ser, T_NODE, T_NODE_EXTENDED, T_NODE_IMPORT, }; @@ -21,6 +21,7 @@ pub(crate) trait ImportStorage: Sync { fn get_partial_parts(&self, id: &str) -> anyhow::Result<Vec<(Vec<usize>, Node)>>; fn insert_complete_node(&self, id: &str, node: Node) -> anyhow::Result<()>; + fn pre_clean(&self) -> anyhow::Result<()>; fn remove_prev_nodes(&self) -> anyhow::Result<()>; fn finish(&self) -> anyhow::Result<()>; } @@ -34,6 +35,17 @@ impl<'a> DatabaseStorage<'a> { } } impl ImportStorage for DatabaseStorage<'_> { + fn pre_clean(&self) -> anyhow::Result<()> { + let txn = self.db.begin_write()?; + let mut table = txn.open_table(T_NODE_IMPORT)?; + if !table.is_empty()? { + info!("clearing temporary node tree from an aborted last import..."); + table.retain(|_, _| false)?; + } + drop(table); + txn.commit()?; + Ok(()) + } fn remove_prev_nodes(&self) -> anyhow::Result<()> { info!("removing old nodes..."); let txn = self.db.inner.begin_write()?; @@ -107,6 +119,9 @@ impl<'a> MemoryStorage<'a> { } } impl ImportStorage for MemoryStorage<'_> { + fn pre_clean(&self) -> anyhow::Result<()> { + Ok(()) + } fn remove_prev_nodes(&self) -> anyhow::Result<()> { info!("removing old nodes..."); let txn = self.db.inner.begin_write()?; |