Skip to content

refactor: Revert "perf: Remove unnecessary caches (#5439)"#7359

Open
bthomee wants to merge 3 commits into
developfrom
bthomee/caches2
Open

refactor: Revert "perf: Remove unnecessary caches (#5439)"#7359
bthomee wants to merge 3 commits into
developfrom
bthomee/caches2

Conversation

@bthomee
Copy link
Copy Markdown
Collaborator

@bthomee bthomee commented May 29, 2026

High Level Overview of Change

This change reverts #5439.

Context of Change

We have identified a potential regression introduced by #5439, whereby the data passed to the node store (bypassing the removed cache) in certain situations could be dropped without ever being written, in turn resulting in a SHAMapMissingNode error. Although this has not been definitely confirmed that this change actually causes the issue, it is very plausible - therefore the PR is being reverted out of an abundance of caution.

Copilot AI review requested due to automatic review settings May 29, 2026 16:08
@bthomee bthomee requested review from g-ripple and vlntb May 29, 2026 16:09
Copy link
Copy Markdown
Contributor

@xrplf-ai-reviewer xrplf-ai-reviewer Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc comment at line 963 misrepresents cache behaviour — see inline.

Review by Claude Opus 4.6 · Prompt: V15

Comment thread cfg/xrpld-example.cfg Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reverts the cache-removal work from #5439 by reintroducing NodeStore caching and related maintenance hooks, motivated by a suspected regression where node data could be dropped before being persisted (leading to SHAMapMissingNode).

Changes:

  • Reintroduces a TaggedCache inside DatabaseNodeImp (including negative-cache “Dummy” entries) and adds a Database::sweep() hook.
  • Wires cache sweeping into ApplicationImp::doSweep() and restores SHAMapStore’s interactions with NodeFamily caches during rotation/online-delete.
  • Documents new [node_db] cache settings and updates tests to supply defaults.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/xrpld/app/misc/SHAMapStoreImp.h Stores pointers to NodeFamily caches for reuse during online delete rotation.
src/xrpld/app/misc/SHAMapStoreImp.cpp Injects default NodeStore cache settings and uses cached pointers for cache maintenance.
src/xrpld/app/main/Application.cpp Adds NodeStore sweep call to periodic sweeping.
src/test/app/SHAMapStore_test.cpp Mirrors NodeStore config defaulting for rotating DB tests.
src/libxrpl/nodestore/DatabaseRotatingImp.cpp Implements sweep() (no-op) for rotating NodeStore.
src/libxrpl/nodestore/DatabaseNodeImp.cpp Restores cache use in store/fetch paths and adds sweep support.
include/xrpl/nodestore/detail/DatabaseRotatingImp.h Declares sweep() override for rotating DB implementation.
include/xrpl/nodestore/detail/DatabaseNodeImp.h Initializes optional TaggedCache from config and declares sweep().
include/xrpl/nodestore/Database.h Adds sweep() to the Database interface.
cfg/xrpld-example.cfg Documents cache_size / cache_age in [node_db].

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +41 to +49
if (cacheSize != 0 || cacheAge != 0)
{
cache_ = std::make_shared<TaggedCache<uint256, NodeObject>>(
"DatabaseNodeImp",
cacheSize.value_or(0),
std::chrono::minutes(cacheAge.value_or(0)),
stopwatch(),
j);
}
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vlntb I'll make this change - I don't think we should do a pure revert when there are clear issues that can be easily fixed.

Comment on lines +104 to +105
case Status::NotFound:
break;
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vlntb this seems like good feedback and worth implementing.

Also, how often would Status::Ok and nodeObject == nullptr (see the switch-case above)? I wonder if it even makes sense to keep the inserting of a dummy value there.

Comment on lines +169 to +182
// Provide default values.
if (!nscfg.exists("cache_size"))
{
nscfg.set(
"cache_size",
std::to_string(app_.config().getValueFor(SizedItem::TreeCacheSize, std::nullopt)));
}

if (!nscfg.exists("cache_age"))
{
nscfg.set(
"cache_age",
std::to_string(app_.config().getValueFor(SizedItem::TreeCacheAge, std::nullopt)));
}
Comment on lines +525 to +540
// Provide default values.
if (!nscfg.exists("cache_size"))
{
nscfg.set(
"cache_size",
std::to_string(
env.app().config().getValueFor(SizedItem::TreeCacheSize, std::nullopt)));
}

if (!nscfg.exists("cache_age"))
{
nscfg.set(
"cache_age",
std::to_string(
env.app().config().getValueFor(SizedItem::TreeCacheAge, std::nullopt)));
}
Comment thread cfg/xrpld-example.cfg Outdated
Comment thread include/xrpl/nodestore/Database.h
Comment thread src/xrpld/app/main/Application.cpp
Comment thread src/xrpld/app/misc/SHAMapStoreImp.h
@codecov
Copy link
Copy Markdown

codecov Bot commented May 29, 2026

Codecov Report

❌ Patch coverage is 63.88889% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.4%. Comparing base (2f3558c) to head (ff0c4f6).

Files with missing lines Patch % Lines
src/libxrpl/nodestore/DatabaseNodeImp.cpp 51.2% 21 Missing ⚠️
include/xrpl/nodestore/detail/DatabaseNodeImp.h 86.7% 2 Missing ⚠️
src/libxrpl/nodestore/DatabaseRotatingImp.cpp 0.0% 1 Missing ⚠️
src/xrpld/app/main/Application.cpp 0.0% 1 Missing ⚠️
src/xrpld/app/misc/SHAMapStoreImp.cpp 91.7% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           develop   #7359     +/-   ##
=========================================
- Coverage     82.4%   82.4%   -0.0%     
=========================================
  Files         1011    1011             
  Lines        76477   76530     +53     
  Branches      7322    7319      -3     
=========================================
+ Hits         63005   63037     +32     
- Misses       13472   13493     +21     
Files with missing lines Coverage Δ
include/xrpl/nodestore/Database.h 100.0% <ø> (ø)
...nclude/xrpl/nodestore/detail/DatabaseRotatingImp.h 66.7% <ø> (ø)
src/xrpld/app/misc/SHAMapStoreImp.h 96.2% <ø> (ø)
src/libxrpl/nodestore/DatabaseRotatingImp.cpp 63.5% <0.0%> (-0.8%) ⬇️
src/xrpld/app/main/Application.cpp 70.5% <0.0%> (-0.1%) ⬇️
src/xrpld/app/misc/SHAMapStoreImp.cpp 75.1% <91.7%> (+0.4%) ⬆️
include/xrpl/nodestore/detail/DatabaseNodeImp.h 78.4% <86.7%> (+5.7%) ⬆️
src/libxrpl/nodestore/DatabaseNodeImp.cpp 60.4% <51.2%> (+1.1%) ⬆️

... and 6 files with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@xrplf-ai-reviewer xrplf-ai-reviewer Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues.

Review by Claude Opus 4.6 · Prompt: V15

Copy link
Copy Markdown
Contributor

@vlntb vlntb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I compared the original PR with the reverted changes. Everything matches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants