xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
include
xrpl
nodestore
detail
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
19
namespace
xrpl::node_store
{
20
21
class
DatabaseRotatingImp
:
public
DatabaseRotating
22
{
23
public
:
24
DatabaseRotatingImp
() =
delete
;
25
DatabaseRotatingImp
(
DatabaseRotatingImp
const
&) =
delete
;
26
DatabaseRotatingImp
&
27
operator=
(
DatabaseRotatingImp
const
&) =
delete
;
28
29
DatabaseRotatingImp
(
30
Scheduler
& scheduler,
31
int
readThreads,
32
std::shared_ptr<Backend>
writableBackend,
33
std::shared_ptr<Backend>
archiveBackend,
34
Section
const
& config,
35
beast::Journal
j);
36
37
~DatabaseRotatingImp
()
override
38
{
39
stop
();
40
}
41
42
void
43
rotate
(
44
std::unique_ptr<node_store::Backend>
&& newBackend,
45
std::function
<
void
(
std::string
const
& writableName,
std::string
const
& archiveName)>
const
&
46
f)
override
;
47
48
std::string
49
getName
()
const override
;
50
51
std::int32_t
52
getWriteLoad
()
const override
;
53
54
void
55
importDatabase
(
Database
& source)
override
;
56
57
bool
58
isSameDB
(
std::uint32_t
,
std::uint32_t
)
override
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
76
private
:
77
std::shared_ptr<Backend>
writableBackend_
;
78
std::shared_ptr<Backend>
archiveBackend_
;
79
mutable
std::mutex
mutex_
;
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.
86
std::atomic<bool>
rotationInFlight_
{
false
};
87
std::atomic<std::uint64_t>
copyForwardCount_
{0};
88
89
std::shared_ptr<NodeObject>
90
fetchNodeObject
(
UInt256
const
& hash,
std::uint32_t
,
FetchReport
& fetchReport,
bool
duplicate)
91
override
;
92
93
void
94
forEach
(
std::function
<
void
(
std::shared_ptr<NodeObject>
)> f)
override
;
95
};
96
97
}
// namespace xrpl::node_store
atomic
std::string
beast::Journal
A generic endpoint for log messages.
Definition
Journal.h:44
xrpl::Section
Holds a collection of configuration values.
Definition
BasicConfig.h:28
xrpl::node_store::DatabaseRotatingImp::isSameDB
bool isSameDB(std::uint32_t, std::uint32_t) override
Check if two ledgers are in the same database.
Definition
DatabaseRotatingImp.h:58
xrpl::node_store::DatabaseRotatingImp::~DatabaseRotatingImp
~DatabaseRotatingImp() override
Definition
DatabaseRotatingImp.h:37
xrpl::node_store::DatabaseRotatingImp::DatabaseRotatingImp
DatabaseRotatingImp()=delete
xrpl::node_store::DatabaseRotatingImp::fetchNodeObject
std::shared_ptr< NodeObject > fetchNodeObject(UInt256 const &hash, std::uint32_t, FetchReport &fetchReport, bool duplicate) override
Definition
DatabaseRotatingImp.cpp:142
xrpl::node_store::DatabaseRotatingImp::setRotationInFlight
void setRotationInFlight(bool inFlight) override
Marks an online-delete rotation as in progress (or completed).
Definition
DatabaseRotatingImp.cpp:82
xrpl::node_store::DatabaseRotatingImp::mutex_
std::mutex mutex_
Definition
DatabaseRotatingImp.h:79
xrpl::node_store::DatabaseRotatingImp::importDatabase
void importDatabase(Database &source) override
Import objects from another database.
Definition
DatabaseRotatingImp.cpp:104
xrpl::node_store::DatabaseRotatingImp::copyForwardCount_
std::atomic< std::uint64_t > copyForwardCount_
Definition
DatabaseRotatingImp.h:87
xrpl::node_store::DatabaseRotatingImp::getName
std::string getName() const override
Retrieve the name associated with this backend.
Definition
DatabaseRotatingImp.cpp:90
xrpl::node_store::DatabaseRotatingImp::rotationInFlight_
std::atomic< bool > rotationInFlight_
Definition
DatabaseRotatingImp.h:86
xrpl::node_store::DatabaseRotatingImp::getWriteLoad
std::int32_t getWriteLoad() const override
Retrieve the estimated number of pending write operations.
Definition
DatabaseRotatingImp.cpp:97
xrpl::node_store::DatabaseRotatingImp::writableBackend_
std::shared_ptr< Backend > writableBackend_
Definition
DatabaseRotatingImp.h:77
xrpl::node_store::DatabaseRotatingImp::sweep
void sweep() override
Remove expired entries from the positive and negative caches.
Definition
DatabaseRotatingImp.cpp:136
xrpl::node_store::DatabaseRotatingImp::rotate
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.
Definition
DatabaseRotatingImp.cpp:45
xrpl::node_store::DatabaseRotatingImp::archiveBackend_
std::shared_ptr< Backend > archiveBackend_
Definition
DatabaseRotatingImp.h:78
xrpl::node_store::DatabaseRotatingImp::operator=
DatabaseRotatingImp & operator=(DatabaseRotatingImp const &)=delete
xrpl::node_store::DatabaseRotatingImp::DatabaseRotatingImp
DatabaseRotatingImp(DatabaseRotatingImp const &)=delete
xrpl::node_store::DatabaseRotatingImp::sync
void sync() override
Definition
DatabaseRotatingImp.cpp:115
xrpl::node_store::DatabaseRotatingImp::store
void store(NodeObjectType type, Blob &&data, UInt256 const &hash, std::uint32_t) override
Store the object.
Definition
DatabaseRotatingImp.cpp:122
xrpl::node_store::DatabaseRotatingImp::forEach
void forEach(std::function< void(std::shared_ptr< NodeObject >)> f) override
Visit every object in the database This is usually called during import.
Definition
DatabaseRotatingImp.cpp:221
xrpl::node_store::DatabaseRotating::DatabaseRotating
DatabaseRotating(Scheduler &scheduler, int readThreads, Section const &config, beast::Journal journal)
Definition
DatabaseRotating.h:22
xrpl::node_store::Database
Persistency layer for NodeObject.
Definition
Database.h:45
xrpl::node_store::Database::stop
virtual void stop()
Definition
libxrpl/nodestore/Database.cpp:144
xrpl::node_store::Scheduler
Scheduling for asynchronous backend activity.
Definition
include/xrpl/nodestore/Scheduler.h:46
cstdint
std::function
functional
std::int32_t
memory
mutex
xrpl::node_store
Definition
ServiceRegistry.h:18
xrpl::NodeObjectType
NodeObjectType
The types of node objects.
Definition
NodeObject.h:18
xrpl::UInt256
BaseUInt< 256 > UInt256
Definition
base_uint.h:580
xrpl::Blob
std::vector< unsigned char > Blob
Storage for linear binary data.
Definition
Blob.h:11
std::shared_ptr
string
xrpl::node_store::FetchReport
Contains information about a fetch operation.
Definition
include/xrpl/nodestore/Scheduler.h:15
std::unique_ptr
Generated by
1.17.0