diff --git a/gc/gc-base/src/main/java/org/projectnessie/gc/identify/IdentifyLiveContents.java b/gc/gc-base/src/main/java/org/projectnessie/gc/identify/IdentifyLiveContents.java index c36e6739a08..dd4889cce7e 100644 --- a/gc/gc-base/src/main/java/org/projectnessie/gc/identify/IdentifyLiveContents.java +++ b/gc/gc-base/src/main/java/org/projectnessie/gc/identify/IdentifyLiveContents.java @@ -15,6 +15,8 @@ */ package org.projectnessie.gc.identify; +import static java.lang.String.format; + import com.google.common.base.Preconditions; import com.google.errorprone.annotations.CanIgnoreReturnValue; import jakarta.annotation.Nullable; @@ -241,6 +243,7 @@ private ReferencesWalkResult identifyContentsForReference( LogEntryHolder holder = new LogEntryHolder(); String lastCommitId = null; + String finalCommitId = null; for (Spliterator spliterator = commits.spliterator(); spliterator.tryAdvance(holder::set); ) { @@ -308,33 +311,34 @@ private ReferencesWalkResult identifyContentsForReference( })); } else { // 1st non-live commit - try { - numContents += collectAllKeys(addContents, Detached.of(lastCommitId)); - } catch (NessieNotFoundException e) { - throw new RuntimeException(e); - } - LOGGER.info( - "live-set#{}: Finished walking the commit log of {} using {} after {} commits, " - + "commit {} is the first non-live commit.", - addContents.id(), - namedReference, - cutoffPolicy, - numCommits, - commitHash); - return ReferencesWalkResult.single(numCommits, numContents); + finalCommitId = commitHash; + break; } } + + // Always consider all content reachable from the last live commit. + if (lastCommitId != null) { + try { + numContents += collectAllKeys(addContents, Detached.of(lastCommitId)); + } catch (NessieNotFoundException e) { + throw new RuntimeException(e); + } + } + + LOGGER.info( + "live-set#{}: Finished walking the commit log of {} using {} after {} commits, {}", + addContents.id(), + namedReference, + cutoffPolicy, + numCommits, + finalCommitId != null + ? format("commit %s is the first non-live commit.", finalCommitId) + : "no more commits"); + return ReferencesWalkResult.single(numCommits, numContents); } catch (NessieNotFoundException e) { throw new RuntimeException( "GC-run#" + addContents.id() + ": Could not find reference " + namedReference, e); } - LOGGER.info( - "live-set#{}: Finished walking the commit log of {} using {} after {} commits, no more commits.", - addContents.id(), - namedReference, - cutoffPolicy, - numCommits); - return ReferencesWalkResult.single(numCommits, numContents); } @SuppressWarnings("resource")