Skip to content

Commit

Permalink
Add an Update access operation to bee-storage (#1232)
Browse files Browse the repository at this point in the history
* add an `Update` trait to `bee_storage::access`

* test the `Update` access operation

* implement `Update` for `bee-storage-memory`

* implement `Update` for `bee-storage-null`

* implement `Update` for `bee-storage-sled`

* implement `Update` for `bee-storage-rocksdb`

* fix punctuation

* bump `bee-storage-*` crates versions

* simplify `update` for `bee-storage-memory`

* nits

* Update bee-storage/bee-storage-test/src/message_id_to_metadata.rs

* fmt :trollface:

Co-authored-by: Thibault Martinez <thibault.martinez.30@gmail.com>
  • Loading branch information
pvdrz and thibault-martinez authored Mar 11, 2022
1 parent b431dc2 commit 45977c8
Show file tree
Hide file tree
Showing 40 changed files with 457 additions and 86 deletions.
103 changes: 85 additions & 18 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion bee-api/bee-rest-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ bee-message = { version = "0.1.6", path = "../../bee-message", default-features
bee-pow = { version = "0.2.0", path = "../../bee-pow", default-features = false }
bee-protocol = { version = "0.2.2", path = "../../bee-protocol", default-features = false, optional = true }
bee-runtime = { version = "0.1.1-alpha", path = "../../bee-runtime", default-features = false, optional = true }
bee-storage = { version = "0.9.0", path = "../../bee-storage/bee-storage", default-features = false, optional = true }
bee-storage = { version = "0.10.0", path = "../../bee-storage/bee-storage", default-features = false, optional = true }
bee-tangle = { version = "0.2.0", path = "../../bee-tangle", default-features = false, optional = true }

async-trait = { version = "0.1.51", default-features = false, optional = true }
Expand Down
2 changes: 1 addition & 1 deletion bee-ledger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ homepage = "https://www.iota.org"
bee-common = { version = "0.6.0", path = "../bee-common/bee-common", default-features = false }
bee-message = { version = "0.1.6", path = "../bee-message", default-features = false }
bee-runtime = { version = "0.1.1-alpha", path = "../bee-runtime", default-features = false, optional = true }
bee-storage = { version = "0.9.0", path = "../bee-storage/bee-storage", default-features = false, optional = true }
bee-storage = { version = "0.10.0", path = "../bee-storage/bee-storage", default-features = false, optional = true }
bee-tangle = { version = "0.2.0", path = "../bee-tangle", default-features = false, optional = true }

async-trait = { version = "0.1.51", default-features = false, optional = true }
Expand Down
8 changes: 4 additions & 4 deletions bee-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ bee-message = { version = "0.1.6", path = "../bee-message", default-features = f
bee-protocol = { version = "0.2.2", path = "../bee-protocol", default-features = false, features = [ "workers" ] }
bee-rest-api = { version = "0.2.0", path = "../bee-api/bee-rest-api", default-features = false, features = [ "endpoints", "peer" ] }
bee-runtime = { version = "0.1.1-alpha", path = "../bee-runtime", default-features = false }
bee-storage = { version = "0.9.0", path = "../bee-storage/bee-storage", default-features = false }
bee-storage-null = { version = "0.1.0", path = "../bee-storage/bee-storage-null", default-features = false }
bee-storage-rocksdb = { version = "0.5.0", path = "../bee-storage/bee-storage-rocksdb", default-features = false, optional = true }
bee-storage-sled = { version = "0.4.0", path = "../bee-storage/bee-storage-sled", default-features = false, optional = true }
bee-storage = { version = "0.10.0", path = "../bee-storage/bee-storage", default-features = false }
bee-storage-null = { version = "0.2.0", path = "../bee-storage/bee-storage-null", default-features = false }
bee-storage-rocksdb = { version = "0.6.0", path = "../bee-storage/bee-storage-rocksdb", default-features = false, optional = true }
bee-storage-sled = { version = "0.5.0", path = "../bee-storage/bee-storage-sled", default-features = false, optional = true }
bee-tangle = { version = "0.2.0", path = "../bee-tangle", default-features = false }

anymap = { version = "0.12.1", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion bee-protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ bee-ledger = { version = "0.6.0", path = "../bee-ledger", default-features = fal
bee-message = { version = "0.1.6", path = "../bee-message", default-features = false, features = [ "serde" ] }
bee-pow = { version = "0.2.0", path = "../bee-pow", default-features = false }
bee-runtime = { version = "0.1.1-alpha", path = "../bee-runtime", default-features = false, optional = true }
bee-storage = { version = "0.9.0", path = "../bee-storage/bee-storage", default-features = false, optional = true }
bee-storage = { version = "0.10.0", path = "../bee-storage/bee-storage", default-features = false, optional = true }
bee-tangle = { version = "0.2.0", path = "../bee-tangle", default-features = false, optional = true }

async-channel = { version = "1.6.1", default-features = false, optional = true }
Expand Down
2 changes: 1 addition & 1 deletion bee-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ keywords = [ "iota", "tangle", "bee", "framework", "runtime" ]
homepage = "https://www.iota.org"

[dependencies]
bee-storage = { version = "0.9.0", path = "../bee-storage/bee-storage", default-features = false }
bee-storage = { version = "0.10.0", path = "../bee-storage/bee-storage", default-features = false }

async-trait = { version = "0.1.51", default-features = false }
dashmap = { version = "4.0.2", default-features = false }
Expand Down
6 changes: 6 additions & 0 deletions bee-storage/bee-storage-memory/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Security -->

## 0.2.0 - 2022-03-11

### Added

- Implementation of `Update` for `Storage`;

## 0.1.0 - 2021-10-21

### Added
Expand Down
4 changes: 2 additions & 2 deletions bee-storage/bee-storage-memory/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bee-storage-memory"
version = "0.1.0"
version = "0.2.0"
authors = [ "IOTA Stiftung" ]
edition = "2021"
description = "An in-memory bee-storage implementation"
Expand All @@ -14,7 +14,7 @@ homepage = "https://www.iota.org"
bee-common = { version = "0.6.0", path = "../../bee-common/bee-common", default-features = false }
bee-ledger = { version = "0.6.1", path = "../../bee-ledger", default-features = false }
bee-message = { version = "0.1.6", path = "../../bee-message", default-features = false }
bee-storage = { version = "0.9.0", path = "../bee-storage", default-features = false }
bee-storage = { version = "0.10.0", path = "../bee-storage", default-features = false }
bee-tangle = { version = "0.2.0", path = "../../bee-tangle", default-features = false }

serde = { version = "1.0.130", default-features = false, features = [ "derive" ] }
Expand Down
1 change: 1 addition & 0 deletions bee-storage/bee-storage-memory/src/access/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ pub mod insert;
pub mod iter;
pub mod multi_fetch;
pub mod truncate;
pub mod update;
22 changes: 22 additions & 0 deletions bee-storage/bee-storage-memory/src/access/update.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2021-2022 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

//! Update access operations.

use crate::storage::Storage;

use bee_message::MessageId;
use bee_storage::{access::Update, backend::StorageBackend};
use bee_tangle::metadata::MessageMetadata;

macro_rules! impl_update {
($key:ty, $value:ty, $field:ident) => {
impl Update<$key, $value> for Storage {
fn update(&self, k: &$key, f: impl FnMut(&mut $value)) -> Result<(), <Self as StorageBackend>::Error> {
Ok(self.inner.write()?.$field.update(k, f))
}
}
};
}

impl_update!(MessageId, MessageMetadata, message_id_to_metadata);
4 changes: 4 additions & 0 deletions bee-storage/bee-storage-memory/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ impl<K: Hash + Eq + Clone, V: Clone> Table<K, V> {
self.inner.clear();
}

pub(crate) fn update(&mut self, k: &K, f: impl FnOnce(&mut V)) {
self.inner.get_mut(k).map(f);
}

pub(crate) fn iter(&self) -> TableIter<K, V> {
self.inner.clone().into_iter().map(Ok)
}
Expand Down
8 changes: 7 additions & 1 deletion bee-storage/bee-storage-null/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Security -->

## 0.1.0 - 2021-10-11
## 0.2.0 - 2022-03-11

### Added

- Implementation of `Update` for `Storage`;

## 0.1.0 - 2021-10-11

### Added

Expand Down
4 changes: 2 additions & 2 deletions bee-storage/bee-storage-null/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bee-storage-null"
version = "0.1.0"
version = "0.2.0"
authors = [ "IOTA Stiftung" ]
edition = "2021"
description = "A bee-storage implementation with no backend, for testing purposes"
Expand All @@ -11,4 +11,4 @@ keywords = [ "iota", "tangle", "bee", "framework", "storage" ]
homepage = "https://www.iota.org"

[dependencies]
bee-storage = { version = "0.9.0", path = "../bee-storage", default-features = false }
bee-storage = { version = "0.10.0", path = "../bee-storage", default-features = false }
1 change: 1 addition & 0 deletions bee-storage/bee-storage-null/src/access/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ pub mod insert;
pub mod iter;
pub mod multi_fetch;
pub mod truncate;
pub mod update;
Loading

0 comments on commit 45977c8

Please sign in to comment.