[
https://issues.apache.org/jira/browse/OAK-12408?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Shivam updated OAK-12408:
-------------------------
Description:
{{AbstractGarbageCollectionStrategy.cleanup(Context)}} can run without a
preceding local compaction (e.g. {{StandbyClientSync}} after sync,
{{{}FileStoreBackupImpl{}}}/{{{}FileStoreBackupRestoreMBean{}}}). In that case
it builds a placeholder via {{{}CompactionResult.skipped(...){}}}, whose
{{requiresGCJournalEntry()}} is hard-coded to {{{}false{}}}:
{code:java}
static CompactionResult skipped(...) {
return new CompactionResult(currentGeneration, gcCount) {
// requiresGCJournalEntry() not overridden -> always false
};
}
{code}
So {{GCJournal.persist(...)}} is never called for this path, even though the
reclaimer *is* actively removing segments from older generations. On a cold
standby, {{currentGeneration}} legitimately advances on every synced
generation, but {{gc.log}} stays frozen and keeps pointing at a stale,
already-superseded root.
h3. Impact
* Standby's own {{gc.log}} never gains new entries after boot, even though
sync + cleanup keep reclaiming segments from newer generations.
* After promoting the standby to primary, later compaction/cleanup cycles
trust this stale {{gc.log}} entry, and reads of already-reclaimed segments
throw {{{}SegmentNotFoundException{}}}.
* Same exposure via the always-registered {{FileStoreBackupRestoreMBean}} on
*any* live instance.
h3. Steps to reproduce
# Set up primary + cold standby.
# Run several rounds of content + online cleanup on primary so multiple
generations/gc.log entries exist.
# Let standby sync + auto-cleanup after each round.
# Standby's {{segmentstore/gc.log}} shows no new entries despite "cleanup
completed... space reclaimed" logs and on-disk generation clearly advancing.
# Promote standby to primary, keep running cleanup — eventually
{{SegmentNotFoundException}} on segments already reclaimed while {{gc.log}} was
frozen.
h3. Suggested fix
{code:java}
@Override
boolean requiresGCJournalEntry() {
return currentGeneration.isCompacted();
}
{code}
* {{GCJournal.persist}} already no-ops when the generation is unchanged, so
this can't cause duplicate/bloated entries.
* Fresh, never-compacted repos are unaffected ({{{}isCompacted(){}}} is false
at generation 0).
* {{{}succeeded(){}}}/{{{}aborted(){}}} paths untouched.
* Verified experimentally: previously 100%-reproducible SNFE after standby
promotion dropped to 0 occurrences across repeated cycles with this change, and
standby {{gc.log}} correctly advanced after every sync+cleanup round.
was:
{{DefaultCleanupContext.isDanglingFutureSegment}} detects unused
(aborted-compaction) segments by
scan position: during cleanup, TAR entries are marked newest-first and every
compacted segment is
treated as reclaimable until the last compacted root recorded in {{gc.log}} is
reached (the
{{aheadOfRoot}} flag). This assumes segments are physically laid out in
compaction write order
(the compacted root written last).
That assumption does not hold for a segment store assembled out of compaction
order — e.g. a cold
standby, whose segments are written via {{FileStore.writeSegment}} in
sync-arrival order. There the
recorded compacted root is not the newest segment, so the reverse scan reaches
live, head-referenced
compacted segments while {{aheadOfRoot}} is still true and marks them
reclaimable. Online revision
cleanup then removes referenced segments, and a subsequent read/compaction
fails with
{{SegmentNotFoundException}}.
h4. Steps to reproduce
# Promote a cold standby to primary (its segment store was assembled via
standby sync).
# Run online (full) revision cleanup.
Cleanup removes still-referenced compacted segments; the following compaction
throws
{{SegmentNotFoundException}} while traversing the head. {{oak-run check}}
passes immediately before
cleanup.
h4. Suggested fix
Make the dangling-segment test generation-based rather than positional: treat a
compacted segment as
an unused future segment only if its generation is strictly newer than the head
generation. This is
independent of physical segment write order and consistent for all store types.
> Standalone cleanup() never journals gc.log leading to SNFE on cold standby /
> backup
> -----------------------------------------------------------------------------------
>
> Key: OAK-12408
> URL: https://issues.apache.org/jira/browse/OAK-12408
> Project: Jackrabbit Oak
> Issue Type: Bug
> Components: segment-tar
> Affects Versions: 2.6.0
> Reporter: Shivam
> Assignee: Rishabh Daim
> Priority: Critical
>
> {{AbstractGarbageCollectionStrategy.cleanup(Context)}} can run without a
> preceding local compaction (e.g. {{StandbyClientSync}} after sync,
> {{{}FileStoreBackupImpl{}}}/{{{}FileStoreBackupRestoreMBean{}}}). In that
> case it builds a placeholder via {{{}CompactionResult.skipped(...){}}}, whose
> {{requiresGCJournalEntry()}} is hard-coded to {{{}false{}}}:
> {code:java}
> static CompactionResult skipped(...) {
> return new CompactionResult(currentGeneration, gcCount) {
> // requiresGCJournalEntry() not overridden -> always false
> };
> }
> {code}
> So {{GCJournal.persist(...)}} is never called for this path, even though the
> reclaimer *is* actively removing segments from older generations. On a cold
> standby, {{currentGeneration}} legitimately advances on every synced
> generation, but {{gc.log}} stays frozen and keeps pointing at a stale,
> already-superseded root.
> h3. Impact
> * Standby's own {{gc.log}} never gains new entries after boot, even though
> sync + cleanup keep reclaiming segments from newer generations.
> * After promoting the standby to primary, later compaction/cleanup cycles
> trust this stale {{gc.log}} entry, and reads of already-reclaimed segments
> throw {{{}SegmentNotFoundException{}}}.
> * Same exposure via the always-registered {{FileStoreBackupRestoreMBean}} on
> *any* live instance.
> h3. Steps to reproduce
> # Set up primary + cold standby.
> # Run several rounds of content + online cleanup on primary so multiple
> generations/gc.log entries exist.
> # Let standby sync + auto-cleanup after each round.
> # Standby's {{segmentstore/gc.log}} shows no new entries despite "cleanup
> completed... space reclaimed" logs and on-disk generation clearly advancing.
> # Promote standby to primary, keep running cleanup — eventually
> {{SegmentNotFoundException}} on segments already reclaimed while {{gc.log}}
> was frozen.
> h3. Suggested fix
> {code:java}
> @Override
> boolean requiresGCJournalEntry() {
> return currentGeneration.isCompacted();
> }
> {code}
> * {{GCJournal.persist}} already no-ops when the generation is unchanged, so
> this can't cause duplicate/bloated entries.
> * Fresh, never-compacted repos are unaffected ({{{}isCompacted(){}}} is
> false at generation 0).
> * {{{}succeeded(){}}}/{{{}aborted(){}}} paths untouched.
> * Verified experimentally: previously 100%-reproducible SNFE after standby
> promotion dropped to 0 occurrences across repeated cycles with this change,
> and standby {{gc.log}} correctly advanced after every sync+cleanup round.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)