diff --git a/CMakeLists.txt b/CMakeLists.txt index 9531049e..e25d9afc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,7 +45,6 @@ target_sources(clio PRIVATE ## Backend src/backend/BackendInterface.cpp src/backend/CassandraBackend.cpp - src/backend/LayeredCache.cpp src/backend/Pg.cpp src/backend/PostgresBackend.cpp src/backend/SimpleCache.cpp diff --git a/src/backend/LayeredCache.cpp b/src/backend/LayeredCache.cpp deleted file mode 100644 index ffde9283..00000000 --- a/src/backend/LayeredCache.cpp +++ /dev/null @@ -1,110 +0,0 @@ -#include -namespace Backend { - -void -LayeredCache::insert( - ripple::uint256 const& key, - Blob const& value, - uint32_t seq) -{ - auto entry = map_[key]; - // stale insert, do nothing - if (seq <= entry.recent.seq) - return; - entry.old = entry.recent; - entry.recent = {seq, value}; - if (value.empty()) - pendingDeletes_.push_back(key); - if (!entry.old.blob.empty()) - pendingSweeps_.push_back(key); -} - -std::optional -LayeredCache::select(CacheEntry const& entry, uint32_t seq) const -{ - if (seq < entry.old.seq) - return {}; - if (seq < entry.recent.seq && !entry.old.blob.empty()) - return entry.old.blob; - if (!entry.recent.blob.empty()) - return entry.recent.blob; - return {}; -} -void -LayeredCache::update(std::vector const& blobs, uint32_t seq) -{ - std::unique_lock lck{mtx_}; - if (seq > mostRecentSequence_) - mostRecentSequence_ = seq; - for (auto const& k : pendingSweeps_) - { - auto e = map_[k]; - e.old = {}; - } - for (auto const& k : pendingDeletes_) - { - map_.erase(k); - } - for (auto const& b : blobs) - { - insert(b.key, b.blob, seq); - } -} -std::optional -LayeredCache::getSuccessor(ripple::uint256 const& key, uint32_t seq) const -{ - ripple::uint256 curKey = key; - while (true) - { - std::shared_lock lck{mtx_}; - if (seq < mostRecentSequence_ - 1) - return {}; - auto e = map_.upper_bound(curKey); - if (e == map_.end()) - return {}; - auto const& entry = e->second; - auto blob = select(entry, seq); - if (!blob) - { - curKey = e->first; - continue; - } - else - return {{e->first, *blob}}; - } -} -std::optional -LayeredCache::getPredecessor(ripple::uint256 const& key, uint32_t seq) const -{ - ripple::uint256 curKey = key; - std::shared_lock lck{mtx_}; - while (true) - { - if (seq < mostRecentSequence_ - 1) - return {}; - auto e = map_.lower_bound(curKey); - --e; - if (e == map_.begin()) - return {}; - auto const& entry = e->second; - auto blob = select(entry, seq); - if (!blob) - { - curKey = e->first; - continue; - } - else - return {{e->first, *blob}}; - } -} -std::optional -LayeredCache::get(ripple::uint256 const& key, uint32_t seq) const -{ - std::shared_lock lck{mtx_}; - auto e = map_.find(key); - if (e == map_.end()) - return {}; - auto const& entry = e->second; - return select(entry, seq); -} -} // namespace Backend diff --git a/src/backend/LayeredCache.h b/src/backend/LayeredCache.h deleted file mode 100644 index 13fdade4..00000000 --- a/src/backend/LayeredCache.h +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef CLIO_LAYEREDCACHE_H_INCLUDED -#define CLIO_LAYEREDCACHE_H_INCLUDED - -#include -#include -#include -#include -#include -#include -#include -namespace Backend { -class LayeredCache -{ - struct SeqBlobPair - { - uint32_t seq; - Blob blob; - }; - struct CacheEntry - { - SeqBlobPair recent; - SeqBlobPair old; - }; - - std::map map_; - std::vector pendingDeletes_; - std::vector pendingSweeps_; - mutable std::shared_mutex mtx_; - uint32_t mostRecentSequence_; - - void - insert(ripple::uint256 const& key, Blob const& value, uint32_t seq); - - /* - void - insert(ripple::uint256 const& key, Blob const& value, uint32_t seq) - { - map_.emplace(key,{{seq,value,{}}); - } - void - update(ripple::uint256 const& key, Blob const& value, uint32_t seq) - { - auto& entry = map_.find(key); - entry.old = entry.recent; - entry.recent = {seq, value}; - pendingSweeps_.push_back(key); - } - void - erase(ripple::uint256 const& key, uint32_t seq) - { - update(key, {}, seq); - pendingDeletes_.push_back(key); - } - */ - std::optional - select(CacheEntry const& entry, uint32_t seq) const; - -public: - void - update(std::vector const& blobs, uint32_t seq); - - std::optional - get(ripple::uint256 const& key, uint32_t seq) const; - - std::optional - getSuccessor(ripple::uint256 const& key, uint32_t seq) const; - - std::optional - getPredecessor(ripple::uint256 const& key, uint32_t seq) const; -}; - -} // namespace Backend -#endif