rippled
DatabaseRotatingImp.h
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012, 2013 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #ifndef RIPPLE_NODESTORE_DATABASEROTATINGIMP_H_INCLUDED
21 #define RIPPLE_NODESTORE_DATABASEROTATINGIMP_H_INCLUDED
22 
23 #include <ripple/nodestore/DatabaseRotating.h>
24 
25 namespace ripple {
26 namespace NodeStore {
27 
29 {
30 public:
31  DatabaseRotatingImp() = delete;
34  operator=(DatabaseRotatingImp const&) = delete;
35 
37  std::string const& name,
38  Scheduler& scheduler,
39  int readThreads,
40  Stoppable& parent,
41  std::shared_ptr<Backend> writableBackend,
42  std::shared_ptr<Backend> archiveBackend,
43  Section const& config,
44  beast::Journal j);
45 
47  {
48  // Stop read threads in base before data members are destroyed
50  }
51 
52  void
55  std::string const& writableBackendName)> const& f) override;
56 
58  getName() const override;
59 
61  getWriteLoad() const override;
62 
63  void
64  import(Database& source) override;
65 
66  void
67  store(NodeObjectType type, Blob&& data, uint256 const& hash, std::uint32_t)
68  override;
69 
70  bool
71  asyncFetch(
72  uint256 const& hash,
73  std::uint32_t ledgerSeq,
74  std::shared_ptr<NodeObject>& nodeObject) override;
75 
76  bool
77  storeLedger(std::shared_ptr<Ledger const> const& srcLedger) override;
78 
80  {
81  // We prefer a client not fill our cache
82  // We don't want to push data out of the cache
83  // before it's retrieved
84  return pCache_->getTargetSize() / asyncDivider;
85  }
86 
87  float
88  getCacheHitRate() override
89  {
90  return pCache_->getHitRate();
91  }
92 
93  void
94  tune(int size, std::chrono::seconds age) override;
95 
96  void
97  sweep() override;
98 
100  getPositiveCache() override
101  {
102  return *pCache_;
103  }
104 
105 private:
106  // Positive cache
108 
109  // Negative cache
111 
115 
118  uint256 const& hash,
120  FetchReport& fetchReport) override;
121 
122  void
124 };
125 
126 } // namespace NodeStore
127 } // namespace ripple
128 
129 #endif
ripple::Section
Holds a collection of configuration values.
Definition: BasicConfig.h:43
ripple::NodeStore::DatabaseRotatingImp::rotateWithLock
void rotateWithLock(std::function< std::unique_ptr< NodeStore::Backend >(std::string const &writableBackendName)> const &f) override
Rotates the backends.
Definition: DatabaseRotatingImp.cpp:59
ripple::NodeStore::DatabaseRotatingImp::getCacheHitRate
float getCacheHitRate() override
Get the positive cache hits to total attempts ratio.
Definition: DatabaseRotatingImp.h:88
ripple::NodeStore::DatabaseRotatingImp::archiveBackend_
std::shared_ptr< Backend > archiveBackend_
Definition: DatabaseRotatingImp.h:113
ripple::NodeStore::Database
Persistency layer for NodeObject.
Definition: Database.h:53
std::string
STL class.
std::shared_ptr
STL class.
ripple::TaggedCache
Map/cache combination.
Definition: TaggedCache.h:52
ripple::NodeStore::DatabaseRotatingImp::sweep
void sweep() override
Remove expired entries from the positive and negative caches.
Definition: DatabaseRotatingImp.cpp:153
ripple::NodeStore::DatabaseRotatingImp::tune
void tune(int size, std::chrono::seconds age) override
Set the maximum number of entries and maximum cache age for both caches.
Definition: DatabaseRotatingImp.cpp:144
std::vector< unsigned char >
ripple::NodeObjectType
NodeObjectType
The types of node objects.
Definition: NodeObject.h:32
std::chrono::seconds
ripple::NodeStore::DatabaseRotatingImp::DatabaseRotatingImp
DatabaseRotatingImp()=delete
ripple::NodeStore::DatabaseRotatingImp::fetchNodeObject
std::shared_ptr< NodeObject > fetchNodeObject(uint256 const &hash, std::uint32_t, FetchReport &fetchReport) override
Definition: DatabaseRotatingImp.cpp:160
ripple::NodeStore::FetchReport
Contains information about a fetch operation.
Definition: ripple/nodestore/Scheduler.h:32
std::function
ripple::NodeStore::DatabaseRotatingImp::getName
std::string getName() const override
Retrieve the name associated with this backend.
Definition: DatabaseRotatingImp.cpp:72
ripple::NodeStore::DatabaseRotatingImp::getPositiveCache
TaggedCache< uint256, NodeObject > const & getPositiveCache() override
Definition: DatabaseRotatingImp.h:100
ripple::base_uint< 256 >
ripple::NodeStore::DatabaseRotatingImp::getWriteLoad
std::int32_t getWriteLoad() const override
Retrieve the estimated number of pending write operations.
Definition: DatabaseRotatingImp.cpp:79
ripple::NodeStore::DatabaseRotatingImp
Definition: DatabaseRotatingImp.h:28
ripple::Stoppable
Provides an interface for starting and stopping.
Definition: Stoppable.h:201
ripple::NodeStore::DatabaseRotatingImp::mutex_
std::mutex mutex_
Definition: DatabaseRotatingImp.h:114
ripple::NodeStore::DatabaseRotatingImp::storeLedger
bool storeLedger(std::shared_ptr< Ledger const > const &srcLedger) override
Store a ledger from a different database.
Definition: DatabaseRotatingImp.cpp:97
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
std::int32_t
ripple::NodeStore::DatabaseRotating
Definition: DatabaseRotating.h:33
ripple::NodeStore::Scheduler
Scheduling for asynchronous backend activity.
Definition: ripple/nodestore/Scheduler.h:61
ripple::NodeStore::DatabaseRotatingImp::~DatabaseRotatingImp
~DatabaseRotatingImp() override
Definition: DatabaseRotatingImp.h:46
ripple::NodeStore::Database::stopReadThreads
void stopReadThreads()
Definition: Database.cpp:93
ripple::NodeStore::DatabaseRotatingImp::asyncFetch
bool asyncFetch(uint256 const &hash, std::uint32_t ledgerSeq, std::shared_ptr< NodeObject > &nodeObject) override
Fetch an object without waiting.
Definition: DatabaseRotatingImp.cpp:128
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::NodeStore::DatabaseRotatingImp::store
void store(NodeObjectType type, Blob &&data, uint256 const &hash, std::uint32_t) override
Store the object.
Definition: DatabaseRotatingImp.cpp:108
ripple::NodeStore::DatabaseRotatingImp::getDesiredAsyncReadCount
int getDesiredAsyncReadCount(std::uint32_t) override
Get the maximum number of async reads the node store prefers.
Definition: DatabaseRotatingImp.h:79
ripple::NodeStore::DatabaseRotatingImp::operator=
DatabaseRotatingImp & operator=(DatabaseRotatingImp const &)=delete
std::mutex
STL class.
std::unique_ptr
STL class.
ripple::NodeStore::DatabaseRotatingImp::for_each
void for_each(std::function< void(std::shared_ptr< NodeObject >)> f) override
Visit every object in the database This is usually called during import.
Definition: DatabaseRotatingImp.cpp:253
ripple::NodeStore::DatabaseRotatingImp::writableBackend_
std::shared_ptr< Backend > writableBackend_
Definition: DatabaseRotatingImp.h:112
ripple::NodeStore::asyncDivider
@ asyncDivider
Definition: nodestore/impl/Tuning.h:32
ripple::NodeStore::DatabaseRotatingImp::nCache_
std::shared_ptr< KeyCache< uint256 > > nCache_
Definition: DatabaseRotatingImp.h:110
ripple::NodeStore::DatabaseRotatingImp::pCache_
std::shared_ptr< TaggedCache< uint256, NodeObject > > pCache_
Definition: DatabaseRotatingImp.h:107