Skip to content

Commit

Permalink
add equal() to ClusterMetadataManifest
Browse files Browse the repository at this point in the history
Signed-off-by: Shivansh Arora <hishiv@amazon.com>
  • Loading branch information
shiv0408 committed Jun 7, 2024
1 parent eef8768 commit 99870a1
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ private static void declareParser(ConstructingObjectParser<ClusterMetadataManife
UPLOADED_CLUSTER_STATE_CUSTOM_METADATA
);
parser.declareObject(
ConstructingObjectParser.constructorArg(),
ConstructingObjectParser.optionalConstructorArg(),
(p, c) -> ClusterStateDiffManifest.fromXContent(p),
DIFF_MANIFEST
);
Expand Down Expand Up @@ -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)
);
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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{"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand All @@ -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();
Expand Down

0 comments on commit 99870a1

Please sign in to comment.