From 64c813f583fe569553898268bb683ddbd7961218 Mon Sep 17 00:00:00 2001 From: Sooraj Sinha Date: Sun, 27 Oct 2024 16:54:17 +0530 Subject: [PATCH] Add opensearch version info while deserialization Signed-off-by: Sooraj Sinha --- CHANGELOG.md | 1 + .../gateway/remote/RemoteClusterStateService.java | 3 ++- .../gateway/remote/RemoteGlobalMetadataManager.java | 3 ++- .../gateway/remote/model/RemoteCustomMetadata.java | 12 +++++++----- .../remote/RemoteGlobalMetadataManagerTests.java | 4 +++- .../remote/model/RemoteCustomMetadataTests.java | 12 ++++++++---- 6 files changed, 23 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e20df483030d6..b09cd6d302506 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -102,6 +102,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - [Workload Management] Fixing Create/Update QueryGroup TransportActions to execute from non-cluster manager nodes ([16422](https://github.com/opensearch-project/OpenSearch/pull/16422)) - Fix flaky test in `testApproximateRangeWithSizeOverDefault` by adjusting totalHits assertion logic ([#16434](https://github.com/opensearch-project/OpenSearch/pull/16434#pullrequestreview-2386999409)) - Revert changes to upload remote state manifest using minimum codec version([#16403](https://github.com/opensearch-project/OpenSearch/pull/16403)) +- Use OpenSearch version to deserializat remote custom metadata([#16494](https://github.com/opensearch-project/OpenSearch/pull/16494)) ### Security diff --git a/server/src/main/java/org/opensearch/gateway/remote/RemoteClusterStateService.java b/server/src/main/java/org/opensearch/gateway/remote/RemoteClusterStateService.java index dc41189afc3cb..8179b6883523e 100644 --- a/server/src/main/java/org/opensearch/gateway/remote/RemoteClusterStateService.java +++ b/server/src/main/java/org/opensearch/gateway/remote/RemoteClusterStateService.java @@ -1262,7 +1262,8 @@ ClusterState readClusterStateInParallel( entry.getKey(), clusterUUID, blobStoreRepository.getCompressor(), - namedWriteableRegistry + namedWriteableRegistry, + manifest.getOpensearchVersion() ), listener ); diff --git a/server/src/main/java/org/opensearch/gateway/remote/RemoteGlobalMetadataManager.java b/server/src/main/java/org/opensearch/gateway/remote/RemoteGlobalMetadataManager.java index 763a8e3ff4951..c7434144e10f8 100644 --- a/server/src/main/java/org/opensearch/gateway/remote/RemoteGlobalMetadataManager.java +++ b/server/src/main/java/org/opensearch/gateway/remote/RemoteGlobalMetadataManager.java @@ -242,7 +242,8 @@ Metadata getGlobalMetadata(String clusterUUID, ClusterMetadataManifest clusterMe key, clusterUUID, compressor, - namedWriteableRegistry + namedWriteableRegistry, + clusterMetadataManifest.getOpensearchVersion() ); builder.putCustom(key, (Custom) getStore(remoteCustomMetadata).read(remoteCustomMetadata)); } catch (IOException e) { diff --git a/server/src/main/java/org/opensearch/gateway/remote/model/RemoteCustomMetadata.java b/server/src/main/java/org/opensearch/gateway/remote/model/RemoteCustomMetadata.java index 8e850e903954a..03055a0be0e64 100644 --- a/server/src/main/java/org/opensearch/gateway/remote/model/RemoteCustomMetadata.java +++ b/server/src/main/java/org/opensearch/gateway/remote/model/RemoteCustomMetadata.java @@ -8,6 +8,7 @@ package org.opensearch.gateway.remote.model; +import org.opensearch.Version; import org.opensearch.cluster.metadata.Metadata.Custom; import org.opensearch.common.io.Streams; import org.opensearch.common.remote.AbstractClusterMetadataWriteableBlobEntity; @@ -67,16 +68,17 @@ public RemoteCustomMetadata( final String customType, final String clusterUUID, final Compressor compressor, - final NamedWriteableRegistry namedWriteableRegistry + final NamedWriteableRegistry namedWriteableRegistry, + final Version version ) { super(clusterUUID, compressor, null); this.blobName = blobName; this.customType = customType; this.namedWriteableRegistry = namedWriteableRegistry; - this.customBlobStoreFormat = new ChecksumWritableBlobStoreFormat<>( - "custom", - is -> readFrom(is, namedWriteableRegistry, customType) - ); + this.customBlobStoreFormat = new ChecksumWritableBlobStoreFormat<>("custom", is -> { + is.setVersion(version); + return readFrom(is, namedWriteableRegistry, customType); + }); } @Override diff --git a/server/src/test/java/org/opensearch/gateway/remote/RemoteGlobalMetadataManagerTests.java b/server/src/test/java/org/opensearch/gateway/remote/RemoteGlobalMetadataManagerTests.java index a2da1e8b0fdb2..9c63c56985b0b 100644 --- a/server/src/test/java/org/opensearch/gateway/remote/RemoteGlobalMetadataManagerTests.java +++ b/server/src/test/java/org/opensearch/gateway/remote/RemoteGlobalMetadataManagerTests.java @@ -8,6 +8,7 @@ package org.opensearch.gateway.remote; +import org.opensearch.Version; import org.opensearch.action.LatchedActionListener; import org.opensearch.cluster.ClusterModule; import org.opensearch.cluster.ClusterName; @@ -487,7 +488,8 @@ public void testGetAsyncReadRunnable_CustomMetadata() throws Exception { IndexGraveyard.TYPE, CLUSTER_UUID, compressor, - namedWriteableRegistry + namedWriteableRegistry, + Version.CURRENT ); when(blobStoreTransferService.downloadBlob(anyIterable(), anyString())).thenReturn( customMetadataForDownload.customBlobStoreFormat.serialize(customMetadata, fileName, compressor).streamInput() diff --git a/server/src/test/java/org/opensearch/gateway/remote/model/RemoteCustomMetadataTests.java b/server/src/test/java/org/opensearch/gateway/remote/model/RemoteCustomMetadataTests.java index 60cceb205f43d..46c0b4d360665 100644 --- a/server/src/test/java/org/opensearch/gateway/remote/model/RemoteCustomMetadataTests.java +++ b/server/src/test/java/org/opensearch/gateway/remote/model/RemoteCustomMetadataTests.java @@ -106,7 +106,8 @@ public void testClusterUUID() { "test-custom", clusterUUID, compressor, - namedWriteableRegistry + namedWriteableRegistry, + Version.CURRENT ); assertThat(remoteObjectForDownload.clusterUUID(), is(clusterUUID)); } @@ -128,7 +129,8 @@ public void testFullBlobName() { "test-custom", clusterUUID, compressor, - namedWriteableRegistry + namedWriteableRegistry, + Version.CURRENT ); assertThat(remoteObjectForDownload.getFullBlobName(), is(TEST_BLOB_NAME)); } @@ -150,7 +152,8 @@ public void testBlobFileName() { "test-custom", clusterUUID, compressor, - namedWriteableRegistry + namedWriteableRegistry, + Version.CURRENT ); assertThat(remoteObjectForDownload.getBlobFileName(), is(TEST_BLOB_FILE_NAME)); } @@ -162,7 +165,8 @@ public void testBlobPathTokens() { "test-custom", clusterUUID, compressor, - namedWriteableRegistry + namedWriteableRegistry, + Version.CURRENT ); assertThat(remoteObjectForDownload.getBlobPathTokens(), is(new String[] { "user", "local", "opensearch", "customMetadata" })); }