Skip to content

Commit f4acda3

Browse files
authored
Add opensearch version info while deserialization (#16494) (#17138)
Signed-off-by: Sooraj Sinha <soosinha@amazon.com>
1 parent 64486b6 commit f4acda3

File tree

6 files changed

+30
-12
lines changed

6 files changed

+30
-12
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
110110
- The `phone-search` analyzer no longer emits the tel/sip prefix, international calling code, extension numbers and unformatted input as a token ([#16993](https://github.com/opensearch-project/OpenSearch/pull/16993))
111111
- Stop processing search requests when _msearch request is cancelled ([#17005](https://github.com/opensearch-project/OpenSearch/pull/17005))
112112
- Fix GRPC AUX_TRANSPORT_PORT and SETTING_GRPC_PORT settings and remove lingering HTTP terminology ([#17037](https://github.com/opensearch-project/OpenSearch/pull/17037))
113+
- Use OpenSearch version to deserialize remote custom metadata([#16494](https://github.com/opensearch-project/OpenSearch/pull/16494))
113114

114115
### Security
115116

server/src/main/java/org/opensearch/gateway/remote/RemoteClusterStateService.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,8 @@ ClusterState readClusterStateInParallel(
12601260
entry.getKey(),
12611261
clusterUUID,
12621262
blobStoreRepository.getCompressor(),
1263-
namedWriteableRegistry
1263+
namedWriteableRegistry,
1264+
manifest.getOpensearchVersion()
12641265
),
12651266
listener
12661267
);

server/src/main/java/org/opensearch/gateway/remote/RemoteGlobalMetadataManager.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ Metadata getGlobalMetadata(String clusterUUID, ClusterMetadataManifest clusterMe
242242
key,
243243
clusterUUID,
244244
compressor,
245-
namedWriteableRegistry
245+
namedWriteableRegistry,
246+
clusterMetadataManifest.getOpensearchVersion()
246247
);
247248
builder.putCustom(key, (Custom) getStore(remoteCustomMetadata).read(remoteCustomMetadata));
248249
} catch (IOException e) {

server/src/main/java/org/opensearch/gateway/remote/model/RemoteCustomMetadata.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
package org.opensearch.gateway.remote.model;
1010

11+
import org.opensearch.Version;
1112
import org.opensearch.cluster.metadata.Metadata.Custom;
1213
import org.opensearch.common.io.Streams;
1314
import org.opensearch.common.remote.AbstractClusterMetadataWriteableBlobEntity;
@@ -67,16 +68,17 @@ public RemoteCustomMetadata(
6768
final String customType,
6869
final String clusterUUID,
6970
final Compressor compressor,
70-
final NamedWriteableRegistry namedWriteableRegistry
71+
final NamedWriteableRegistry namedWriteableRegistry,
72+
final Version version
7173
) {
7274
super(clusterUUID, compressor, null);
7375
this.blobName = blobName;
7476
this.customType = customType;
7577
this.namedWriteableRegistry = namedWriteableRegistry;
76-
this.customBlobStoreFormat = new ChecksumWritableBlobStoreFormat<>(
77-
"custom",
78-
is -> readFrom(is, namedWriteableRegistry, customType)
79-
);
78+
this.customBlobStoreFormat = new ChecksumWritableBlobStoreFormat<>("custom", is -> {
79+
is.setVersion(version);
80+
return readFrom(is, namedWriteableRegistry, customType);
81+
});
8082
}
8183

8284
@Override

server/src/test/java/org/opensearch/gateway/remote/RemoteGlobalMetadataManagerTests.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
package org.opensearch.gateway.remote;
1010

11+
import org.opensearch.Version;
1112
import org.opensearch.action.LatchedActionListener;
1213
import org.opensearch.cluster.ClusterModule;
1314
import org.opensearch.cluster.ClusterName;
@@ -480,14 +481,21 @@ public void testGetAsyncWriteRunnable_TemplatesMetadata() throws Exception {
480481
}
481482

482483
public void testGetAsyncReadRunnable_CustomMetadata() throws Exception {
484+
for (Version version : List.of(Version.CURRENT, Version.V_2_15_0, Version.V_2_13_0)) {
485+
verifyCustomMetadataReadForVersion(version);
486+
}
487+
}
488+
489+
private void verifyCustomMetadataReadForVersion(Version version) throws Exception {
483490
Metadata.Custom customMetadata = getCustomMetadata();
484491
String fileName = randomAlphaOfLength(10);
485492
RemoteCustomMetadata customMetadataForDownload = new RemoteCustomMetadata(
486493
fileName,
487494
IndexGraveyard.TYPE,
488495
CLUSTER_UUID,
489496
compressor,
490-
namedWriteableRegistry
497+
namedWriteableRegistry,
498+
version
491499
);
492500
when(blobStoreTransferService.downloadBlob(anyIterable(), anyString())).thenReturn(
493501
customMetadataForDownload.customBlobStoreFormat.serialize(customMetadata, fileName, compressor).streamInput()
@@ -695,4 +703,5 @@ public void testGetUpdatedCustoms() {
695703
assertThat(customsDiff.getUpserts(), is(expectedUpserts));
696704
assertThat(customsDiff.getDeletes(), is(List.of(CustomMetadata1.TYPE)));
697705
}
706+
698707
}

server/src/test/java/org/opensearch/gateway/remote/model/RemoteCustomMetadataTests.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ public void testClusterUUID() {
106106
"test-custom",
107107
clusterUUID,
108108
compressor,
109-
namedWriteableRegistry
109+
namedWriteableRegistry,
110+
Version.CURRENT
110111
);
111112
assertThat(remoteObjectForDownload.clusterUUID(), is(clusterUUID));
112113
}
@@ -128,7 +129,8 @@ public void testFullBlobName() {
128129
"test-custom",
129130
clusterUUID,
130131
compressor,
131-
namedWriteableRegistry
132+
namedWriteableRegistry,
133+
Version.CURRENT
132134
);
133135
assertThat(remoteObjectForDownload.getFullBlobName(), is(TEST_BLOB_NAME));
134136
}
@@ -150,7 +152,8 @@ public void testBlobFileName() {
150152
"test-custom",
151153
clusterUUID,
152154
compressor,
153-
namedWriteableRegistry
155+
namedWriteableRegistry,
156+
Version.CURRENT
154157
);
155158
assertThat(remoteObjectForDownload.getBlobFileName(), is(TEST_BLOB_FILE_NAME));
156159
}
@@ -162,7 +165,8 @@ public void testBlobPathTokens() {
162165
"test-custom",
163166
clusterUUID,
164167
compressor,
165-
namedWriteableRegistry
168+
namedWriteableRegistry,
169+
Version.CURRENT
166170
);
167171
assertThat(remoteObjectForDownload.getBlobPathTokens(), is(new String[] { "user", "local", "opensearch", "customMetadata" }));
168172
}

0 commit comments

Comments
 (0)