Skip to content

Commit 175cbd0

Browse files
himshikhaBukhtawar
andauthored
[Backport 2.17] Add cluster state checksum in manifest #15218 (#15658)
* Add cluster state checksum in manifest (#15218) Signed-off-by: Himshikha Gupta <[email protected]> Co-authored-by: Bukhtawar Khan <[email protected]>
1 parent 63524e3 commit 175cbd0

37 files changed

+2032
-52
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
4343
- Add support to upload snapshot shard blobs with hashed prefix ([#15426](https://github.com/opensearch-project/OpenSearch/pull/15426))
4444
- Add canRemain method to TargetPoolAllocationDecider to move shards from local to remote pool for hot to warm tiering ([#15010](https://github.com/opensearch-project/OpenSearch/pull/15010))
4545
- Add support for pluggable deciders for concurrent search ([#15363](https://github.com/opensearch-project/OpenSearch/pull/15363))
46+
- [Remote Publication] Added checksum validation for cluster state behind a cluster setting ([#15218](https://github.com/opensearch-project/OpenSearch/pull/15218))
4647

4748
### Dependencies
4849
- Bump `netty` from 4.1.111.Final to 4.1.112.Final ([#15081](https://github.com/opensearch-project/OpenSearch/pull/15081))

libs/core/src/main/java/org/opensearch/core/common/io/stream/StreamOutput.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ public final <K, V> void writeMapOfLists(final Map<K, List<V>> map, final Writer
633633
* @param keyWriter The key writer
634634
* @param valueWriter The value writer
635635
*/
636-
public final <K, V> void writeMap(final Map<K, V> map, final Writer<K> keyWriter, final Writer<V> valueWriter) throws IOException {
636+
public <K, V> void writeMap(final Map<K, V> map, final Writer<K> keyWriter, final Writer<V> valueWriter) throws IOException {
637637
writeVInt(map.size());
638638
for (final Map.Entry<K, V> entry : map.entrySet()) {
639639
keyWriter.write(this, entry.getKey());

server/src/internalClusterTest/java/org/opensearch/gateway/remote/RemoteRoutingTableServiceIT.java

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ protected Settings nodeSettings(int nodeOrdinal) {
6767
)
6868
.put("node.attr." + REMOTE_STORE_ROUTING_TABLE_REPOSITORY_NAME_ATTRIBUTE_KEY, REMOTE_ROUTING_TABLE_REPO)
6969
.put(REMOTE_PUBLICATION_EXPERIMENTAL, true)
70+
.put(RemoteClusterStateService.REMOTE_CLUSTER_STATE_CHECKSUM_VALIDATION_ENABLED_SETTING.getKey(), true)
7071
.build();
7172
}
7273

server/src/internalClusterTest/java/org/opensearch/gateway/remote/RemoteStatePublicationIT.java

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ protected Settings nodeSettings(int nodeOrdinal) {
9090
.put("node.attr." + REMOTE_STORE_ROUTING_TABLE_REPOSITORY_NAME_ATTRIBUTE_KEY, routingTableRepoName)
9191
.put(routingTableRepoTypeAttributeKey, ReloadableFsRepository.TYPE)
9292
.put(routingTableRepoSettingsAttributeKeyPrefix + "location", segmentRepoPath)
93+
.put(RemoteClusterStateService.REMOTE_CLUSTER_STATE_CHECKSUM_VALIDATION_ENABLED_SETTING.getKey(), true)
9394
.build();
9495
}
9596

server/src/main/java/org/opensearch/cluster/AbstractDiffable.java

+5
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ private static class CompleteDiff<T extends Diffable<T>> implements Diff<T> {
8383
this.part = part;
8484
}
8585

86+
@Override
87+
public String toString() {
88+
return "CompleteDiff{" + "part=" + part + '}';
89+
}
90+
8691
/**
8792
* Creates simple diff without changes
8893
*/

server/src/main/java/org/opensearch/cluster/ClusterState.java

+29-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ default boolean isPrivate() {
156156

157157
}
158158

159-
private static final NamedDiffableValueSerializer<Custom> CUSTOM_VALUE_SERIALIZER = new NamedDiffableValueSerializer<>(Custom.class);
159+
public static final NamedDiffableValueSerializer<Custom> CUSTOM_VALUE_SERIALIZER = new NamedDiffableValueSerializer<>(Custom.class);
160160

161161
public static final String UNKNOWN_UUID = "_na_";
162162

@@ -839,6 +839,34 @@ private static class ClusterStateDiff implements Diff<ClusterState> {
839839
minimumClusterManagerNodesOnPublishingClusterManager = after.minimumClusterManagerNodesOnPublishingClusterManager;
840840
}
841841

842+
@Override
843+
public String toString() {
844+
return new StringBuilder().append("ClusterStateDiff{toVersion=")
845+
.append(toVersion)
846+
.append(", fromUuid='")
847+
.append(fromUuid)
848+
.append('\'')
849+
.append(", toUuid='")
850+
.append(toUuid)
851+
.append('\'')
852+
.append(", clusterName=")
853+
.append(clusterName)
854+
.append(", routingTable=")
855+
.append(routingTable)
856+
.append(", nodes=")
857+
.append(nodes)
858+
.append(", metadata=")
859+
.append(metadata)
860+
.append(", blocks=")
861+
.append(blocks)
862+
.append(", customs=")
863+
.append(customs)
864+
.append(", minimumClusterManagerNodesOnPublishingClusterManager=")
865+
.append(minimumClusterManagerNodesOnPublishingClusterManager)
866+
.append("}")
867+
.toString();
868+
}
869+
842870
ClusterStateDiff(StreamInput in, DiscoveryNode localNode) throws IOException {
843871
clusterName = new ClusterName(in);
844872
fromUuid = in.readString();

server/src/main/java/org/opensearch/cluster/DiffableUtils.java

+12
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,18 @@ public Map<K, T> getUpserts() {
271271
return upserts;
272272
}
273273

274+
@Override
275+
public String toString() {
276+
return new StringBuilder().append("MapDiff{deletes=")
277+
.append(deletes)
278+
.append(", diffs=")
279+
.append(diffs)
280+
.append(", upserts=")
281+
.append(upserts)
282+
.append("}")
283+
.toString();
284+
}
285+
274286
@Override
275287
public void writeTo(StreamOutput out) throws IOException {
276288
out.writeCollection(deletes, (o, v) -> keySerializer.writeKey(v, o));

server/src/main/java/org/opensearch/cluster/block/ClusterBlock.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
* @opensearch.api
5353
*/
5454
@PublicApi(since = "1.0.0")
55-
public class ClusterBlock implements Writeable, ToXContentFragment {
55+
public class ClusterBlock implements Writeable, ToXContentFragment, Comparable<ClusterBlock> {
5656

5757
private final int id;
5858
@Nullable
@@ -217,7 +217,13 @@ public int hashCode() {
217217
return Objects.hash(id, uuid);
218218
}
219219

220+
@Override
221+
public int compareTo(ClusterBlock block) {
222+
return Integer.compare(block.id(), this.id());
223+
}
224+
220225
public boolean isAllowReleaseResources() {
221226
return allowReleaseResources;
222227
}
228+
223229
}

server/src/main/java/org/opensearch/cluster/block/ClusterBlocks.java

+5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.opensearch.core.common.io.stream.StreamInput;
4343
import org.opensearch.core.common.io.stream.StreamOutput;
4444
import org.opensearch.core.rest.RestStatus;
45+
import org.opensearch.index.translog.BufferedChecksumStreamOutput;
4546

4647
import java.io.IOException;
4748
import java.util.Collections;
@@ -303,6 +304,10 @@ public void writeTo(StreamOutput out) throws IOException {
303304
out.writeMap(indicesBlocks, StreamOutput::writeString, (o, s) -> writeBlockSet(s, o));
304305
}
305306

307+
public void writeVerifiableTo(BufferedChecksumStreamOutput out) throws IOException {
308+
writeTo(out);
309+
}
310+
306311
private static void writeBlockSet(Set<ClusterBlock> blocks, StreamOutput out) throws IOException {
307312
out.writeCollection(blocks);
308313
}

server/src/main/java/org/opensearch/cluster/coordination/CoordinationMetadata.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.opensearch.core.xcontent.ToXContentFragment;
4343
import org.opensearch.core.xcontent.XContentBuilder;
4444
import org.opensearch.core.xcontent.XContentParser;
45+
import org.opensearch.index.translog.BufferedChecksumStreamOutput;
4546

4647
import java.io.IOException;
4748
import java.util.Arrays;
@@ -149,6 +150,10 @@ public void writeTo(StreamOutput out) throws IOException {
149150
out.writeCollection(votingConfigExclusions);
150151
}
151152

153+
public void writeVerifiableTo(BufferedChecksumStreamOutput out) throws IOException {
154+
writeTo(out);
155+
}
156+
152157
@Override
153158
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
154159
return builder.field(TERM_PARSE_FIELD.getPreferredName(), term)
@@ -272,7 +277,7 @@ public CoordinationMetadata build() {
272277
* @opensearch.api
273278
*/
274279
@PublicApi(since = "1.0.0")
275-
public static class VotingConfigExclusion implements Writeable, ToXContentFragment {
280+
public static class VotingConfigExclusion implements Writeable, ToXContentFragment, Comparable<VotingConfigExclusion> {
276281
public static final String MISSING_VALUE_MARKER = "_absent_";
277282
private final String nodeId;
278283
private final String nodeName;
@@ -361,6 +366,10 @@ public String toString() {
361366
return sb.toString();
362367
}
363368

369+
@Override
370+
public int compareTo(VotingConfigExclusion votingConfigExclusion) {
371+
return votingConfigExclusion.getNodeId().compareTo(this.getNodeId());
372+
}
364373
}
365374

366375
/**

server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java

+27
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import org.opensearch.index.IndexModule;
7070
import org.opensearch.index.mapper.MapperService;
7171
import org.opensearch.index.seqno.SequenceNumbers;
72+
import org.opensearch.index.translog.BufferedChecksumStreamOutput;
7273
import org.opensearch.indices.replication.SegmentReplicationSource;
7374
import org.opensearch.indices.replication.common.ReplicationType;
7475

@@ -88,6 +89,7 @@
8889
import java.util.Map;
8990
import java.util.Objects;
9091
import java.util.Set;
92+
import java.util.TreeSet;
9193
import java.util.function.Function;
9294

9395
import static org.opensearch.cluster.metadata.Metadata.CONTEXT_MODE_PARAM;
@@ -1287,6 +1289,31 @@ public void writeTo(StreamOutput out) throws IOException {
12871289
}
12881290
}
12891291

1292+
public void writeVerifiableTo(BufferedChecksumStreamOutput out) throws IOException {
1293+
out.writeString(index.getName()); // uuid will come as part of settings
1294+
out.writeLong(version);
1295+
out.writeVLong(mappingVersion);
1296+
out.writeVLong(settingsVersion);
1297+
out.writeVLong(aliasesVersion);
1298+
out.writeInt(routingNumShards);
1299+
out.writeByte(state.id());
1300+
writeSettingsToStream(settings, out);
1301+
out.writeVLongArray(primaryTerms);
1302+
out.writeMapValues(mappings, (stream, val) -> val.writeTo(stream));
1303+
out.writeMapValues(aliases, (stream, val) -> val.writeTo(stream));
1304+
out.writeMap(customData, StreamOutput::writeString, (stream, val) -> val.writeTo(stream));
1305+
out.writeMap(
1306+
inSyncAllocationIds,
1307+
StreamOutput::writeVInt,
1308+
(stream, val) -> DiffableUtils.StringSetValueSerializer.getInstance().write(new TreeSet<>(val), stream)
1309+
);
1310+
out.writeMapValues(rolloverInfos, (stream, val) -> val.writeTo(stream));
1311+
out.writeBoolean(isSystem);
1312+
if (out.getVersion().onOrAfter(Version.V_2_17_0)) {
1313+
out.writeOptionalWriteable(context);
1314+
}
1315+
}
1316+
12901317
public boolean isSystem() {
12911318
return isSystem;
12921319
}

server/src/main/java/org/opensearch/cluster/metadata/IndexTemplateMetadata.java

+11
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import org.opensearch.core.xcontent.XContentBuilder;
5151
import org.opensearch.core.xcontent.XContentParser;
5252
import org.opensearch.index.mapper.MapperService;
53+
import org.opensearch.index.translog.BufferedChecksumStreamOutput;
5354

5455
import java.io.IOException;
5556
import java.io.UncheckedIOException;
@@ -257,6 +258,16 @@ public void writeTo(StreamOutput out) throws IOException {
257258
out.writeOptionalVInt(version);
258259
}
259260

261+
public void writeVerifiableTo(BufferedChecksumStreamOutput out) throws IOException {
262+
out.writeString(name);
263+
out.writeInt(order);
264+
out.writeStringCollection(patterns);
265+
Settings.writeSettingsToStream(settings, out);
266+
out.writeMap(mappings, StreamOutput::writeString, (stream, val) -> val.writeTo(stream));
267+
out.writeMapValues(aliases, (stream, val) -> val.writeTo(stream));
268+
out.writeOptionalVInt(version);
269+
}
270+
260271
@Override
261272
public String toString() {
262273
try {

server/src/main/java/org/opensearch/cluster/metadata/Metadata.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ static Custom fromXContent(XContentParser parser, String name) throws IOExceptio
254254

255255
public static final String GLOBAL_STATE_FILE_PREFIX = "global-";
256256

257-
private static final NamedDiffableValueSerializer<Custom> CUSTOM_VALUE_SERIALIZER = new NamedDiffableValueSerializer<>(Custom.class);
257+
public static final NamedDiffableValueSerializer<Custom> CUSTOM_VALUE_SERIALIZER = new NamedDiffableValueSerializer<>(Custom.class);
258258

259259
private final String clusterUUID;
260260
private final boolean clusterUUIDCommitted;

server/src/main/java/org/opensearch/cluster/metadata/TemplatesMetadata.java

+10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.opensearch.core.xcontent.ToXContentFragment;
1515
import org.opensearch.core.xcontent.XContentBuilder;
1616
import org.opensearch.core.xcontent.XContentParser;
17+
import org.opensearch.index.translog.BufferedChecksumStreamOutput;
1718

1819
import java.io.IOException;
1920
import java.util.Collections;
@@ -65,6 +66,10 @@ public void writeTo(StreamOutput out) throws IOException {
6566
}
6667
}
6768

69+
public void writeVerifiableTo(BufferedChecksumStreamOutput out) throws IOException {
70+
out.writeMapValues(templates, (stream, value) -> value.writeVerifiableTo((BufferedChecksumStreamOutput) stream));
71+
}
72+
6873
@Override
6974
public boolean equals(Object o) {
7075
if (this == o) return true;
@@ -80,6 +85,11 @@ public int hashCode() {
8085
return templates != null ? templates.hashCode() : 0;
8186
}
8287

88+
@Override
89+
public String toString() {
90+
return "TemplatesMetadata{" + "templates=" + templates + '}';
91+
}
92+
8393
/**
8494
* Builder for the templates metadata
8595
*

server/src/main/java/org/opensearch/cluster/node/DiscoveryNode.java

+20-6
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.opensearch.core.common.transport.TransportAddress;
4545
import org.opensearch.core.xcontent.ToXContentFragment;
4646
import org.opensearch.core.xcontent.XContentBuilder;
47+
import org.opensearch.index.translog.BufferedChecksumStreamOutput;
4748
import org.opensearch.node.Node;
4849

4950
import java.io.IOException;
@@ -397,12 +398,7 @@ public void writeToWithAttribute(StreamOutput out) throws IOException {
397398
}
398399

399400
public void writeToUtil(StreamOutput out, boolean includeAllAttributes) throws IOException {
400-
out.writeString(nodeName);
401-
out.writeString(nodeId);
402-
out.writeString(ephemeralId);
403-
out.writeString(hostName);
404-
out.writeString(hostAddress);
405-
address.writeTo(out);
401+
writeNodeDetails(out);
406402
if (includeAllAttributes) {
407403
out.writeVInt(attributes.size());
408404
for (Map.Entry<String, String> entry : attributes.entrySet()) {
@@ -412,7 +408,25 @@ public void writeToUtil(StreamOutput out, boolean includeAllAttributes) throws I
412408
} else {
413409
out.writeVInt(0);
414410
}
411+
writeRolesAndVersion(out);
412+
}
413+
414+
public void writeVerifiableTo(BufferedChecksumStreamOutput out) throws IOException {
415+
writeNodeDetails(out);
416+
out.writeMap(attributes, StreamOutput::writeString, StreamOutput::writeString);
417+
writeRolesAndVersion(out);
418+
}
419+
420+
private void writeNodeDetails(StreamOutput out) throws IOException {
421+
out.writeString(nodeName);
422+
out.writeString(nodeId);
423+
out.writeString(ephemeralId);
424+
out.writeString(hostName);
425+
out.writeString(hostAddress);
426+
address.writeTo(out);
427+
}
415428

429+
private void writeRolesAndVersion(StreamOutput out) throws IOException {
416430
if (out.getVersion().onOrAfter(LegacyESVersion.V_7_3_0)) {
417431
out.writeVInt(roles.size());
418432
for (final DiscoveryNodeRole role : roles) {

0 commit comments

Comments
 (0)