-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Add POJO classes required for cluster state publication from remote #14006
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
Merged
shwetathareja
merged 14 commits into
opensearch-project:main
from
shiv0408:remote_state_pojos
Jun 11, 2024
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
255075c
Add POJO classes required for cluster state publication from remote
shiv0408 c83706a
Add remote routing table changes in diff Manifest
alchemist51 830b002
Use InputStreams rather than XContent for serialization
shiv0408 da6580f
Address PR comments
shiv0408 f147333
Add tests
shiv0408 0895c40
apply spotless
shiv0408 7d628d2
Merged codec V3 with V2
shiv0408 fc6fb72
apply spotless
shiv0408 3868cb9
revert version change
shiv0408 f39d686
Address PR comments
shiv0408 2ab8c9e
Add UTs for RemoteClusterStateCustom
shiv0408 955871a
change codec version to V2 in tests
shiv0408 20cb7c0
Merge branch 'refs/heads/main' into remote_state_pojos
shiv0408 721bc18
Merge branch 'main' into remote_state_pojos
soosinha 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
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
373 changes: 334 additions & 39 deletions
373
server/src/main/java/org/opensearch/gateway/remote/ClusterMetadataManifest.java
Large diffs are not rendered by default.
Oops, something went wrong.
659 changes: 656 additions & 3 deletions
659
server/src/main/java/org/opensearch/gateway/remote/ClusterStateDiffManifest.java
Large diffs are not rendered by default.
Oops, something went wrong.
118 changes: 118 additions & 0 deletions
118
server/src/main/java/org/opensearch/gateway/remote/RemoteClusterStateAttributesManager.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,118 @@ | ||
| /* | ||
| * 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.gateway.remote; | ||
|
|
||
| import org.opensearch.action.LatchedActionListener; | ||
| import org.opensearch.cluster.ClusterState; | ||
| import org.opensearch.cluster.ClusterState.Custom; | ||
| import org.opensearch.cluster.block.ClusterBlocks; | ||
| import org.opensearch.cluster.node.DiscoveryNodes; | ||
| import org.opensearch.common.CheckedRunnable; | ||
| import org.opensearch.common.remote.AbstractRemoteWritableBlobEntity; | ||
| import org.opensearch.core.action.ActionListener; | ||
| import org.opensearch.core.common.io.stream.NamedWriteableRegistry; | ||
| import org.opensearch.core.compress.Compressor; | ||
| import org.opensearch.core.xcontent.NamedXContentRegistry; | ||
| import org.opensearch.core.xcontent.ToXContent; | ||
| import org.opensearch.gateway.remote.model.RemoteClusterBlocks; | ||
| import org.opensearch.gateway.remote.model.RemoteClusterStateBlobStore; | ||
| import org.opensearch.gateway.remote.model.RemoteClusterStateCustoms; | ||
| import org.opensearch.gateway.remote.model.RemoteDiscoveryNodes; | ||
| import org.opensearch.gateway.remote.model.RemoteReadResult; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.HashMap; | ||
| import java.util.HashSet; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
|
|
||
| /** | ||
| * A Manager which provides APIs to upload and download attributes of ClusterState to the {@link RemoteClusterStateBlobStore} | ||
| * | ||
| * @opensearch.internal | ||
| */ | ||
| public class RemoteClusterStateAttributesManager { | ||
| public static final String CLUSTER_STATE_ATTRIBUTE = "cluster_state_attribute"; | ||
| public static final String DISCOVERY_NODES = "nodes"; | ||
| public static final String CLUSTER_BLOCKS = "blocks"; | ||
| public static final int CLUSTER_STATE_ATTRIBUTES_CURRENT_CODEC_VERSION = 1; | ||
| private final RemoteClusterStateBlobStore<ClusterBlocks, RemoteClusterBlocks> clusterBlocksBlobStore; | ||
| private final RemoteClusterStateBlobStore<DiscoveryNodes, RemoteDiscoveryNodes> discoveryNodesBlobStore; | ||
| private final RemoteClusterStateBlobStore<Custom, RemoteClusterStateCustoms> customsBlobStore; | ||
| private final Compressor compressor; | ||
| private final NamedXContentRegistry namedXContentRegistry; | ||
| private final NamedWriteableRegistry namedWriteableRegistry; | ||
|
|
||
| RemoteClusterStateAttributesManager( | ||
| RemoteClusterStateBlobStore<ClusterBlocks, RemoteClusterBlocks> clusterBlocksBlobStore, | ||
| RemoteClusterStateBlobStore<DiscoveryNodes, RemoteDiscoveryNodes> discoveryNodesBlobStore, | ||
| RemoteClusterStateBlobStore<Custom, RemoteClusterStateCustoms> customsBlobStore, | ||
| Compressor compressor, | ||
| NamedXContentRegistry namedXContentRegistry, | ||
| NamedWriteableRegistry namedWriteableRegistry | ||
| ) { | ||
| this.clusterBlocksBlobStore = clusterBlocksBlobStore; | ||
| this.discoveryNodesBlobStore = discoveryNodesBlobStore; | ||
| this.customsBlobStore = customsBlobStore; | ||
| this.compressor = compressor; | ||
| this.namedXContentRegistry = namedXContentRegistry; | ||
| this.namedWriteableRegistry = namedWriteableRegistry; | ||
| } | ||
|
|
||
| /** | ||
| * Allows async upload of Cluster State Attribute components to remote | ||
| */ | ||
| CheckedRunnable<IOException> getAsyncMetadataWriteAction( | ||
| String component, | ||
| AbstractRemoteWritableBlobEntity blobEntity, | ||
| RemoteClusterStateBlobStore remoteEntityStore, | ||
| LatchedActionListener<ClusterMetadataManifest.UploadedMetadata> latchedActionListener | ||
| ) { | ||
| return () -> remoteEntityStore.writeAsync(blobEntity, getActionListener(component, blobEntity, latchedActionListener)); | ||
| } | ||
|
|
||
| private ActionListener<Void> getActionListener( | ||
| String component, | ||
| AbstractRemoteWritableBlobEntity remoteObject, | ||
| LatchedActionListener<ClusterMetadataManifest.UploadedMetadata> latchedActionListener | ||
| ) { | ||
| return ActionListener.wrap( | ||
| resp -> latchedActionListener.onResponse(remoteObject.getUploadedMetadata()), | ||
| ex -> latchedActionListener.onFailure(new RemoteStateTransferException(component, remoteObject, ex)) | ||
| ); | ||
| } | ||
|
|
||
| public CheckedRunnable<IOException> getAsyncMetadataReadAction( | ||
| String component, | ||
| AbstractRemoteWritableBlobEntity blobEntity, | ||
| RemoteClusterStateBlobStore remoteEntityStore, | ||
| LatchedActionListener<RemoteReadResult> listener | ||
| ) { | ||
| final ActionListener actionListener = ActionListener.wrap( | ||
| response -> listener.onResponse(new RemoteReadResult((ToXContent) response, CLUSTER_STATE_ATTRIBUTE, component)), | ||
| listener::onFailure | ||
| ); | ||
| return () -> remoteEntityStore.readAsync(blobEntity, actionListener); | ||
| } | ||
|
|
||
| public Map<String, ClusterState.Custom> getUpdatedCustoms(ClusterState clusterState, ClusterState previousClusterState) { | ||
shiv0408 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Map<String, ClusterState.Custom> updatedCustoms = new HashMap<>(); | ||
| Set<String> currentCustoms = new HashSet<>(clusterState.customs().keySet()); | ||
| for (Map.Entry<String, ClusterState.Custom> entry : previousClusterState.customs().entrySet()) { | ||
| if (currentCustoms.contains(entry.getKey()) && !entry.getValue().equals(clusterState.customs().get(entry.getKey()))) { | ||
| updatedCustoms.put(entry.getKey(), clusterState.customs().get(entry.getKey())); | ||
| } | ||
| currentCustoms.remove(entry.getKey()); | ||
| } | ||
| for (String custom : currentCustoms) { | ||
| updatedCustoms.put(custom, clusterState.customs().get(custom)); | ||
| } | ||
| return updatedCustoms; | ||
| } | ||
| } | ||
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.
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.