rippled
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 <ripple/app/ledger/LedgerMaster.h>
21 #include <ripple/app/main/Application.h>
22 #include <ripple/app/main/Tuning.h>
23 #include <ripple/shamap/NodeFamily.h>
24 #include <sstream>
25 
26 namespace 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 
49 void
51 {
52  fbCache_->sweep();
53  tnCache_->sweep();
54 }
55 
56 void
58 {
59  {
61  maxSeq_ = 0;
62  }
63 
64  fbCache_->reset();
65  tnCache_->reset();
66 }
67 
68 void
70 {
71  JLOG(j_.error()) << "Missing node in " << seq;
72  if (app_.config().reporting())
73  {
75  ss << "Node not read, likely a Cassandra error in ledger seq " << seq
76  << " object hash " << nodeHash;
77  Throw<std::runtime_error>(ss.str());
78  }
79 
81  if (maxSeq_ == 0)
82  {
83  maxSeq_ = seq;
84 
85  do
86  {
87  // Try to acquire the most recent missing ledger
88  seq = maxSeq_;
89 
90  lock.unlock();
91 
92  // This can invoke the missing node handler
94 
95  lock.lock();
96  } while (maxSeq_ != seq);
97  }
98  else if (maxSeq_ < seq)
99  {
100  // We found a more recent ledger with a missing node
101  maxSeq_ = seq;
102  }
103 }
104 
105 void
107 {
108  if (hash.isNonZero())
109  {
110  JLOG(j_.error()) << "Missing node in " << to_string(hash);
111 
113  hash, seq, InboundLedger::Reason::GENERIC);
114  }
115 }
116 
117 } // namespace ripple
ripple::Application
Definition: Application.h:115
ripple::NodeFamily::app_
Application & app_
Definition: NodeFamily.h:95
sstream
ripple::NodeFamily::sweep
void sweep() override
Definition: NodeFamily.cpp:50
ripple::TaggedCache
Map/cache combination.
Definition: Application.h:64
ripple::SizedItem
SizedItem
Definition: Config.h:48
ripple::base_uint::isNonZero
bool isNonZero() const
Definition: base_uint.h:537
ripple::detail::BasicFullBelowCache
Remembers which tree keys have all descendants resident.
Definition: FullBelowCache.h:38
ripple::InboundLedger::Reason::GENERIC
@ GENERIC
ripple::CollectorManager
Provides the beast::insight::Collector service.
Definition: CollectorManager.h:29
ripple::SizedItem::treeCacheAge
@ treeCacheAge
std::stringstream
STL class.
std::lock_guard
STL class.
ripple::stopwatch
Stopwatch & stopwatch()
Returns an instance of a wall clock.
Definition: chrono.h:88
ripple::fullBelowExpiration
constexpr std::chrono::seconds fullBelowExpiration
Definition: app/main/Tuning.h:26
ripple::NodeFamily::reset
void reset() override
Definition: NodeFamily.cpp:57
ripple::Application::getInboundLedgers
virtual InboundLedgers & getInboundLedgers()=0
ripple::base_uint< 256 >
ripple::Config::reporting
bool reporting() const
Definition: Config.h:337
ripple::Application::getLedgerMaster
virtual LedgerMaster & getLedgerMaster()=0
ripple::InboundLedgers::acquire
virtual std::shared_ptr< Ledger const > acquire(uint256 const &hash, std::uint32_t seq, InboundLedger::Reason)=0
ripple::NodeFamily::j_
const beast::Journal j_
Definition: NodeFamily.h:97
ripple::Application::config
virtual Config & config()=0
ripple::NodeFamily::maxSeq_
LedgerIndex maxSeq_
Definition: NodeFamily.h:103
std::unique_lock
STL class.
beast::Journal::error
Stream error() const
Definition: Journal.h:333
ripple::NodeFamily::acquire
void acquire(uint256 const &hash, std::uint32_t seq)
Definition: NodeFamily.cpp:106
ripple::NodeFamily::NodeFamily
NodeFamily()=delete
std::uint32_t
ripple::fullBelowTargetSize
constexpr std::size_t fullBelowTargetSize
Definition: app/main/Tuning.h:25
ripple::NodeFamily::maxSeqMutex_
std::mutex maxSeqMutex_
Definition: NodeFamily.h:104
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::SizedItem::treeCacheSize
@ treeCacheSize
ripple::NodeFamily::tnCache_
std::shared_ptr< TreeNodeCache > tnCache_
Definition: NodeFamily.h:100
std
STL namespace.
ripple::NodeFamily::missingNodeAcquireBySeq
void missingNodeAcquireBySeq(std::uint32_t seq, uint256 const &hash) override
Acquire ledger that has a missing node by ledger sequence.
Definition: NodeFamily.cpp:69
std::stringstream::str
T str(T... args)
ripple::to_string
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
Definition: app/misc/impl/Manifest.cpp:41
ripple::NodeFamily::fbCache_
std::shared_ptr< FullBelowCache > fbCache_
Definition: NodeFamily.h:99
ripple::LedgerMaster::getHashBySeq
uint256 getHashBySeq(std::uint32_t index)
Get a ledger's hash by sequence number using the cache.
Definition: LedgerMaster.cpp:1743