Skip to content

Commit

Permalink
Co-authored-by: Dan Laine <[email protected]>
Browse files Browse the repository at this point in the history
  • Loading branch information
rkuris committed Jun 11, 2024
1 parent 6dbc8dd commit 36029d1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
1 change: 1 addition & 0 deletions storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
19 changes: 8 additions & 11 deletions storage/src/linear/proposed.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand All @@ -24,11 +27,8 @@ pub type ProposedImmutable = Proposed<Immutable>;
/// A proposal backed by a [WriteLinearStore] or a [ReadLinearStore]
/// The generic is either [Mutable] or [Immutable]
pub struct Proposed<M: Send + Sync + Debug> {
/// The new data in a proposal
pub new: BTreeMap<u64, Box<[u8]>>,
/// The old data in a proposal
pub old: BTreeMap<u64, Box<[u8]>>,
parent: RwLock<LinearStoreParent>,
changed: HashMap<LinearAddress, (Node, AreaIndex)>,
phantom_data: PhantomData<M>,
}

Expand All @@ -37,18 +37,16 @@ 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,
}
}

/// 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,
}
}
Expand Down Expand Up @@ -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(),
}
}
Expand Down
4 changes: 2 additions & 2 deletions storage/src/nodestore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -483,7 +483,7 @@ impl Version {
}
}

type FreeLists = [Option<LinearAddress>; NUM_AREA_SIZES];
pub type FreeLists = [Option<LinearAddress>; NUM_AREA_SIZES];

/// Persisted metadata for a [NodeStore].
/// The [NodeStoreHeader] is at the start of the LinearStore.
Expand Down

0 comments on commit 36029d1

Please sign in to comment.