rippled
DatabaseNodeImp.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_DATABASENODEIMP_H_INCLUDED
21 #define RIPPLE_NODESTORE_DATABASENODEIMP_H_INCLUDED
22 
23 #include <ripple/basics/chrono.h>
24 #include <ripple/nodestore/Database.h>
25 
26 namespace ripple {
27 namespace NodeStore {
28 
29 class DatabaseNodeImp : public Database
30 {
31 public:
32  DatabaseNodeImp() = delete;
33  DatabaseNodeImp(DatabaseNodeImp const&) = delete;
35  operator=(DatabaseNodeImp const&) = delete;
36 
38  std::string const& name,
39  Scheduler& scheduler,
40  int readThreads,
41  Stoppable& parent,
43  Section const& config,
45  : Database(name, parent, scheduler, readThreads, config, j)
46  , backend_(std::move(backend))
47  {
48  assert(backend_);
49  setParent(parent);
50  }
51 
52  ~DatabaseNodeImp() override
53  {
54  // Stop read threads in base before data members are destroyed
56  }
57 
59  getName() const override
60  {
61  return backend_->getName();
62  }
63 
65  getWriteLoad() const override
66  {
67  return backend_->getWriteLoad();
68  }
69 
70  void
71  import(Database& source) override
72  {
73  importInternal(*backend_.get(), source);
74  }
75 
76  void
77  store(NodeObjectType type, Blob&& data, uint256 const& hash, std::uint32_t)
78  override;
79 
81  {
82  // only one database
83  return true;
84  }
85 
86  bool
87  storeLedger(std::shared_ptr<Ledger const> const& srcLedger) override
88  {
89  return Database::storeLedger(*srcLedger, backend_);
90  }
91 
92  void
93  sweep() override;
94 
95 private:
96  // Persistent key/value storage
98 
101  uint256 const& hash,
103  FetchReport& fetchReport) override;
104 
105  void
107  {
108  backend_->for_each(f);
109  }
110 };
111 
112 } // namespace NodeStore
113 } // namespace ripple
114 
115 #endif
ripple::Section
Holds a collection of configuration values.
Definition: BasicConfig.h:43
ripple::NodeStore::DatabaseNodeImp::backend_
std::shared_ptr< Backend > backend_
Definition: DatabaseNodeImp.h:97
ripple::NodeStore::DatabaseNodeImp::getWriteLoad
std::int32_t getWriteLoad() const override
Retrieve the estimated number of pending write operations.
Definition: DatabaseNodeImp.h:65
ripple::NodeStore::Database
Persistency layer for NodeObject.
Definition: Database.h:52
std::string
STL class.
std::shared_ptr
STL class.
std::vector< unsigned char >
ripple::NodeObjectType
NodeObjectType
The types of node objects.
Definition: NodeObject.h:32
ripple::NodeStore::DatabaseNodeImp::fetchNodeObject
std::shared_ptr< NodeObject > fetchNodeObject(uint256 const &hash, std::uint32_t, FetchReport &fetchReport) override
Definition: DatabaseNodeImp.cpp:46
ripple::NodeStore::DatabaseNodeImp
Definition: DatabaseNodeImp.h:29
ripple::NodeStore::FetchReport
Contains information about a fetch operation.
Definition: ripple/nodestore/Scheduler.h:32
std::function
ripple::NodeStore::DatabaseNodeImp::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: DatabaseNodeImp.h:106
ripple::Stoppable::setParent
void setParent(Stoppable &parent)
Set the parent of this Stoppable.
Definition: Stoppable.cpp:43
ripple::base_uint< 256 >
ripple::Stoppable
Provides an interface for starting and stopping.
Definition: Stoppable.h:201
ripple::NodeStore::Database::importInternal
void importInternal(Backend &dstBackend, Database &srcDB)
Definition: Database.cpp:103
ripple::NodeStore::DatabaseNodeImp::DatabaseNodeImp
DatabaseNodeImp()=delete
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
std::int32_t
ripple::NodeStore::Scheduler
Scheduling for asynchronous backend activity.
Definition: ripple/nodestore/Scheduler.h:60
ripple::NodeStore::DatabaseNodeImp::operator=
DatabaseNodeImp & operator=(DatabaseNodeImp const &)=delete
ripple::NodeStore::DatabaseNodeImp::isSameDB
bool isSameDB(std::uint32_t, std::uint32_t) override
Definition: DatabaseNodeImp.h:80
ripple::NodeStore::DatabaseNodeImp::store
void store(NodeObjectType type, Blob &&data, uint256 const &hash, std::uint32_t) override
Store the object.
Definition: DatabaseNodeImp.cpp:28
ripple::NodeStore::Database::stopReadThreads
void stopReadThreads()
Definition: Database.cpp:75
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::NodeStore::Database::storeLedger
virtual bool storeLedger(std::shared_ptr< Ledger const > const &srcLedger)=0
Store a ledger from a different database.
ripple::NodeStore::DatabaseNodeImp::storeLedger
bool storeLedger(std::shared_ptr< Ledger const > const &srcLedger) override
Store a ledger from a different database.
Definition: DatabaseNodeImp.h:87
ripple::NodeStore::DatabaseNodeImp::sweep
void sweep() override
Remove expired entries from the positive and negative caches.
Definition: DatabaseNodeImp.cpp:40
std
STL namespace.
ripple::NodeStore::DatabaseNodeImp::DatabaseNodeImp
DatabaseNodeImp(std::string const &name, Scheduler &scheduler, int readThreads, Stoppable &parent, std::shared_ptr< Backend > backend, Section const &config, beast::Journal j)
Definition: DatabaseNodeImp.h:37
ripple::NodeStore::DatabaseNodeImp::getName
std::string getName() const override
Retrieve the name associated with this backend.
Definition: DatabaseNodeImp.h:59
ripple::NodeStore::DatabaseNodeImp::~DatabaseNodeImp
~DatabaseNodeImp() override
Definition: DatabaseNodeImp.h:52