forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Remote State] Create interface RemoteEntitiesManager (opensearch-pro…
…ject#14671) * Create interface RemoteEntitiesManager Signed-off-by: Shivansh Arora <[email protected]> Signed-off-by: Kaushal Kumar <[email protected]>
- Loading branch information
1 parent
9acd749
commit 23eac8d
Showing
15 changed files
with
769 additions
and
674 deletions.
There are no files selected for viewing
This file contains 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 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 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
84 changes: 84 additions & 0 deletions
84
server/src/main/java/org/opensearch/common/remote/AbstractRemoteWritableEntityManager.java
This file contains 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,84 @@ | ||
/* | ||
* 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.common.remote; | ||
|
||
import org.opensearch.core.action.ActionListener; | ||
import org.opensearch.gateway.remote.ClusterMetadataManifest; | ||
import org.opensearch.gateway.remote.model.RemoteReadResult; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* An abstract class that provides a base implementation for managing remote entities in the remote store. | ||
*/ | ||
public abstract class AbstractRemoteWritableEntityManager implements RemoteWritableEntityManager { | ||
/** | ||
* A map that stores the remote writable entity stores, keyed by the entity type. | ||
*/ | ||
protected final Map<String, RemoteWritableEntityStore> remoteWritableEntityStores = new HashMap<>(); | ||
|
||
/** | ||
* Retrieves the remote writable entity store for the given entity. | ||
* | ||
* @param entity the entity for which the store is requested | ||
* @return the remote writable entity store for the given entity | ||
* @throws IllegalArgumentException if the entity type is unknown | ||
*/ | ||
protected RemoteWritableEntityStore getStore(AbstractRemoteWritableBlobEntity entity) { | ||
RemoteWritableEntityStore remoteStore = remoteWritableEntityStores.get(entity.getType()); | ||
if (remoteStore == null) { | ||
throw new IllegalArgumentException("Unknown entity type [" + entity.getType() + "]"); | ||
} | ||
return remoteStore; | ||
} | ||
|
||
/** | ||
* Returns an ActionListener for handling the write operation for the specified component, remote object, and latched action listener. | ||
* | ||
* @param component the component for which the write operation is performed | ||
* @param remoteEntity the remote object to be written | ||
* @param listener the listener to be notified when the write operation completes | ||
* @return an ActionListener for handling the write operation | ||
*/ | ||
protected abstract ActionListener<Void> getWrappedWriteListener( | ||
String component, | ||
AbstractRemoteWritableBlobEntity remoteEntity, | ||
ActionListener<ClusterMetadataManifest.UploadedMetadata> listener | ||
); | ||
|
||
/** | ||
* Returns an ActionListener for handling the read operation for the specified component, | ||
* remote object, and latched action listener. | ||
* | ||
* @param component the component for which the read operation is performed | ||
* @param remoteEntity the remote object to be read | ||
* @param listener the listener to be notified when the read operation completes | ||
* @return an ActionListener for handling the read operation | ||
*/ | ||
protected abstract ActionListener<Object> getWrappedReadListener( | ||
String component, | ||
AbstractRemoteWritableBlobEntity remoteEntity, | ||
ActionListener<RemoteReadResult> listener | ||
); | ||
|
||
@Override | ||
public void writeAsync( | ||
String component, | ||
AbstractRemoteWritableBlobEntity entity, | ||
ActionListener<ClusterMetadataManifest.UploadedMetadata> listener | ||
) { | ||
getStore(entity).writeAsync(entity, getWrappedWriteListener(component, entity, listener)); | ||
} | ||
|
||
@Override | ||
public void readAsync(String component, AbstractRemoteWritableBlobEntity entity, ActionListener<RemoteReadResult> listener) { | ||
getStore(entity).readAsync(entity, getWrappedReadListener(component, entity, listener)); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
server/src/main/java/org/opensearch/common/remote/RemoteWritableEntityManager.java
This file contains 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,47 @@ | ||
/* | ||
* 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.common.remote; | ||
|
||
import org.opensearch.core.action.ActionListener; | ||
import org.opensearch.gateway.remote.ClusterMetadataManifest.UploadedMetadata; | ||
import org.opensearch.gateway.remote.model.RemoteReadResult; | ||
|
||
/** | ||
* The RemoteWritableEntityManager interface provides async read and write methods for managing remote entities in the remote store | ||
*/ | ||
public interface RemoteWritableEntityManager { | ||
|
||
/** | ||
* Performs an asynchronous read operation for the specified component and entity. | ||
* | ||
* @param component the component for which the read operation is performed | ||
* @param entity the entity to be read | ||
* @param listener the listener to be notified when the read operation completes. | ||
* The listener's {@link ActionListener#onResponse(Object)} method | ||
* is called with a {@link RemoteReadResult} object containing the | ||
* read data on successful read. The | ||
* {@link ActionListener#onFailure(Exception)} method is called with | ||
* an exception if the read operation fails. | ||
*/ | ||
void readAsync(String component, AbstractRemoteWritableBlobEntity entity, ActionListener<RemoteReadResult> listener); | ||
|
||
/** | ||
* Performs an asynchronous write operation for the specified component and entity. | ||
* | ||
* @param component the component for which the write operation is performed | ||
* @param entity the entity to be written | ||
* @param listener the listener to be notified when the write operation completes. | ||
* The listener's {@link ActionListener#onResponse(Object)} method | ||
* is called with a {@link UploadedMetadata} object containing the | ||
* uploaded metadata on successful write. The | ||
* {@link ActionListener#onFailure(Exception)} method is called with | ||
* an exception if the write operation fails. | ||
*/ | ||
void writeAsync(String component, AbstractRemoteWritableBlobEntity entity, ActionListener<UploadedMetadata> listener); | ||
} |
This file contains 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.