[
https://issues.apache.org/jira/browse/OAK-12532?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18144055#comment-18144055
]
Rishabh Daim commented on OAK-12532:
------------------------------------
PR LGTM, I have merged it. [~mmatessi] thanks for your contribution.
> Revision GC never completes on MongoDB: MongoVersionGCSupport.identifyGarbage
> is exponential in number of sweep revisions
> -------------------------------------------------------------------------------------------------------------------------
>
> Key: OAK-12532
> URL: https://issues.apache.org/jira/browse/OAK-12532
> Project: Jackrabbit Oak
> Issue Type: Bug
> Components: documentmk, mongomk
> Affects Versions: 1.78.0, 2.8.0
> Reporter: Marco Matessi
> Assignee: Rishabh Daim
> Priority: Major
> Fix For: 2.10.0
>
>
> *Context.*
> Our application embeds Oak 2.8.0 (DocumentNodeStore on MongoDB, outside OSGi)
> and runs on Kubernetes. Since nothing schedules revision GC outside OSGi, it
> had never run; we introduced a daily maintenance job that runs blob GC
> (MarkSweepGarbageCollector) and then revision GC
> (VersionGarbageCollector.gc(24h)), guarded by a cluster-wide lock so that it
> runs on one instance at a time. Every new pod gets a new cluster id, so over
> months of deployments the root document accumulated 153 entries in _sweepRev
> (only 1 active cluster node).
> *Symptom.*
> On the first runs blob GC completed in a couple of minutes, but revision GC
> never did: runs were still going after 1h51m and 12h43m, one core at 100% and
> no Mongo activity, until a deployment restarted the process. Meanwhile the
> lock stayed held and other maintenance tasks failed.
> The "versionGC" settings document was never created, i.e. no iteration ever
> completed, although the repository is small (~64k documents, 1,063 split
> documents). The official oak-run 2.8.0 "revisions collect" on a copy of the
> database behaves the same: --timeLimit has no effect and SIGTERM does not
> stop it.
> Thread dumps always show 260+ nested LazyIteratorChain frames:
> {code:java}
> org.apache.commons.collections4.iterators.LazyIteratorChain.updateCurrentIterator(LazyIteratorChain.java:149)
> org.apache.commons.collections4.iterators.LazyIteratorChain.hasNext(LazyIteratorChain.java:84)
> org.apache.commons.collections4.iterators.LazyIteratorChain.hasNext(LazyIteratorChain.java:86)
> ... (262-267 nested LazyIteratorChain frames)
> org.apache.jackrabbit.oak.plugins.document.SplitDocumentCleanUp.disconnect(SplitDocumentCleanUp.java:62)
> org.apache.jackrabbit.oak.plugins.document.VersionGCSupport.deleteSplitDocuments(VersionGCSupport.java:165)
> org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector$GCJob.collectSplitDocuments(VersionGarbageCollector.java:1093)
> {code}
> *Cause.*
> Since OAK-11451 (Guava removal, 1.78.0; 1.76.0 is not affected),
> MongoVersionGCSupport.identifyGarbage() chains the results of its queries in
> a loop:
> {code:java}
> Iterable<NodeDocument> allResults = emptyList();
> for (Bson query : queries) {
> ...
> allResults = IterableUtils.chainedIterable(allResults, iterable);
> }
> {code}
> When DEFAULT_NO_BRANCH is collected, createQueries() returns one query per
> sweep revision entry plus one final query, so the chain is nested once per
> cluster id. Guava's Iterables.concat flattened nested concatenations;
> commons-collections4 LazyIteratorChain.hasNext() calls hasNext() twice on the
> nested iterator, so an element returned by the first queries costs ~2^(N+1)
> hasNext() calls (known issue COLLECTIONS-722). In this repository the
> DEFAULT_NO_BRANCH split documents belong to low cluster ids, i.e. to the most
> deeply nested queries.
> *Fix.*
> Collect the per-query iterables in a list and chain them once:
> {code:java}
> List<Iterable<NodeDocument>> results = new ArrayList<>(queries.size());
> for (Bson query : queries) {
> ...
> results.add(iterable);
> }
> return IterableUtils.chainedIterable(results);
> {code}
> *Verification.*
> * Patched oak-run 2.8.0, same command and data: GC completes in 4.1 s (local
> copy) / 4.0 min (original database, --delay 0.5) with splitDocGCCount=986,
> intermediateSplitDocGCCount=55; repository content verified unchanged.
> * Synthetic reproduction (MongoDB, N cluster ids each with a
> DEFAULT_NO_BRANCH split document):
> ||N||stock 2.8.0||patched||
> |20|0.58 s|< 0.5 s|
> |26|12.6 s|< 0.5 s|
> |28|50.3 s|< 0.5 s|
> |30|timeout (180 s)|< 0.5 s|
> |153|does not complete|1.4 s|
> * Regression test: MongoRevisionGCTest#identifyGarbageWithManySweepRevisions
> (40 sweep revisions, 1 DEFAULT_NO_BRANCH document) times out after 30 s
> without the fix and passes with it.
> No other occurrence of the "x = chainedIterable(x, ...)" pattern exists in
> the code base.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)