Skip to content

OAK-12249: lazy ES index provisioning — skip creation for empty reindex - #2955

Closed
bhabegger wants to merge 2 commits into
apache:trunkfrom
bhabegger:OAK-12249-lazy-provisioning
Closed

OAK-12249: lazy ES index provisioning — skip creation for empty reindex#2955
bhabegger wants to merge 2 commits into
apache:trunkfrom
bhabegger:OAK-12249-lazy-provisioning

Conversation

@bhabegger

@bhabegger bhabegger commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

See #3085 instead

Summary

  • Defers provisionIndex() from the ElasticIndexWriter constructor to the first updateDocument(), deleteDocumentTree(), or deleteDocument() call when both FT_OAK-12249 and FT_OAK-12248 are enabled
  • A reindex that produces zero documents never creates an Elasticsearch index or alias, eliminating the empty-index problem described in OAK-12249
  • ensureProvisioned() handles the incremental-write-after-empty-reindex case: if an alias does not exist when the first document arrives, it creates a new backing index with a fresh seed and points the alias at it

Dependency on OAK-12248

OAK-12248 (#2950, graceful 404 handling) has merged to trunk. This branch is rebased on top of it — the diff now shows only the OAK-12249 commits.

The runtime dependency remains: isLazyProvisioningActive() returns true only when both FT_OAK-12249 and FT_OAK-12248 are enabled. Enabling FT_OAK-12249 alone falls back to eager provisioning and logs a WARN.

Tests

Three new unit tests in ElasticIndexWriterTest:

  • lazyProvisioning_requiresGraceful404Toggle — asserts lazy provisioning is inactive when OAK-12248 toggle is off
  • emptyReindex_doesNotCreateEsIndex — verifies no ES index is created during construction when no documents are written
  • nonEmptyReindex_provisionsOnFirstDocument — verifies provisionIndex() is called on the first updateDocument() and not before

All 11 tests in ElasticIndexWriterTest pass; full oak-search-elastic suite (514 tests) passes.

Jira

https://issues.apache.org/jira/browse/OAK-12249

@bhabegger
bhabegger force-pushed the OAK-12249-lazy-provisioning branch from d61927f to 77817e0 Compare June 15, 2026 06:15
@bhabegger
bhabegger force-pushed the OAK-12249-lazy-provisioning branch 2 times, most recently from 4c36816 to 2fdbd8e Compare June 24, 2026 06:17
@bhabegger
bhabegger marked this pull request as ready for review June 24, 2026 06:22
bhabegger and others added 2 commits August 17, 2026 11:19
When FT_OAK-12249 and FT_OAK-12248 are both enabled, ElasticIndexWriter
defers provisionIndex() from the constructor to the first updateDocument()
or deleteDocuments() call. A reindex that produces zero documents never
creates an Elasticsearch index or alias, eliminating the empty-index
problem described in OAK-12249.

Deployment order is enforced at runtime: isLazyProvisioningActive() returns
true only when both toggles are on. Enabling FT_OAK-12249 alone logs a WARN
and falls back to eager provisioning, preventing 404 errors on query paths
that lack graceful 404 handling.

ensureProvisioned() handles the incremental-write-after-empty-reindex case:
if an alias does not exist when the first document arrives, it creates a new
backing index with a fresh seed and points the alias at it.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Rebased OAK-12249-lazy-provisioning onto trunk (was 77 commits behind);
OAK-12248 has since merged. The rebase surfaced two issues:

- FulltextIndexWriter.deleteDocuments(path) was split into
  deleteDocumentTree(path)/deleteDocument(path) by OAK-12244 after this
  branch was cut. LazyElasticIndexWriter now implements both, delegating
  to the real ElasticIndexWriter.
- OSGi baseline check requires explicit @Version bumps for the new/changed
  public API surface introduced by the OAK-12249 commit: elastic (2.5.0,
  minor), elastic.index (3.0.0, major — ElasticIndexWriterFactory.newInstance()
  return type changed), and elastic.query/elastic.util (2.4.1 — declaring
  an explicit version at all registers as a micro change against the
  previously-undeclared baseline).

Verified against a clean trunk checkout that neither issue exists upstream;
both are specific to this branch's diff. `mvn -pl oak-search-elastic install`
(compile + baseline) and the full test suite (514 tests) pass.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@bhabegger

Copy link
Copy Markdown
Contributor Author

Replaced by #3085

@bhabegger bhabegger closed this Aug 18, 2026
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