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/CollectorManager.h>
23#include <xrpld/app/main/Tuning.h>
24#include <xrpld/shamap/NodeFamily.h>
25
26namespace ripple {
27
29 : app_(app)
30 , db_(app.getNodeStore())
31 , j_(app.journal("NodeFamily"))
32 , fbCache_(std::make_shared<FullBelowCache>(
33 "Node family full below cache",
34 stopwatch(),
35 app.journal("NodeFamilyFulLBelowCache"),
36 cm.collector(),
39 , tnCache_(std::make_shared<TreeNodeCache>(
40 "Node family tree node cache",
41 app.config().getValueFor(SizedItem::treeCacheSize),
42 std::chrono::seconds(
43 app.config().getValueFor(SizedItem::treeCacheAge)),
44 stopwatch(),
45 j_))
46{
47}
48
49void
51{
52 fbCache_->sweep();
53 tnCache_->sweep();
54}
55
56void
58{
59 {
61 maxSeq_ = 0;
62 }
63
64 fbCache_->reset();
65 tnCache_->reset();
66}
67
68void
70{
71 JLOG(j_.error()) << "Missing node in " << seq;
73 if (maxSeq_ == 0)
74 {
75 maxSeq_ = seq;
76
77 do
78 {
79 // Try to acquire the most recent missing ledger
80 seq = maxSeq_;
81
82 lock.unlock();
83
84 // This can invoke the missing node handler
86
87 lock.lock();
88 } while (maxSeq_ != seq);
89 }
90 else if (maxSeq_ < seq)
91 {
92 // We found a more recent ledger with a missing node
93 maxSeq_ = seq;
94 }
95}
96
97void
99{
100 if (hash.isNonZero())
101 {
102 JLOG(j_.error()) << "Missing node in " << to_string(hash);
103
106 }
107}
108
109} // 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:98
std::shared_ptr< TreeNodeCache > tnCache_
Definition NodeFamily.h:95
void sweep() override
void acquire(uint256 const &hash, std::uint32_t seq)
std::shared_ptr< FullBelowCache > fbCache_
Definition NodeFamily.h:94
beast::Journal const j_
Definition NodeFamily.h:92
Application & app_
Definition NodeFamily.h:90
std::mutex maxSeqMutex_
Definition NodeFamily.h:99
void reset() override
void missingNodeAcquireBySeq(std::uint32_t seq, uint256 const &hash) override
Acquire ledger that has a missing node by ledger sequence.
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:25
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.