[ 
https://issues.apache.org/jira/browse/OAK-12357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18136395#comment-18136395
 ] 

Julian Sedding commented on OAK-12357:
--------------------------------------

I discovered that this is not only an efficiency issue. It can also affect 
correctness.

When checkpoints are present and the non-empty "before" and "onto" states 
contain different content, {{CheckpointCompactor}} can incorrectly restore 
content from "before" and discard content from "onto". After processing the 
first checkpoint, it uses the "compacted" result as the diff base for the next 
checkpoint rather than the previous uncompacted checkpoint root.

E.g. assuming two distinct FileStores
 * A source store containing the {{before}} and {{after}} states.
 * A target store containing the {{onto}} state, into which the compacted 
result is written.

Initially, the states contain:
{noformat}
Source: before                 Target: onto
/                              /
├── unchanged                  └── parent
└── parent                         └── child-onto
    └── child-before
{noformat}
A first checkpoint in the source store contains the same state as the 
{{before}} state. It then adds {{parent/child-after}} and creates a second 
checkpoint. The final {{after}} state has the same content as the second 
checkpoint:
{noformat}
Source: checkpoint 1           Source: checkpoint 2 and after
/                              /
├── unchanged                  ├── unchanged
└── parent                     └── parent
    └── child-before               ├── child-before
                                   └── child-after
{noformat}
Compaction applies the changes between {{before}} and {{after}} onto the target 
state. Since {{child-before}} and {{unchanged}} already existed in {{before}} 
and were not changed, they must not be copied into the target. Conversely, 
{{child-onto}} must survive, and the newly added {{child-after}} must be 
included.

The expected compacted content is:
{noformat}
Compacted checkpoint 1        Compacted checkpoint 2 and final root
/                              /
└── parent                     └── parent
    └── child-onto                 ├── child-onto
                                   └── child-after
{noformat}
The faulty implementation uses the compacted first checkpoint as the diff base 
for the second checkpoint. Because that compacted state contains {{child-onto}} 
instead of {{child-before}}, the next diff incorrectly removes {{child-onto}} 
and restores {{child-before}}, thus causing content corruption.

>  CheckpointCompactor: concurrent checkpoints make compaction retry cycles 
> re-traverse the whole repository
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: OAK-12357
>                 URL: https://issues.apache.org/jira/browse/OAK-12357
>             Project: Jackrabbit Oak
>          Issue Type: Bug
>          Components: segment-tar
>    Affects Versions: 2.4.0
>            Reporter: Miroslav Smiljanic
>            Assignee: Miroslav Smiljanic
>            Priority: Major
>
> When new checkpoints are created while compaction runs (async indexing does 
> this constantly), the CheckpointCompactor's retry cycles diff the current 
> repository against the previously *compacted* state. That compacted state is 
> in a different GC generation, and since Oak decides what changed by comparing 
> record ids, nothing matches across generations - so the diff re-reads and 
> re-writes the whole tree every cycle, no matter how little actually changed. 
> On large repositories the retry cycles never catch up, the forced final step 
> times out, nothing is reclaimed, and the segment store keeps growing.
> The fix diffs each retry cycle against the previous *uncompacted* root 
> instead, which is in the same generation as the live state, so record ids 
> match and only the real changes are processed; the compacted result is still 
> used, but only as the state the changes are applied onto (as the legacy 
> compactor already does). This is a follow-up to OAK-12134, which fixed the 
> same checkpoint-triggered problem for the first state processed but left the 
> retry cycles diffing against the compacted state. New tests change a few 
> children under a wide node and verify a retry compacts only those, not the 
> whole tree.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to