Skip to content

accounts-db: Split data file is optional - #15798

Merged
brooksprumo merged 1 commit into
anza-xyz:masterfrom
brooksprumo:split-file/optional-data
Oct 7, 2026
Merged

brooksprumo merged 1 commit into
anza-xyz:masterfrom
brooksprumo:split-file/optional-data

Conversation

@brooksprumo

@brooksprumo brooksprumo commented Oct 5, 2026 •

Copy link
Copy Markdown

Problem

When running a validator using SplitFile, I noticed that lots of storages have empty data files. These are just wasted file descriptors.

Here's my node running on mnb. There's over 300k SplitFiles with empty data files!

Screenshot 2026-10-05 at 4 51 34 PM

(The spike in the middle is during a full snapshot, which opens additional storage files.)

Summary of Changes

Allow the data file in SplitFile to be optional.

When constructing a new SplitFile, the data file will not be created immediately. Instead, it will be deferred until writing an account that has large enough data to require the data file.

Testing

Ran this on my dev box and confirmed no empty split data files were created.

additional stats

Here's stats from my dev box running this PR. Left most edge is right when the validator starts up.

This shows the trend of number of append vecs vs split files over time. A majority of storages are split files after a few hours of running.
Screenshot 2026-10-06 at 9 00 47 AM

This shows the number of split files with empty data files. The majority of split files have empty data files.
Screenshot 2026-10-06 at 9 00 53 AM

Here's the total number of bytes stored across all the meta files.
Screenshot 2026-10-06 at 9 01 00 AM

Here's the total number of bytes stored across all the data files.
Screenshot 2026-10-06 at 9 01 08 AM

@brooksprumo brooksprumo self-assigned this Oct 5, 2026
@codecov-commenter

codecov-commenter commented Oct 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.3%. Comparing base (b4d53f0) to head (55b9589).

Additional details and impacted files
@@           Coverage Diff            @@
##           master   #15798    +/-   ##
========================================
  Coverage    82.3%    82.3%            
========================================
  Files         938      938            
  Lines      374330   374511   +181     
========================================
+ Hits       308244   308534   +290     
+ Misses      66086    65977   -109     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@brooksprumo
brooksprumo marked this pull request as ready for review October 6, 2026 12:43
@brooksprumo
brooksprumo requested a review from a team as a code owner October 6, 2026 12:43
@brooksprumo
brooksprumo marked this pull request as draft October 6, 2026 12:43
@brooksprumo
brooksprumo force-pushed the split-file/optional-data branch from 5fe1c31 to 4251d0d Compare October 6, 2026 12:58
@brooksprumo
brooksprumo marked this pull request as ready for review October 6, 2026 13:20
@brooksprumo
brooksprumo requested a review from roryharr October 6, 2026 13:20
let path = match self {
Self::AppendVec(av) => av.path(),
Self::Split(split) => split.data_path(),
Self::Split(split) => split.data_path().unwrap_or_else(|| {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Btw: Not sure if you are aware/already plan on addressing:

Even if there is a data file here for split_files, it isn't used right now.

In general though, why can't this be an option?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Cleanup PR is all ready to go: #15815

Can go further as preferred too.

@brooksprumo
brooksprumo force-pushed the split-file/optional-data branch from 4251d0d to 55b9589 Compare October 7, 2026 02:47
@brooksprumo

Copy link
Copy Markdown
Author

Force pushed after rebasing to handle merge conflicts. No code was changed.

@brooksprumo
brooksprumo requested a review from roryharr October 7, 2026 02:48
data_uid: data_header.uid,
});
}
let (data_path, data_file, data_len) = if let Some(data) = data {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What are the trade-offs between OnceLock lazy file descriptor allocation vs always having a data file on writes and freeing when converting to read?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Creating a new data file, writing the header, then later having to delete the data file in case nothing actually needs it

  • there are potential failures/errors that happen at each of create/write/delete that need to be handled
  • perf is worse because creating file, writing file, and deleting file all hit filesystem

this was actually the impl I started with, but it didn't actually make the code much easier/nicer to work with.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

One related thought (and maybe it should just be a follow-up): Why not handle the read file the same as the write file then?
IE: Don't open the FD until its needed.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yeah, that's a fair question. I'd say we can do that. It'd be more symmetrical with the data file if we also do it with the meta file. And then new() likely becomes infallible, which is nice. And also new() doesn't allocate anything, more akin to a Vec::new().

On the flip side, I'm not sure when this would be beneficial though. If we're creating a storage, do we ever not write to it? By not creating the meta file in new(), it does make the rest of the code a little more complicated though.

The impl of write_accounts() will do the same/similar as the data_file. The other change is the rest of the API. Today we know there is always a meta file. Would we instead then need to return an Option around all the meta file stuff too? Or do we unwrap/expect? What about when opening an existing SplitFile (SplitFile::open())? Should meta be an Option? What if both meta and data are None? What is it even opening? We'd likely have to change the open() API, because a None meta and a Some data would need to be invalid.

I think the idea is interesting, but agree it probably should be more of a follow-up. I think there's a lot of API questions it opens up. The main goal I'd like to solve here in this PR is to not create empty data files.

@brooksprumo
brooksprumo requested a review from roryharr October 7, 2026 17:16
@brooksprumo
brooksprumo added this pull request to the merge queue Oct 7, 2026
Merged via the queue into anza-xyz:master with commit db548a3 Oct 7, 2026
50 checks passed
@brooksprumo
brooksprumo deleted the split-file/optional-data branch October 7, 2026 23:49
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