global: snapshot

This commit is contained in:
nym21
2025-04-27 16:29:21 +02:00
parent 1e38c21f8e
commit 9ae0a57f22
22 changed files with 1643 additions and 555 deletions

View File

@@ -4,7 +4,7 @@ use brk_core::{
AddressBytes, AddressBytesHash, BlockHashPrefix, Height, OutputType, OutputTypeIndex, TxIndex,
TxidPrefix,
};
use brk_vec::{Value, Version};
use brk_vec::{StoredIndex, Value, Version};
use fjall::{PersistMode, TransactionalKeyspace};
use crate::Indexes;
@@ -88,11 +88,12 @@ impl Stores {
if starting_indexes.height != Height::ZERO {
vecs.height_to_blockhash
.iter_from(starting_indexes.height, |(_, blockhash, ..)| {
let blockhashprefix = BlockHashPrefix::from(blockhash);
.into_iter()
.skip(starting_indexes.height.unwrap_to_usize())
.for_each(|(_, v)| {
let blockhashprefix = BlockHashPrefix::from(Value::into_inner(v));
self.blockhashprefix_to_height.remove(blockhashprefix);
Ok(())
})?;
});
if let Some(mut index) = vecs
.height_to_first_p2pk65index
@@ -234,8 +235,10 @@ impl Stores {
if starting_indexes.txindex != TxIndex::ZERO {
vecs.txindex_to_txid
.iter_from(starting_indexes.txindex, |(txindex, txid, ..)| {
let txidprefix = TxidPrefix::from(&txid);
.into_iter()
.skip(starting_indexes.txindex.unwrap_to_usize())
.for_each(|(txindex, txid)| {
let txidprefix = TxidPrefix::from(&txid.into_inner());
// "d5d27987d2a3dfc724e359870c6644b40e497bdc0589a033220fe15429d88599"
let is_not_first_dup = txindex != TxIndex::new(142783)
@@ -248,9 +251,7 @@ impl Stores {
if is_not_first_dup && is_not_second_dup {
self.txidprefix_to_txindex.remove(txidprefix);
}
Ok(())
})?;
});
} else {
self.txidprefix_to_txindex.reset_partition()?;
}

View File

@@ -5,8 +5,8 @@ use std::{
};
use brk_vec::{
Compressed, DynamicVec, Error, GenericVec, Result, StoredIndex, StoredType, StoredVec, Value,
Version,
Compressed, DynamicVec, Error, GenericVec, Result, StoredIndex, StoredType, StoredVec,
StoredVecIterator, Value, Version,
};
use super::Height;
@@ -54,13 +54,6 @@ where
self.inner.double_unwrap_cached_get(index)
}
pub fn iter_from<F>(&mut self, index: I, f: F) -> Result<()>
where
F: FnMut((I, T, &mut dyn DynamicVec<I = I, T = T>)) -> Result<()>,
{
self.inner.iter_from(index, f)
}
#[inline]
pub fn push_if_needed(&mut self, index: I, value: T) -> Result<()> {
match self.inner.len().cmp(&index.to_usize()?) {
@@ -127,6 +120,10 @@ where
fn path_height_(path: &Path) -> PathBuf {
path.join("height")
}
pub fn iter(&self) -> StoredVecIterator<'_, I, T> {
self.into_iter()
}
}
pub trait AnyIndexedVec: Send + Sync {
@@ -147,3 +144,16 @@ where
self.flush(height)
}
}
impl<'a, I, T> IntoIterator for &'a IndexedVec<I, T>
where
I: StoredIndex,
T: StoredType,
{
type Item = (I, Value<'a, T>);
type IntoIter = StoredVecIterator<'a, I, T>;
fn into_iter(self) -> Self::IntoIter {
self.inner.into_iter()
}
}