Fix: clear difflayer cache when truncate not triggered #141
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR aims to fix a potential memory leak issue in nodebuffer.
Rationale
In #121 we introduced a potential memory leak risk. When the block height difference between stateid and truncate tail in the differlayer exceeds the limit size (90,000), we attempt to trigger a truncate. However, to prevent repeated deletions, we added a condition. If the condition is not met, we do not perform the truncate and return directly, waiting until the next trigger. Before returning, we forgot to clear the difflayer cache, which causes the difflayer to be unrecoverable, resulting in a memory leak. The diagram shows the monitoring of this part of the memory (pathdb_difflayer_hashcache_size).
The metric shows the memory usage of difflayer before and after enabling this fix.
Example
N/A
Changes