1#include <xrpl/nodestore/detail/DatabaseRotatingImp.h>
3#include <xrpl/basics/Blob.h>
4#include <xrpl/basics/Log.h>
5#include <xrpl/basics/base_uint.h>
6#include <xrpl/basics/contract.h>
7#include <xrpl/beast/utility/Journal.h>
8#include <xrpl/config/BasicConfig.h>
9#include <xrpl/nodestore/Backend.h>
10#include <xrpl/nodestore/Database.h>
11#include <xrpl/nodestore/DatabaseRotating.h>
12#include <xrpl/nodestore/NodeObject.h>
13#include <xrpl/nodestore/Scheduler.h>
14#include <xrpl/nodestore/Types.h>
50 std::string const newWritableBackendName = newBackend->getName();
73 JLOG(
j_.warn()) <<
"Rotating: copied forward " << copyForwards
74 <<
" archive-served reads into the writable backend "
75 "during the rotation window";
78 f(newWritableBackendName, newArchiveBackendName);
85 JLOG(
j_.debug()) <<
"Rotating: copy-forward on archive reads "
86 << (inFlight ?
"enabled" :
"disabled");
106 auto const backend = [&] {
126 auto const backend = [&] {
131 backend->store(nObj);
153 status = backend->fetch(hash, &nodeObject);
157 JLOG(
j_.fatal()) <<
"Exception, " << e.
what();
167 JLOG(
j_.fatal()) <<
"Corrupt NodeObject #" << hash;
170 JLOG(
j_.warn()) <<
"Unknown status=" <<
static_cast<int>(status);
180 auto [writable, archive] = [&] {
186 nodeObject = fetch(writable);
190 nodeObject = fetch(archive);
209 writable->store(nodeObject);
223 auto [writable, archive] = [&] {
229 writable->forEach(f);
A generic endpoint for log messages.
static std::shared_ptr< NodeObject > createObject(NodeObjectType type, Blob &&data, uint256 const &hash)
Create an object from fields.
Holds a collection of configuration values.
void store(NodeObjectType type, Blob &&data, uint256 const &hash, std::uint32_t) override
Store the object.
DatabaseRotatingImp()=delete
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::atomic< bool > rotationInFlight_
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_
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.
void storeStats(std::uint64_t count, std::uint64_t sz)
void importInternal(Backend &dstBackend, Database &srcDB)
Scheduling for asynchronous backend activity.
Status
Return codes from Backend operations.
NodeObjectType
The types of node objects.
XRPL_NO_SANITIZE_ADDRESS void rethrow()
Rethrow the exception currently being handled.
std::vector< unsigned char > Blob
Storage for linear binary data.
Contains information about a fetch operation.