Skip to content

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

Merged
fabriziofortino merged 1 commit into
apache:trunkfrom
oak-indexing:OAK-12249-lazy-provisioning
Sep 1, 2026
Merged

OAK-12249: lazy ES index provisioning — skip creation for empty reindex#3085
fabriziofortino merged 1 commit into
apache:trunkfrom
oak-indexing:OAK-12249-lazy-provisioning

Conversation

@bhabegger

Copy link
Copy Markdown
Contributor

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 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.

Note

Supersedes #2955, opened from #2955 (bhabegger/jackrabbit-oak), moved to this fork to pick up CI.

Jira

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

@fabriziofortino fabriziofortino left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic LGTM. Just a few improvements.

Comment on lines +53 to +55
@Override
public ElasticIndexWriter getWriter() {
return (ElasticIndexWriter) super.getWriter();
public FulltextIndexWriter<ElasticDocument> getWriter() {
return super.getWriter();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is actually no need for that. We could remove it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed :)

* See the License for the specific language governing permissions and
* limitations under the License.
*/
@Version("2.4.1")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, I'm not sure what to put here. This was to get the build working. Should I align, already increase waiting for that PR to merge ?

@bhabegger
bhabegger force-pushed the OAK-12249-lazy-provisioning branch 3 times, most recently from 892ed26 to 3d68cd4 Compare August 31, 2026 11:27
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>
@bhabegger
bhabegger force-pushed the OAK-12249-lazy-provisioning branch from 3d68cd4 to ef33424 Compare September 1, 2026 09:26
@fabriziofortino
fabriziofortino merged commit 82208b8 into apache:trunk Sep 1, 2026
2 of 3 checks passed
@rishabhdaim

Copy link
Copy Markdown
Contributor

This PR changed classes in org.apache.jackrabbit.oak.plugins.index.elastic.query and org.apache.jackrabbit.oak.plugins.index.elastic.util (e.g. lazy provisioning changes to ElasticIndexWriter/ensureProvisioned()), but the @Version in the corresponding package-info.java files was not bumped.

Both packages are still declared as 2.4.1, while the OSGi baseline check (comparing against the last released 2.6.0 jar) now computes 2.6.1 as required for both:

[ERROR] org.apache.jackrabbit.oak.plugins.index.elastic.query: Version increase required; detected 2.4.1, suggested 2.6.1
[ERROR] org.apache.jackrabbit.oak.plugins.index.elastic.util: Version increase required; detected 2.4.1, suggested 2.6.1

This breaks mvn install/verify for oak-search-elastic for anyone building on trunk today. Could we get a follow-up bumping both @Version annotations to 2.6.1?

@reschke

reschke commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

@bhabegger

Copy link
Copy Markdown
Contributor Author

Yeah, the situation was weird. My PR was building fine until it didn't anymore without adding the package-info.json files. So I didn't know exactly what was going on, whether they should be added or not, with which version, etc. Anyway, there was a commit that was missed before the PR got merged.

@reschke

reschke commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

@bhabegger - the right thing here would have been to ask.

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.

4 participants