Skip to content

Commit c5ef40f

Browse files
author
Anshu Agarwal
committed
Merge branch 'main' into snapshot-pinned-timestamp-delete
Signed-off-by: Anshu Agarwal <anshukag@amazon.com>
2 parents 54bee31 + a60b668 commit c5ef40f

File tree

51 files changed

+2007
-465
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2007
-465
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
4646
- [Remote Publication] Add remote download stats ([#15291](https://github.com/opensearch-project/OpenSearch/pull/15291)))
4747
- Add support for comma-separated list of index names to be used with Snapshot Status API ([#15409](https://github.com/opensearch-project/OpenSearch/pull/15409))
4848
- Add prefix support to hashed prefix & infix path types on remote store ([#15557](https://github.com/opensearch-project/OpenSearch/pull/15557))
49+
- Optimise snapshot deletion to speed up snapshot deletion and creation ([#15568](https://github.com/opensearch-project/OpenSearch/pull/15568))
4950
- [Remote Publication] Added checksum validation for cluster state behind a cluster setting ([#15218](https://github.com/opensearch-project/OpenSearch/pull/15218))
5051

5152
### Dependencies

client/rest-high-level/src/test/java/org/opensearch/client/SnapshotRequestConvertersTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public void testSnapshotsStatus() {
238238
boolean ignoreUnavailable = randomBoolean();
239239
String endpoint = "/_snapshot/" + repository + "/" + snapshotNames.toString() + "/_status";
240240

241-
SnapshotsStatusRequest snapshotsStatusRequest = new SnapshotsStatusRequest(repository, snapshots, indices);
241+
SnapshotsStatusRequest snapshotsStatusRequest = (new SnapshotsStatusRequest(repository, snapshots)).indices(indices);
242242
RequestConvertersTests.setRandomClusterManagerTimeout(snapshotsStatusRequest, expectedParams);
243243
snapshotsStatusRequest.ignoreUnavailable(ignoreUnavailable);
244244
expectedParams.put("ignore_unavailable", Boolean.toString(ignoreUnavailable));

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -969,9 +969,13 @@ public <T extends Writeable> void writeOptionalArray(@Nullable T[] array) throws
969969
}
970970

971971
public void writeOptionalWriteable(@Nullable Writeable writeable) throws IOException {
972+
writeOptionalWriteable((out, writable) -> writable.writeTo(out), writeable);
973+
}
974+
975+
public <T extends Writeable> void writeOptionalWriteable(final Writer<T> writer, @Nullable T writeable) throws IOException {
972976
if (writeable != null) {
973977
writeBoolean(true);
974-
writeable.writeTo(this);
978+
writer.write(this, writeable);
975979
} else {
976980
writeBoolean(false);
977981
}

qa/repository-multi-version/src/test/java/org/opensearch/upgrades/MultiVersionRepositoryAccessIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public void testUpgradeMovesRepoToNewMetaVersion() throws IOException {
243243
private static void assertSnapshotStatusSuccessful(RestHighLevelClient client, String repoName,
244244
String[] snapshots, String[] indices) throws IOException {
245245
final SnapshotsStatusResponse statusResponse = client.snapshot()
246-
.status(new SnapshotsStatusRequest(repoName, snapshots, indices), RequestOptions.DEFAULT);
246+
.status((new SnapshotsStatusRequest(repoName, snapshots)).indices(indices), RequestOptions.DEFAULT);
247247
for (SnapshotStatus status : statusResponse.getSnapshots()) {
248248
assertThat(status.getShardsStats().getFailedShards(), is(0));
249249
}

server/src/internalClusterTest/java/org/opensearch/remotestore/RestoreShallowSnapshotV2IT.java

+805
Large diffs are not rendered by default.

server/src/main/java/org/opensearch/action/admin/cluster/allocation/ClusterAllocationExplanation.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public ClusterAllocationExplanation(StreamInput in) throws IOException {
9595
@Override
9696
public void writeTo(StreamOutput out) throws IOException {
9797
shardRouting.writeTo(out);
98-
out.writeOptionalWriteable(currentNode);
98+
out.writeOptionalWriteable((stream, node) -> node.writeToWithAttribute(stream), currentNode);
9999
out.writeOptionalWriteable(relocationTargetNode);
100100
out.writeOptionalWriteable(clusterInfo);
101101
shardAllocationDecision.writeTo(out);

server/src/main/java/org/opensearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequest.java

+34-2
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ private static StorageType fromString(String string) {
121121
private StorageType storageType = StorageType.LOCAL;
122122
@Nullable
123123
private String sourceRemoteStoreRepository = null;
124+
@Nullable
125+
private String sourceRemoteTranslogRepository = null;
124126

125127
@Nullable // if any snapshot UUID will do
126128
private String snapshotUuid;
@@ -159,6 +161,9 @@ public RestoreSnapshotRequest(StreamInput in) throws IOException {
159161
if (in.getVersion().onOrAfter(Version.V_2_10_0)) {
160162
sourceRemoteStoreRepository = in.readOptionalString();
161163
}
164+
if (in.getVersion().onOrAfter(Version.CURRENT)) {
165+
sourceRemoteTranslogRepository = in.readOptionalString();
166+
}
162167
}
163168

164169
@Override
@@ -183,6 +188,9 @@ public void writeTo(StreamOutput out) throws IOException {
183188
if (out.getVersion().onOrAfter(Version.V_2_10_0)) {
184189
out.writeOptionalString(sourceRemoteStoreRepository);
185190
}
191+
if (out.getVersion().onOrAfter(Version.CURRENT)) {
192+
out.writeOptionalString(sourceRemoteTranslogRepository);
193+
}
186194
}
187195

188196
@Override
@@ -545,6 +553,16 @@ public RestoreSnapshotRequest setSourceRemoteStoreRepository(String sourceRemote
545553
return this;
546554
}
547555

556+
/**
557+
* Sets Source Remote Translog Repository for all the restored indices
558+
*
559+
* @param sourceRemoteTranslogRepository name of the remote translog repository that should be used for all restored indices.
560+
*/
561+
public RestoreSnapshotRequest setSourceRemoteTranslogRepository(String sourceRemoteTranslogRepository) {
562+
this.sourceRemoteTranslogRepository = sourceRemoteTranslogRepository;
563+
return this;
564+
}
565+
548566
/**
549567
* Returns Source Remote Store Repository for all the restored indices
550568
*
@@ -554,6 +572,15 @@ public String getSourceRemoteStoreRepository() {
554572
return sourceRemoteStoreRepository;
555573
}
556574

575+
/**
576+
* Returns Source Remote Translog Repository for all the restored indices
577+
*
578+
* @return source Remote Translog Repository
579+
*/
580+
public String getSourceRemoteTranslogRepository() {
581+
return sourceRemoteTranslogRepository;
582+
}
583+
557584
/**
558585
* Parses restore definition
559586
*
@@ -673,6 +700,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
673700
if (sourceRemoteStoreRepository != null) {
674701
builder.field("source_remote_store_repository", sourceRemoteStoreRepository);
675702
}
703+
if (sourceRemoteTranslogRepository != null) {
704+
builder.field("source_remote_translog_repository", sourceRemoteTranslogRepository);
705+
}
676706
builder.endObject();
677707
return builder;
678708
}
@@ -701,7 +731,8 @@ public boolean equals(Object o) {
701731
&& Arrays.equals(ignoreIndexSettings, that.ignoreIndexSettings)
702732
&& Objects.equals(snapshotUuid, that.snapshotUuid)
703733
&& Objects.equals(storageType, that.storageType)
704-
&& Objects.equals(sourceRemoteStoreRepository, that.sourceRemoteStoreRepository);
734+
&& Objects.equals(sourceRemoteStoreRepository, that.sourceRemoteStoreRepository)
735+
&& Objects.equals(sourceRemoteTranslogRepository, that.sourceRemoteTranslogRepository);
705736
return equals;
706737
}
707738

@@ -721,7 +752,8 @@ public int hashCode() {
721752
indexSettings,
722753
snapshotUuid,
723754
storageType,
724-
sourceRemoteStoreRepository
755+
sourceRemoteStoreRepository,
756+
sourceRemoteTranslogRepository
725757
);
726758
result = 31 * result + Arrays.hashCode(indices);
727759
result = 31 * result + Arrays.hashCode(ignoreIndexSettings);

server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/SnapshotsStatusRequest.java

+12
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ public SnapshotsStatusRequest() {}
6767
* @param repository repository name
6868
* @param snapshots list of snapshots
6969
*/
70+
public SnapshotsStatusRequest(String repository, String[] snapshots) {
71+
this.repository = repository;
72+
this.snapshots = snapshots;
73+
}
74+
75+
/**
76+
* Constructs a new get snapshots request with given repository name and list of snapshots
77+
*
78+
* @param repository repository name
79+
* @param snapshots list of snapshots
80+
* @param indices list of indices
81+
*/
7082
public SnapshotsStatusRequest(String repository, String[] snapshots, String[] indices) {
7183
this.repository = repository;
7284
this.snapshots = snapshots;

server/src/main/java/org/opensearch/action/support/nodes/BaseNodeResponse.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,6 @@ public DiscoveryNode getNode() {
6767

6868
@Override
6969
public void writeTo(StreamOutput out) throws IOException {
70-
node.writeTo(out);
70+
node.writeToWithAttribute(out);
7171
}
7272
}

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

+12-2
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ public void writeTo(StreamOutput out) throws IOException {
781781
out.writeString(stateUUID);
782782
metadata.writeTo(out);
783783
routingTable.writeTo(out);
784-
nodes.writeTo(out);
784+
nodes.writeToWithAttribute(out);
785785
blocks.writeTo(out);
786786
// filter out custom states not supported by the other node
787787
int numberOfCustoms = 0;
@@ -887,13 +887,23 @@ public void writeTo(StreamOutput out) throws IOException {
887887
out.writeString(toUuid);
888888
out.writeLong(toVersion);
889889
routingTable.writeTo(out);
890-
nodes.writeTo(out);
890+
nodesWriteToWithAttributes(nodes, out);
891891
metadata.writeTo(out);
892892
blocks.writeTo(out);
893893
customs.writeTo(out);
894894
out.writeVInt(minimumClusterManagerNodesOnPublishingClusterManager);
895895
}
896896

897+
private void nodesWriteToWithAttributes(Diff<DiscoveryNodes> nodes, StreamOutput out) throws IOException {
898+
DiscoveryNodes part = nodes.apply(null);
899+
if (part != null) {
900+
out.writeBoolean(true);
901+
part.writeToWithAttribute(out);
902+
} else {
903+
out.writeBoolean(false);
904+
}
905+
}
906+
897907
@Override
898908
public ClusterState apply(ClusterState state) {
899909
Builder builder = new Builder(clusterName);

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ public Join(StreamInput in) throws IOException {
7878

7979
@Override
8080
public void writeTo(StreamOutput out) throws IOException {
81-
sourceNode.writeTo(out);
82-
targetNode.writeTo(out);
81+
sourceNode.writeToWithAttribute(out);
82+
targetNode.writeToWithAttribute(out);
8383
out.writeLong(term);
8484
out.writeLong(lastAcceptedTerm);
8585
out.writeLong(lastAcceptedVersion);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public JoinRequest(StreamInput in) throws IOException {
8484
@Override
8585
public void writeTo(StreamOutput out) throws IOException {
8686
super.writeTo(out);
87-
sourceNode.writeTo(out);
87+
sourceNode.writeToWithAttribute(out);
8888
out.writeLong(minimumTerm);
8989
out.writeOptionalWriteable(optionalJoin.orElse(null));
9090
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public StartJoinRequest(StreamInput input) throws IOException {
6464
@Override
6565
public void writeTo(StreamOutput out) throws IOException {
6666
super.writeTo(out);
67-
sourceNode.writeTo(out);
67+
sourceNode.writeToWithAttribute(out);
6868
out.writeLong(term);
6969
}
7070

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

+23-4
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ public DiscoveryNode(StreamInput in) throws IOException {
330330
for (int i = 0; i < size; i++) {
331331
this.attributes.put(in.readString(), in.readString());
332332
}
333+
333334
int rolesSize = in.readVInt();
334335
final Set<DiscoveryNodeRole> roles = new HashSet<>(rolesSize);
335336
for (int i = 0; i < rolesSize; i++) {
@@ -359,13 +360,31 @@ public DiscoveryNode(StreamInput in) throws IOException {
359360

360361
@Override
361362
public void writeTo(StreamOutput out) throws IOException {
363+
if (out.getVersion().onOrAfter(Version.V_3_0_0)) {
364+
writeToUtil(out, false);
365+
} else {
366+
writeToUtil(out, true);
367+
}
368+
369+
}
370+
371+
public void writeToWithAttribute(StreamOutput out) throws IOException {
372+
writeToUtil(out, true);
373+
}
374+
375+
public void writeToUtil(StreamOutput out, boolean includeAllAttributes) throws IOException {
362376
writeNodeDetails(out);
363377

364-
out.writeVInt(attributes.size());
365-
for (Map.Entry<String, String> entry : attributes.entrySet()) {
366-
out.writeString(entry.getKey());
367-
out.writeString(entry.getValue());
378+
if (includeAllAttributes) {
379+
out.writeVInt(attributes.size());
380+
for (Map.Entry<String, String> entry : attributes.entrySet()) {
381+
out.writeString(entry.getKey());
382+
out.writeString(entry.getValue());
383+
}
384+
} else {
385+
out.writeVInt(0);
368386
}
387+
369388
writeRolesAndVersion(out);
370389
}
371390

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -690,10 +690,18 @@ public String shortSummary() {
690690

691691
@Override
692692
public void writeTo(StreamOutput out) throws IOException {
693+
writeToUtil((output, value) -> value.writeTo(output), out);
694+
}
695+
696+
public void writeToWithAttribute(StreamOutput out) throws IOException {
697+
writeToUtil((output, value) -> value.writeToWithAttribute(output), out);
698+
}
699+
700+
public void writeToUtil(final Writer<DiscoveryNode> writer, StreamOutput out) throws IOException {
693701
writeClusterManager(out);
694702
out.writeVInt(nodes.size());
695703
for (DiscoveryNode node : this) {
696-
node.writeTo(out);
704+
writer.write(out, node);
697705
}
698706
}
699707

0 commit comments

Comments
 (0)