xrpld
Loading...
Searching...
No Matches
DatabaseRotatingImp.h
1#pragma once
2
3#include <xrpl/basics/Blob.h>
4#include <xrpl/basics/base_uint.h>
5#include <xrpl/beast/utility/Journal.h>
6#include <xrpl/nodestore/Backend.h>
7#include <xrpl/nodestore/Database.h>
8#include <xrpl/nodestore/DatabaseRotating.h>
9#include <xrpl/nodestore/NodeObject.h>
10#include <xrpl/nodestore/Scheduler.h>
11
12#include <atomic>
13#include <cstdint>
14#include <functional>
15#include <memory>
16#include <mutex>
17#include <string>
18
19namespace xrpl::node_store {
20
22{
23public:
28
30 Scheduler& scheduler,
31 int readThreads,
32 std::shared_ptr<Backend> writableBackend,
33 std::shared_ptr<Backend> archiveBackend,
34 Section const& config,
36
38 {
39 stop();
40 }
41
42 void
43 rotate(
45 std::function<void(std::string const& writableName, std::string const& archiveName)> const&
46 f) override;
47
49 getName() const override;
50
52 getWriteLoad() const override;
53
54 void
55 importDatabase(Database& source) override;
56
57 bool
59 {
60 // rotating store acts as one logical database
61 return true;
62 }
63
64 void
65 store(NodeObjectType type, Blob&& data, uint256 const& hash, std::uint32_t) override;
66
67 void
68 sync() override;
69
70 void
71 sweep() override;
72
73 void
74 setRotationInFlight(bool inFlight) override;
75
76private:
80
81 // True between SHAMapStore starting the cache-freshen phase and the
82 // completion of rotate(). While true, archive hits on ordinary
83 // (duplicate == false) fetches are copied forward into the writable
84 // backend; copyForwardCount_ tallies them per rotation for the
85 // summary line logged at swap.
88
90 fetchNodeObject(uint256 const& hash, std::uint32_t, FetchReport& fetchReport, bool duplicate)
91 override;
92
93 void
95};
96
97} // namespace xrpl::node_store
A generic endpoint for log messages.
Definition Journal.h:44
Holds a collection of configuration values.
Definition BasicConfig.h:29
void store(NodeObjectType type, Blob &&data, uint256 const &hash, std::uint32_t) override
Store the object.
bool isSameDB(std::uint32_t, std::uint32_t) override
Check if two ledgers are in the same database.
void setRotationInFlight(bool inFlight) override
Marks an online-delete rotation as in progress (or completed).
void importDatabase(Database &source) override
Import objects from another database.
std::atomic< std::uint64_t > copyForwardCount_
std::string getName() const override
Retrieve the name associated with this backend.
std::int32_t getWriteLoad() const override
Retrieve the estimated number of pending write operations.
std::shared_ptr< Backend > writableBackend_
void sweep() override
Remove expired entries from the positive and negative caches.
void rotate(std::unique_ptr< node_store::Backend > &&newBackend, std::function< void(std::string const &writableName, std::string const &archiveName)> const &f) override
Rotates the backends.
std::shared_ptr< Backend > archiveBackend_
DatabaseRotatingImp & operator=(DatabaseRotatingImp const &)=delete
DatabaseRotatingImp(DatabaseRotatingImp const &)=delete
void forEach(std::function< void(std::shared_ptr< NodeObject >)> f) override
Visit every object in the database This is usually called during import.
std::shared_ptr< NodeObject > fetchNodeObject(uint256 const &hash, std::uint32_t, FetchReport &fetchReport, bool duplicate) override
DatabaseRotating(Scheduler &scheduler, int readThreads, Section const &config, beast::Journal journal)
Persistency layer for NodeObject.
Definition Database.h:45
Scheduling for asynchronous backend activity.
NodeObjectType
The types of node objects.
Definition NodeObject.h:18
std::vector< unsigned char > Blob
Storage for linear binary data.
Definition Blob.h:11
BaseUInt< 256 > uint256
Definition base_uint.h:580
Contains information about a fetch operation.