-
Notifications
You must be signed in to change notification settings - Fork 14
feat: Pluggable gc with exemptions #17
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
048538f
Add garbage collection to blobs
rklaehn 627b1db
rustls cargo deny fix
rklaehn cdec081
codespell
rklaehn bf66e58
Merge branch 'main' into pluggable-gc-with-exemptions
rklaehn 08cc840
Add some very basic gc tests
rklaehn e7943c2
Update tests/blobs.rs
rklaehn ca2b9a0
fix weird compile error - probably due to merge conflict
rklaehn 715d668
fix blobs test
rklaehn 24a1172
Merge branch 'main' into pluggable-gc-with-exemptions
rklaehn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#![cfg(feature = "net_protocol")] | ||
use std::{ | ||
sync::{Arc, Mutex}, | ||
time::Duration, | ||
}; | ||
|
||
use iroh_blobs::{net_protocol::Blobs, store::GcConfig, util::local_pool::LocalPool, Hash}; | ||
use iroh_net::Endpoint; | ||
use testresult::TestResult; | ||
|
||
#[tokio::test] | ||
async fn blobs_gc_smoke() -> TestResult<()> { | ||
let pool = LocalPool::default(); | ||
let endpoint = Endpoint::builder().bind().await?; | ||
let blobs = Blobs::memory().build(pool.handle(), &endpoint); | ||
let client = blobs.clone().client(); | ||
blobs.start_gc(GcConfig { | ||
period: Duration::from_millis(1), | ||
done_callback: None, | ||
})?; | ||
let h1 = client.add_bytes(b"test".to_vec()).await?; | ||
tokio::time::sleep(Duration::from_millis(100)).await; | ||
assert!(client.has(h1.hash).await?); | ||
client.tags().delete(h1.tag).await?; | ||
tokio::time::sleep(Duration::from_millis(100)).await; | ||
assert!(!client.has(h1.hash).await?); | ||
Ok(()) | ||
} | ||
|
||
#[tokio::test] | ||
async fn blobs_gc_protected() -> TestResult<()> { | ||
let pool = LocalPool::default(); | ||
let endpoint = Endpoint::builder().bind().await?; | ||
let blobs = Blobs::memory().build(pool.handle(), &endpoint); | ||
let client: iroh_blobs::rpc::client::blobs::Client< | ||
quic_rpc::transport::flume::FlumeConnector< | ||
iroh_blobs::rpc::proto::Response, | ||
iroh_blobs::rpc::proto::Request, | ||
>, | ||
> = blobs.clone().client(); | ||
let h1 = client.add_bytes(b"test".to_vec()).await?; | ||
let protected: Arc<Mutex<Vec<Hash>>> = Arc::new(Mutex::new(Vec::new())); | ||
let protected2 = protected.clone(); | ||
blobs.add_protected(Box::new(move |x| { | ||
let protected = protected2.clone(); | ||
Box::pin(async move { | ||
let protected = protected.lock().unwrap(); | ||
for h in protected.as_slice() { | ||
x.insert(*h); | ||
} | ||
}) | ||
}))?; | ||
blobs.start_gc(GcConfig { | ||
period: Duration::from_millis(1), | ||
done_callback: None, | ||
})?; | ||
tokio::time::sleep(Duration::from_millis(100)).await; | ||
// protected from gc due to tag | ||
assert!(client.has(h1.hash).await?); | ||
client.tags().delete(h1.tag).await?; | ||
protected.lock().unwrap().push(h1.hash); | ||
tokio::time::sleep(Duration::from_millis(100)).await; | ||
// protected from gc due to being in protected set | ||
assert!(client.has(h1.hash).await?); | ||
protected.lock().unwrap().clear(); | ||
tokio::time::sleep(Duration::from_millis(100)).await; | ||
// not protected, must be gone | ||
assert!(!client.has(h1.hash).await?); | ||
Ok(()) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.