diff --git a/server/src/main/java/org/opensearch/gateway/remote/ClusterMetadataManifest.java b/server/src/main/java/org/opensearch/gateway/remote/ClusterMetadataManifest.java index c42ab68c89014..d2062920eac82 100644 --- a/server/src/main/java/org/opensearch/gateway/remote/ClusterMetadataManifest.java +++ b/server/src/main/java/org/opensearch/gateway/remote/ClusterMetadataManifest.java @@ -317,7 +317,7 @@ private static void declareParser(ConstructingObjectParser ClusterStateDiffManifest.fromXContent(p), DIFF_MANIFEST ); @@ -543,10 +543,26 @@ public ClusterMetadataManifest(StreamInput in) throws IOException { this.routingTableVersion = in.readLong(); this.indicesRouting = Collections.unmodifiableList(in.readList(UploadedIndexMetadata::new)); this.metadataVersion = in.readLong(); - this.uploadedDiscoveryNodesMetadata = new UploadedMetadataAttribute(in); - this.uploadedClusterBlocksMetadata = new UploadedMetadataAttribute(in); - this.uploadedTransientSettingsMetadata = new UploadedMetadataAttribute(in); - this.uploadedHashesOfConsistentSettings = new UploadedMetadataAttribute(in); + if (in.readBoolean()) { + this.uploadedDiscoveryNodesMetadata = new UploadedMetadataAttribute(in); + } else { + this.uploadedDiscoveryNodesMetadata = null; + } + if (in.readBoolean()) { + this.uploadedClusterBlocksMetadata = new UploadedMetadataAttribute(in); + } else { + this.uploadedClusterBlocksMetadata = null; + } + if (in.readBoolean()) { + this.uploadedTransientSettingsMetadata = new UploadedMetadataAttribute(in); + } else { + this.uploadedTransientSettingsMetadata = null; + } + if (in.readBoolean()) { + this.uploadedHashesOfConsistentSettings = new UploadedMetadataAttribute(in); + } else { + this.uploadedHashesOfConsistentSettings = null; + } this.uploadedClusterStateCustomMap = Collections.unmodifiableMap( in.readMap(StreamInput::readString, UploadedMetadataAttribute::new) ); @@ -696,10 +712,30 @@ public void writeTo(StreamOutput out) throws IOException { out.writeLong(routingTableVersion); out.writeCollection(indicesRouting); out.writeLong(metadataVersion); - uploadedDiscoveryNodesMetadata.writeTo(out); - uploadedClusterBlocksMetadata.writeTo(out); - uploadedTransientSettingsMetadata.writeTo(out); - uploadedHashesOfConsistentSettings.writeTo(out); + if (uploadedDiscoveryNodesMetadata != null) { + out.writeBoolean(true); + uploadedDiscoveryNodesMetadata.writeTo(out); + } else { + out.writeBoolean(false); + } + if (uploadedClusterBlocksMetadata != null) { + out.writeBoolean(true); + uploadedClusterBlocksMetadata.writeTo(out); + } else { + out.writeBoolean(false); + } + if (uploadedTransientSettingsMetadata != null) { + out.writeBoolean(true); + uploadedTransientSettingsMetadata.writeTo(out); + } else { + out.writeBoolean(false); + } + if (uploadedHashesOfConsistentSettings != null) { + out.writeBoolean(true); + uploadedHashesOfConsistentSettings.writeTo(out); + } else { + out.writeBoolean(false); + } out.writeMap(uploadedClusterStateCustomMap, StreamOutput::writeString, (o, v) -> v.writeTo(o)); } else if (out.getVersion().onOrAfter(Version.V_2_12_0)) { out.writeInt(codecVersion); @@ -717,30 +753,31 @@ public boolean equals(Object o) { return false; } final ClusterMetadataManifest that = (ClusterMetadataManifest) o; - return Objects.equals(indices, that.indices) - && clusterTerm == that.clusterTerm - && stateVersion == that.stateVersion - && Objects.equals(clusterUUID, that.clusterUUID) - && Objects.equals(stateUUID, that.stateUUID) - && Objects.equals(opensearchVersion, that.opensearchVersion) - && Objects.equals(nodeId, that.nodeId) - && Objects.equals(committed, that.committed) - && Objects.equals(previousClusterUUID, that.previousClusterUUID) - && Objects.equals(clusterUUIDCommitted, that.clusterUUIDCommitted) - && Objects.equals(globalMetadataFileName, that.globalMetadataFileName) - && Objects.equals(codecVersion, that.codecVersion) - && Objects.equals(routingTableVersion, that.routingTableVersion) - && Objects.equals(indicesRouting, that.indicesRouting) - && Objects.equals(uploadedCoordinationMetadata, that.uploadedCoordinationMetadata) - && Objects.equals(uploadedSettingsMetadata, that.uploadedSettingsMetadata) - && Objects.equals(uploadedTemplatesMetadata, that.uploadedTemplatesMetadata) - && Objects.equals(uploadedCustomMetadataMap, that.uploadedCustomMetadataMap) - && Objects.equals(metadataVersion, that.metadataVersion) - && Objects.equals(uploadedDiscoveryNodesMetadata, that.uploadedDiscoveryNodesMetadata) - && Objects.equals(uploadedClusterBlocksMetadata, that.uploadedClusterBlocksMetadata) - && Objects.equals(uploadedTransientSettingsMetadata, that.uploadedTransientSettingsMetadata) - && Objects.equals(uploadedHashesOfConsistentSettings, that.uploadedHashesOfConsistentSettings) - && Objects.equals(uploadedClusterStateCustomMap, that.uploadedClusterStateCustomMap); + boolean ret = Objects.equals(indices, that.indices); + ret = ret && clusterTerm == that.clusterTerm; + ret = ret && stateVersion == that.stateVersion; + ret = ret && Objects.equals(clusterUUID, that.clusterUUID); + ret = ret && Objects.equals(stateUUID, that.stateUUID); + ret = ret && Objects.equals(opensearchVersion, that.opensearchVersion); + ret = ret && Objects.equals(nodeId, that.nodeId); + ret = ret && Objects.equals(committed, that.committed); + ret = ret && Objects.equals(previousClusterUUID, that.previousClusterUUID); + ret = ret && Objects.equals(clusterUUIDCommitted, that.clusterUUIDCommitted); + ret = ret && Objects.equals(globalMetadataFileName, that.globalMetadataFileName); + ret = ret && Objects.equals(codecVersion, that.codecVersion); + ret = ret && Objects.equals(routingTableVersion, that.routingTableVersion); + ret = ret && Objects.equals(indicesRouting, that.indicesRouting); + ret = ret && Objects.equals(uploadedCoordinationMetadata, that.uploadedCoordinationMetadata); + ret = ret && Objects.equals(uploadedSettingsMetadata, that.uploadedSettingsMetadata); + ret = ret && Objects.equals(uploadedTemplatesMetadata, that.uploadedTemplatesMetadata); + ret = ret && Objects.equals(uploadedCustomMetadataMap, that.uploadedCustomMetadataMap); + ret = ret && Objects.equals(metadataVersion, that.metadataVersion); + ret = ret && Objects.equals(uploadedDiscoveryNodesMetadata, that.uploadedDiscoveryNodesMetadata); + ret = ret && Objects.equals(uploadedClusterBlocksMetadata, that.uploadedClusterBlocksMetadata); + ret = ret && Objects.equals(uploadedTransientSettingsMetadata, that.uploadedTransientSettingsMetadata); + ret = ret && Objects.equals(uploadedHashesOfConsistentSettings, that.uploadedHashesOfConsistentSettings); + ret = ret && Objects.equals(uploadedClusterStateCustomMap, that.uploadedClusterStateCustomMap); + return ret; } @Override @@ -1234,6 +1271,19 @@ public static UploadedMetadataAttribute fromXContent(XContentParser parser) thro return PARSER.parse(parser, null, parser.currentName()); } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + UploadedMetadataAttribute that = (UploadedMetadataAttribute) o; + return Objects.equals(attributeName, that.attributeName) && Objects.equals(uploadedFilename, that.uploadedFilename); + } + + @Override + public int hashCode() { + return Objects.hash(attributeName, uploadedFilename); + } + @Override public String toString() { return "UploadedMetadataAttribute{" diff --git a/server/src/test/java/org/opensearch/gateway/remote/ClusterMetadataManifestTests.java b/server/src/test/java/org/opensearch/gateway/remote/ClusterMetadataManifestTests.java index 21893257b0dc5..e868004f90d60 100644 --- a/server/src/test/java/org/opensearch/gateway/remote/ClusterMetadataManifestTests.java +++ b/server/src/test/java/org/opensearch/gateway/remote/ClusterMetadataManifestTests.java @@ -33,6 +33,7 @@ import static org.opensearch.gateway.remote.ClusterMetadataManifest.CODEC_V0; import static org.opensearch.gateway.remote.ClusterMetadataManifest.CODEC_V1; +import static org.opensearch.gateway.remote.RemoteClusterStateAttributesManager.DISCOVERY_NODES; public class ClusterMetadataManifestTests extends OpenSearchTestCase { @@ -176,6 +177,8 @@ public void testClusterMetadataManifestSerializationEqualsHashCode() { ).stream().collect(Collectors.toMap(UploadedMetadataAttribute::getAttributeName, Function.identity())) ) .routingTableVersion(1L) + .discoveryNodesMetadata(new UploadedMetadataAttribute(DISCOVERY_NODES, "discovery-nodes-file")) + .build(); { // Mutate Cluster Term EqualsHashCodeTestUtils.checkEqualsAndHashCode( @@ -326,7 +329,7 @@ public void testClusterMetadataManifestXContentV2() throws IOException { .opensearchVersion(Version.CURRENT) .nodeId("test-node-id") .committed(false) - .codecVersion(ClusterMetadataManifest.CODEC_V3) + .codecVersion(ClusterMetadataManifest.CODEC_V2) .indices(Collections.singletonList(uploadedIndexMetadata)) .previousClusterUUID("prev-cluster-uuid") .clusterUUIDCommitted(true) @@ -353,7 +356,6 @@ public void testClusterMetadataManifestXContentV2() throws IOException { ) ).stream().collect(Collectors.toMap(UploadedMetadataAttribute::getAttributeName, Function.identity())) ) - .routingTableVersion(0) .build(); final XContentBuilder builder = JsonXContent.contentBuilder(); builder.startObject();