rippled
Loading...
Searching...
No Matches
DatabaseCon.cpp
1#include <xrpl/basics/Log.h>
2#include <xrpl/basics/contract.h>
3#include <xrpl/rdb/DatabaseCon.h>
4#include <xrpl/rdb/SociDB.h>
5
6#include <boost/algorithm/string.hpp>
7#include <boost/format.hpp>
8
9#include <memory>
10#include <unordered_map>
11
12namespace xrpl {
13
15{
17 // Mutex protects the CheckpointersCollection
19 // Each checkpointer is given a unique id. All the checkpointers that are
20 // part of a DatabaseCon are part of this collection. When the DatabaseCon
21 // is destroyed, its checkpointer is removed from the collection
23
24public:
27 {
29 auto it = checkpointers_.find(id);
30 if (it != checkpointers_.end())
31 return it->second;
32 return {};
33 }
34
35 void
37 {
39 checkpointers_.erase(id);
40 }
41
43 create(std::shared_ptr<soci::session> const& session, JobQueue& jobQueue, Logs& logs)
44 {
46 auto const id = nextId_++;
47 auto const r = makeCheckpointer(id, session, jobQueue, logs);
48 checkpointers_[id] = r;
49 return r;
50 }
51};
52
54
60
62{
63 if (checkpointer_)
64 {
66
68 checkpointer_.reset();
69
70 // The references to our Checkpointer held by 'checkpointer_' and
71 // 'checkpointers' have been removed, so if the use count is nonzero, a
72 // checkpoint is currently in progress. Wait for it to end, otherwise
73 // creating a new DatabaseCon to the same database may fail due to the
74 // database being locked by our (now old) Checkpointer.
75 while (wk.use_count())
76 {
78 }
79 }
80}
81
83
84void
86{
87 if (!q)
88 Throw<std::logic_error>("No JobQueue");
90}
91
92} // namespace xrpl
void erase(std::uintptr_t id)
std::shared_ptr< Checkpointer > create(std::shared_ptr< soci::session > const &session, JobQueue &jobQueue, Logs &logs)
std::shared_ptr< Checkpointer > fromId(std::uintptr_t id)
std::unordered_map< std::uintptr_t, std::shared_ptr< Checkpointer > > checkpointers_
std::shared_ptr< soci::session > const session_
void setupCheckpointing(JobQueue *, Logs &)
std::shared_ptr< Checkpointer > checkpointer_
A pool of threads to perform work.
Definition JobQueue.h:37
Manages partitions for logging.
Definition Log.h:32
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
CheckpointersCollection checkpointers
std::shared_ptr< Checkpointer > makeCheckpointer(std::uintptr_t id, std::weak_ptr< soci::session >, JobQueue &, Logs &)
Returns a new checkpointer which makes checkpoints of a soci database every checkpointPageCount pages...
Definition SociDB.cpp:288
std::shared_ptr< Checkpointer > checkpointerFromId(std::uintptr_t id)
T sleep_for(T... args)
static std::unique_ptr< std::vector< std::string > const > globalPragma
Definition DatabaseCon.h:87
T use_count(T... args)