Skip to content

OAK-12244: fix cascade delete when node loses mixin indexability#2953

Open
bhabegger wants to merge 1 commit into
apache:OAK-12244from
bhabegger:issue/OAK-12244-cascade-fix
Open

OAK-12244: fix cascade delete when node loses mixin indexability#2953
bhabegger wants to merge 1 commit into
apache:OAK-12244from
bhabegger:issue/OAK-12244-cascade-fix

Conversation

@bhabegger

@bhabegger bhabegger commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

OAK-12244: fix mixin type changes not reflected in fulltext index

Root cause: when a node gains or loses a mixin type at runtime,
FulltextIndexEditor did not update the index because propertiesChanged
was never set — jcr:mixinTypes is not normally listed in a rule's
property definitions.

Fix: track wasIndexable (rule matched before) alongside isIndexable()
(rule matches after). In leave(), act on the indexing-rule transition:

  • !wasIndexable && isIndexable(): node gained a rule → addOrUpdate
  • wasIndexable && !isIndexable(): node lost a rule → deleteDocument

Split FulltextIndexWriter into two explicit operations:

  • deleteDocumentTree(path): node physically removed; cascade is correct
  • deleteDocument(path): node lost indexability at runtime; exact only

The original deleteDocuments used a PrefixQuery that cascaded to all
descendants; in the mixin-loss branch this was a bug — children carrying
their own mixin types were incorrectly evicted from the index.

Additional changes:

  • Snapshot FT_OAK_12244_DISABLE once per commit cycle in FulltextIndexEditorContext
    as typeChangeTrackingEnabled so enter() and leave() always agree
  • Skip getApplicableIndexingRule(before) on the hot path via hasNodeTypeChange
    guard when neither jcr:primaryType nor jcr:mixinTypes changed
  • Register FT_OAK_12244 toggle in ElasticIndexProviderService
  • Reuse CommitFailedException code 5 for the deleteDocument error path

Tests:

  • PropertyIndexCommonTest: end-to-end integration tests (all backends)
  • LuceneIndexEditor2Test: unit tests verifying writer.docs / writer.deletedPaths
  • Verified: 1245 tests, 0 failures in oak-lucene

@bhabegger bhabegger force-pushed the issue/OAK-12244-cascade-fix branch 3 times, most recently from 8d5336d to 47e6df3 Compare June 12, 2026 08:49
Root cause: when a node gains or loses a mixin type at runtime,
FulltextIndexEditor did not update the index because propertiesChanged
was never set — jcr:mixinTypes is not normally listed in a rule's
property definitions.

Fix: track wasIndexable (rule matched before) alongside isIndexable()
(rule matches after). In leave(), act on the indexing-rule transition:
- !wasIndexable && isIndexable(): node gained a rule → addOrUpdate
- wasIndexable && !isIndexable(): node lost a rule → deleteDocument

Split FulltextIndexWriter into two explicit operations:
- deleteDocumentTree(path): node physically removed; cascade is correct
- deleteDocument(path): node lost indexability at runtime; exact only

The original deleteDocuments used a PrefixQuery that cascaded to all
descendants; in the mixin-loss branch this was a bug — children carrying
their own mixin types were incorrectly evicted from the index.

Additional changes:
- Snapshot FT_OAK_12244_DISABLE once per commit cycle in FulltextIndexEditorContext
  as typeChangeTrackingEnabled so enter() and leave() always agree
- Skip getApplicableIndexingRule(before) on the hot path via hasNodeTypeChange
  guard when neither jcr:primaryType nor jcr:mixinTypes changed
- Register FT_OAK_12244 toggle in ElasticIndexProviderService
- Reuse CommitFailedException code 5 for the deleteDocument error path

Tests:
- PropertyIndexCommonTest: end-to-end integration tests (all backends)
- LuceneIndexEditor2Test: unit tests verifying writer.docs / writer.deletedPaths
- Verified: 1245 tests, 0 failures in oak-lucene
@bhabegger bhabegger force-pushed the issue/OAK-12244-cascade-fix branch from 47e6df3 to 61f3c61 Compare June 12, 2026 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant