mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-16 05:28:12 -07:00
global: snapshot
This commit is contained in:
@@ -15,7 +15,7 @@ pub enum Error {
|
||||
FjallV2(fjall2::Error),
|
||||
FjallV3(fjall3::Error),
|
||||
VecDB(vecdb::Error),
|
||||
SeqDB(vecdb::SeqDBError),
|
||||
RawDB(vecdb::RawDBError),
|
||||
Minreq(minreq::Error),
|
||||
SystemTimeError(time::SystemTimeError),
|
||||
BitcoinConsensusEncode(bitcoin::consensus::encode::Error),
|
||||
@@ -106,10 +106,10 @@ impl From<vecdb::Error> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<vecdb::SeqDBError> for Error {
|
||||
impl From<vecdb::RawDBError> for Error {
|
||||
#[inline]
|
||||
fn from(value: vecdb::SeqDBError) -> Self {
|
||||
Self::SeqDB(value)
|
||||
fn from(value: vecdb::RawDBError) -> Self {
|
||||
Self::RawDB(value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ impl fmt::Display for Error {
|
||||
Error::IO(error) => Display::fmt(&error, f),
|
||||
Error::Jiff(error) => Display::fmt(&error, f),
|
||||
Error::Minreq(error) => Display::fmt(&error, f),
|
||||
Error::SeqDB(error) => Display::fmt(&error, f),
|
||||
Error::RawDB(error) => Display::fmt(&error, f),
|
||||
Error::SonicRS(error) => Display::fmt(&error, f),
|
||||
Error::SystemTimeError(error) => Display::fmt(&error, f),
|
||||
Error::VecDB(error) => Display::fmt(&error, f),
|
||||
|
||||
@@ -17,22 +17,22 @@ use rayon::prelude::*;
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
use vecdb::{AnyVec, Exit, GenericStoredVec, Reader, VecIteratorExtended};
|
||||
mod indexes;
|
||||
mod stores_redb;
|
||||
// mod stores_redb;
|
||||
// mod stores_v2;
|
||||
// mod stores_v3;
|
||||
mod stores_v3;
|
||||
mod vecs;
|
||||
|
||||
pub use indexes::*;
|
||||
pub use stores_redb::*;
|
||||
// pub use stores_redb::*;
|
||||
// pub use stores_v2::*;
|
||||
// pub use stores_v3::*;
|
||||
pub use stores_v3::*;
|
||||
pub use vecs::*;
|
||||
|
||||
// One version for all data sources
|
||||
// Increment on **change _OR_ addition**
|
||||
const VERSION: Version = Version::new(23);
|
||||
const SNAPSHOT_BLOCK_RANGE: usize = 1_000;
|
||||
const COLLISIONS_CHECKED_UP_TO: Height = Height::new(920_000);
|
||||
const COLLISIONS_CHECKED_UP_TO: Height = Height::new(0);
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Indexer {
|
||||
@@ -746,7 +746,7 @@ impl Indexer {
|
||||
}
|
||||
|
||||
// let i = Instant::now();
|
||||
self.vecs.punch_holes()?;
|
||||
self.vecs.compact()?;
|
||||
// info!("Punched holes in db in {}s", i.elapsed().as_secs());
|
||||
|
||||
Ok(starting_indexes)
|
||||
|
||||
@@ -8,7 +8,7 @@ use brk_types::{
|
||||
TxOutIndex, TxidPrefix, TypeIndex, TypeIndexAndOutPoint, TypeIndexAndTxIndex, Unit, Version,
|
||||
Vout,
|
||||
};
|
||||
use fjall3::{PersistMode, TxDatabase};
|
||||
use fjall3::{Database, PersistMode};
|
||||
use log::info;
|
||||
use rayon::prelude::*;
|
||||
use vecdb::{AnyVec, GenericStoredVec, StoredIndex, VecIterator, VecIteratorExtended};
|
||||
@@ -19,7 +19,7 @@ use super::Vecs;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Stores {
|
||||
pub database: TxDatabase,
|
||||
pub database: Database,
|
||||
|
||||
pub addressbyteshash_to_typeindex: Store<AddressBytesHash, TypeIndex>,
|
||||
pub blockhashprefix_to_height: Store<BlockHashPrefix, Height>,
|
||||
@@ -37,7 +37,7 @@ impl Stores {
|
||||
|
||||
fs::create_dir_all(&pathbuf)?;
|
||||
|
||||
let database = match brk_store::open_fjall2_database(path) {
|
||||
let database = match brk_store::open_fjall3_database(path) {
|
||||
Ok(database) => database,
|
||||
Err(_) => {
|
||||
fs::remove_dir_all(path)?;
|
||||
|
||||
@@ -364,8 +364,8 @@ impl Vecs {
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn punch_holes(&self) -> Result<()> {
|
||||
self.db.punch_holes()?;
|
||||
pub fn compact(&self) -> Result<()> {
|
||||
self.db.compact()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ use std::{
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_types::Version;
|
||||
use fjall3::{TxDatabase, TxKeyspace};
|
||||
use fjall3::{Database, Keyspace};
|
||||
|
||||
use super::Height;
|
||||
|
||||
@@ -18,13 +18,13 @@ pub struct StoreMeta {
|
||||
|
||||
impl StoreMeta {
|
||||
pub fn checked_open<F>(
|
||||
_database: &TxDatabase,
|
||||
_database: &Database,
|
||||
path: &Path,
|
||||
version: Version,
|
||||
open_partition_handle: F,
|
||||
) -> Result<(Self, TxKeyspace)>
|
||||
) -> Result<(Self, Keyspace)>
|
||||
where
|
||||
F: Fn() -> Result<TxKeyspace>,
|
||||
F: Fn() -> Result<Keyspace>,
|
||||
{
|
||||
fs::create_dir_all(path)?;
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ use brk_error::Result;
|
||||
use brk_types::{Height, Version};
|
||||
use byteview8::ByteView;
|
||||
use fjall3::{
|
||||
KeyspaceCreateOptions, TxDatabase, TxKeyspace, ValueType,
|
||||
config::{BloomConstructionPolicy, FilterPolicy, FilterPolicyEntry},
|
||||
Database, Keyspace, KeyspaceCreateOptions, ValueType,
|
||||
config::{BloomConstructionPolicy, FilterPolicy, FilterPolicyEntry, PinningPolicy},
|
||||
};
|
||||
|
||||
mod meta;
|
||||
@@ -19,16 +19,16 @@ use crate::any::AnyStore;
|
||||
pub struct StoreFjallV3<Key, Value> {
|
||||
meta: StoreMeta,
|
||||
name: &'static str,
|
||||
database: TxDatabase,
|
||||
keyspace: TxKeyspace,
|
||||
database: Database,
|
||||
keyspace: Keyspace,
|
||||
puts: FxHashMap<Key, Value>,
|
||||
dels: FxHashSet<Key>,
|
||||
}
|
||||
|
||||
const MAJOR_FJALL_VERSION: Version = Version::new(3);
|
||||
|
||||
pub fn open_fjall2_database(path: &Path) -> fjall3::Result<TxDatabase> {
|
||||
TxDatabase::builder(path.join("fjall"))
|
||||
pub fn open_fjall3_database(path: &Path) -> fjall3::Result<Database> {
|
||||
Database::builder(path.join("fjall"))
|
||||
.max_write_buffer_size(32 * 1024 * 1024)
|
||||
.cache_size(1024 * 1024 * 1024)
|
||||
.open()
|
||||
@@ -41,12 +41,14 @@ where
|
||||
ByteView: From<K> + From<V>,
|
||||
{
|
||||
fn open_keyspace(
|
||||
database: &TxDatabase,
|
||||
database: &Database,
|
||||
name: &str,
|
||||
bloom_filters: Option<bool>,
|
||||
) -> Result<TxKeyspace> {
|
||||
) -> Result<Keyspace> {
|
||||
let mut options = KeyspaceCreateOptions::default()
|
||||
.manual_journal_persist(true)
|
||||
.filter_block_pinning_policy(PinningPolicy::all(false))
|
||||
.index_block_pinning_policy(PinningPolicy::all(false))
|
||||
.max_memtable_size(8 * 1024 * 1024);
|
||||
|
||||
if bloom_filters.is_some_and(|b| !b) {
|
||||
@@ -61,7 +63,7 @@ where
|
||||
}
|
||||
|
||||
pub fn import(
|
||||
database: &TxDatabase,
|
||||
database: &Database,
|
||||
path: &Path,
|
||||
name: &str,
|
||||
version: Version,
|
||||
@@ -112,10 +114,7 @@ where
|
||||
|
||||
#[inline]
|
||||
pub fn is_empty(&self) -> Result<bool> {
|
||||
self.database
|
||||
.read_tx()
|
||||
.is_empty(&self.keyspace)
|
||||
.map_err(|e| e.into())
|
||||
self.keyspace.is_empty().map_err(|e| e.into())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -178,7 +177,7 @@ where
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut batch = self.database.inner().batch();
|
||||
let mut batch = self.database.batch();
|
||||
let mut items = mem::take(&mut self.puts)
|
||||
.into_iter()
|
||||
.map(|(key, value)| Item::Value { key, value })
|
||||
@@ -193,7 +192,7 @@ where
|
||||
.into_iter()
|
||||
.map(|i| i.fjall(&self.keyspace))
|
||||
.collect::<Vec<_>>();
|
||||
batch.commit_keyspace(self.keyspace.inner())?;
|
||||
batch.commit_keyspace(&self.keyspace)?;
|
||||
|
||||
// let mut wtx = self.database.write_tx();
|
||||
|
||||
@@ -266,20 +265,20 @@ impl<K, V> Item<K, V> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fjall(self, keyspace: &TxKeyspace) -> fjall3::Item
|
||||
pub fn fjall(self, keyspace: &Keyspace) -> fjall3::Item
|
||||
where
|
||||
K: Into<ByteView>,
|
||||
V: Into<ByteView>,
|
||||
{
|
||||
match self {
|
||||
Item::Value { key, value } => fjall3::Item {
|
||||
keyspace_id: keyspace.inner().id,
|
||||
keyspace_id: keyspace.id,
|
||||
key: key.into().into(),
|
||||
value: value.into().into(),
|
||||
value_type: ValueType::Value,
|
||||
},
|
||||
Item::Tomb(key) => fjall3::Item {
|
||||
keyspace_id: keyspace.inner().id,
|
||||
keyspace_id: keyspace.id,
|
||||
key: key.into().into(),
|
||||
value: [].into(),
|
||||
value_type: ValueType::WeakTombstone,
|
||||
|
||||
Reference in New Issue
Block a user