Skip to content

Commit

Permalink
feat(gc): delete partial index
Browse files Browse the repository at this point in the history
  • Loading branch information
PhotonQuantum committed Feb 10, 2023
1 parent 3264655 commit 5edf51e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
4 changes: 4 additions & 0 deletions rsync-gc/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub async fn commit_gc(
conn: &mut (impl aio::ConnectionLike + Send),
namespace: &str,
index: &[u64],
delete_partial: bool,
) -> Result<()> {
let mut pipe = redis::pipe();
pipe.atomic();
Expand All @@ -71,6 +72,9 @@ pub async fn commit_gc(
for i in index {
pipe.del(format!("{namespace}:stale:{i}"));
}
if delete_partial {
pipe.del(format!("{namespace}:partial"));
}
pipe.del(format!("{namespace}:partial-stale"));

let result: Vec<bool> = pipe.query_async(conn).await?;
Expand Down
17 changes: 15 additions & 2 deletions rsync-gc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,24 @@ async fn main() -> Result<()> {
info!("deleted {} objects", deleted);

info!("deleting stale objects...");
let hashes = hashes_to_remove(&mut redis_conn, &redis_opts.namespace, &delete, &keep).await?;
let hashes = hashes_to_remove(
&mut redis_conn,
&redis_opts.namespace,
&delete,
&keep,
opts.delete_partial,
)
.await?;
bulk_delete_objs(&s3, &s3_opts, &hashes).await?;
info!("deleted {} objects", hashes.len());

commit_gc(&mut redis_conn, &redis_opts.namespace, &delete).await?;
commit_gc(
&mut redis_conn,
&redis_opts.namespace,
&delete,
opts.delete_partial,
)
.await?;

Ok(())
}
3 changes: 3 additions & 0 deletions rsync-gc/src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ pub struct Opts {
/// How many revisions to keep.
#[clap(short, long)]
pub keep: usize,
/// Whether to delete partial files.
#[clap(long, default_value = "false")]
pub delete_partial: bool,
/// S3 endpoint url.
/// For specifying authentication, use environment variables:
/// AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY
Expand Down
12 changes: 10 additions & 2 deletions rsync-gc/src/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::collections::HashSet;
use std::iter;

use eyre::Result;
use itertools::Either;
use redis::{aio, AsyncCommands};

use rsync_core::metadata::{MetaExtra, Metadata};
Expand All @@ -11,12 +12,19 @@ pub async fn hashes_to_remove(
namespace: &str,
stale_indices: &[u64],
alive_indices: &[u64],
delete_partial: bool,
) -> Result<HashSet<[u8; 20]>> {
// We also need to remove partial-stale index.
let stale_indices = stale_indices
.iter()
.map(|index| format!("{namespace}:stale:{index}"))
.chain(iter::once(format!("{namespace}:partial-stale")));
// We also need to remove partial-stale index.
.chain(iter::once(format!("{namespace}:partial-stale")))
// May need to delete partial.
.chain(if delete_partial {
Either::Left(iter::once(format!("{namespace}:partial")))
} else {
Either::Right(iter::empty())
});
let alive_indices = alive_indices
.iter()
.map(|index| format!("{namespace}:index:{index}"));
Expand Down

0 comments on commit 5edf51e

Please sign in to comment.