Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BucketListDB in-memory Buckets #4630

Merged
merged 4 commits into from
Feb 1, 2025
Merged

Conversation

SirTyson
Copy link
Contributor

Description

Partially resolves #3696

This change refactors the BucketIndex parts of BucketListDB to be more friendly towards the Hot Archive BucketList. This includes cleanups to metrics, which previously only tracked metrics for the main thread access of the BucketList. Now, both BucketList types and background threads record metrics properly.

Additionally, this change removes the IndividualIndex and instead caches small Buckets entirely in-memory so we never read from disk. RangeIndex is largely unchanged but has been renamed to DiskIndex.

A follow up PR will add a random eviction cache to the DiskIndex. I tried to break this up as much as possible, but it was easiest to do the refactor + in-memory buckets at the same time so I didn't have to refactor IndividualIndex.

The BUCKETLIST_DB_INDEX_CUTOFF config setting determines the maximum size at which we keep bucket in-memory. I've set this to 250 MB, which is approximately the first 4-5 levels of the BucketList. This increases total memory consumption of stellar-core from 2.2 GB to 3 GB. This seems reasonable, and we could probably go even higher, but I'm holding off for now as the random eviction cache will further increase memory requirements.

Checklist

  • Reviewed the contributing document
  • Rebased on top of master (no merge commits)
  • Ran clang-format v8.0.0 (via make format or the Visual Studio extension)
  • Compiles
  • Ran all tests
  • If change impacts performance, include supporting evidence per the performance document

@SirTyson SirTyson added this pull request to the merge queue Jan 31, 2025
@SirTyson SirTyson removed this pull request from the merge queue due to a manual request Jan 31, 2025
@SirTyson SirTyson enabled auto-merge January 31, 2025 22:17
@SirTyson SirTyson added this pull request to the merge queue Jan 31, 2025
Merged via the queue into stellar:master with commit 96a822e Feb 1, 2025
13 checks passed
@SirTyson SirTyson deleted the bl-cache-2 branch February 1, 2025 00:58
github-merge-queue bot pushed a commit that referenced this pull request Feb 13, 2025
# Description

Resolves #4633

This PR indexes bucket files during `VerifyBucketsWork`. Previously we
would download Buckets, iterate all the buckets to check their hash,
then iterate through all the buckets again to index them. Since startup
is primarily disk bound, iterating through the entire BucketList twice
is expensive. This change does the hash verification and indexing step
in the same pass so we only have to read the BucketList once.

This introduces no new DOS vectors. Indexing unverified buckets could
lead to an OOM based DOS attack, where a malicious History Archive
provider hosts malicious buckets that are very large. However, such OOM
attacks are already possible via a zip bomb, and History Archive
providers are fairly trusted, so this is not a significant concern. To
mitigate this I've added an INFO level log message saying what history
archive a given file is being downloaded from. In the event of a DOS
attack, these logs would give us enough info to quickly assign blame to
the attacker and remove them from quorum sets.

On my laptop, this decreases startup time from `new-db` by about 16%.

Rebased on top of #4630.

# Checklist
- [x] Reviewed the
[contributing](https://github.com/stellar/stellar-core/blob/master/CONTRIBUTING.md#submitting-changes)
document
- [x] Rebased on top of master (no merge commits)
- [x] Ran `clang-format` v8.0.0 (via `make format` or the Visual Studio
extension)
- [x] Compiles
- [x] Ran all tests
- [ ] If change impacts performance, include supporting evidence per the
[performance
document](https://github.com/stellar/stellar-core/blob/master/performance-eval/performance-eval.md)
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.

Add persistent cache to BucketListDB
2 participants