Jose Andrés Cordero created OAK-12557:
-----------------------------------------
Summary: Child nodes may become invisible to other cluster nodes
after a split of the parent, FullGC deletes them as orphans
Key: OAK-12557
URL: https://issues.apache.org/jira/browse/OAK-12557
Project: Jackrabbit Oak
Issue Type: Bug
Components: documentmk
Affects Versions: 2.8.0, 1.8.0
Reporter: Jose Andrés Cordero
Assignee: Jose Andrés Cordero
h3. Problem
A cluster node can compute a \{{lastRevision}} for a node that has no component
for another cluster node. Children and property values written by that other
cluster node then become invisible to the reader.
FullGC relies on this view:
* in orphan modes it deletes live child documents as orphans.
* in EMPTYPROPS modes it can remove live properties.
Embedded verification uses the same view and does not detect it.
This was observed in production. FullGC (\{{ALL_ORPHANS_EMPTYPROPS}}) deleted
three live Lucene segment documents of an async index
(\{{/oak:index/<index>/:data/_292j4.cfe|.cfs|.si}}) about one second after the
index's \{{:data}} document was split. The index could no longer be opened and
had to be reindexed.
h3. Conditions
# Cluster node A changes a node directly in almost every commit, for example
\{{:data}} of a Lucene index written by the async indexer. The commit root is a
different document, for example \{{/}} because \{{/:async}} is updated in the
same commit. The node has no \{{_lastRev}} entry for A.
# A commits once more and splits the document right after that. The split moves
all changes of A to a previous document, except the most recent one.
# Cluster node B reads the document before its background read refreshed its
cached commit root document, so it does not yet see the \{{_revisions}} entry
of A's most recent change. B is another cluster node or a read-only
DocumentNodeStore such as \{{oak-run revisions ... fullGC}}. The window is
short (up to \{{asyncDelay}}, about 1 s), but busy indexes split often.
h3. What goes wrong
* \{{NodeDocument.createLastRevs()}} skips changes whose commit value resolves
to \{{null}}. The only local change of A cannot be resolved by B, and the older
ones were split off, so \{{lastRevs}} has no entry for A.
* \{{getNodeAtRevision()}} returns a \{{DocumentNodeState}} whose
\{{lastRevision}} has no component for A.
* Children are read at the parent's \{{lastRevision}}.
\{{RevisionVector.isRevisionNewer()}} treats the missing component as newer, so
all children created by A are invisible (\{{getChildNode(name).exists() ==
false}}).
* \{{VersionGarbageCollector.FullGC.isDeletedOrOrphanedNode()}} only checks
\{{!traversedState.exists()}} and removes the live documents.
* Related symptom: \{{isMostRecentCommitted()}} ignores the newer change that
cannot be resolved, so \{{requiresCompleteMapCheck()}} does not look into
previous documents. B then returns an older local property value instead of the
newer one that was moved to the previous document.
h3. Example (production documents, reconstructed from the oplog)
{noformat}
3:/oak:index/ntBaseLucene-2/:data (written by cluster 3, no _lastRev)
07:41:17.268 cluster 3 commits r1a1c467764e-0-3 (dirListing), commit root "/"
07:41:17.276 "/" gets _revisions.r1a1c467764e-0-3 = c
07:41:17.414 split of :data by cluster 3: 28 cluster-3 _commitRoot entries
moved
to a previous document, only r1a1c467764e-0-3 is left for cluster
3
07:41:17.616 FullGC (read-only node store, "/" cached before 07:41:17.276):
lastRevision of :data has no entry for cluster 3
-> _292j4.cfe/.cfs/.si (created by cluster 3 at r1a1a1a432f0-0-3)
do not exist
-> <Collected> [...] orphaned node in mode
[ALL_ORPHANS_EMPTYPROPS]
07:41:18.788 the three documents are removed
{noformat}
Replaying exactly these documents with \{{oak-run revisions ... fullGC
--fullGcMode 4 --dryRun true}}:
* without the fix, the 3 documents are collected;
* with the fix, nothing is collected. The \{{lastRevision}} of \{{:data}} has
\{{readRevision[3]}} for cluster 3, and the segment exists.
h3. Relation to OAK-12531
This is the same family of problem: the per-cluster last revision is derived
from local \{{_commitRoot}} entries when \{{_lastRev}} is absent. OAK-12531
does not fix it:
* OAK-12531 keeps \{{_commitRoot}} entries that FullGC itself removes, in the
KEEP_ONE modes;
* here the entries were moved by a regular split, and the mode was
\{{ALL_ORPHANS_EMPTYPROPS}}.
The scenario is reproduced with OAK-12531 applied.
h3. Proposed fix
Both changes are in \{{NodeDocument}}:
* \{{createLastRevs()}}: if the most recent local change of *another* cluster
node cannot be resolved to a committed revision, use
\{{readRevision[clusterId]}} for that cluster node instead of dropping it.
** This is the same rule \{{getNodeAtRevision()}} already applies when a
\{{_lastRev}} is newer than the read revision.
** A higher \{{lastRevision}} (never higher than the read revision) is safe. It
only reduces node cache hits until the reader has caught up.
* \{{isMostRecentCommitted()}}: an unresolvable change of another cluster node
that is newer than the local value is treated as "may be committed", so the
existing complete map check consults previous documents.
A cluster node's own changes are excluded, because it always knows their commit
status. This keeps the behavior checked by
\{{DocumentNodeStoreTest.ignoreUncommitted}}.
The fix is enabled by default. The legacy behavior can be restored with:
* feature toggle \{{FT_LEGACY_UNRESOLVED_LAST_REV_OAK-XXXXX}}, registered by
\{{DocumentNodeStoreService}};
* system property \{{oak.documentMK.legacyUnresolvedLastRev=true}}, for oak-run
based tools that have no OSGi whiteboard.
h3. Tests
* \{{UnresolvedLastRevTest}}: child visibility and child names; the
\{{lastRevision}} fallback and its precise value again after catch-up; property
value read from the previous document; legacy behavior; runtime toggle; system
property.
* \{{FullGCUnresolvedLastRevTest}}: parameterized over all FullGC modes. A live
segment is not deleted and a live property is not removed. The legacy variants
reproduce the deletion (7 orphan modes) and the property removal (8 EMPTYPROPS
modes).
* \{{DocumentNodeStoreServiceTest.legacyUnresolvedLastRevToggle}}: the toggle
is registered, off by default, and switches the behavior.
Without the fix, 19 of the new tests fail. With the fix, the full
oak-store-document test suite passes.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)