Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor storage interface #1435

Merged
merged 20 commits into from
Dec 6, 2022
4 changes: 3 additions & 1 deletion core/storage/face/batch_writeable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ namespace kagome::storage::face {
* @brief Creates new Write Batch - an object, which can be used to
* efficiently write bulk data.
*/
virtual std::unique_ptr<WriteBatch<K, V>> batch() = 0;
virtual std::unique_ptr<WriteBatch<K, V>> batch() {
abort();
turuslan marked this conversation as resolved.
Show resolved Hide resolved
}
};

} // namespace kagome::storage::face
Expand Down
24 changes: 5 additions & 19 deletions core/storage/face/generic_maps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,23 @@
#include "storage/face/writeable.hpp"

namespace kagome::storage::face {

/**
* @brief An abstraction over a readable and iterable key-value map.
* @tparam K key type
* @tparam V value type
*/
template <typename K, typename V>
struct ReadOnlyMap : Iterable<K, V>, Readable<K, V> {};

template <typename K, typename V>
struct ReadOnlyStorage : Iterable<K, V>, Readable<K, V> {};

/**
* @brief An abstraction over a readable, writeable, iterable key-value map.
* @tparam K key type
* @tparam V value type
*/
template <typename K, typename V>
struct GenericMap : ReadOnlyMap<K, V>,
Writeable<K, V>,
BatchWriteable<K, V> {};

template <typename K, typename V>
struct GenericStorage : ReadOnlyStorage<K, V>,
struct GenericStorage : Readable<K, V>,
Iterable<K, V>,
Writeable<K, V>,
BatchWriteable<K, V> {
/**
* Reports RAM state size
* @return size in bytes
*/
virtual size_t size() const = 0;
virtual size_t size() const {
abort();
}
};

} // namespace kagome::storage::face
Expand Down
5 changes: 0 additions & 5 deletions core/storage/trie/impl/trie_storage_backend_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,4 @@ namespace kagome::storage::trie {
const common::BufferView &key) const {
return common::Buffer{node_prefix_}.put(key);
}

size_t TrieStorageBackendImpl::size() const {
return storage_->size();
}

} // namespace kagome::storage::trie
2 changes: 0 additions & 2 deletions core/storage/trie/impl/trie_storage_backend_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ namespace kagome::storage::trie {
BufferOrView &&value) override;
outcome::result<void> remove(const common::BufferView &key) override;

size_t size() const override;

private:
common::Buffer prefixKey(const common::BufferView &key) const;

Expand Down
3 changes: 1 addition & 2 deletions core/storage/trie/polkadot_trie/polkadot_trie.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ namespace kagome::storage::trie {
* For specification see Polkadot Runtime Environment Protocol Specification
* '2.1.2 The General Tree Structure' and further
*/
class PolkadotTrie : public face::ReadOnlyMap<Buffer, Buffer>,
public face::Writeable<Buffer, Buffer> {
class PolkadotTrie : public BufferStorage {
public:
using NodePtr = std::shared_ptr<TrieNode>;
using ConstNodePtr = std::shared_ptr<const TrieNode>;
Expand Down
4 changes: 1 addition & 3 deletions core/storage/trie/trie_batches.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@

namespace kagome::storage::trie {

class TrieBatch : public face::Readable<Buffer, Buffer>,
public face::Writeable<Buffer, Buffer>,
public face::Iterable<Buffer, Buffer> {
class TrieBatch : public BufferStorage {
public:
~TrieBatch() override = default;

Expand Down