Skip to content

Commit

Permalink
Remove tangle LRU cache (#771)
Browse files Browse the repository at this point in the history
* Bogo eviction

* Decrement cache size

* Replace Hashmap with Vec

* Bring back allow eviction

* Insert before allowing eviction

* Abstract partitions away (#2)

* move partitions to their own type

* drop guards manually

* remove interned methods

* remove unused methods

* add safety guarantees

* Re-add Cargo.lock

* Remove unused test functions

* Remove some hooks relics

* traverse the table until we can evict something

* retry eviction

* remove unused import

* improve eviction logs

* decrease the number of partitions

* add number of partitions to the tangle config

* avoid zero partitions

* fix clippy lints

* Nits

* Config nits

* move max retries to a constant

* Revert to match

Co-authored-by: Christian Poveda <31802960+pvdrz@users.noreply.github.com>
Co-authored-by: Christian Poveda <christian.poveda@iota.org>
  • Loading branch information
3 people committed Oct 15, 2021
1 parent ac794b4 commit e0b9ad3
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 131 deletions.
11 changes: 0 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions bee-tangle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ bee-storage = { version = "0.9.0", path = "../bee-storage/bee-storage" }

async-trait = "0.1.51"
bitflags = "1.2.1"
dashmap = "4.0.2"
futures = "0.3.17"
hashbrown = "0.11.2"
log = "0.4.14"
lru = "0.7.0"
rand = "0.8.4"
ref-cast = "1.0.6"
serde = { version = "1.0.130", features = [ "derive" ] }
Expand Down
18 changes: 15 additions & 3 deletions bee-tangle/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,30 @@

use serde::Deserialize;

use std::num::NonZeroUsize;

const DEFAULT_BELOW_MAX_DEPTH: u32 = 15;
// SAFETY: initialised with a non-zero value.
const DEFAULT_NUM_PARTITIONS: NonZeroUsize = unsafe { NonZeroUsize::new_unchecked(16) };

/// A builder type for a tangle configuration.
#[derive(Default, Deserialize)]
pub struct TangleConfigBuilder {
below_max_depth: Option<u32>,
num_partitions: Option<NonZeroUsize>,
}

impl TangleConfigBuilder {
/// Create a new `TangleConfigBuilder`.
/// Create a new [`TangleConfigBuilder`].
pub fn new() -> Self {
Self::default()
}

/// Finish building tangle configuration, to create a `TangleConfig`.
/// Finish building tangle configuration, to create a [`TangleConfig`].
pub fn finish(self) -> TangleConfig {
TangleConfig {
below_max_depth: self.below_max_depth.unwrap_or(DEFAULT_BELOW_MAX_DEPTH),
num_partitions: self.num_partitions.unwrap_or(DEFAULT_NUM_PARTITIONS),
}
}
}
Expand All @@ -29,10 +35,11 @@ impl TangleConfigBuilder {
#[derive(Clone)]
pub struct TangleConfig {
below_max_depth: u32,
num_partitions: NonZeroUsize,
}

impl TangleConfig {
/// Begin building a new `TangleConfig`.
/// Begin building a new [`TangleConfig`].
pub fn build() -> TangleConfigBuilder {
TangleConfigBuilder::new()
}
Expand All @@ -41,4 +48,9 @@ impl TangleConfig {
pub fn below_max_depth(&self) -> u32 {
self.below_max_depth
}

/// Get the value of `num_partitions`.
pub fn num_partitions(&self) -> NonZeroUsize {
self.num_partitions
}
}
1 change: 1 addition & 0 deletions bee-tangle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub mod urts;
mod conflict;
mod vec_set;
mod vertex;
mod vertices;

pub use conflict::ConflictReason;
pub use tangle::Tangle;
Expand Down
Loading

0 comments on commit e0b9ad3

Please sign in to comment.