[ 
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{}}}.

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.
 # 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.

  was:
{{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.


> 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{}}}.
> 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.
>  # 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.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to