store: replace fjal reset by dir nuking

This commit is contained in:
nym21
2026-04-03 17:49:46 +02:00
parent 768e6870cb
commit 5bf06530ce
10 changed files with 68 additions and 424 deletions

View File

@@ -114,6 +114,18 @@ impl Indexer {
}
}
/// Fully resets the indexer by deleting stores from disk and reimporting.
/// Unlike stores.reset() which uses keyspace.clear() (leaving a journal
/// record that gets replayed on every recovery), this cleanly recreates.
fn full_reset(&mut self) -> Result<()> {
info!("Full reset...");
self.vecs.reset()?;
let stores_path = self.path.join("stores");
fs::remove_dir_all(&stores_path).ok();
self.stores = Stores::forced_import(&self.path, VERSION)?;
Ok(())
}
pub fn index(&mut self, reader: &Reader, client: &Client, exit: &Exit) -> Result<Indexes> {
self.index_(reader, client, exit, false)
}
@@ -135,9 +147,7 @@ impl Indexer {
return Ok(());
}
info!("XOR bytes changed, full reset...");
self.vecs.reset()?;
self.stores.reset()?;
self.full_reset()?;
fs::write(self.path.join("xor.dat"), *current)?;
@@ -179,8 +189,7 @@ impl Indexer {
}
None => {
info!("Data inconsistency detected, resetting indexer...");
self.vecs.reset()?;
self.stores.reset()?;
self.full_reset()?;
(Indexes::default(), None)
}
}
@@ -308,13 +317,35 @@ impl Indexer {
drop(readers);
let lock = exit.lock();
self.stores.commit(indexes.height)?;
let tasks = self.stores.take_all_pending_ingests(indexes.height)?;
self.vecs.stamped_write(indexes.height)?;
let fjall_db = self.stores.db.clone();
self.vecs.db.run_bg(move |db| {
let _lock = lock;
sleep(Duration::from_secs(5));
info!("Exporting...");
let i = Instant::now();
if !tasks.is_empty() {
let i = Instant::now();
for task in tasks {
task().map_err(vecdb::RawDBError::other)?;
}
debug!("Stores committed in {:?}", i.elapsed());
let i = Instant::now();
fjall_db
.persist(PersistMode::SyncData)
.map_err(RawDBError::other)?;
debug!("Stores persisted in {:?}", i.elapsed());
}
db.compact()?;
info!("Exported in {:?}", i.elapsed());
Ok(())
});

View File

@@ -116,13 +116,6 @@ impl Stores {
)?,
};
debug!(
"Stores imported: txid_prefix empty={}, blockhash empty={}, keyspace_count={}",
stores.txid_prefix_to_tx_index.is_empty()?,
stores.blockhash_prefix_to_height.is_empty()?,
database.keyspace_count(),
);
Ok(stores)
}
@@ -409,17 +402,5 @@ impl Stores {
}
}
pub fn reset(&mut self) -> Result<()> {
info!("Resetting stores...");
// Clear all stores (both in-memory buffers and on-disk keyspaces)
self.par_iter_any_mut()
.try_for_each(|store| store.reset())?;
// Persist the cleared state
self.db.persist(PersistMode::SyncAll)?;
Ok(())
}
}