From e448dd330a8498aa58e04e7465aab62c4a5348a6 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 --- .../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 ++++++++---- 5 files changed, 22 insertions(+), 12 deletions(-) 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" })); }