Skip to content

Commit 983a483

Browse files
dhwanilpatelshiv0408
authored andcommitted
Upload global cluster state to remote store (opensearch-project#10404)
* Upload global cluster state to remote store Signed-off-by: Dhwanil Patel <[email protected]> Signed-off-by: Shivansh Arora <[email protected]>
1 parent a8afdfa commit 983a483

File tree

9 files changed

+617
-39
lines changed

9 files changed

+617
-39
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1414
- Provide service accounts tokens to extensions ([#9618](https://github.com/opensearch-project/OpenSearch/pull/9618))
1515
- [Admission control] Add enhancements to FS stats to include read/write time, queue size and IO time ([#10541](https://github.com/opensearch-project/OpenSearch/pull/10541))
1616
- [Admission control] Add Resource usage collector service and resource usage tracker ([#9890](https://github.com/opensearch-project/OpenSearch/pull/9890))
17-
- Change file names for remote cluster state ([#10557](https://github.com/opensearch-project/OpenSearch/pull/10557))
17+
- [Remote cluster state] Change file names for remote cluster state ([#10557](https://github.com/opensearch-project/OpenSearch/pull/10557))
18+
- [Remote cluster state] Upload global metadata in cluster state to remote store([#10404](https://github.com/opensearch-project/OpenSearch/pull/10404))
1819

1920
### Dependencies
2021
- Bump `log4j-core` from 2.18.0 to 2.19.0
@@ -121,4 +122,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
121122
### Security
122123

123124
[Unreleased 3.0]: https://github.com/opensearch-project/OpenSearch/compare/2.x...HEAD
124-
[Unreleased 2.x]: https://github.com/opensearch-project/OpenSearch/compare/2.12...2.x
125+
[Unreleased 2.x]: https://github.com/opensearch-project/OpenSearch/compare/2.12...2.x

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

Lines changed: 115 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,18 @@
3333
*/
3434
public class ClusterMetadataManifest implements Writeable, ToXContentFragment {
3535

36+
public static final int CODEC_V0 = 0; // Older codec version, where we haven't introduced codec versions for manifest.
37+
public static final int CODEC_V1 = 1; // In Codec V1 we have introduced global-metadata and codec version in Manifest file.
38+
3639
private static final ParseField CLUSTER_TERM_FIELD = new ParseField("cluster_term");
3740
private static final ParseField STATE_VERSION_FIELD = new ParseField("state_version");
3841
private static final ParseField CLUSTER_UUID_FIELD = new ParseField("cluster_uuid");
3942
private static final ParseField STATE_UUID_FIELD = new ParseField("state_uuid");
4043
private static final ParseField OPENSEARCH_VERSION_FIELD = new ParseField("opensearch_version");
4144
private static final ParseField NODE_ID_FIELD = new ParseField("node_id");
4245
private static final ParseField COMMITTED_FIELD = new ParseField("committed");
46+
private static final ParseField CODEC_VERSION_FIELD = new ParseField("codec_version");
47+
private static final ParseField GLOBAL_METADATA_FIELD = new ParseField("global_metadata");
4348
private static final ParseField INDICES_FIELD = new ParseField("indices");
4449
private static final ParseField PREVIOUS_CLUSTER_UUID = new ParseField("previous_cluster_uuid");
4550
private static final ParseField CLUSTER_UUID_COMMITTED = new ParseField("cluster_uuid_committed");
@@ -84,7 +89,33 @@ private static boolean clusterUUIDCommitted(Object[] fields) {
8489
return (boolean) fields[9];
8590
}
8691

87-
private static final ConstructingObjectParser<ClusterMetadataManifest, Void> PARSER = new ConstructingObjectParser<>(
92+
private static int codecVersion(Object[] fields) {
93+
return (int) fields[10];
94+
}
95+
96+
private static String globalMetadataFileName(Object[] fields) {
97+
return (String) fields[11];
98+
}
99+
100+
private static final ConstructingObjectParser<ClusterMetadataManifest, Void> PARSER_V0 = new ConstructingObjectParser<>(
101+
"cluster_metadata_manifest",
102+
fields -> new ClusterMetadataManifest(
103+
term(fields),
104+
version(fields),
105+
clusterUUID(fields),
106+
stateUUID(fields),
107+
opensearchVersion(fields),
108+
nodeId(fields),
109+
committed(fields),
110+
CODEC_V0,
111+
null,
112+
indices(fields),
113+
previousClusterUUID(fields),
114+
clusterUUIDCommitted(fields)
115+
)
116+
);
117+
118+
private static final ConstructingObjectParser<ClusterMetadataManifest, Void> PARSER_V1 = new ConstructingObjectParser<>(
88119
"cluster_metadata_manifest",
89120
fields -> new ClusterMetadataManifest(
90121
term(fields),
@@ -94,29 +125,45 @@ private static boolean clusterUUIDCommitted(Object[] fields) {
94125
opensearchVersion(fields),
95126
nodeId(fields),
96127
committed(fields),
128+
codecVersion(fields),
129+
globalMetadataFileName(fields),
97130
indices(fields),
98131
previousClusterUUID(fields),
99132
clusterUUIDCommitted(fields)
100133
)
101134
);
102135

136+
private static final ConstructingObjectParser<ClusterMetadataManifest, Void> CURRENT_PARSER = PARSER_V1;
137+
103138
static {
104-
PARSER.declareLong(ConstructingObjectParser.constructorArg(), CLUSTER_TERM_FIELD);
105-
PARSER.declareLong(ConstructingObjectParser.constructorArg(), STATE_VERSION_FIELD);
106-
PARSER.declareString(ConstructingObjectParser.constructorArg(), CLUSTER_UUID_FIELD);
107-
PARSER.declareString(ConstructingObjectParser.constructorArg(), STATE_UUID_FIELD);
108-
PARSER.declareInt(ConstructingObjectParser.constructorArg(), OPENSEARCH_VERSION_FIELD);
109-
PARSER.declareString(ConstructingObjectParser.constructorArg(), NODE_ID_FIELD);
110-
PARSER.declareBoolean(ConstructingObjectParser.constructorArg(), COMMITTED_FIELD);
111-
PARSER.declareObjectArray(
139+
declareParser(PARSER_V0, CODEC_V0);
140+
declareParser(PARSER_V1, CODEC_V1);
141+
}
142+
143+
private static void declareParser(ConstructingObjectParser<ClusterMetadataManifest, Void> parser, long codec_version) {
144+
parser.declareLong(ConstructingObjectParser.constructorArg(), CLUSTER_TERM_FIELD);
145+
parser.declareLong(ConstructingObjectParser.constructorArg(), STATE_VERSION_FIELD);
146+
parser.declareString(ConstructingObjectParser.constructorArg(), CLUSTER_UUID_FIELD);
147+
parser.declareString(ConstructingObjectParser.constructorArg(), STATE_UUID_FIELD);
148+
parser.declareInt(ConstructingObjectParser.constructorArg(), OPENSEARCH_VERSION_FIELD);
149+
parser.declareString(ConstructingObjectParser.constructorArg(), NODE_ID_FIELD);
150+
parser.declareBoolean(ConstructingObjectParser.constructorArg(), COMMITTED_FIELD);
151+
parser.declareObjectArray(
112152
ConstructingObjectParser.constructorArg(),
113153
(p, c) -> UploadedIndexMetadata.fromXContent(p),
114154
INDICES_FIELD
115155
);
116-
PARSER.declareString(ConstructingObjectParser.constructorArg(), PREVIOUS_CLUSTER_UUID);
117-
PARSER.declareBoolean(ConstructingObjectParser.constructorArg(), CLUSTER_UUID_COMMITTED);
156+
parser.declareString(ConstructingObjectParser.constructorArg(), PREVIOUS_CLUSTER_UUID);
157+
parser.declareBoolean(ConstructingObjectParser.constructorArg(), CLUSTER_UUID_COMMITTED);
158+
159+
if (codec_version >= CODEC_V1) {
160+
parser.declareInt(ConstructingObjectParser.constructorArg(), CODEC_VERSION_FIELD);
161+
parser.declareString(ConstructingObjectParser.constructorArg(), GLOBAL_METADATA_FIELD);
162+
}
118163
}
119164

165+
private final int codecVersion;
166+
private final String globalMetadataFileName;
120167
private final List<UploadedIndexMetadata> indices;
121168
private final long clusterTerm;
122169
private final long stateVersion;
@@ -168,6 +215,14 @@ public boolean isClusterUUIDCommitted() {
168215
return clusterUUIDCommitted;
169216
}
170217

218+
public int getCodecVersion() {
219+
return codecVersion;
220+
}
221+
222+
public String getGlobalMetadataFileName() {
223+
return globalMetadataFileName;
224+
}
225+
171226
public ClusterMetadataManifest(
172227
long clusterTerm,
173228
long version,
@@ -176,6 +231,8 @@ public ClusterMetadataManifest(
176231
Version opensearchVersion,
177232
String nodeId,
178233
boolean committed,
234+
int codecVersion,
235+
String globalMetadataFileName,
179236
List<UploadedIndexMetadata> indices,
180237
String previousClusterUUID,
181238
boolean clusterUUIDCommitted
@@ -187,6 +244,8 @@ public ClusterMetadataManifest(
187244
this.opensearchVersion = opensearchVersion;
188245
this.nodeId = nodeId;
189246
this.committed = committed;
247+
this.codecVersion = codecVersion;
248+
this.globalMetadataFileName = globalMetadataFileName;
190249
this.indices = Collections.unmodifiableList(indices);
191250
this.previousClusterUUID = previousClusterUUID;
192251
this.clusterUUIDCommitted = clusterUUIDCommitted;
@@ -203,6 +262,13 @@ public ClusterMetadataManifest(StreamInput in) throws IOException {
203262
this.indices = Collections.unmodifiableList(in.readList(UploadedIndexMetadata::new));
204263
this.previousClusterUUID = in.readString();
205264
this.clusterUUIDCommitted = in.readBoolean();
265+
if (in.getVersion().onOrAfter(Version.V_3_0_0)) {
266+
this.codecVersion = in.readInt();
267+
this.globalMetadataFileName = in.readString();
268+
} else {
269+
this.codecVersion = CODEC_V0; // Default codec
270+
this.globalMetadataFileName = null;
271+
}
206272
}
207273

208274
public static Builder builder() {
@@ -231,6 +297,10 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
231297
builder.endArray();
232298
builder.field(PREVIOUS_CLUSTER_UUID.getPreferredName(), getPreviousClusterUUID());
233299
builder.field(CLUSTER_UUID_COMMITTED.getPreferredName(), isClusterUUIDCommitted());
300+
if (onOrAfterCodecVersion(CODEC_V1)) {
301+
builder.field(CODEC_VERSION_FIELD.getPreferredName(), getCodecVersion());
302+
builder.field(GLOBAL_METADATA_FIELD.getPreferredName(), getGlobalMetadataFileName());
303+
}
234304
return builder;
235305
}
236306

@@ -246,6 +316,10 @@ public void writeTo(StreamOutput out) throws IOException {
246316
out.writeCollection(indices);
247317
out.writeString(previousClusterUUID);
248318
out.writeBoolean(clusterUUIDCommitted);
319+
if (out.getVersion().onOrAfter(Version.V_3_0_0)) {
320+
out.writeInt(codecVersion);
321+
out.writeString(globalMetadataFileName);
322+
}
249323
}
250324

251325
@Override
@@ -266,12 +340,16 @@ public boolean equals(Object o) {
266340
&& Objects.equals(nodeId, that.nodeId)
267341
&& Objects.equals(committed, that.committed)
268342
&& Objects.equals(previousClusterUUID, that.previousClusterUUID)
269-
&& Objects.equals(clusterUUIDCommitted, that.clusterUUIDCommitted);
343+
&& Objects.equals(clusterUUIDCommitted, that.clusterUUIDCommitted)
344+
&& Objects.equals(globalMetadataFileName, that.globalMetadataFileName)
345+
&& Objects.equals(codecVersion, that.codecVersion);
270346
}
271347

272348
@Override
273349
public int hashCode() {
274350
return Objects.hash(
351+
codecVersion,
352+
globalMetadataFileName,
275353
indices,
276354
clusterTerm,
277355
stateVersion,
@@ -290,8 +368,16 @@ public String toString() {
290368
return Strings.toString(MediaTypeRegistry.JSON, this);
291369
}
292370

371+
public boolean onOrAfterCodecVersion(int codecVersion) {
372+
return this.codecVersion >= codecVersion;
373+
}
374+
375+
public static ClusterMetadataManifest fromXContentV0(XContentParser parser) throws IOException {
376+
return PARSER_V0.parse(parser, null);
377+
}
378+
293379
public static ClusterMetadataManifest fromXContent(XContentParser parser) throws IOException {
294-
return PARSER.parse(parser, null);
380+
return CURRENT_PARSER.parse(parser, null);
295381
}
296382

297383
/**
@@ -301,6 +387,8 @@ public static ClusterMetadataManifest fromXContent(XContentParser parser) throws
301387
*/
302388
public static class Builder {
303389

390+
private String globalMetadataFileName;
391+
private int codecVersion;
304392
private List<UploadedIndexMetadata> indices;
305393
private long clusterTerm;
306394
private long stateVersion;
@@ -317,6 +405,16 @@ public Builder indices(List<UploadedIndexMetadata> indices) {
317405
return this;
318406
}
319407

408+
public Builder codecVersion(int codecVersion) {
409+
this.codecVersion = codecVersion;
410+
return this;
411+
}
412+
413+
public Builder globalMetadataFileName(String globalMetadataFileName) {
414+
this.globalMetadataFileName = globalMetadataFileName;
415+
return this;
416+
}
417+
320418
public Builder clusterTerm(long clusterTerm) {
321419
this.clusterTerm = clusterTerm;
322420
return this;
@@ -378,6 +476,8 @@ public Builder(ClusterMetadataManifest manifest) {
378476
this.opensearchVersion = manifest.opensearchVersion;
379477
this.nodeId = manifest.nodeId;
380478
this.committed = manifest.committed;
479+
this.globalMetadataFileName = manifest.globalMetadataFileName;
480+
this.codecVersion = manifest.codecVersion;
381481
this.indices = new ArrayList<>(manifest.indices);
382482
this.previousClusterUUID = manifest.previousClusterUUID;
383483
this.clusterUUIDCommitted = manifest.clusterUUIDCommitted;
@@ -392,6 +492,8 @@ public ClusterMetadataManifest build() {
392492
opensearchVersion,
393493
nodeId,
394494
committed,
495+
codecVersion,
496+
globalMetadataFileName,
395497
indices,
396498
previousClusterUUID,
397499
clusterUUIDCommitted

0 commit comments

Comments
 (0)