-
Notifications
You must be signed in to change notification settings - Fork 46
feat(plugin): add ingestion plugin framework and example implementation #855
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
Open
umeshdangat
wants to merge
6
commits into
Yelp:main
Choose a base branch
from
duckbills:umesh_add_support_for_ingestion_plugin
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.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
330923f
feat(plugin): add ingestion plugin framework and example implementation
umeshdangat d91bf79
remove redundant code
umeshdangat 1daeaf2
Refactor ingestion plugin lifecycle to support async execution and pl…
umeshdangat dd4b9bf
fix ExamplePlugin to use executorService
umeshdangat 24ebf7d
feat(ingestion): add ingestion plugin framework and revert example pl…
umeshdangat 3c5416a
address PR comments, use JsonUtils to add type safe deser, move inges…
umeshdangat 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
34 changes: 34 additions & 0 deletions
34
src/main/java/com/yelp/nrtsearch/server/config/IngestionPluginConfigs.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,34 @@ | ||
/* | ||
* Copyright 2025 Yelp Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.yelp.nrtsearch.server.config; | ||
|
||
import com.fasterxml.jackson.annotation.JsonAnySetter; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class IngestionPluginConfigs { | ||
|
||
private final Map<String, Map<String, Object>> pluginConfigs = new HashMap<>(); | ||
|
||
@JsonAnySetter | ||
public void addPluginConfig(String pluginName, Map<String, Object> config) { | ||
pluginConfigs.put(pluginName, config); | ||
} | ||
|
||
public Map<String, Map<String, Object>> getPluginConfigs() { | ||
return pluginConfigs; | ||
} | ||
} |
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
102 changes: 102 additions & 0 deletions
102
src/main/java/com/yelp/nrtsearch/server/ingestion/AbstractIngestor.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,102 @@ | ||
/* | ||
* Copyright 2025 Yelp Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.yelp.nrtsearch.server.ingestion; | ||
|
||
import com.yelp.nrtsearch.server.config.NrtsearchConfig; | ||
import com.yelp.nrtsearch.server.grpc.AddDocumentRequest; | ||
import com.yelp.nrtsearch.server.handler.AddDocumentHandler; | ||
import com.yelp.nrtsearch.server.index.IndexState; | ||
import com.yelp.nrtsearch.server.state.GlobalState; | ||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
/** | ||
* Abstract base class for ingestion implementations. Provides common ingestion utilities like | ||
* addDocuments and commit. Plugin-specific ingestion logic should extend this class and implement | ||
* start/stop. | ||
*/ | ||
public abstract class AbstractIngestor implements Ingestor { | ||
protected final NrtsearchConfig config; | ||
protected GlobalState globalState; | ||
|
||
public AbstractIngestor(NrtsearchConfig config) { | ||
this.config = config; | ||
} | ||
|
||
/** | ||
* Called by the framework to initialize the ingestor with global state. Must be called before | ||
* addDocuments or commit. | ||
*/ | ||
@Override | ||
public void initialize(GlobalState globalState) { | ||
this.globalState = globalState; | ||
} | ||
|
||
/** | ||
* Add documents to the index. | ||
* | ||
* @param addDocRequests list of documents to add | ||
* @param indexName target index | ||
* @return sequence number of the indexing operation | ||
* @throws Exception if indexing fails | ||
*/ | ||
@Override | ||
public long addDocuments(List<AddDocumentRequest> addDocRequests, String indexName) | ||
throws Exception { | ||
verifyInitialized(indexName); | ||
return new AddDocumentHandler.DocumentIndexer(globalState, addDocRequests, indexName) | ||
.runIndexingJob(); | ||
} | ||
|
||
/** | ||
* Commit changes to the index. | ||
* | ||
* @param indexName target index | ||
* @throws IOException if commit fails | ||
*/ | ||
@Override | ||
public void commit(String indexName) throws IOException { | ||
verifyInitialized(indexName); | ||
IndexState indexState = globalState.getIndexOrThrow(indexName); | ||
indexState.commit(); | ||
} | ||
|
||
private void verifyInitialized(String indexName) throws IOException { | ||
if (globalState == null) { | ||
throw new IllegalStateException("Ingestor not initialized with GlobalState"); | ||
} | ||
IndexState indexState = globalState.getIndexOrThrow(indexName); | ||
if (indexState == null) { | ||
throw new IllegalStateException("Index not found: " + indexName); | ||
} | ||
} | ||
|
||
/** | ||
* Start ingestion logic. Must be implemented by plugin-specific subclass. | ||
* | ||
* @throws IOException if startup fails | ||
*/ | ||
@Override | ||
public abstract void start() throws IOException; | ||
|
||
/** | ||
* Stop ingestion logic. Must be implemented by plugin-specific subclass. | ||
* | ||
* @throws IOException if shutdown fails | ||
*/ | ||
@Override | ||
public abstract void stop() throws IOException; | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/yelp/nrtsearch/server/ingestion/IngestionPluginUtils.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,41 @@ | ||
/* | ||
* Copyright 2025 Yelp Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.yelp.nrtsearch.server.ingestion; | ||
|
||
import com.yelp.nrtsearch.server.plugins.IngestionPlugin; | ||
import com.yelp.nrtsearch.server.state.GlobalState; | ||
import java.io.IOException; | ||
import java.util.concurrent.ExecutorService; | ||
|
||
public class IngestionPluginUtils { | ||
public static void initializeAndStart(IngestionPlugin plugin, GlobalState globalState) | ||
throws IOException { | ||
Ingestor ingestor = plugin.getIngestor(); | ||
if (ingestor instanceof AbstractIngestor abstractIngestor) { | ||
abstractIngestor.initialize(globalState); | ||
} | ||
|
||
ExecutorService executor = plugin.getIngestionExecutor(); | ||
executor.submit( | ||
() -> { | ||
try { | ||
ingestor.start(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
}); | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
src/main/java/com/yelp/nrtsearch/server/ingestion/Ingestor.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,95 @@ | ||
/* | ||
* Copyright 2024 Yelp Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.yelp.nrtsearch.server.ingestion; | ||
|
||
import com.yelp.nrtsearch.server.grpc.AddDocumentRequest; | ||
import com.yelp.nrtsearch.server.state.GlobalState; | ||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
/** | ||
* Interface for ingestion logic used by plugins. | ||
* | ||
* <p>This interface defines the lifecycle and operations for ingesting documents into an index. | ||
* Plugin implementations can use this interface to encapsulate source-specific ingestion logic | ||
* (e.g., reading from Kafka, S3, etc.) while leveraging shared indexing utilities. | ||
* | ||
* <p>Implementations are expected to: | ||
* | ||
* <ul> | ||
* <li>Initialize with {@link GlobalState} before starting | ||
* <li>Start ingestion in a background thread (if needed) | ||
* <li>Use {@link #addDocuments(List, String)} and {@link #commit(String)} to index data | ||
* <li>Clean up resources in {@link #stop()} | ||
* </ul> | ||
*/ | ||
public interface Ingestor { | ||
|
||
/** | ||
* Initialize the ingestor with the global server state. | ||
* | ||
* <p>This method is called once by the framework before ingestion starts. Implementations should | ||
* store the global state for later use (e.g., to access index state). | ||
* | ||
* @param globalState the global server state | ||
*/ | ||
void initialize(GlobalState globalState); | ||
|
||
/** | ||
* Start the ingestion process. | ||
* | ||
* <p>This method should contain the logic to begin reading from the ingestion source (e.g., | ||
* Kafka, file system, etc.). It may block or spawn background threads depending on the | ||
* implementation. | ||
* | ||
* @throws IOException if ingestion startup fails | ||
*/ | ||
void start() throws IOException; | ||
|
||
/** | ||
* Stop the ingestion process and clean up resources. | ||
* | ||
* <p>This method is called during plugin shutdown. Implementations should stop any background | ||
* threads, close connections, and release resources. | ||
* | ||
* @throws IOException if ingestion shutdown fails | ||
*/ | ||
void stop() throws IOException; | ||
|
||
/** | ||
* Add a batch of documents to the specified index. | ||
* | ||
* <p>This method is typically called from within the ingestion loop to index new data. It returns | ||
* the Lucene sequence number of the indexing operation. | ||
* | ||
* @param addDocRequests list of document requests to add | ||
* @param indexName name of the target index | ||
* @return sequence number of the indexing operation | ||
* @throws Exception if indexing fails | ||
*/ | ||
long addDocuments(List<AddDocumentRequest> addDocRequests, String indexName) throws Exception; | ||
|
||
/** | ||
* Commit any pending changes to the specified index. | ||
* | ||
* <p>This method should be called periodically or after a batch of documents is added to ensure | ||
* durability and visibility of the changes. | ||
* | ||
* @param indexName name of the target index | ||
* @throws IOException if commit fails | ||
*/ | ||
void commit(String indexName) throws IOException; | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/yelp/nrtsearch/server/plugins/IngestionPlugin.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,30 @@ | ||
/* | ||
* Copyright 2025 Yelp Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.yelp.nrtsearch.server.plugins; | ||
|
||
import com.yelp.nrtsearch.server.ingestion.Ingestor; | ||
import java.util.concurrent.ExecutorService; | ||
|
||
public interface IngestionPlugin { | ||
/** Interface for ingestion logic used by plugins */ | ||
Ingestor getIngestor(); | ||
|
||
/** | ||
* Provide an executor service for running ingestion. Plugin is responsible for managing its | ||
* lifecycle. | ||
*/ | ||
ExecutorService getIngestionExecutor(); | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.