Skip to content

Commit 8dc1910

Browse files
authored
Fix ref delete during ref expiration (#873)
1 parent 72a9b28 commit 8dc1910

File tree

2 files changed

+35
-34
lines changed

2 files changed

+35
-34
lines changed

icechunk/src/ops/gc.rs

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,9 @@ async fn gc_transaction_logs(
344344

345345
#[derive(Debug, PartialEq, Eq, Clone)]
346346
pub enum ExpireRefResult {
347-
NothingToDo,
347+
NothingToDo {
348+
ref_is_expired: bool,
349+
},
348350
Done {
349351
released_snapshots: HashSet<SnapshotId>,
350352
edited_snapshot: SnapshotId,
@@ -427,7 +429,7 @@ pub async fn expire_ref(
427429
{
428430
// Either the reference is the root, or it is pointing to the root as first parent
429431
// Nothing to do
430-
return Ok(ExpireRefResult::NothingToDo);
432+
return Ok(ExpireRefResult::NothingToDo { ref_is_expired });
431433
}
432434

433435
let root = asset_manager.fetch_snapshot(&root).await?;
@@ -501,44 +503,41 @@ pub async fn expire(
501503
}
502504
})
503505
.try_fold(ExpireResult::default(), |mut result, (r, ref_result)| async move {
504-
match ref_result {
506+
let ref_is_expired = match ref_result {
505507
ExpireRefResult::Done {
506508
released_snapshots,
507509
edited_snapshot,
508510
ref_is_expired,
509511
} => {
510512
result.released_snapshots.extend(released_snapshots.into_iter());
511513
result.edited_snapshots.insert(edited_snapshot);
512-
if ref_is_expired {
513-
match &r {
514-
Ref::Tag(name) => {
515-
if expired_tags == ExpiredRefAction::Delete {
516-
delete_tag(storage, storage_settings, name.as_str())
517-
.await
518-
.map_err(GCError::Ref)?;
519-
result.deleted_refs.insert(r);
520-
}
521-
}
522-
Ref::Branch(name) => {
523-
if expired_branches == ExpiredRefAction::Delete
524-
&& name != Ref::DEFAULT_BRANCH
525-
{
526-
delete_branch(
527-
storage,
528-
storage_settings,
529-
name.as_str(),
530-
)
531-
.await
532-
.map_err(GCError::Ref)?;
533-
result.deleted_refs.insert(r);
534-
}
535-
}
514+
ref_is_expired
515+
}
516+
ExpireRefResult::NothingToDo { ref_is_expired } => ref_is_expired,
517+
};
518+
if ref_is_expired {
519+
match &r {
520+
Ref::Tag(name) => {
521+
if expired_tags == ExpiredRefAction::Delete {
522+
delete_tag(storage, storage_settings, name.as_str())
523+
.await
524+
.map_err(GCError::Ref)?;
525+
result.deleted_refs.insert(r);
526+
}
527+
}
528+
Ref::Branch(name) => {
529+
if expired_branches == ExpiredRefAction::Delete
530+
&& name != Ref::DEFAULT_BRANCH
531+
{
532+
delete_branch(storage, storage_settings, name.as_str())
533+
.await
534+
.map_err(GCError::Ref)?;
535+
result.deleted_refs.insert(r);
536536
}
537537
}
538-
Ok(result)
539538
}
540-
ExpireRefResult::NothingToDo => Ok(result),
541539
}
540+
Ok(result)
542541
})
543542
.await
544543
}

icechunk/tests/test_gc.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ pub async fn test_expire_ref() -> Result<(), Box<dyn std::error::Error>> {
293293
)
294294
.await?
295295
{
296-
ExpireRefResult::NothingToDo => {
296+
ExpireRefResult::NothingToDo { .. } => {
297297
panic!()
298298
}
299299
ExpireRefResult::Done { released_snapshots, ref_is_expired, .. } => {
@@ -330,7 +330,7 @@ pub async fn test_expire_ref() -> Result<(), Box<dyn std::error::Error>> {
330330
)
331331
.await?
332332
{
333-
ExpireRefResult::NothingToDo => panic!(),
333+
ExpireRefResult::NothingToDo { .. } => panic!(),
334334
ExpireRefResult::Done { released_snapshots, ref_is_expired, .. } => {
335335
assert!(!ref_is_expired);
336336
assert_eq!(released_snapshots.len(), 4);
@@ -365,7 +365,7 @@ pub async fn test_expire_ref() -> Result<(), Box<dyn std::error::Error>> {
365365
)
366366
.await?
367367
{
368-
ExpireRefResult::NothingToDo => panic!(),
368+
ExpireRefResult::NothingToDo { .. } => panic!(),
369369
ExpireRefResult::Done { released_snapshots, ref_is_expired, .. } => {
370370
assert!(!ref_is_expired);
371371
assert_eq!(released_snapshots.len(), 5);
@@ -400,7 +400,7 @@ pub async fn test_expire_ref() -> Result<(), Box<dyn std::error::Error>> {
400400
)
401401
.await?
402402
{
403-
ExpireRefResult::NothingToDo => panic!(),
403+
ExpireRefResult::NothingToDo { .. } => panic!(),
404404
ExpireRefResult::Done { released_snapshots, ref_is_expired, .. } => {
405405
assert!(!ref_is_expired);
406406
assert_eq!(released_snapshots.len(), 5);
@@ -462,7 +462,9 @@ pub async fn test_expire_ref_with_odd_timestamps()
462462
)
463463
.await?
464464
{
465-
ExpireRefResult::NothingToDo => {}
465+
ExpireRefResult::NothingToDo { ref_is_expired } => {
466+
assert!(!ref_is_expired);
467+
}
466468
_ => panic!(),
467469
}
468470

0 commit comments

Comments
 (0)