-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[WIP] Native engine abstractions #20821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
bharath-techie
wants to merge
6
commits into
opensearch-project:main
Choose a base branch
from
bharath-techie:native-eng
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,600
−44
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cedcba2
Native engine abstractions / skeleton flow
bharath-techie 7a637fe
Moving reader manager out of engine and adding contexts + providers
bharath-techie c1c389c
Refactor CompositeEngine to use factory (#50)
Bukhtawar 7464980
Introduce segment collector interface and simplify Providers (#51)
Bukhtawar 338bc6e
Decouple IndexFileDeleter (#52)
Bukhtawar 7f5f3e6
wiring result stream and adding tests
bharath-techie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...analytics-framework/src/main/java/org/opensearch/analytics/backend/EngineResultBatch.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.analytics.backend; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Read-only view of a single record batch. Provides field names, row count, | ||
| * and positional access to field values. | ||
| * | ||
| * @opensearch.internal | ||
| */ | ||
| public interface EngineResultBatch { | ||
|
|
||
| /** | ||
| * Ordered list of field (column) names in this batch. | ||
| */ | ||
| List<String> getFieldNames(); | ||
|
|
||
| /** | ||
| * Number of rows in this batch. | ||
| */ | ||
| int getRowCount(); | ||
|
|
||
| /** | ||
| * Returns the value at the given row index for the named field. | ||
| * | ||
| * @param fieldName column name | ||
| * @param rowIndex zero-based row index | ||
| * @return the value (may be null) | ||
| */ | ||
| Object getFieldValue(String fieldName, int rowIndex); | ||
| } |
18 changes: 18 additions & 0 deletions
18
...s-framework/src/main/java/org/opensearch/analytics/backend/EngineResultBatchIterator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.analytics.backend; | ||
|
|
||
| import java.util.Iterator; | ||
|
|
||
| /** | ||
| * Single-pass iterator over record batches from an {@link EngineResultStream}. | ||
| * | ||
| * @opensearch.internal | ||
| */ | ||
| public interface EngineResultBatchIterator extends Iterator<EngineResultBatch> {} |
28 changes: 28 additions & 0 deletions
28
...nalytics-framework/src/main/java/org/opensearch/analytics/backend/EngineResultStream.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.analytics.backend; | ||
|
|
||
| /** | ||
| * A closeable stream of record batches returned by engine execution. | ||
| * Callers iterate batches via the returned iterator and MUST close the stream | ||
| * when done to release native resources. | ||
| * | ||
| * @opensearch.internal | ||
| */ | ||
| public interface EngineResultStream extends AutoCloseable { | ||
|
|
||
| /** | ||
| * Returns an iterator over the record batches in this stream. | ||
| * Each call returns the same iterator instance — the stream is single-pass. | ||
| */ | ||
| EngineResultBatchIterator iterator(); | ||
|
|
||
| @Override | ||
| void close(); | ||
| } |
94 changes: 94 additions & 0 deletions
94
.../analytics-framework/src/main/java/org/opensearch/analytics/backend/jni/NativeHandle.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.analytics.backend.jni; | ||
|
|
||
| import java.lang.ref.Cleaner; | ||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
|
|
||
| /** | ||
| * Base class for type-safe native pointer wrappers. | ||
| * Provides automatic resource management and prevents use-after-close errors. | ||
| * Subclasses must implement {@link #doClose()} to release native resources. | ||
| * Cleaner is used to ensure resources are cleaned up even if the object is not explicitly closed. | ||
| */ | ||
| public abstract class NativeHandle implements AutoCloseable { | ||
|
|
||
| protected final long ptr; | ||
| private final AtomicBoolean closed = new AtomicBoolean(false); | ||
| protected static final long NULL_POINTER = 0L; | ||
| private final Cleaner.Cleanable cleanable; | ||
|
|
||
| private static final Cleaner CLEANER = Cleaner.create(); | ||
|
|
||
| /** | ||
| * Creates a new native handle. | ||
| * @param ptr the native pointer (must not be 0) | ||
| * @throws IllegalArgumentException if ptr is 0 | ||
| */ | ||
| protected NativeHandle(long ptr) { | ||
| if (ptr == NULL_POINTER) { | ||
| throw new IllegalArgumentException("Null native pointer"); | ||
| } | ||
| this.ptr = ptr; | ||
| this.cleanable = CLEANER.register(this, new CleanupAction(ptr, this::doClose)); | ||
| } | ||
|
|
||
| /** | ||
| * Ensures the handle is still open. | ||
| * @throws IllegalStateException if the handle has been closed | ||
| */ | ||
| public void ensureOpen() { | ||
| if (closed.get()) { | ||
| throw new IllegalStateException("Handle already closed"); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Gets the native pointer value. | ||
| * @return the native pointer | ||
| * @throws IllegalStateException if the handle has been closed | ||
| */ | ||
| public long getPointer() { | ||
| ensureOpen(); | ||
| return ptr; | ||
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
| if (closed.compareAndSet(false, true)) { | ||
| cleanable.clean(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Releases the native resource. | ||
| * Called once when the handle is closed. | ||
| * Subclasses must implement this to free native memory. | ||
| */ | ||
| protected abstract void doClose(); | ||
|
|
||
| /** | ||
| * Cleans up the native resource. | ||
| * Called by the cleaner when the handle is garbage collected. | ||
| */ | ||
| private static final class CleanupAction implements Runnable { | ||
| private final long ptr; | ||
| private final Runnable doClose; | ||
|
|
||
| CleanupAction(long ptr, Runnable doClose) { | ||
| this.ptr = ptr; | ||
| this.doClose = doClose; | ||
| } | ||
|
|
||
| @Override | ||
| public void run() { | ||
| doClose.run(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we let the bridge talk to the engine ? if we need to remove this dependency.
We can come back to this after we figure out if context is required in analytics plugin for delegates.