diff --git a/storage/Cargo.toml b/storage/Cargo.toml index d8a8b4bc3..b4efac648 100644 --- a/storage/Cargo.toml +++ b/storage/Cargo.toml @@ -14,6 +14,7 @@ serde = { version = "1.0.199", features = ["derive"] } smallvec = { version = "1.13.2", features = ["serde", "write", "union"] } sha2 = "0.10.8" bytemuck = { version = "1.14.3", features = ["derive"] } +integer-encoding = "4.0.0" [dev-dependencies] rand = "0.8.5" diff --git a/storage/src/linear/proposed.rs b/storage/src/linear/proposed.rs index 096318ffb..470d42150 100644 --- a/storage/src/linear/proposed.rs +++ b/storage/src/linear/proposed.rs @@ -1,12 +1,15 @@ // Copyright (C) 2023, Ava Labs, Inc. All rights reserved. // See the file LICENSE.md for licensing terms. -use std::collections::BTreeMap; +use std::collections::{BTreeMap, HashMap}; use std::fmt::Debug; use std::io::{Error, Read}; use std::marker::PhantomData; use std::sync::{Arc, RwLock}; +use crate::nodestore::AreaIndex; +use crate::{LinearAddress, Node}; + use super::layered::{Layer, LayeredReader}; use super::{LinearStoreParent, ReadLinearStore, WriteLinearStore}; @@ -24,11 +27,8 @@ pub type ProposedImmutable = Proposed; /// A proposal backed by a [WriteLinearStore] or a [ReadLinearStore] /// The generic is either [Mutable] or [Immutable] pub struct Proposed { - /// The new data in a proposal - pub new: BTreeMap>, - /// The old data in a proposal - pub old: BTreeMap>, parent: RwLock, + changed: HashMap, phantom_data: PhantomData, } @@ -37,8 +37,7 @@ impl ProposedMutable { pub fn new(parent: LinearStoreParent) -> Self { Self { parent: RwLock::new(parent), - new: Default::default(), - old: Default::default(), + changed: Default::default(), phantom_data: PhantomData, } } @@ -46,9 +45,8 @@ impl ProposedMutable { /// Freeze a mutable proposal, consuming it, and making it immutable pub fn freeze(self) -> ProposedImmutable { ProposedImmutable { - old: self.old, - new: self.new, parent: self.parent, + changed: Default::default(), phantom_data: PhantomData, } } @@ -198,9 +196,8 @@ impl WriteLinearStore for ProposedMutable { fn freeze(self) -> ProposedImmutable { Proposed { - new: self.new, - old: self.old, parent: self.parent, + changed: self.changed, phantom_data: Default::default(), } } diff --git a/storage/src/nodestore.rs b/storage/src/nodestore.rs index 53599b666..b9cf491d9 100644 --- a/storage/src/nodestore.rs +++ b/storage/src/nodestore.rs @@ -46,7 +46,7 @@ const AREA_SIZES: [u64; 21] = [ /// The type of an index into the [AREA_SIZES] array /// This is not usize because we can store this as a single byte -type AreaIndex = u8; +pub type AreaIndex = u8; // TODO danlaine: have type for index in AREA_SIZES // Implement try_into() for it. @@ -483,7 +483,7 @@ impl Version { } } -type FreeLists = [Option; NUM_AREA_SIZES]; +pub type FreeLists = [Option; NUM_AREA_SIZES]; /// Persisted metadata for a [NodeStore]. /// The [NodeStoreHeader] is at the start of the LinearStore.