parser: split txid_to_txdata db

This commit is contained in:
k
2024-08-08 09:21:59 +02:00
parent 5aaa05d579
commit eb9b57eef4
4 changed files with 13 additions and 15 deletions

View File

@@ -38,7 +38,7 @@ where
}
const ROOT_DB: usize = 0;
const PAGE_SIZE: u64 = 4096 * 256; // 1mo - Must be a multiplier of 4096
const PAGE_SIZE: u64 = 4096;
impl<Key, Value> Database<Key, Value>
where

View File

@@ -39,7 +39,7 @@ impl DerefMut for AddressIndexToAddressData {
}
}
const DB_MAX_SIZE: usize = 500_000;
pub const ADDRESS_INDEX_DB_MAX_SIZE: usize = 250_000;
impl AddressIndexToAddressData {
pub fn unsafe_insert(&mut self, key: Key, value: Value) -> Option<Value> {
@@ -74,8 +74,8 @@ impl AddressIndexToAddressData {
self.entry(db_index).or_insert_with(|| {
let db_name = format!(
"{}..{}",
db_index * DB_MAX_SIZE,
(db_index + 1) * DB_MAX_SIZE
db_index * ADDRESS_INDEX_DB_MAX_SIZE,
(db_index + 1) * ADDRESS_INDEX_DB_MAX_SIZE
);
Database::open(Self::folder(), &db_name).unwrap()
@@ -120,7 +120,7 @@ impl AddressIndexToAddressData {
}
fn db_index(key: &Key) -> usize {
*key as usize / DB_MAX_SIZE
*key as usize / ADDRESS_INDEX_DB_MAX_SIZE
}
}

View File

@@ -9,7 +9,7 @@ use rayon::prelude::*;
use crate::structs::{Date, EmptyAddressData, Height};
use super::{AnyDatabaseGroup, Database as _Database, Metadata};
use super::{AnyDatabaseGroup, Database as _Database, Metadata, ADDRESS_INDEX_DB_MAX_SIZE};
type Key = u32;
type Value = EmptyAddressData;
@@ -36,8 +36,6 @@ impl DerefMut for AddressIndexToEmptyAddressData {
}
}
const DB_MAX_SIZE: usize = 500_000;
impl AddressIndexToEmptyAddressData {
pub fn unsafe_insert(&mut self, key: Key, value: Value) -> Option<Value> {
self.metadata.called_insert();
@@ -76,8 +74,8 @@ impl AddressIndexToEmptyAddressData {
self.entry(db_index).or_insert_with(|| {
let db_name = format!(
"{}..{}",
db_index * DB_MAX_SIZE,
(db_index + 1) * DB_MAX_SIZE
db_index * ADDRESS_INDEX_DB_MAX_SIZE,
(db_index + 1) * ADDRESS_INDEX_DB_MAX_SIZE
);
Database::open(Self::folder(), &db_name).unwrap()
@@ -85,7 +83,7 @@ impl AddressIndexToEmptyAddressData {
}
fn db_index(key: &Key) -> usize {
*key as usize / DB_MAX_SIZE
*key as usize / ADDRESS_INDEX_DB_MAX_SIZE
}
}

View File

@@ -20,11 +20,11 @@ type Database = _Database<Key, Value>;
pub struct TxidToTxData {
pub metadata: Metadata,
map: BTreeMap<u8, Database>,
map: BTreeMap<u16, Database>,
}
impl Deref for TxidToTxData {
type Target = BTreeMap<u8, Database>;
type Target = BTreeMap<u16, Database>;
fn deref(&self) -> &Self::Target {
&self.map
@@ -113,8 +113,8 @@ impl TxidToTxData {
U8x31::from(&txid[1..])
}
fn db_index(txid: &Txid) -> u8 {
txid[0]
fn db_index(txid: &Txid) -> u16 {
((txid[0] as u16) << 4) + ((txid[1] as u16) >> 4)
}
}