Repository navigation
accounts-db: Split data file is optional - #15798
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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:
|
5fe1c31 to
4251d0d
Compare
| let path = match self { | ||
| Self::AppendVec(av) => av.path(), | ||
| Self::Split(split) => split.data_path(), | ||
| Self::Split(split) => split.data_path().unwrap_or_else(|| { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Cleanup PR is all ready to go: #15815
Can go further as preferred too.
4251d0d to
55b9589
Compare
|
Force pushed after rebasing to handle merge conflicts. No code was changed. |
| data_uid: data_header.uid, | ||
| }); | ||
| } | ||
| let (data_path, data_file, data_len) = if let Some(data) = data { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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!
(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.

This shows the number of split files with empty data files. The majority of split files have empty data files.

Here's the total number of bytes stored across all the meta files.

Here's the total number of bytes stored across all the data files.
