diff --git a/Cargo.lock b/Cargo.lock index 5257ff89f..55bd8a9fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -28,19 +28,6 @@ dependencies = [ "cpufeatures", ] -[[package]] -name = "ahash" -version = "0.8.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" -dependencies = [ - "cfg-if", - "getrandom 0.3.3", - "once_cell", - "version_check", - "zerocopy", -] - [[package]] name = "aho-corasick" version = "1.1.3" @@ -1828,9 +1815,9 @@ checksum = "26995317201fa17f3656c36716aed4a7c81743a9634ac4c99c0eeda495db0cec" [[package]] name = "oxc" -version = "0.72.2" +version = "0.72.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91ecbc3f076425da55380d3f3f873bbbd0a10f56d9f9b6c0d15c88a2188f127" +checksum = "44c130580b8327276f252c7a84b484bc35c9432e23ec41b081506d0a5bc71a28" dependencies = [ "oxc_allocator", "oxc_ast", @@ -1871,9 +1858,9 @@ dependencies = [ [[package]] name = "oxc_allocator" -version = "0.72.2" +version = "0.72.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94677be5d1874da150784b9d551bae0dfad7e5a6121a2c6acccda335c05504ea" +checksum = "92e50218e74886659d1d13de8e6a4ff13c7e96924ed0017bc193a1feb8001b18" dependencies = [ "allocator-api2", "bumpalo", @@ -1884,9 +1871,9 @@ dependencies = [ [[package]] name = "oxc_ast" -version = "0.72.2" +version = "0.72.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26f7b73c9a8e265169d98cd2395cbab52fcb849d3297b1ec2511a1d908775c73" +checksum = "3a2c546ff7887418facf35f7996f0ca2099bde75931597429b408746bbaaddcd" dependencies = [ "bitflags", "cow-utils", @@ -1901,9 +1888,9 @@ dependencies = [ [[package]] name = "oxc_ast_macros" -version = "0.72.2" +version = "0.72.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f411489fef9ace92fdea3105490f9aab07a78c9adff25b62345b1a1bd49ee0c" +checksum = "4ce8952bd09048ac55421aeecc06cc69db9f7220a25d69f3da8c6da3d95e5d6d" dependencies = [ "phf", "proc-macro2", @@ -1913,9 +1900,9 @@ dependencies = [ [[package]] name = "oxc_ast_visit" -version = "0.72.2" +version = "0.72.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf97a9b275654d7fc921c0c472ceab1ae167b670c9a761e5c2aec66b9076157b" +checksum = "9a02f6d1e34a893acd0d6a0994ff56c861b08d472476c1bea95f9c04c6da3426" dependencies = [ "oxc_allocator", "oxc_ast", @@ -1925,9 +1912,9 @@ dependencies = [ [[package]] name = "oxc_cfg" -version = "0.72.2" +version = "0.72.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ac937d952a9990180f9090b5784713f66407a467f34e84f78bd204a7c2d6d73" +checksum = "d869bb28669f0747c181d5f5e28d9aad063e6e4043af3222c9ab7358b9e8788f" dependencies = [ "bitflags", "itertools", @@ -1940,9 +1927,9 @@ dependencies = [ [[package]] name = "oxc_codegen" -version = "0.72.2" +version = "0.72.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b09bbfd5a9faadff9578858f28dcfb46e2f9c4929ee0d8e076f928afe618010f" +checksum = "88e275fbd0f26987ef15aa29fef129e75d8e3799e309797444c6ed4c5761ba2b" dependencies = [ "bitflags", "cow-utils", @@ -1961,18 +1948,18 @@ dependencies = [ [[package]] name = "oxc_data_structures" -version = "0.72.2" +version = "0.72.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ebee1a21c5d47b6e845357274904ec9568b001d3ff6ab04d4cc4754fd148c2" +checksum = "caccf3f0c0515f32520b6207a0ef4bafd0858f94685e84a50f38c53464418e8b" dependencies = [ "rustversion", ] [[package]] name = "oxc_diagnostics" -version = "0.72.2" +version = "0.72.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fa03ff098ecf135235ed3c88e013a22e9b58caf1108d32eca5261daf2d88330" +checksum = "79d4d0062c704ee11dbd56d6178f91ea17ccac05a59fe655b120a2b64d038739" dependencies = [ "cow-utils", "oxc-miette", @@ -1980,9 +1967,9 @@ dependencies = [ [[package]] name = "oxc_ecmascript" -version = "0.72.2" +version = "0.72.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1b5dba7d2918b9a59f82ce974b85cc6de1e577d06f49d1e608505e9da6a0b02" +checksum = "3e0e3cc7daeec1ed3ed75abc02a456d7046c5878c61bda972d26e39850f25298" dependencies = [ "cow-utils", "num-bigint", @@ -1994,9 +1981,9 @@ dependencies = [ [[package]] name = "oxc_estree" -version = "0.72.2" +version = "0.72.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a870fcc8a8a8eeb3471cb51df3628f04e9f53521608e735a34bd9b6f96ce78c" +checksum = "68bb8e3cedd84c69241a0438d14ca09294ab95049b52dc7813bba017554c96fb" [[package]] name = "oxc_index" @@ -2006,9 +1993,9 @@ checksum = "2fa07b0cfa997730afed43705766ef27792873fdf5215b1391949fec678d2392" [[package]] name = "oxc_mangler" -version = "0.72.2" +version = "0.72.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1330ed79d68bae3bcc3d9ceca8b690f1d27056315ad4a6a97a8eda55e8bb8244" +checksum = "3038ab2f2b76130ea02ff016da89fc6c2a4a3935da50a5f1a16ebd982873dc2f" dependencies = [ "fixedbitset", "itertools", @@ -2023,9 +2010,9 @@ dependencies = [ [[package]] name = "oxc_minifier" -version = "0.72.2" +version = "0.72.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e788a77708893ba1cf82a9291ce18bdb6fbb69711aeeaf50514fd775c17a1a3" +checksum = "fe473cd85aef3e71f7039c50f5fc85cc0e5a6a8fe98c49084aef4b993ffc7382" dependencies = [ "cow-utils", "oxc_allocator", @@ -2045,9 +2032,9 @@ dependencies = [ [[package]] name = "oxc_parser" -version = "0.72.2" +version = "0.72.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca8194f22ac433d9f2575f3f5a35fdc2ec403877a2c98b8bbb7047acc73e07e6" +checksum = "d3bb3f8ed289796dcd7fecc4cfec895fbe29c269cf63658b63f352ce8fd7caf7" dependencies = [ "bitflags", "cow-utils", @@ -2068,9 +2055,9 @@ dependencies = [ [[package]] name = "oxc_regular_expression" -version = "0.72.2" +version = "0.72.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bac34c62476a83f00f36fb08991730db51a722082125067f9562257fd97cbb88" +checksum = "b8e58c2970fa7dcb10a5c757706c5824c43f13abb908a4651b221033c96c1ddc" dependencies = [ "bitflags", "oxc_allocator", @@ -2084,9 +2071,9 @@ dependencies = [ [[package]] name = "oxc_semantic" -version = "0.72.2" +version = "0.72.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "564256e85189bf5e6fb331f08892eeb8e13f3fcadb0dc08a85ce7db59519e174" +checksum = "ee61a7e935fa88d87b02c2279ffcf0704433006fa06a635e827fcdfc53b8f741" dependencies = [ "itertools", "oxc_allocator", @@ -2120,9 +2107,9 @@ dependencies = [ [[package]] name = "oxc_span" -version = "0.72.2" +version = "0.72.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "886510fc6db2c5a7a905feeb966e613527bdbe2e544057923957ba79e3e93142" +checksum = "f290a8f173016c5b84327297bb3f2b9c158b0733703ac2f29d9e77f9b4821ddd" dependencies = [ "compact_str", "oxc-miette", @@ -2133,9 +2120,9 @@ dependencies = [ [[package]] name = "oxc_syntax" -version = "0.72.2" +version = "0.72.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dddefc02737686c68da8597a88ba5514e7134aba006c61f72fb1752451f95cc" +checksum = "1d83f7a8a718db14fd6e8f864b70b0961e3b4ae44c9a28102262357c27aee944" dependencies = [ "bitflags", "cow-utils", @@ -2154,9 +2141,9 @@ dependencies = [ [[package]] name = "oxc_traverse" -version = "0.72.2" +version = "0.72.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa88eafbdafb3f0da21b03fb41b146602360dc2e952810e9d26688b2510e3693" +checksum = "3a82547d2081445a2661ee858140845624f7c83b285a59f0144bb1190fcd464e" dependencies = [ "itoa", "oxc_allocator", @@ -2172,12 +2159,12 @@ dependencies = [ [[package]] name = "papergrid" -version = "0.15.0" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30268a8d20c2c0d126b2b6610ab405f16517f6ba9f244d8c59ac2c512a8a1ce7" +checksum = "6978128c8b51d8f4080631ceb2302ab51e32cc6e8615f735ee2f83fd269ae3f1" dependencies = [ - "ahash", "bytecount", + "fnv", "unicode-width", ] @@ -2833,9 +2820,9 @@ checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" [[package]] name = "tabled" -version = "0.19.0" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "228d124371171cd39f0f454b58f73ddebeeef3cef3207a82ffea1c29465aea43" +checksum = "e39a2ee1fbcd360805a771e1b300f78cc88fec7b8d3e2f71cd37bbf23e725c7d" dependencies = [ "papergrid", "tabled_derive", diff --git a/Cargo.toml b/Cargo.toml index 5af237a51..830c00ed5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,7 +47,7 @@ rayon = "1.10.0" serde = { version = "1.0.219" } serde_derive = "1.0.219" serde_json = { version = "1.0.140", features = ["float_roundtrip"] } -tabled = "0.19.0" +tabled = "0.20.0" tokio = { version = "1.45.1", features = ["rt-multi-thread"] } zerocopy = { version = "0.8.25" } zerocopy-derive = "0.8.25" diff --git a/crates/brk_computer/src/vecs/stateful/mod.rs b/crates/brk_computer/src/vecs/stateful/mod.rs index 0912a7b2a..bb4182734 100644 --- a/crates/brk_computer/src/vecs/stateful/mod.rs +++ b/crates/brk_computer/src/vecs/stateful/mod.rs @@ -29,7 +29,7 @@ use super::{ pub mod cohort; mod outputs; -const VERSION: Version = Version::new(5); +const VERSION: Version = Version::new(4); #[derive(Clone)] pub struct Vecs { @@ -809,7 +809,7 @@ impl Vecs { Some("0sats"), _computation, format, - version + Version::ZERO, + version + VERSION + Version::ZERO, fetched, keyspace, &stores_path, @@ -820,7 +820,7 @@ impl Vecs { Some("from_1sat_to_10sats"), _computation, format, - version + Version::ZERO, + version + VERSION + Version::ZERO, fetched, keyspace, &stores_path, @@ -831,7 +831,7 @@ impl Vecs { Some("from_10sats_to_100sats"), _computation, format, - version + Version::ZERO, + version + VERSION + Version::ZERO, fetched, keyspace, &stores_path, @@ -842,7 +842,7 @@ impl Vecs { Some("from_100sats_to_1_000sats"), _computation, format, - version + Version::ZERO, + version + VERSION + Version::ZERO, fetched, keyspace, &stores_path, @@ -853,7 +853,7 @@ impl Vecs { Some("from_1_000sats_to_10_000sats"), _computation, format, - version + Version::ZERO, + version + VERSION + Version::ZERO, fetched, keyspace, &stores_path, @@ -864,7 +864,7 @@ impl Vecs { Some("from_10_000sats_to_100_000sats"), _computation, format, - version + Version::ZERO, + version + VERSION + Version::ZERO, fetched, keyspace, &stores_path, @@ -875,7 +875,7 @@ impl Vecs { Some("from_100_000sats_to_1_000_000sats"), _computation, format, - version + Version::ZERO, + version + VERSION + Version::ZERO, fetched, keyspace, &stores_path, @@ -886,7 +886,7 @@ impl Vecs { Some("from_1_000_000sats_to_10_000_000sats"), _computation, format, - version + Version::ZERO, + version + VERSION + Version::ZERO, fetched, keyspace, &stores_path, @@ -897,7 +897,7 @@ impl Vecs { Some("from_10_000_000sats_to_1btc"), _computation, format, - version + Version::ZERO, + version + VERSION + Version::ZERO, fetched, keyspace, &stores_path, @@ -908,7 +908,7 @@ impl Vecs { Some("from_1btc_to_10btc"), _computation, format, - version + Version::ZERO, + version + VERSION + Version::ZERO, fetched, keyspace, &stores_path, @@ -919,7 +919,7 @@ impl Vecs { Some("from_10btc_to_100btc"), _computation, format, - version + Version::ZERO, + version + VERSION + Version::ZERO, fetched, keyspace, &stores_path, @@ -930,7 +930,7 @@ impl Vecs { Some("from_100btc_to_1_000btc"), _computation, format, - version + Version::ZERO, + version + VERSION + Version::ZERO, fetched, keyspace, &stores_path, @@ -941,7 +941,7 @@ impl Vecs { Some("from_1_000btc_to_10_000btc"), _computation, format, - version + Version::ZERO, + version + VERSION + Version::ZERO, fetched, keyspace, &stores_path, @@ -952,7 +952,7 @@ impl Vecs { Some("from_10_000btc_to_100_000btc"), _computation, format, - version + Version::ZERO, + version + VERSION + Version::ZERO, fetched, keyspace, &stores_path, @@ -963,7 +963,7 @@ impl Vecs { Some("from_100_000btc"), _computation, format, - version + Version::ZERO, + version + VERSION + Version::ZERO, fetched, keyspace, &stores_path, @@ -976,7 +976,7 @@ impl Vecs { Some("up_to_1_000sats"), _computation, format, - version + Version::ZERO, + version + VERSION + Version::ZERO, fetched, keyspace, &stores_path, @@ -987,7 +987,7 @@ impl Vecs { Some("up_to_10_000sats"), _computation, format, - version + Version::ZERO, + version + VERSION + Version::ZERO, fetched, keyspace, &stores_path, @@ -998,7 +998,7 @@ impl Vecs { Some("up_to_1btc"), _computation, format, - version + Version::ZERO, + version + VERSION + Version::ZERO, fetched, keyspace, &stores_path, @@ -1009,7 +1009,7 @@ impl Vecs { Some("up_to_10btc"), _computation, format, - version + Version::ZERO, + version + VERSION + Version::ZERO, fetched, keyspace, &stores_path, @@ -1020,7 +1020,7 @@ impl Vecs { Some("up_to_100btc"), _computation, format, - version + Version::ZERO, + version + VERSION + Version::ZERO, fetched, keyspace, &stores_path, @@ -1033,7 +1033,7 @@ impl Vecs { Some("from_1_000sats"), _computation, format, - version + Version::ZERO, + version + VERSION + Version::ZERO, fetched, keyspace, &stores_path, @@ -1044,7 +1044,7 @@ impl Vecs { Some("from_1btc"), _computation, format, - version + Version::ZERO, + version + VERSION + Version::ZERO, fetched, keyspace, &stores_path, @@ -1055,7 +1055,7 @@ impl Vecs { Some("from_10btc"), _computation, format, - version + Version::ZERO, + version + VERSION + Version::ZERO, fetched, keyspace, &stores_path, @@ -1066,7 +1066,7 @@ impl Vecs { Some("from_100btc"), _computation, format, - version + Version::ZERO, + version + VERSION + Version::ZERO, fetched, keyspace, &stores_path, @@ -1222,15 +1222,6 @@ impl Vecs { &stores_path, true, )?, - // opreturn: cohort::Vecs::forced_import( - // path, - // Some("opreturn"), - // _computation, - // format, - // VERSION + Version::ZERO, - // fetched, - // keyspace - // )?, p2wpkh: cohort::Vecs::forced_import( path, Some("p2wpkh"), @@ -1538,6 +1529,8 @@ impl Vecs { .unwrap() .into_inner(); + // dbg!(input_type); + if input_type.is_unspendable() { unreachable!() } diff --git a/crates/brk_computer/src/vecs/stateful/outputs.rs b/crates/brk_computer/src/vecs/stateful/outputs.rs index e72185d6e..4b6f5c9a9 100644 --- a/crates/brk_computer/src/vecs/stateful/outputs.rs +++ b/crates/brk_computer/src/vecs/stateful/outputs.rs @@ -68,6 +68,8 @@ impl OutputCohorts for Outputs<(OutputFilter, cohort::Vecs)> { let last_timestamp = chain_state.last().unwrap().timestamp; let current_price = chain_state.last().unwrap().price; + // dbg!(&height_to_sent); + height_to_sent.into_iter().for_each(|(height, sent)| { let block_state = chain_state.get(height.unwrap_to_usize()).unwrap(); let prev_price = block_state.price; @@ -107,8 +109,12 @@ impl OutputCohorts for Outputs<(OutputFilter, cohort::Vecs)> { ); }); - sent.by_type.spendable.as_typed_vec().into_iter().for_each( - |(output_type, supply_state)| { + sent.by_type + .spendable + .as_typed_vec() + .into_iter() + .filter(|(_, suply_state)| suply_state.utxos > 0) + .for_each(|(output_type, supply_state)| { self.by_type.get_mut(output_type).1.state.send( supply_state, current_price, @@ -117,8 +123,7 @@ impl OutputCohorts for Outputs<(OutputFilter, cohort::Vecs)> { days_old_foat, older_than_hour, ) - }, - ); + }); sent.by_size_group .into_iter() diff --git a/crates/brk_server/Cargo.toml b/crates/brk_server/Cargo.toml index 083a8ea9c..d29e2d080 100644 --- a/crates/brk_server/Cargo.toml +++ b/crates/brk_server/Cargo.toml @@ -25,7 +25,7 @@ color-eyre = { workspace = true } jiff = { workspace = true } log = { workspace = true } minreq = { workspace = true } -oxc = { version = "0.72.2", features = ["codegen", "minifier"] } +oxc = { version = "0.72.3", features = ["codegen", "minifier"] } serde = { workspace = true } tokio = { workspace = true } tower-http = { version = "0.6.6", features = ["compression-full", "trace"] } diff --git a/crates/brk_state/src/cohort.rs b/crates/brk_state/src/cohort.rs index 51723add3..f389f9b3e 100644 --- a/crates/brk_state/src/cohort.rs +++ b/crates/brk_state/src/cohort.rs @@ -62,7 +62,20 @@ impl CohortState { if let Some(realized) = self.realized.as_mut() { let price = price.unwrap(); realized.decrement(supply_state, price); - *self.price_to_amount.puts_entry_or_default(&price) -= supply_state.value; + self.decrement_price_to_amount(supply_state, price); + } + } + + fn decrement_price_to_amount(&mut self, supply_state: &SupplyState, price: Dollars) { + let amount = self.price_to_amount.puts_entry_or_default(&price); + *amount -= supply_state.value; + if *amount == Sats::ZERO { + if self.price_to_amount.puts_remove(&price).is_none() { + unreachable!() + } + if !self.price_to_amount.dels_insert(price) { + unreachable!() + } } } @@ -95,7 +108,7 @@ impl CohortState { let current_price = current_price.unwrap(); let prev_price = prev_price.unwrap(); realized.send(supply_state, current_price, prev_price, older_than_hour); - *self.price_to_amount.puts_entry_or_default(&prev_price) -= supply_state.value; + self.decrement_price_to_amount(supply_state, prev_price); } } @@ -164,8 +177,8 @@ impl CohortState { } pub fn commit(&mut self, height: Height) -> Result<()> { - self.price_to_amount - .retain_or_del(|_, sats| *sats > Sats::ZERO); + // self.price_to_amount + // .retain_or_del(|_, sats| *sats > Sats::ZERO); let price_to_amount_puts = self.price_to_amount.clone_puts(); self.price_to_amount.commit(height)?; self.price_to_amount.append_puts(price_to_amount_puts); diff --git a/crates/brk_state/src/outputs/by_spendable_type.rs b/crates/brk_state/src/outputs/by_spendable_type.rs index cc5169dad..9f404a103 100644 --- a/crates/brk_state/src/outputs/by_spendable_type.rs +++ b/crates/brk_state/src/outputs/by_spendable_type.rs @@ -4,7 +4,7 @@ use brk_core::OutputType; use super::OutputFilter; -#[derive(Default, Clone)] +#[derive(Default, Clone, Debug)] pub struct OutputsBySpendableType { pub p2pk65: T, pub p2pk33: T, diff --git a/crates/brk_state/src/outputs/by_type.rs b/crates/brk_state/src/outputs/by_type.rs index 9495c6887..cf2a542bf 100644 --- a/crates/brk_state/src/outputs/by_type.rs +++ b/crates/brk_state/src/outputs/by_type.rs @@ -4,7 +4,7 @@ use brk_core::OutputType; use super::{OutputsBySpendableType, OutputsByUnspendableType}; -#[derive(Default, Clone)] +#[derive(Default, Clone, Debug)] pub struct OutputsByType { pub spendable: OutputsBySpendableType, pub unspendable: OutputsByUnspendableType, diff --git a/crates/brk_state/src/outputs/by_unspendable_type.rs b/crates/brk_state/src/outputs/by_unspendable_type.rs index 6f5673539..f777a094c 100644 --- a/crates/brk_state/src/outputs/by_unspendable_type.rs +++ b/crates/brk_state/src/outputs/by_unspendable_type.rs @@ -1,6 +1,6 @@ use std::ops::{Add, AddAssign}; -#[derive(Default, Clone)] +#[derive(Default, Clone, Debug)] pub struct OutputsByUnspendableType { pub opreturn: T, } diff --git a/crates/brk_state/src/transacted.rs b/crates/brk_state/src/transacted.rs index 620f91f69..271892c5a 100644 --- a/crates/brk_state/src/transacted.rs +++ b/crates/brk_state/src/transacted.rs @@ -8,7 +8,7 @@ use brk_core::{OutputType, Sats}; use super::{OutputsByType, SupplyState}; -#[derive(Default)] +#[derive(Default, Debug)] pub struct Transacted { pub spendable_supply: SupplyState, pub by_type: OutputsByType, diff --git a/crates/brk_store/src/lib.rs b/crates/brk_store/src/lib.rs index 006d8d9b5..5da7cd179 100644 --- a/crates/brk_store/src/lib.rs +++ b/crates/brk_store/src/lib.rs @@ -31,6 +31,7 @@ pub struct Store { puts: BTreeMap, dels: BTreeSet, bloom_filter_bits: Option>, + override_partition: bool, } /// Use default if will read @@ -80,6 +81,7 @@ where puts: BTreeMap::new(), dels: BTreeSet::new(), bloom_filter_bits, + override_partition: false, }) } @@ -119,9 +121,20 @@ where where V: Default, { + if !self.dels.is_empty() { + self.dels.remove(key); + } self.puts.entry(key.clone()).or_default() } + pub fn puts_remove(&mut self, key: &K) -> Option { + self.puts.remove(key) + } + + pub fn dels_insert(&mut self, key: K) -> bool { + self.dels.insert(key) + } + pub fn tx_iter(&self) -> impl Iterator { self.rtx .iter(&self.partition.load()) @@ -142,7 +155,9 @@ where } pub fn copy_db_to_puts(&mut self) { + self.override_partition = true; self.append_puts(self.tx_iter().collect()); + self.meta.reset_len(); } // pub fn unordered_clone_iter(&self) -> impl Iterator { @@ -180,18 +195,18 @@ where } } - pub fn retain_or_del(&mut self, retain: F) - where - F: Fn(&K, &mut V) -> bool, - { - self.puts.retain(|k, v| { - let ret = retain(k, v); - if !ret { - self.dels.insert(k.clone()); - } - ret - }); - } + // pub fn retain_or_del(&mut self, retain: F) + // where + // F: Fn(&K, &mut V) -> bool, + // { + // self.puts.retain(|k, v| { + // let ret = retain(k, v); + // if !ret { + // self.dels.insert(k.clone()); + // } + // ret + // }); + // } pub fn commit(&mut self, height: Height) -> Result<()> { if self.has(height) && self.puts.is_empty() && self.dels.is_empty() { @@ -200,6 +215,10 @@ where self.meta.export(self.len(), height)?; + if self.override_partition { + self.reset_partition()?; + } + let mut wtx = self.keyspace.write_tx(); let partition = &self.partition.load(); @@ -242,7 +261,18 @@ where } pub fn len(&self) -> usize { - self.meta.len() + self.puts.len() - self.dels.len() + let len = self.meta.len() + self.puts.len() - self.dels.len(); + if len > 18440000000000000000 { + dbg!(( + len, + self.meta.path(), + self.meta.len(), + self.puts.len(), + &self.dels, + )); + unreachable!() + } + len } pub fn is_empty(&self) -> bool { self.len() == 0 @@ -308,6 +338,7 @@ where puts: self.puts.clone(), dels: self.dels.clone(), bloom_filter_bits: self.bloom_filter_bits, + override_partition: self.override_partition, } } } diff --git a/crates/brk_store/src/meta.rs b/crates/brk_store/src/meta.rs index c763f2c46..86c46ad25 100644 --- a/crates/brk_store/src/meta.rs +++ b/crates/brk_store/src/meta.rs @@ -36,18 +36,28 @@ impl StoreMeta { let mut partition = open_partition_handle()?; + let mut did_reset = false; + if !is_same_version { + did_reset = true; Self::reset_(path)?; keyspace.delete_partition(partition)?; keyspace.persist(fjall::PersistMode::SyncAll)?; partition = open_partition_handle()?; } + let len = Self::read_length_(path); + + if did_reset && len != 0 { + dbg!(&path); + unreachable!(); + } + let slf = Self { pathbuf: path.to_owned(), version, height: Height::try_from(Self::path_height_(path).as_path()).ok(), - len: Self::read_length_(path), + len, }; slf.version.write(&slf.path_version())?; @@ -58,6 +68,10 @@ impl StoreMeta { pub fn len(&self) -> usize { self.len } + + pub fn reset_len(&mut self) { + self.len = 0 + } // pub fn is_empty(&self) -> bool { // self.len() == 0 // } @@ -110,7 +124,7 @@ impl StoreMeta { fn read_length_(path: &Path) -> usize { fs::read(Self::path_length(path)) - .map(|v| usize::from_ne_bytes(copy_first_8bytes(v.as_slice()).unwrap_or_default())) + .map(|v| usize::from_ne_bytes(copy_first_8bytes(v.as_slice()).unwrap())) .unwrap_or_default() } fn write_length(&self) -> io::Result<()> {