20 #ifndef RIPPLE_SHAMAP_SHAMAP_H_INCLUDED
21 #define RIPPLE_SHAMAP_SHAMAP_H_INCLUDED
23 #include <ripple/basics/UnorderedContainers.h>
24 #include <ripple/beast/utility/Journal.h>
25 #include <ripple/nodestore/Database.h>
26 #include <ripple/nodestore/NodeObject.h>
27 #include <ripple/shamap/Family.h>
28 #include <ripple/shamap/FullBelowCache.h>
29 #include <ripple/shamap/SHAMapAddNode.h>
30 #include <ripple/shamap/SHAMapItem.h>
31 #include <ripple/shamap/SHAMapMissingNode.h>
32 #include <ripple/shamap/SHAMapNodeID.h>
33 #include <ripple/shamap/SHAMapSyncFilter.h>
34 #include <ripple/shamap/SHAMapTreeNode.h>
35 #include <ripple/shamap/TreeNodeCache.h>
36 #include <boost/thread/mutex.hpp>
37 #include <boost/thread/shared_lock_guard.hpp>
38 #include <boost/thread/shared_mutex.hpp>
248 Slice const& rootNode,
253 Slice const& rawNode,
295 dump(
bool withHashes =
false)
const;
343 template <
class Node>
348 template <
class Node>
363 int branch = 0)
const;
382 bool& pending)
const;
415 int& maxCount)
const;
573 : map_(map), item_(nullptr)
577 item_ = temp->peekItem().get();
581 : map_(map), item_(item)
589 : stack_(
std::move(stack)), map_(map), item_(item)
608 auto temp = map_->peekNextItem(item_->key(), stack_);
610 item_ = temp->peekItem().get();
637 inline SHAMap::const_iterator
SHAMap(SHAMap const &)=delete
SHAMapHash getHash() const
bool deepCompare(SHAMap &other) const
std::stack< StackEntry, std::deque< StackEntry > > stack_
bool hasInnerNode(SHAMapNodeID const &nodeID, SHAMapHash const &hash) const
Does this map have this inner node?
Family const & family() const
SHAMapTreeNode * findKey(uint256 const &id) const
Return nullptr if key not found.
void canonicalize(SHAMapHash const &hash, std::shared_ptr< SHAMapAbstractNode > &) const
An immutable linear range of bytes.
MissingNodes(int max, SHAMapSyncFilter *filter, int maxDefer, std::uint32_t generation)
void dump(bool withHashes=false) const
SHAMapAbstractNode * descendThrow(SHAMapInnerNode *, int branch) const
bool getNodeFat(SHAMapNodeID node, std::vector< SHAMapNodeID > &nodeIDs, std::vector< Blob > &rawNode, bool fatLeaves, std::uint32_t depth) const
SharedPtrNodeStack stack_
void getFetchPack(SHAMap const *have, bool includeLeaves, int max, std::function< void(SHAMapHash const &, const Blob &)>) const
NodeObjectType
The types of node objects.
void visitNodes(std::function< bool(SHAMapAbstractNode &)> const &function) const
Visit every node in this SHAMap.
std::uint32_t generation_
std::shared_ptr< SHAMapItem const > const & peekItem(uint256 const &id) const
std::map< uint256, DeltaItem > Delta
const_iterator begin() const
SHAMapSyncFilter * filter_
std::shared_ptr< SHAMap > snapShot(bool isMutable) const
value_type const * pointer
void gmn_ProcessNodes(MissingNodes &, MissingNodes::StackEntry &node)
std::shared_ptr< SHAMapAbstractNode > fetchNode(SHAMapHash const &hash) const
Dir::const_iterator const_iterator
pointer operator->() const
std::shared_ptr< SHAMapAbstractNode > fetchNodeNT(SHAMapHash const &hash) const
std::vector< uint256 > getNeededHashes(int max, SHAMapSyncFilter *filter)
bool operator==(Manifest const &lhs, Manifest const &rhs)
bool getRootNode(Serializer &s, SHANodeFormat format) const
SHAMapAbstractNode * descendAsync(SHAMapInnerNode *parent, int branch, SHAMapSyncFilter *filter, bool &pending) const
bool addGiveItem(std::shared_ptr< SHAMapItem const >, bool isTransaction, bool hasMeta)
std::shared_ptr< SHAMapItem const > const & onlyBelow(SHAMapAbstractNode *) const
If there is only one leaf below this node, get its contents.
std::map< SHAMapInnerNode *, SHAMapNodeID > resumes_
bool hasItem(uint256 const &id) const
friend bool operator==(const_iterator const &x, const_iterator const &y)
std::vector< std::tuple< SHAMapInnerNode *, SHAMapNodeID, int > > deferredReads_
bool hasLeafNode(uint256 const &tag, SHAMapHash const &hash) const
Does this map have this leaf node?
void visitDifferences(SHAMap const *have, std::function< bool(SHAMapAbstractNode &)>) const
Visit every node in this SHAMap that is not present in the specified SHAMap.
SHAMap & operator=(SHAMap const &)=delete
void visitLeaves(std::function< void(std::shared_ptr< SHAMapItem const > const &)> const &) const
Visit every leaf node in this SHAMap.
A SHAMap is both a radix tree with a fan-out of 16 and a Merkle tree.
const_iterator & operator++()
bool operator!=(Manifest const &lhs, Manifest const &rhs)
std::tuple< SHAMapInnerNode *, SHAMapNodeID, int, int, bool > StackEntry
std::shared_ptr< SHAMapAbstractNode > getCache(SHAMapHash const &hash) const
std::set< SHAMapHash > missingHashes_
A generic endpoint for log messages.
void setLedgerSeq(std::uint32_t lseq)
std::vector< std::pair< SHAMapNodeID, uint256 > > getMissingNodes(int maxNodes, SHAMapSyncFilter *filter)
Check for nodes in the SHAMap not available.
std::shared_ptr< SHAMapAbstractNode > fetchNodeFromDB(SHAMapHash const &hash) const
bool fetchRoot(SHAMapHash const &hash, SHAMapSyncFilter *filter)
void walkMap(std::vector< SHAMapMissingNode > &missingNodes, int maxMissing) const
const_iterator upper_bound(uint256 const &id) const
reference operator*() const
bool walkBranch(SHAMapAbstractNode *node, std::shared_ptr< SHAMapItem const > const &otherMapItem, bool isFirstMap, Delta &differences, int &maxCount) const
std::shared_ptr< SHAMapAbstractNode > checkFilter(SHAMapHash const &hash, SHAMapSyncFilter *filter) const
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
SHAMapAbstractNode * descend(SHAMapInnerNode *, int branch) const
std::shared_ptr< SHAMapAbstractNode > descendNoStore(std::shared_ptr< SHAMapInnerNode > const &, int branch) const
int flushDirty(NodeObjectType t, std::uint32_t seq)
Convert all modified nodes to shared nodes.
SHAMapTreeNode * firstBelow(std::shared_ptr< SHAMapAbstractNode >, SharedPtrNodeStack &stack, int branch=0) const
const_iterator end() const
std::shared_ptr< SHAMapAbstractNode > root_
bool compare(SHAMap const &otherMap, Delta &differences, int maxCount) const
bool addItem(SHAMapItem &&i, bool isTransaction, bool hasMeta)
SHAMapTreeNode * walkTowardsKey(uint256 const &id, SharedPtrNodeStack *stack=nullptr) const
Walk towards the specified id, returning the node.
void gmn_ProcessDeferredReads(MissingNodes &)
int walkSubTree(bool doWrite, NodeObjectType t, std::uint32_t seq)
SHAMapTreeNode const * peekFirstItem(SharedPtrNodeStack &stack) const
value_type const * pointer
void dirtyUp(SharedPtrNodeStack &stack, uint256 const &target, std::shared_ptr< SHAMapAbstractNode > terminal)
Update hashes up to the root.
std::shared_ptr< Node > preFlushNode(std::shared_ptr< Node > node) const
prepare a node to be modified before flushing
SHAMapAddNode addKnownNode(SHAMapNodeID const &nodeID, Slice const &rawNode, SHAMapSyncFilter *filter)
std::shared_ptr< Node > unshareNode(std::shared_ptr< Node >, SHAMapNodeID const &nodeID)
Unshare the node, allowing it to be modified.
MissingNodes & operator=(const MissingNodes &)=delete
bool updateGiveItem(std::shared_ptr< SHAMapItem const >, bool isTransaction, bool hasMeta)
SHAMapAddNode addRootNode(SHAMapHash const &hash, Slice const &rootNode, SHAMapSyncFilter *filter)
SHAMapTreeNode const * peekNextItem(uint256 const &id, SharedPtrNodeStack &stack) const
value_type const & reference
std::vector< std::pair< SHAMapNodeID, uint256 > > missingNodes_
bool delItem(uint256 const &id)
std::shared_ptr< SHAMapAbstractNode > writeNode(NodeObjectType t, std::uint32_t seq, std::shared_ptr< SHAMapAbstractNode > node) const
write and canonicalize modified node
value_type const & reference