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

Gc tests #1585

Merged
merged 12 commits into from
Oct 10, 2023
Merged

Gc tests #1585

merged 12 commits into from
Oct 10, 2023

Conversation

rklaehn
Copy link
Contributor

@rklaehn rklaehn commented Oct 6, 2023

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):

  • test that docs are protected
  • actually change gc default to enabled

Change checklist

  • Self-review.
  • Documentation updates if relevant.
  • Tests if relevant.

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.
@@ -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());
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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> {
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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.

@rklaehn rklaehn marked this pull request as ready for review October 9, 2023 12:17
@rklaehn rklaehn requested a review from Frando October 9, 2023 12:18
let outboard_path = self.owned_outboard_path(&hash);
std::fs::write(outboard_path, outboard)?;
std::fs::rename(temp_outboard_path, outboard_path)?;
Copy link
Contributor Author

@rklaehn rklaehn Oct 9, 2023

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...

@rklaehn rklaehn requested a review from dignifiedquire October 9, 2023 15:03
iroh/tests/gc.rs Outdated
@@ -0,0 +1,440 @@
#![cfg(all(feature = "mem-db", feature = "iroh-collection"))]
Copy link
Contributor

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

Copy link
Contributor Author

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;
Copy link
Contributor

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?

Copy link
Contributor Author

@rklaehn rklaehn Oct 10, 2023

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.

Copy link
Contributor

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.
@rklaehn rklaehn added this pull request to the merge queue Oct 10, 2023
Merged via the queue into main with commit 079bb9e Oct 10, 2023
15 checks passed
@rklaehn rklaehn deleted the gc-tests branch October 10, 2023 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants