42 boost::intrusive_ptr<SHAMapItem const>
const& otherMapItem,
52 bool emptyBranch = !otherMapItem;
54 while (!nodeStack.
empty())
56 node = nodeStack.
top();
63 for (
int i = 0; i < 16; ++i)
64 if (!inner->isEmptyBranch(i))
72 if (emptyBranch || (item->key() != otherMapItem->key()))
85 else if (item->slice() != otherMapItem->slice())
90 item->key(),
DeltaRef(item, otherMapItem)));
93 item->key(),
DeltaRef(otherMapItem, item)));
113 otherMapItem->key(), DeltaRef(
nullptr, otherMapItem)));
116 otherMapItem->key(), DeltaRef(otherMapItem,
nullptr)));
126SHAMap::compare(
SHAMap const& otherMap,
Delta& differences,
int maxCount)
const
134 isValid() && otherMap.
isValid(),
135 "ripple::SHAMap::compare : valid state and valid input");
137 if (getHash() == otherMap.
getHash())
144 nodeStack.
push({root_.get(), otherMap.
root_.get()});
145 while (!nodeStack.
empty())
147 auto [ourNode, otherNode] = nodeStack.
top();
150 if (!ourNode || !otherNode)
152 UNREACHABLE(
"ripple::SHAMap::compare : missing a node");
153 Throw<SHAMapMissingNode>(type_,
uint256());
156 if (ourNode->isLeaf() && otherNode->isLeaf())
161 if (ours->peekItem()->key() == other->peekItem()->key())
163 if (ours->peekItem()->slice() != other->peekItem()->slice())
166 ours->peekItem()->key(),
167 DeltaRef(ours->peekItem(), other->peekItem())));
175 ours->peekItem()->key(),
176 DeltaRef(ours->peekItem(),
nullptr)));
181 other->peekItem()->key(),
182 DeltaRef(
nullptr, other->peekItem())));
187 else if (ourNode->isInner() && otherNode->isLeaf())
192 ours, other->peekItem(),
true, differences, maxCount))
195 else if (ourNode->isLeaf() && otherNode->isInner())
200 other, ours->peekItem(),
false, differences, maxCount))
203 else if (ourNode->isInner() && otherNode->isInner())
207 for (
int i = 0; i < 16; ++i)
208 if (ours->getChildHash(i) != other->getChildHash(i))
210 if (other->isEmptyBranch(i))
215 iNode,
nullptr,
true, differences, maxCount))
218 else if (ours->isEmptyBranch(i))
223 iNode,
nullptr,
false, differences, maxCount))
228 {descendThrow(ours, i),
233 UNREACHABLE(
"ripple::SHAMap::compare : invalid node");
243 if (!root_->isInner())
249 nodeStack.
push(intr_ptr::static_pointer_cast<SHAMapInnerNode>(root_));
251 while (!nodeStack.
empty())
256 for (
int i = 0; i < 16; ++i)
258 if (!node->isEmptyBranch(i))
261 descendNoStore(*node, i);
265 if (nextNode->isInner())
267 intr_ptr::static_pointer_cast<SHAMapInnerNode>(
272 missingNodes.
emplace_back(type_, node->getChildHash(i));
273 if (--maxMissing <= 0)
282SHAMap::walkMapParallel(
284 int maxMissing)
const
286 if (!root_->isInner())
292 auto const& innerRoot =
293 intr_ptr::static_pointer_cast<SHAMapInnerNode>(root_);
294 for (
int i = 0; i < 16; ++i)
296 if (!innerRoot->isEmptyBranch(i))
297 topChildren[i] = descendNoStore(*innerRoot, i);
311 for (
int rootChildIndex = 0; rootChildIndex < 16; ++rootChildIndex)
313 auto const& child = topChildren[rootChildIndex];
314 if (!child || !child->isInner())
317 nodeStacks[rootChildIndex].push(
318 intr_ptr::static_pointer_cast<SHAMapInnerNode>(child));
320 JLOG(journal_.debug()) <<
"starting worker " << rootChildIndex;
322 [&m, &missingNodes, &maxMissing, &exceptions,
this](
326 while (!nodeStack.empty())
328 intr_ptr::SharedPtr<SHAMapInnerNode> node =
329 std::move(nodeStack.top());
332 "ripple::SHAMap::walkMapParallel : non-null node");
335 for (int i = 0; i < 16; ++i)
337 if (node->isEmptyBranch(i))
339 intr_ptr::SharedPtr<SHAMapTreeNode> nextNode =
340 descendNoStore(*node, i);
344 if (nextNode->isInner())
346 intr_ptr::static_pointer_cast<
347 SHAMapInnerNode>(nextNode));
351 std::lock_guard l{m};
352 missingNodes.emplace_back(
353 type_, node->getChildHash(i));
354 if (--maxMissing <= 0)
366 std::move(nodeStacks[rootChildIndex])));
373 if (exceptions.empty())
376 ss <<
"Exception(s) in ledger load: ";
377 for (
auto const& e : exceptions)
378 ss << e.what() <<
", ";
379 JLOG(journal_.error()) << ss.
str();