rippled
Loading...
Searching...
No Matches
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 <xrpld/nodestore/DatabaseRotating.h>
24
25#include <mutex>
26
27namespace ripple {
28namespace NodeStore {
29
31{
32public:
37
39 Scheduler& scheduler,
40 int readThreads,
41 std::shared_ptr<Backend> writableBackend,
42 std::shared_ptr<Backend> archiveBackend,
43 Section const& config,
45
47 {
48 stop();
49 }
50
51 void
54 std::string const& writableBackendName)> const& f) override;
55
57 getName() const override;
58
60 getWriteLoad() const override;
61
62 void
63 importDatabase(Database& source) override;
64
65 bool
67 {
68 // rotating store acts as one logical database
69 return true;
70 }
71
72 void
73 store(NodeObjectType type, Blob&& data, uint256 const& hash, std::uint32_t)
74 override;
75
76 void
77 sync() override;
78
79 void
80 sweep() override;
81
82private:
85 // This needs to be a recursive mutex because callbacks in `rotateWithLock`
86 // can call function that also lock the mutex. A current example of this is
87 // a callback from SHAMapStoreImp, which calls `clearCaches`. This
88 // `clearCaches` call eventually calls `fetchNodeObject` which tries to
89 // relock the mutex. It would be desirable to rewrite the code so the lock
90 // was not held during a callback.
92
95 uint256 const& hash,
97 FetchReport& fetchReport,
98 bool duplicate) override;
99
100 void
102};
103
104} // namespace NodeStore
105} // namespace ripple
106
107#endif
A generic endpoint for log messages.
Definition: Journal.h:59
std::int32_t getWriteLoad() const override
Retrieve the estimated number of pending write operations.
DatabaseRotatingImp(DatabaseRotatingImp const &)=delete
std::shared_ptr< Backend > archiveBackend_
std::shared_ptr< NodeObject > fetchNodeObject(uint256 const &hash, std::uint32_t, FetchReport &fetchReport, bool duplicate) override
void rotateWithLock(std::function< std::unique_ptr< NodeStore::Backend >(std::string const &writableBackendName)> const &f) override
Rotates the backends.
void store(NodeObjectType type, Blob &&data, uint256 const &hash, std::uint32_t) override
Store the object.
void importDatabase(Database &source) override
Import objects from another database.
std::string getName() const override
Retrieve the name associated with this backend.
void sweep() override
Remove expired entries from the positive and negative caches.
bool isSameDB(std::uint32_t, std::uint32_t) override
std::shared_ptr< Backend > writableBackend_
DatabaseRotatingImp & operator=(DatabaseRotatingImp const &)=delete
void for_each(std::function< void(std::shared_ptr< NodeObject >)> f) override
Visit every object in the database This is usually called during import.
Persistency layer for NodeObject.
Definition: Database.h:50
Scheduling for asynchronous backend activity.
Holds a collection of configuration values.
Definition: BasicConfig.h:46
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
NodeObjectType
The types of node objects.
Definition: NodeObject.h:32
Contains information about a fetch operation.