Skip to content

Commit a2fa7e6

Browse files
Sachin Kalegbbafna
Sachin Kale
andcommitted
Restore snapshot changes for V2
Signed-off-by: Sachin Kale <[email protected]> Co-authored-by: Gaurav Bafna <[email protected]>
1 parent 770a791 commit a2fa7e6

File tree

15 files changed

+457
-89
lines changed

15 files changed

+457
-89
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.remotestore;
10+
11+
import org.opensearch.common.settings.Settings;
12+
import org.opensearch.indices.RemoteStoreSettings;
13+
import org.opensearch.repositories.blobstore.BlobStoreRepository;
14+
import org.opensearch.test.OpenSearchIntegTestCase;
15+
16+
import java.nio.file.Path;
17+
18+
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;
19+
20+
@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0)
21+
public class RestoreShallowSnapshotV2IT extends RemoteRestoreSnapshotIT {
22+
@Override
23+
protected Settings nodeSettings(int nodeOrdinal) {
24+
return Settings.builder()
25+
.put(super.nodeSettings(nodeOrdinal))
26+
.put(RemoteStoreSettings.CLUSTER_REMOTE_STORE_PINNED_TIMESTAMP_ENABLED.getKey(), true)
27+
.build();
28+
}
29+
30+
@Override
31+
protected void createRepository(String repoName, String type, Settings.Builder settings) {
32+
logger.info("--> creating repository [{}] [{}]", repoName, type);
33+
settings.put(BlobStoreRepository.REMOTE_STORE_INDEX_SHALLOW_COPY.getKey(), true)
34+
.put(BlobStoreRepository.SHALLOW_SNAPSHOT_V2.getKey(), true);
35+
assertAcked(clusterAdmin().preparePutRepository(repoName).setType(type).setSettings(settings));
36+
}
37+
38+
@Override
39+
protected void createRepository(String repoName, String type, Path location) {
40+
Settings.Builder settings = Settings.builder()
41+
.put("location", location)
42+
.put(BlobStoreRepository.REMOTE_STORE_INDEX_SHALLOW_COPY.getKey(), true)
43+
.put(BlobStoreRepository.SHALLOW_SNAPSHOT_V2.getKey(), true);
44+
45+
createRepository(repoName, type, settings);
46+
}
47+
}

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/TransportSnapshotsStatusAction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ private Map<ShardId, IndexShardSnapshotStatus> snapshotShards(
447447
// could not be taken due to partial being set to false.
448448
shardSnapshotStatus = IndexShardSnapshotStatus.newFailed("skipped");
449449
} else {
450-
shardSnapshotStatus = repository.getShardSnapshotStatus(snapshotInfo.snapshotId(), indexId, shardId);
450+
shardSnapshotStatus = repository.getShardSnapshotStatus(snapshotInfo, indexId, shardId);
451451
}
452452
shardStatus.put(shardId, shardSnapshotStatus);
453453
}

server/src/main/java/org/opensearch/cluster/routing/RecoverySource.java

+60-5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
import java.io.IOException;
4949
import java.util.Objects;
5050

51+
import static org.opensearch.Version.CURRENT;
52+
5153
/**
5254
* Represents the recovery source of a shard. Available recovery types are:
5355
* <p>
@@ -264,6 +266,9 @@ public static class SnapshotRecoverySource extends RecoverySource {
264266
private final boolean isSearchableSnapshot;
265267
private final boolean remoteStoreIndexShallowCopy;
266268
private final String sourceRemoteStoreRepository;
269+
private final String sourceRemoteTranslogRepository;
270+
271+
private final long pinnedTimestamp;
267272

268273
public SnapshotRecoverySource(String restoreUUID, Snapshot snapshot, Version version, IndexId indexId) {
269274
this(restoreUUID, snapshot, version, indexId, false, false, null);
@@ -277,6 +282,30 @@ public SnapshotRecoverySource(
277282
boolean isSearchableSnapshot,
278283
boolean remoteStoreIndexShallowCopy,
279284
@Nullable String sourceRemoteStoreRepository
285+
) {
286+
this(
287+
restoreUUID,
288+
snapshot,
289+
version,
290+
indexId,
291+
isSearchableSnapshot,
292+
remoteStoreIndexShallowCopy,
293+
sourceRemoteStoreRepository,
294+
null,
295+
0L
296+
);
297+
}
298+
299+
public SnapshotRecoverySource(
300+
String restoreUUID,
301+
Snapshot snapshot,
302+
Version version,
303+
IndexId indexId,
304+
boolean isSearchableSnapshot,
305+
boolean remoteStoreIndexShallowCopy,
306+
@Nullable String sourceRemoteStoreRepository,
307+
@Nullable String sourceRemoteTranslogRepository,
308+
long pinnedTimestamp
280309
) {
281310
this.restoreUUID = restoreUUID;
282311
this.snapshot = Objects.requireNonNull(snapshot);
@@ -285,6 +314,8 @@ public SnapshotRecoverySource(
285314
this.isSearchableSnapshot = isSearchableSnapshot;
286315
this.remoteStoreIndexShallowCopy = remoteStoreIndexShallowCopy;
287316
this.sourceRemoteStoreRepository = sourceRemoteStoreRepository;
317+
this.sourceRemoteTranslogRepository = sourceRemoteTranslogRepository;
318+
this.pinnedTimestamp = pinnedTimestamp;
288319
}
289320

290321
SnapshotRecoverySource(StreamInput in) throws IOException {
@@ -304,6 +335,13 @@ public SnapshotRecoverySource(
304335
remoteStoreIndexShallowCopy = false;
305336
sourceRemoteStoreRepository = null;
306337
}
338+
if (in.getVersion().onOrAfter(CURRENT)) {
339+
sourceRemoteTranslogRepository = in.readOptionalString();
340+
pinnedTimestamp = in.readLong();
341+
} else {
342+
sourceRemoteTranslogRepository = null;
343+
pinnedTimestamp = 0L;
344+
}
307345
}
308346

309347
public String restoreUUID() {
@@ -336,10 +374,18 @@ public String sourceRemoteStoreRepository() {
336374
return sourceRemoteStoreRepository;
337375
}
338376

377+
public String sourceRemoteTranslogRepository() {
378+
return sourceRemoteTranslogRepository;
379+
}
380+
339381
public boolean remoteStoreIndexShallowCopy() {
340382
return remoteStoreIndexShallowCopy;
341383
}
342384

385+
public long pinnedTimestamp() {
386+
return pinnedTimestamp;
387+
}
388+
343389
@Override
344390
protected void writeAdditionalFields(StreamOutput out) throws IOException {
345391
out.writeString(restoreUUID);
@@ -353,6 +399,10 @@ protected void writeAdditionalFields(StreamOutput out) throws IOException {
353399
out.writeBoolean(remoteStoreIndexShallowCopy);
354400
out.writeOptionalString(sourceRemoteStoreRepository);
355401
}
402+
if (out.getVersion().onOrAfter(CURRENT)) {
403+
out.writeOptionalString(sourceRemoteTranslogRepository);
404+
out.writeLong(pinnedTimestamp);
405+
}
356406
}
357407

358408
@Override
@@ -369,7 +419,8 @@ public void addAdditionalFields(XContentBuilder builder, ToXContent.Params param
369419
.field("restoreUUID", restoreUUID)
370420
.field("isSearchableSnapshot", isSearchableSnapshot)
371421
.field("remoteStoreIndexShallowCopy", remoteStoreIndexShallowCopy)
372-
.field("sourceRemoteStoreRepository", sourceRemoteStoreRepository);
422+
.field("sourceRemoteStoreRepository", sourceRemoteStoreRepository)
423+
.field("sourceRemoteTranslogRepository", sourceRemoteTranslogRepository);
373424
}
374425

375426
@Override
@@ -394,8 +445,11 @@ public boolean equals(Object o) {
394445
&& isSearchableSnapshot == that.isSearchableSnapshot
395446
&& remoteStoreIndexShallowCopy == that.remoteStoreIndexShallowCopy
396447
&& sourceRemoteStoreRepository != null
397-
? sourceRemoteStoreRepository.equals(that.sourceRemoteStoreRepository)
398-
: that.sourceRemoteStoreRepository == null;
448+
? sourceRemoteStoreRepository.equals(that.sourceRemoteStoreRepository)
449+
: that.sourceRemoteStoreRepository == null && sourceRemoteTranslogRepository != null
450+
? sourceRemoteTranslogRepository.equals(that.sourceRemoteTranslogRepository)
451+
: that.sourceRemoteTranslogRepository == null && pinnedTimestamp == that.pinnedTimestamp;
452+
399453
}
400454

401455
@Override
@@ -407,10 +461,11 @@ public int hashCode() {
407461
version,
408462
isSearchableSnapshot,
409463
remoteStoreIndexShallowCopy,
410-
sourceRemoteStoreRepository
464+
sourceRemoteStoreRepository,
465+
sourceRemoteTranslogRepository,
466+
pinnedTimestamp
411467
);
412468
}
413-
414469
}
415470

416471
/**

0 commit comments

Comments
 (0)