Skip to content

Commit

Permalink
Add opensearch version info while deserialization (#16494)
Browse files Browse the repository at this point in the history
Signed-off-by: Sooraj Sinha <[email protected]>
  • Loading branch information
soosinha authored Jan 27, 2025
1 parent 7e51088 commit 3032bef
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Stop processing search requests when _msearch request is cancelled ([#17005](https://github.com/opensearch-project/OpenSearch/pull/17005))
- Fix GRPC AUX_TRANSPORT_PORT and SETTING_GRPC_PORT settings and remove lingering HTTP terminology ([#17037](https://github.com/opensearch-project/OpenSearch/pull/17037))
- Fix exists queries on nested flat_object fields throws exception ([#16803](https://github.com/opensearch-project/OpenSearch/pull/16803))
- Use OpenSearch version to deserialize remote custom metadata([#16494](https://github.com/opensearch-project/OpenSearch/pull/16494))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1281,7 +1281,8 @@ ClusterState readClusterStateInParallel(
entry.getKey(),
clusterUUID,
blobStoreRepository.getCompressor(),
namedWriteableRegistry
namedWriteableRegistry,
manifest.getOpensearchVersion()
),
listener
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -480,14 +481,21 @@ public void testGetAsyncWriteRunnable_TemplatesMetadata() throws Exception {
}

public void testGetAsyncReadRunnable_CustomMetadata() throws Exception {
for (Version version : List.of(Version.CURRENT, Version.V_2_15_0, Version.V_2_13_0)) {
verifyCustomMetadataReadForVersion(version);
}
}

private void verifyCustomMetadataReadForVersion(Version version) throws Exception {
Metadata.Custom customMetadata = getCustomMetadata();
String fileName = randomAlphaOfLength(10);
RemoteCustomMetadata customMetadataForDownload = new RemoteCustomMetadata(
fileName,
IndexGraveyard.TYPE,
CLUSTER_UUID,
compressor,
namedWriteableRegistry
namedWriteableRegistry,
version
);
when(blobStoreTransferService.downloadBlob(anyIterable(), anyString())).thenReturn(
customMetadataForDownload.customBlobStoreFormat.serialize(customMetadata, fileName, compressor).streamInput()
Expand Down Expand Up @@ -695,4 +703,5 @@ public void testGetUpdatedCustoms() {
assertThat(customsDiff.getUpserts(), is(expectedUpserts));
assertThat(customsDiff.getDeletes(), is(List.of(CustomMetadata1.TYPE)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ public void testClusterUUID() {
"test-custom",
clusterUUID,
compressor,
namedWriteableRegistry
namedWriteableRegistry,
Version.CURRENT
);
assertThat(remoteObjectForDownload.clusterUUID(), is(clusterUUID));
}
Expand All @@ -128,7 +129,8 @@ public void testFullBlobName() {
"test-custom",
clusterUUID,
compressor,
namedWriteableRegistry
namedWriteableRegistry,
Version.CURRENT
);
assertThat(remoteObjectForDownload.getFullBlobName(), is(TEST_BLOB_NAME));
}
Expand All @@ -150,7 +152,8 @@ public void testBlobFileName() {
"test-custom",
clusterUUID,
compressor,
namedWriteableRegistry
namedWriteableRegistry,
Version.CURRENT
);
assertThat(remoteObjectForDownload.getBlobFileName(), is(TEST_BLOB_FILE_NAME));
}
Expand All @@ -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" }));
}
Expand Down

0 comments on commit 3032bef

Please sign in to comment.