CatapultServer  v0.5.0.1 (Elephant)
CatapultCache.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "CatapultCacheDelta.h"
24 #include "CatapultCacheView.h"
25 #include "SubCachePlugin.h"
26 
27 namespace catapult {
28  namespace cache {
29  class CacheChangesStorage;
30  class CacheHeight;
31  class CacheStorage;
32  class SubCachePlugin;
33  }
34  namespace model { struct BlockChainConfiguration; }
35 }
36 
37 namespace catapult { namespace cache {
38 
40  class CatapultCache {
41  public:
43  explicit CatapultCache(std::vector<std::unique_ptr<SubCachePlugin>>&& subCaches);
44 
47 
48  public:
49  // make this class move only (the definitions are in the source file in order to allow forward declarations)
52 
53  public:
55  template<typename TCache>
56  const TCache& sub() const {
57  return *static_cast<const TCache*>(m_subCaches[TCache::Id]->get());
58  }
59 
60  public:
63 
66 
71 
73  void commit(Height height);
74 
75  public:
77  std::vector<std::unique_ptr<const CacheStorage>> storages() const;
78 
80  std::vector<std::unique_ptr<CacheStorage>> storages();
81 
83  std::vector<std::unique_ptr<const CacheChangesStorage>> changesStorages() const;
84 
85  private:
86  std::unique_ptr<CacheHeight> m_pCacheHeight; // use a unique_ptr to allow fwd declare
87  std::vector<std::unique_ptr<SubCachePlugin>> m_subCaches;
88  };
89 }}
catapult::cache::CatapultCacheDetachableDelta::m_pCacheHeightView
std::unique_ptr< const CacheHeightView > m_pCacheHeightView
Definition: CatapultCacheDetachableDelta.h:54
catapult::Hash256
utils::ByteArray< Hash256_Size, Hash256_tag > Hash256
Definition: src/catapult/types.h:47
catapult::cache::CatapultCacheDetachableDelta::~CatapultCacheDetachableDelta
~CatapultCacheDetachableDelta()
Destroys the detachable cache delta.
catapult::crypto::Sha3_256
void Sha3_256(const RawBuffer &dataBuffer, Hash256 &hash) noexcept
Calculates the 256-bit SHA3 hash of dataBuffer into hash.
Definition: Hashes.cpp:81
BlockChainConfiguration.h
catapult::cache::CatapultCache::createDetachableDelta
CatapultCacheDetachableDelta createDetachableDelta() const
Definition: CatapultCache.cpp:260
catapult::cache::CatapultCacheDelta
Delta on top of a catapult cache.
Definition: CatapultCacheDelta.h:31
CATAPULT_THROW_INVALID_ARGUMENT_2
#define CATAPULT_THROW_INVALID_ARGUMENT_2(MESSAGE, PARAM1, PARAM2)
Macro used to throw a catapult invalid argument with two parameters.
Definition: exceptions.h:187
catapult::cache::CatapultCacheDetachableDelta::m_detachedDelta
CatapultCacheDetachedDelta m_detachedDelta
Definition: CatapultCacheDetachableDelta.h:55
catapult::cache::CatapultCacheView::height
Height height() const
Gets the cache height associated with the read lock.
Definition: CatapultCache.cpp:108
catapult::cache::CatapultCache::operator=
CatapultCache & operator=(CatapultCache &&)
catapult::cache::CatapultCache::CatapultCache
CatapultCache(std::vector< std::unique_ptr< SubCachePlugin >> &&subCaches)
Creates a catapult cache around subCaches.
Definition: CatapultCache.cpp:235
catapult::cache::CatapultCache::storages
std::vector< std::unique_ptr< const CacheStorage > > storages() const
Gets cache storages for all sub caches.
Definition: CatapultCache.cpp:282
Id
NamespaceId Id
Definition: RootNamespaceHistorySerializer.cpp:100
catapult::cache::CatapultCacheDetachedDelta::tryLock
std::unique_ptr< CatapultCacheDelta > tryLock()
Definition: CatapultCache.cpp:197
catapult::utils::BaseValue< uint64_t, Height_tag >
catapult::cache::StateHashInfo
Information about a cache state hash.
Definition: StateHashInfo.h:28
catapult::cache::CatapultCacheDelta::~CatapultCacheDelta
~CatapultCacheDelta()
Destroys the delta.
NetworkInfo.h
Hashes.h
CatapultCacheDelta.h
catapult::cache::CatapultCacheDetachableDelta::height
Height height() const
Gets the cache height associated with this delta.
Definition: CatapultCache.cpp:175
catapult::cache::CatapultCacheView::toReadOnly
ReadOnlyCatapultCache toReadOnly() const
Creates a read-only view of this view.
Definition: CatapultCache.cpp:112
catapult::cache::CatapultCacheDetachedDelta::~CatapultCacheDetachedDelta
~CatapultCacheDetachedDelta()
Destroys the delta.
CatapultCacheView.h
SubCachePluginAdapter.h
m_detachedDelta
CatapultCacheDetachedDelta m_detachedDelta
Definition: RelockableDetachedCatapultCache.cpp:42
catapult::cache::CatapultCacheView::m_subViews
std::vector< std::unique_ptr< const SubCacheView > > m_subViews
Definition: CatapultCacheView.h:69
catapult::cache::CatapultCacheDetachedDelta::CatapultCacheDetachedDelta
CatapultCacheDetachedDelta(std::vector< std::unique_ptr< DetachedSubCacheView >> &&detachedSubViews)
Creates a detached cache delta from detachedSubViews.
Definition: CatapultCache.cpp:187
catapult::cache::CatapultCacheDetachableDelta::CatapultCacheDetachableDelta
CatapultCacheDetachableDelta(CacheHeightView &&cacheHeightView, std::vector< std::unique_ptr< DetachedSubCacheView >> &&detachedSubViews)
Creates a detachable cache delta from a cache height view (cacheHeightView) and detachedSubViews.
Definition: CatapultCache.cpp:163
catapult::cache::CatapultCache
Central cache holding all sub caches.
Definition: CatapultCache.h:40
catapult::cache::CatapultCacheView::m_pCacheHeight
std::unique_ptr< CacheHeightView > m_pCacheHeight
Definition: CatapultCacheView.h:68
catapult::cache::CatapultCache::changesStorages
std::vector< std::unique_ptr< const CacheChangesStorage > > changesStorages() const
Gets cache changes storages for all sub caches.
Definition: CatapultCache.cpp:296
catapult::cache::CatapultCacheDelta::operator=
CatapultCacheDelta & operator=(CatapultCacheDelta &&)
catapult::cache::CatapultCacheDelta::calculateStateHash
StateHashInfo calculateStateHash(Height height) const
Calculates the cache state hash given height.
Definition: CatapultCache.cpp:130
catapult::cache::CatapultCache::commit
void commit(Height height)
Commits all pending changes to the underlying storage and sets the cache height to height.
Definition: CatapultCache.cpp:269
CATAPULT_THROW_INVALID_ARGUMENT_1
#define CATAPULT_THROW_INVALID_ARGUMENT_1(MESSAGE, PARAM1)
Macro used to throw a catapult invalid argument with a single parameter.
Definition: exceptions.h:183
catapult::cache::CatapultCache::m_pCacheHeight
std::unique_ptr< CacheHeight > m_pCacheHeight
Definition: CatapultCache.h:86
StackLogger.h
catapult::cache::CatapultCacheDelta::toReadOnly
ReadOnlyCatapultCache toReadOnly() const
Creates a read-only view of this delta.
Definition: CatapultCache.cpp:155
CatapultCache.h
CatapultCacheDetachedDelta.h
catapult::cache::CatapultCacheView
Locked view on top of the catapult cache.
Definition: CatapultCacheView.h:36
catapult::cache::CatapultCache::createView
CatapultCacheView createView() const
Returns a locked cache view based on this cache.
Definition: CatapultCache.cpp:246
catapult::cache::CatapultCacheDetachedDelta::operator=
CatapultCacheDetachedDelta & operator=(CatapultCacheDetachedDelta &&)
ReadOnlyCatapultCache.h
catapult::cache::CatapultCacheDetachableDelta::detach
CatapultCacheDetachedDelta detach()
Detaches the detached delta from this delta.
Definition: CatapultCache.cpp:179
catapult::cache::CatapultCacheDetachedDelta
Detached delta of the catapult cache.
Definition: CatapultCacheDetachedDelta.h:30
catapult::cache::CatapultCache::createDelta
CatapultCacheDelta createDelta()
Returns a locked cache delta based on this cache.
Definition: CatapultCache.cpp:253
catapult::cache::CatapultCacheDelta::m_subViews
std::vector< std::unique_ptr< SubCacheView > > m_subViews
Definition: CatapultCacheDelta.h:69
catapult::cache::CatapultCache::sub
const TCache & sub() const
Gets a specific sub cache.
Definition: CatapultCache.h:56
SubCachePlugin.h
catapult
Definition: AddressExtractionExtension.cpp:28
CatapultCacheDetachableDelta.h
catapult::Hash256_Size
constexpr size_t Hash256_Size
Definition: src/catapult/types.h:34
catapult::cache::CatapultCacheView::CatapultCacheView
CatapultCacheView(CacheHeightView &&cacheHeightView, std::vector< std::unique_ptr< const SubCacheView >> &&subViews)
Creates a locked catapult cache view from a cache height view (cacheHeightView) and subViews.
Definition: CatapultCache.cpp:93
catapult::cache::CatapultCache::~CatapultCache
~CatapultCache()
Destroys the cache.
catapult::cache::CatapultCacheDetachableDelta
Definition: CatapultCacheDetachableDelta.h:32
catapult::cache::CacheHeightView
A read only view on top of a cache height.
Definition: CacheHeight.h:28
catapult::cache::CacheHeight
A synchronized height associated with a catapult cache.
Definition: CacheHeight.h:70
catapult::cache::CatapultCacheView::operator=
CatapultCacheView & operator=(CatapultCacheView &&)
catapult::cache::CatapultCache::m_subCaches
std::vector< std::unique_ptr< SubCachePlugin > > m_subCaches
Definition: CatapultCache.h:87
catapult::cache::CatapultCacheView::~CatapultCacheView
~CatapultCacheView()
Releases the read lock.
catapult::cache::CatapultCacheDelta::CatapultCacheDelta
CatapultCacheDelta(std::vector< std::unique_ptr< SubCacheView >> &&subViews)
Creates a locked catapult cache delta from subViews.
Definition: CatapultCache.cpp:120
catapult::cache::CatapultCacheDelta::setSubCacheMerkleRoots
void setSubCacheMerkleRoots(const std::vector< Hash256 > &subCacheMerkleRoots)
Sets the merkle roots for all sub caches (subCacheMerkleRoots).
Definition: CatapultCache.cpp:134
CacheHeight.h
catapult::cache::ReadOnlyCatapultCache
A read-only overlay on top of a catapult cache.
Definition: ReadOnlyCatapultCache.h:27
catapult::utils::LogLevel::Warning
Level for logging warning events.
catapult::utils::RawBuffer
BasicRawBuffer< const uint8_t > RawBuffer
A const binary buffer.
Definition: RawBuffer.h:62
catapult::cache::CatapultCacheDetachedDelta::m_detachedSubViews
std::vector< std::unique_ptr< DetachedSubCacheView > > m_detachedSubViews
Definition: CatapultCacheDetachedDelta.h:49
catapult::cache::CatapultCacheView::calculateStateHash
StateHashInfo calculateStateHash() const
Calculates the cache state hash.
Definition: CatapultCache.cpp:104