-
Notifications
You must be signed in to change notification settings - Fork 180
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
Gc tests #1585
Conversation
first batch is basic smoke tests
this adds 1000 files via download while gc is running at high frequency. 1/100 of these files are tagged, the others not. the tagged files should survive, the untagged files should be gone.
# Conflicts: # iroh/src/node.rs
@@ -251,7 +251,7 @@ pub trait Store: ReadableStore + PartialMap { | |||
/// | |||
/// Sweeping might take long, but it can safely be done in the background. | |||
fn gc_sweep(&self) -> LocalBoxStream<'_, GcSweepEvent> { | |||
let blobs = self.blobs(); | |||
let blobs = self.blobs().chain(self.partial_blobs()); |
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 an actual bug. I was not considering partial blogs for cleanup.
@@ -124,6 +130,18 @@ pub enum SetTagOption { | |||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] | |||
pub struct HashAndFormat(pub Hash, pub BlobFormat); | |||
|
|||
impl HashAndFormat { | |||
/// Create a new hash and format pair, using the default (raw) format. | |||
pub fn raw(hash: Hash) -> Self { |
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.
just for convenience
@@ -895,42 +895,65 @@ impl Store { | |||
Ok((tag, size)) | |||
} | |||
|
|||
fn import_bytes_sync(&self, data: Bytes, format: BlobFormat) -> io::Result<TempTag> { |
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.
Use finalize_import_sync from import_bytes_sync for DRY
// all writes here are protected by the temp tag | ||
let complete_io_guard = self.0.complete_io_mutex.lock().unwrap(); | ||
// move the data file into place, or create a reference to it | ||
let new = match file { |
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 a bug before. You must pass through the format.
if somebody adds a hashseq using import_stream or import_reader, the resulting temp tag must still be with format HashSeq.
let outboard_path = self.owned_outboard_path(&hash); | ||
std::fs::write(outboard_path, outboard)?; | ||
std::fs::rename(temp_outboard_path, outboard_path)?; |
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 a bug before. You must never write to the final outboard file. It can only come into existence by an atomic mv
. It would have been really hard to observe this though...
iroh/tests/gc.rs
Outdated
@@ -0,0 +1,440 @@ | |||
#![cfg(all(feature = "mem-db", feature = "iroh-collection"))] |
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 about also running the tests with the fs
db? Would probably be good to make sure deletions there work similarly good
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.
The "gc_flat_stress" and "gc_flat_partial" tests are using the flat file db.
The idea was to use a "perfect" db in the smoke tests to see if the gc_loop / driver is implemented correctly, and then use db specific tests like gc_flat_xxx to make sure that the db actually works.
I guess I can make the tests generic.
iroh/tests/gc.rs
Outdated
} | ||
|
||
async fn step() { | ||
tokio::time::sleep(Duration::from_millis(100)).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 not use tokios timer https://docs.rs/tokio/latest/tokio/time/fn.pause.html#auto-advance testing functionality, this actually worked quite well for me when testing other timer based behaviour?
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.
I hate it.
It depends on the notion that every single place in your code base and your dependencies that deals with time is using the tokio stuff, otherwise it will break in weird ways. Have a single place in your own code or your library code where you compute differences between SystemTime
, and it is going to fail. But not outright fail. Fail in a subtle way, or succeed where it should not succeed.
It's another of these attempts of the tokio people to make tokio the default stdlib of rust. Is Lennart Poettering of systemd a secret tokio contributor?
I had thought about having an event stream from the db that you could use to detect when a GC has been performed instead of a fixed delay. I did not do it bc I thought that would lock in the fact that we are using a certain GC method (mark and sweep). But I would prefer to do this over using that tokio stuff.
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.
Is Lennart Poettering of systemd a secret tokio contributor?
🤣
# Conflicts: # iroh-bytes/src/util.rs
Windows does not allow you to delete files when they are open. You don't get an error, deletion via remove_file just does nothing.
Description
Add a number of basic tests as well as a stress test to gc
Questions
I had some consistent windows failures on Friday. But now it seems to work on windows. Not sure what is going on - was windows CI just broken on Friday?
Missing (this or next PR):
Change checklist
Documentation updates if relevant.