rippled
Loading...
Searching...
No Matches
NodeFamily.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2020 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#include <xrpld/app/ledger/LedgerMaster.h>
21#include <xrpld/app/main/Application.h>
22#include <xrpld/app/main/Tuning.h>
23#include <xrpld/shamap/NodeFamily.h>
24
25#include <xrpl/basics/TaggedCache.ipp>
26
27namespace ripple {
28
30 : app_(app)
31 , db_(app.getNodeStore())
32 , j_(app.journal("NodeFamily"))
33 , fbCache_(std::make_shared<FullBelowCache>(
34 "Node family full below cache",
35 stopwatch(),
36 app.journal("NodeFamilyFulLBelowCache"),
37 cm.collector(),
40 , tnCache_(std::make_shared<TreeNodeCache>(
41 "Node family tree node cache",
42 app.config().getValueFor(SizedItem::treeCacheSize),
43 std::chrono::seconds(
44 app.config().getValueFor(SizedItem::treeCacheAge)),
45 stopwatch(),
46 j_))
47{
48}
49
50void
52{
53 fbCache_->sweep();
54 tnCache_->sweep();
55}
56
57void
59{
60 {
62 maxSeq_ = 0;
63 }
64
65 fbCache_->reset();
66 tnCache_->reset();
67}
68
69void
71{
72 JLOG(j_.error()) << "Missing node in " << seq;
74 if (maxSeq_ == 0)
75 {
76 maxSeq_ = seq;
77
78 do
79 {
80 // Try to acquire the most recent missing ledger
81 seq = maxSeq_;
82
83 lock.unlock();
84
85 // This can invoke the missing node handler
87
88 lock.lock();
89 } while (maxSeq_ != seq);
90 }
91 else if (maxSeq_ < seq)
92 {
93 // We found a more recent ledger with a missing node
94 maxSeq_ = seq;
95 }
96}
97
98void
100{
101 if (hash.isNonZero())
102 {
103 JLOG(j_.error()) << "Missing node in " << to_string(hash);
104
107 }
108}
109
110} // namespace ripple
Stream error() const
Definition: Journal.h:346
virtual InboundLedgers & getInboundLedgers()=0
virtual LedgerMaster & getLedgerMaster()=0
Provides the beast::insight::Collector service.
virtual std::shared_ptr< Ledger const > acquire(uint256 const &hash, std::uint32_t seq, InboundLedger::Reason)=0
uint256 getHashBySeq(std::uint32_t index)
Get a ledger's hash by sequence number using the cache.
LedgerIndex maxSeq_
Definition: NodeFamily.h:99
std::shared_ptr< TreeNodeCache > tnCache_
Definition: NodeFamily.h:96
void sweep() override
Definition: NodeFamily.cpp:51
void acquire(uint256 const &hash, std::uint32_t seq)
Definition: NodeFamily.cpp:99
std::shared_ptr< FullBelowCache > fbCache_
Definition: NodeFamily.h:95
beast::Journal const j_
Definition: NodeFamily.h:93
Application & app_
Definition: NodeFamily.h:91
std::mutex maxSeqMutex_
Definition: NodeFamily.h:100
void reset() override
Definition: NodeFamily.cpp:58
void missingNodeAcquireBySeq(std::uint32_t seq, uint256 const &hash) override
Acquire ledger that has a missing node by ledger sequence.
Definition: NodeFamily.cpp:70
Map/cache combination.
Definition: TaggedCache.h:62
bool isNonZero() const
Definition: base_uint.h:545
Remembers which tree keys have all descendants resident.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
SizedItem
Definition: Config.h:44
constexpr std::chrono::seconds fullBelowExpiration
Stopwatch & stopwatch()
Returns an instance of a wall clock.
Definition: chrono.h:119
std::string to_string(base_uint< Bits, Tag > const &a)
Definition: base_uint.h:630
constexpr std::size_t fullBelowTargetSize
STL namespace.
Set the sequence number on a JTx.
Definition: seq.h:34