Skip to content

Refactor lock and simplify maps#200

Closed
Bukhtawar wants to merge 10 commits intoalchemist51:cieefrom
Bukhtawar:ciee-refactor-lock
Closed

Refactor lock and simplify maps#200
Bukhtawar wants to merge 10 commits intoalchemist51:cieefrom
Bukhtawar:ciee-refactor-lock

Conversation

@Bukhtawar
Copy link
Copy Markdown

@Bukhtawar Bukhtawar commented Mar 28, 2026

Description

CompositeWriter.java — Replaced the Map.Entry<DataFormat, Writer<DocumentInput<?>>> primary writer field with two plain fields (primaryFormat and primaryWriter), eliminating the AbstractMap.SimpleImmutableEntry allocation and .getKey()/.getValue() indirection at every call site. Switched secondaryWritersByFormat from LinkedHashMap to IdentityHashMap wrapped with Collections.unmodifiableMap(), so lookups in addDoc() use == reference equality instead of String.equals() on format names.

CompositeDocumentInput.java and CompositeIndexingExecutionEngine.java — Switched secondary input maps from LinkedHashMap/Map.copyOf() to IdentityHashMap/Collections.unmodifiableMap() to preserve identity semantics end-to-end, since the same DataFormat singleton instances flow from engine construction through document input creation to writer lookup.

CompositeDataFormatWriterPool.java — Replaced the checkoutAll() implementation with an atomic swap pattern. The old version held the pool lock while iterating all writers, locking each one, and removing each from the striped queue (N×16 lock acquisitions). The new version holds the pool lock only for two pointer swaps (microseconds), then waits for in-flight writes outside any pool lock. Updated releaseAndUnlock() to gracefully handle old-generation writers being returned after the swap.

Related Issues

Resolves opensearch-project#20909

Check List

  • Functionality includes testing.
  • API changes companion pull request created, if applicable.
  • Public documentation issue/PR created, if applicable.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

alchemist51 and others added 6 commits March 27, 2026 11:57
Signed-off-by: Arpit Bandejiya <abandeji@amazon.com>
Co-authored-by: Bukhtawar Khan <bukhtawa@amazon.com>
Signed-off-by: Arpit Bandejiya <abandeji@amazon.com>
Signed-off-by: Arpit Bandejiya <abandeji@amazon.com>
Signed-off-by: Arpit Bandejiya <abandeji@amazon.com>
Signed-off-by: Arpit Bandejiya <abandeji@amazon.com>
Signed-off-by: Bukhtawar Khan <bukhtawa@amazon.com>
Signed-off-by: Bukhtawar Khan <bukhtawa@amazon.com>
Co-authored-by: Arpit Bandejiya <abandeji@amazon.com>
Signed-off-by: Bukhtawar Khan <bukhtawa@amazon.com>
@Bukhtawar Bukhtawar force-pushed the ciee-refactor-lock branch from c942b9c to 530d346 Compare March 29, 2026 08:43
Bukhtawar and others added 2 commits March 29, 2026 14:15
Signed-off-by: Bukhtawar Khan <bukhtawa@amazon.com>
@alchemist51 alchemist51 force-pushed the ciee branch 2 times, most recently from fc6e33a to a37d2ef Compare March 29, 2026 13:58
@alchemist51
Copy link
Copy Markdown
Owner

We will get back on the lockable pool later

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