Skip to content

feat(java): add async batch indexing helpers - #6731

Open
Fluf22 wants to merge 4 commits into
mainfrom
feat/java-async-batch-helpers
Open

Fluf22 wants to merge 4 commits into
mainfrom
feat/java-async-batch-helpers

Conversation

@Fluf22

@Fluf22 Fluf22 commented Jul 16, 2026 •

Copy link
Copy Markdown
Collaborator

🧭 What and Why

🎟 JIRA Ticket: CR-11794

Customers migrating from Java v3 lost the async batch-indexing helpers (partialUpdateObjectsAsync and friends) and now have to block application threads on bulk updates. This restores a CompletableFuture surface for the batch helpers, backed by the same core the sync helpers use, plus an opt-in maxConcurrency knob (default 1 = today's exact sequential semantics). Java-only on purpose: the other ten clients are either already async-idiomatic or idiomatically blocking.

Changes included:

  • chunkedBatchAsync, saveObjectsAsync, partialUpdateObjectsAsync, deleteObjectsAsync on SearchClient. Async variants don't wait for tasks — call waitForTask per taskID, or use the sync variant.
  • ChunkedHelperOptions.maxConcurrency to parallelize chunk uploads, off by default.
  • Bug fix riding along: deleteObjects(indexName, objectIDs, requestOptions) silently dropped its requestOptions; batchSize < 1 is now rejected.

🧪 Test

Hand-written JUnit suite (com.algolia.manual, runs in CTS) covering chunking math, concurrency bounds, failure propagation, and sync/async request equivalence.

Reviewer note: the wave recursion uses thenComposeAsync on the client executor deliberately — plain thenCompose can nest on the stack when futures complete before callback registration.

@algolia-api-clients-automation-bot

algolia-api-clients-automation-bot Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

💥 Breaking changes detected !!

Either this PR or a previous PR not released yet introduced breaking changes, be careful when merging.
You can find the details in the 'client java@21' CI job.

✔️ Code generated!

Name Link
🪓 Triggered by 2cddb2d551260def28468b7b701ae60ef83ebad2
🍃 Generated commit de746e9bfe34a8af928c86b1ea5c623dfcc66cc8
🌲 Generated branch generated/feat/java-async-batch-helpers
📊 Benchmark results

Benchmarks performed on the method using a mock server, the results might not reflect the real-world performance.

Language Req/s
java 1111

@Fluf22
Fluf22 marked this pull request as ready for review July 16, 2026 14:17
@Fluf22
Fluf22 requested a review from a team as a code owner July 16, 2026 14:17
eric-zaharia
eric-zaharia previously approved these changes Jul 16, 2026
@Fluf22
Fluf22 force-pushed the feat/java-async-batch-helpers branch from 6c9c70a to 77839a0 Compare July 16, 2026 16:09
@Fluf22 Fluf22 self-assigned this Jul 16, 2026
@Fluf22
Fluf22 requested a review from eric-zaharia July 16, 2026 18:57
@aikido-pr-checks

aikido-pr-checks Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

Summary by Aikido

Security Issues: 0 Quality Issues: 0 Resolved Issues: 0

🚀 New Features

  • Added asynchronous batch indexing helpers returning CompletableFutures for SearchClient

⚡ Enhancements

  • Added configurable chunk concurrency while preserving sequential default batch semantics

🐛 Bugfixes

  • Fixed delete request options propagation and rejected invalid batch sizes

🔧 Refactors

  • Moved async continuations onto the client's executor for predictable scheduling behavior

More info

Adds CompletableFuture-returning batch helpers to the Java v4 SearchClient
(chunkedBatchAsync, saveObjectsAsync, partialUpdateObjectsAsync,
deleteObjectsAsync), restoring the async surface lost in the v3 -> v4
upgrade (customer escalation CR-11794). All helpers share one private
wave-based async core; the sync chunkedBatch is reimplemented on top of it
with byte-for-byte equivalent request behavior, and an opt-in
maxConcurrency knob (default 1, sequential) is added to
ChunkedHelperOptions.

- Fixes deleteObjects(indexName, objectIDs, requestOptions) silently
  dropping the caller's requestOptions.
- chunkedBatch now rejects batchSize < 1 with AlgoliaRuntimeException,
  matching chunkedPush's existing guard.
- Java-only by design: 7 of the 11 clients are already async-idiomatic
  (C#, Kotlin, Scala, JS, Swift, Dart, Python) and Go/PHP/Ruby are
  idiomatically blocking; Java is the only client with a first-class
  async idiom whose helpers lacked it.
- Move async helpers into templates/java/async_batch_helpers.mustache partial
- Collapse duplicated hazard Javadoc onto chunkedBatchAsync and
  ChunkedHelperOptions.setMaxConcurrency as canonical homes
- Drop the chunkedBatchAsyncInternal pass-through and the unnecessary
  synchronizedList (waves are strictly sequential)
- Run wave continuations on the client executor via ApiClient.getExecutor()
  instead of ForkJoinPool.commonPool()
- Dedup deleteObjects objectID wrapping into objectIDsToDeleteRequests
Sync chunkedBatch drives waves on the calling thread instead of awaiting chunkedBatchAsync, so the Iterable is never consumed on the client executor, iterator exceptions propagate unwrapped, and interrupts stop further waves. chunkedBatchAsync now reports Iterable failures in the first wave through the returned future.
@Fluf22
Fluf22 force-pushed the feat/java-async-batch-helpers branch from e23baca to bb330ab Compare September 25, 2026 08:10

This branch has not been deployed

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

2 participants