mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
decouple LedgerHistory and TaggedCache, renaming
This commit is contained in:
@@ -170,9 +170,6 @@ public:
|
||||
bool
|
||||
retrieve(key_type const& key, T& data);
|
||||
|
||||
mutex_type&
|
||||
peekMutex();
|
||||
|
||||
std::vector<key_type>
|
||||
getKeys() const;
|
||||
|
||||
|
||||
@@ -668,29 +668,6 @@ TaggedCache<
|
||||
return true;
|
||||
}
|
||||
|
||||
template <
|
||||
class Key,
|
||||
class T,
|
||||
bool IsKeyCache,
|
||||
class SharedWeakUnionPointer,
|
||||
class SharedPointerType,
|
||||
class Hash,
|
||||
class KeyEqual,
|
||||
class Mutex>
|
||||
inline auto
|
||||
TaggedCache<
|
||||
Key,
|
||||
T,
|
||||
IsKeyCache,
|
||||
SharedWeakUnionPointer,
|
||||
SharedPointerType,
|
||||
Hash,
|
||||
KeyEqual,
|
||||
Mutex>::peekMutex() -> mutex_type&
|
||||
{
|
||||
return m_mutex;
|
||||
}
|
||||
|
||||
template <
|
||||
class Key,
|
||||
class T,
|
||||
|
||||
@@ -62,8 +62,6 @@ LedgerHistory::insert(
|
||||
ledger->stateMap().getHash().isNonZero(),
|
||||
"ripple::LedgerHistory::insert : nonzero hash");
|
||||
|
||||
std::unique_lock sl(m_ledgers_by_hash.peekMutex());
|
||||
|
||||
bool const alreadyHad = m_ledgers_by_hash.canonicalize_replace_cache(
|
||||
ledger->info().hash, ledger);
|
||||
if (validated)
|
||||
@@ -81,7 +79,6 @@ LedgerHistory::insert(
|
||||
LedgerHash
|
||||
LedgerHistory::getLedgerHash(LedgerIndex index)
|
||||
{
|
||||
std::unique_lock sl(m_ledgers_by_hash.peekMutex());
|
||||
if (auto p = mLedgersByIndex.get(index))
|
||||
return *p;
|
||||
return {};
|
||||
@@ -90,14 +87,10 @@ LedgerHistory::getLedgerHash(LedgerIndex index)
|
||||
std::shared_ptr<Ledger const>
|
||||
LedgerHistory::getLedgerBySeq(LedgerIndex index)
|
||||
{
|
||||
if (auto p = mLedgersByIndex.get(index))
|
||||
{
|
||||
std::unique_lock sl(m_ledgers_by_hash.peekMutex());
|
||||
if (auto p = mLedgersByIndex.get(index))
|
||||
{
|
||||
uint256 const hash = *p;
|
||||
sl.unlock();
|
||||
return getLedgerByHash(hash);
|
||||
}
|
||||
uint256 const hash = *p;
|
||||
return getLedgerByHash(hash);
|
||||
}
|
||||
|
||||
std::shared_ptr<Ledger const> ret = loadByIndex(index, app_);
|
||||
@@ -111,8 +104,6 @@ LedgerHistory::getLedgerBySeq(LedgerIndex index)
|
||||
|
||||
{
|
||||
// Add this ledger to the local tracking by index
|
||||
std::unique_lock sl(m_ledgers_by_hash.peekMutex());
|
||||
|
||||
XRPL_ASSERT(
|
||||
ret->isImmutable(),
|
||||
"ripple::LedgerHistory::getLedgerBySeq : immutable result ledger");
|
||||
@@ -466,8 +457,6 @@ LedgerHistory::builtLedger(
|
||||
XRPL_ASSERT(
|
||||
!hash.isZero(), "ripple::LedgerHistory::builtLedger : nonzero hash");
|
||||
|
||||
std::unique_lock sl(m_consensus_validated.peekMutex());
|
||||
|
||||
auto entry = std::make_shared<cv_entry>();
|
||||
m_consensus_validated.canonicalize_replace_client(index, entry);
|
||||
|
||||
@@ -508,8 +497,6 @@ LedgerHistory::validatedLedger(
|
||||
!hash.isZero(),
|
||||
"ripple::LedgerHistory::validatedLedger : nonzero hash");
|
||||
|
||||
std::unique_lock sl(m_consensus_validated.peekMutex());
|
||||
|
||||
auto entry = std::make_shared<cv_entry>();
|
||||
m_consensus_validated.canonicalize_replace_client(index, entry);
|
||||
|
||||
@@ -543,7 +530,6 @@ LedgerHistory::validatedLedger(
|
||||
bool
|
||||
LedgerHistory::fixIndex(LedgerIndex ledgerIndex, LedgerHash const& ledgerHash)
|
||||
{
|
||||
std::unique_lock sl(m_ledgers_by_hash.peekMutex());
|
||||
if (auto cur = mLedgersByIndex.get(ledgerIndex))
|
||||
{
|
||||
if (*cur != ledgerHash)
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#include <xrpld/app/ledger/Ledger.h>
|
||||
#include <xrpld/app/main/Application.h>
|
||||
#include <xrpld/core/detail/LRUMap.h>
|
||||
#include <xrpld/core/detail/LRUCache.h>
|
||||
|
||||
#include <xrpl/beast/insight/Collector.h>
|
||||
#include <xrpl/protocol/RippleLedgerHash.h>
|
||||
@@ -150,7 +150,8 @@ private:
|
||||
ConsensusValidated m_consensus_validated;
|
||||
|
||||
// Maps ledger indexes to the corresponding hash.
|
||||
LRUMap<LedgerIndex, LedgerHash> mLedgersByIndex; // validated ledgers
|
||||
LRUCache<LedgerIndex, LedgerHash, concurrency::ExclusiveMutex>
|
||||
mLedgersByIndex; // validated ledgers
|
||||
|
||||
beast::Journal j_;
|
||||
};
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#ifndef RIPPLE_APP_LRU_MAP_H_INCLUDED
|
||||
#define RIPPLE_APP_LRU_MAP_H_INCLUDED
|
||||
#ifndef RIPPLE_APP_LRU_CACHE_H_INCLUDED
|
||||
#define RIPPLE_APP_LRU_CACHE_H_INCLUDED
|
||||
|
||||
#include <list>
|
||||
#include <mutex>
|
||||
@@ -59,7 +59,7 @@ template <
|
||||
class Key,
|
||||
class Value,
|
||||
class Concurrency = concurrency::SingleThreaded>
|
||||
class LRUMap
|
||||
class LRUCache
|
||||
{
|
||||
using List = std::list<Key>; // MRU .. LRU
|
||||
using DataMap = std::unordered_map<Key, Value>; // Key -> Value
|
||||
@@ -69,31 +69,31 @@ class LRUMap
|
||||
// list
|
||||
|
||||
public:
|
||||
explicit LRUMap(std::size_t capacity) : capacity_(capacity)
|
||||
explicit LRUCache(std::size_t capacity) : capacity_(capacity)
|
||||
{
|
||||
if (capacity_ == 0)
|
||||
throw std::invalid_argument("LRUMap capacity must be positive.");
|
||||
throw std::invalid_argument("LRUCache capacity must be positive.");
|
||||
data_.reserve(capacity_);
|
||||
pos_.reserve(capacity_);
|
||||
|
||||
// TODO:
|
||||
// static_assert(std::is_default_constructible_v<Value>,
|
||||
// "LRUMap requires Value to be default-constructible for
|
||||
// "LRUCache requires Value to be default-constructible for
|
||||
// operator[]");
|
||||
// static_assert(std::is_copy_constructible_v<Key> ||
|
||||
// std::is_move_constructible_v<Key>,
|
||||
// "LRUMap requires Key to be copy- or move-constructible");
|
||||
// "LRUCache requires Key to be copy- or move-constructible");
|
||||
}
|
||||
|
||||
LRUMap(LRUMap const&) = delete;
|
||||
LRUCache(LRUCache const&) = delete;
|
||||
|
||||
LRUMap&
|
||||
operator=(LRUMap const&) = delete;
|
||||
LRUCache&
|
||||
operator=(LRUCache const&) = delete;
|
||||
|
||||
LRUMap(LRUMap&&) = delete;
|
||||
LRUCache(LRUCache&&) = delete;
|
||||
|
||||
LRUMap&
|
||||
operator=(LRUMap&&) = delete;
|
||||
LRUCache&
|
||||
operator=(LRUCache&&) = delete;
|
||||
|
||||
Value&
|
||||
operator[](Key const& key)
|
||||
Reference in New Issue
Block a user