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  Scheduler& scheduler,
38  int readThreads,
39  std::shared_ptr<Backend> writableBackend,
40  std::shared_ptr<Backend> archiveBackend,
41  Section const& config,
42  beast::Journal j);
43 
45  {
46  stop();
47  }
48 
49  void
52  std::string const& writableBackendName)> const& f) override;
53 
55  getName() const override;
56 
58  getWriteLoad() const override;
59 
60  void
61  importDatabase(Database& source) override;
62 
64  {
65  // rotating store acts as one logical database
66  return true;
67  }
68 
69  void
70  store(NodeObjectType type, Blob&& data, uint256 const& hash, std::uint32_t)
71  override;
72 
73  void
74  sync() override;
75 
76  bool
77  storeLedger(std::shared_ptr<Ledger const> const& srcLedger) override;
78 
79  void
80  sweep() override;
81 
82 private:
85  mutable std::mutex mutex_;
86 
89  uint256 const& hash,
91  FetchReport& fetchReport,
92  bool duplicate) override;
93 
94  void
96 };
97 
98 } // namespace NodeStore
99 } // namespace ripple
100 
101 #endif
ripple::Section
Holds a collection of configuration values.
Definition: BasicConfig.h:42
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:45
ripple::NodeStore::DatabaseRotatingImp::~DatabaseRotatingImp
~DatabaseRotatingImp()
Definition: DatabaseRotatingImp.h:44
ripple::NodeStore::DatabaseRotatingImp::importDatabase
void importDatabase(Database &source) override
Import objects from another database.
Definition: DatabaseRotatingImp.cpp:72
ripple::NodeStore::DatabaseRotatingImp::archiveBackend_
std::shared_ptr< Backend > archiveBackend_
Definition: DatabaseRotatingImp.h:84
ripple::NodeStore::Database
Persistency layer for NodeObject.
Definition: Database.h:51
std::string
STL class.
std::shared_ptr
STL class.
ripple::NodeStore::DatabaseRotatingImp::sweep
void sweep() override
Remove expired entries from the positive and negative caches.
Definition: DatabaseRotatingImp.cpp:119
ripple::NodeStore::DatabaseRotatingImp::fetchNodeObject
std::shared_ptr< NodeObject > fetchNodeObject(uint256 const &hash, std::uint32_t, FetchReport &fetchReport, bool duplicate) override
Definition: DatabaseRotatingImp.cpp:125
std::vector< unsigned char >
ripple::NodeObjectType
NodeObjectType
The types of node objects.
Definition: NodeObject.h:32
ripple::NodeStore::DatabaseRotatingImp::DatabaseRotatingImp
DatabaseRotatingImp()=delete
ripple::NodeStore::Database::stop
virtual void stop()
Definition: Database.cpp:165
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:58
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:65
ripple::NodeStore::DatabaseRotatingImp
Definition: DatabaseRotatingImp.h:28
ripple::NodeStore::DatabaseRotatingImp::mutex_
std::mutex mutex_
Definition: DatabaseRotatingImp.h:85
ripple::NodeStore::DatabaseRotatingImp::storeLedger
bool storeLedger(std::shared_ptr< Ledger const > const &srcLedger) override
Store a ledger from a different database.
Definition: DatabaseRotatingImp.cpp:83
ripple::NodeStore::DatabaseRotatingImp::sync
void sync() override
Definition: DatabaseRotatingImp.cpp:94
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:60
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:101
ripple::NodeStore::DatabaseRotatingImp::operator=
DatabaseRotatingImp & operator=(DatabaseRotatingImp const &)=delete
std::mutex
STL class.
ripple::NodeStore::DatabaseRotatingImp::isSameDB
bool isSameDB(std::uint32_t, std::uint32_t) override
Definition: DatabaseRotatingImp.h:63
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:195
ripple::NodeStore::DatabaseRotatingImp::writableBackend_
std::shared_ptr< Backend > writableBackend_
Definition: DatabaseRotatingImp.h:83