-
Notifications
You must be signed in to change notification settings - Fork 166
fix(gc): backfill new db records since snapshot epoch #5640
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
fix(gc): backfill new db records since snapshot epoch #5640
Conversation
if let Err(e) = db.put_many_keyed(mem_db) { | ||
tracing::warn!("{e}"); | ||
} | ||
tracing::info!( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sample log from my laptop on mainnet
:
2025-05-12T09:19:35.957856Z INFO forest::db::gc::snapshot: backfilled 57345 new db records since snapshot epoch, approximate heap size: 82.9 MiB, took 559ms 304us 167ns
…s-since-snapshot-epoch
61cc52d
to
e694b48
Compare
src/db/gc/snapshot.rs
Outdated
|
||
if let Err(e) = self.reboot_tx.send(()) { | ||
tracing::warn!("{e}"); | ||
} | ||
|
||
*self.memory_db_head_key.write() = db.heaviest_tipset_key().ok(); | ||
tokio::time::sleep(Duration::from_secs(1)).await; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why 1s? Why do we need to sleep
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was to ensure write_ops_rx
to be fully read but it was hacky. This commit refactors the logic and removes the sleep hack.
src/db/gc/snapshot.rs
Outdated
// Backfill new db records during snapshot export | ||
if let Ok(db) = open_db(self.db_root_dir.clone(), &self.db_config) { | ||
if let Some(mem_db) = self.memory_db.write().take() { | ||
let count = mem_db.len(); | ||
let approximate_heap_size = { | ||
let mut s = 0; | ||
for (_k, v) in mem_db.iter() { | ||
s += 64; | ||
s += v.len(); | ||
} | ||
s | ||
}; | ||
let start = Instant::now(); | ||
if let Err(e) = db.put_many_keyed(mem_db) { | ||
tracing::warn!("{e}"); | ||
} | ||
tracing::info!( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use more meaningful variable names. Especially the meaning of s
is not clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
src/db/gc/snapshot.rs
Outdated
let approximate_heap_size = { | ||
let mut s = 0; | ||
for (_k, v) in mem_db.iter() { | ||
s += 64; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is 64
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the size of Cid
pub type Cid = CidGeneric<64>;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, it's better to use std::mem::size_of::<Cid>()
src/db/gc/snapshot.rs
Outdated
blessed_lite_snapshot: RwLock<Option<PathBuf>>, | ||
db: RwLock<Option<Arc<DB>>>, | ||
// On mainnet, it takes ~50MiB-100MiB RAM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we can mention this in the gc guide also
…s-since-snapshot-epoch
…s-since-snapshot-epoch
Summary of changes
This PR patches the snapshot GC to avoid losing db records that are inserted during snapshot export
Changes introduced in this pull request:
Reference issue to close (if applicable)
Closes
Other information and links
Change checklist