Skip to content

Commit 68f2190

Browse files
sachinpkaleSachin Kalegbbafna
committed
Restore snapshot changes for shallow snapshot V2 (#15462)
--------- Signed-off-by: Sachin Kale <[email protected]> Co-authored-by: Sachin Kale <[email protected]> Co-authored-by: Gaurav Bafna <[email protected]>
1 parent dac70e8 commit 68f2190

File tree

14 files changed

+1245
-94
lines changed

14 files changed

+1245
-94
lines changed

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

Lines changed: 805 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ private static StorageType fromString(String string) {
122122
private StorageType storageType = StorageType.LOCAL;
123123
@Nullable
124124
private String sourceRemoteStoreRepository = null;
125+
@Nullable
126+
private String sourceRemoteTranslogRepository = null;
125127

126128
@Nullable // if any snapshot UUID will do
127129
private String snapshotUuid;
@@ -165,6 +167,9 @@ public RestoreSnapshotRequest(StreamInput in) throws IOException {
165167
if (in.getVersion().onOrAfter(Version.V_2_10_0)) {
166168
sourceRemoteStoreRepository = in.readOptionalString();
167169
}
170+
if (in.getVersion().onOrAfter(Version.V_2_17_0)) {
171+
sourceRemoteTranslogRepository = in.readOptionalString();
172+
}
168173
}
169174

170175
@Override
@@ -198,6 +203,9 @@ public void writeTo(StreamOutput out) throws IOException {
198203
if (out.getVersion().onOrAfter(Version.V_2_10_0)) {
199204
out.writeOptionalString(sourceRemoteStoreRepository);
200205
}
206+
if (out.getVersion().onOrAfter(Version.V_2_17_0)) {
207+
out.writeOptionalString(sourceRemoteTranslogRepository);
208+
}
201209
}
202210

203211
@Override
@@ -560,6 +568,16 @@ public RestoreSnapshotRequest setSourceRemoteStoreRepository(String sourceRemote
560568
return this;
561569
}
562570

571+
/**
572+
* Sets Source Remote Translog Repository for all the restored indices
573+
*
574+
* @param sourceRemoteTranslogRepository name of the remote translog repository that should be used for all restored indices.
575+
*/
576+
public RestoreSnapshotRequest setSourceRemoteTranslogRepository(String sourceRemoteTranslogRepository) {
577+
this.sourceRemoteTranslogRepository = sourceRemoteTranslogRepository;
578+
return this;
579+
}
580+
563581
/**
564582
* Returns Source Remote Store Repository for all the restored indices
565583
*
@@ -569,6 +587,15 @@ public String getSourceRemoteStoreRepository() {
569587
return sourceRemoteStoreRepository;
570588
}
571589

590+
/**
591+
* Returns Source Remote Translog Repository for all the restored indices
592+
*
593+
* @return source Remote Translog Repository
594+
*/
595+
public String getSourceRemoteTranslogRepository() {
596+
return sourceRemoteTranslogRepository;
597+
}
598+
572599
/**
573600
* Parses restore definition
574601
*
@@ -688,6 +715,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
688715
if (sourceRemoteStoreRepository != null) {
689716
builder.field("source_remote_store_repository", sourceRemoteStoreRepository);
690717
}
718+
if (sourceRemoteTranslogRepository != null) {
719+
builder.field("source_remote_translog_repository", sourceRemoteTranslogRepository);
720+
}
691721
builder.endObject();
692722
return builder;
693723
}
@@ -716,7 +746,8 @@ public boolean equals(Object o) {
716746
&& Arrays.equals(ignoreIndexSettings, that.ignoreIndexSettings)
717747
&& Objects.equals(snapshotUuid, that.snapshotUuid)
718748
&& Objects.equals(storageType, that.storageType)
719-
&& Objects.equals(sourceRemoteStoreRepository, that.sourceRemoteStoreRepository);
749+
&& Objects.equals(sourceRemoteStoreRepository, that.sourceRemoteStoreRepository)
750+
&& Objects.equals(sourceRemoteTranslogRepository, that.sourceRemoteTranslogRepository);
720751
return equals;
721752
}
722753

@@ -736,7 +767,8 @@ public int hashCode() {
736767
indexSettings,
737768
snapshotUuid,
738769
storageType,
739-
sourceRemoteStoreRepository
770+
sourceRemoteStoreRepository,
771+
sourceRemoteTranslogRepository
740772
);
741773
result = 31 * result + Arrays.hashCode(indices);
742774
result = 31 * result + Arrays.hashCode(ignoreIndexSettings);

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

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@ public static class SnapshotRecoverySource extends RecoverySource {
265265
private final boolean isSearchableSnapshot;
266266
private final boolean remoteStoreIndexShallowCopy;
267267
private final String sourceRemoteStoreRepository;
268+
private final String sourceRemoteTranslogRepository;
269+
270+
private final long pinnedTimestamp;
268271

269272
public SnapshotRecoverySource(String restoreUUID, Snapshot snapshot, Version version, IndexId indexId) {
270273
this(restoreUUID, snapshot, version, indexId, false, false, null);
@@ -278,6 +281,30 @@ public SnapshotRecoverySource(
278281
boolean isSearchableSnapshot,
279282
boolean remoteStoreIndexShallowCopy,
280283
@Nullable String sourceRemoteStoreRepository
284+
) {
285+
this(
286+
restoreUUID,
287+
snapshot,
288+
version,
289+
indexId,
290+
isSearchableSnapshot,
291+
remoteStoreIndexShallowCopy,
292+
sourceRemoteStoreRepository,
293+
null,
294+
0L
295+
);
296+
}
297+
298+
public SnapshotRecoverySource(
299+
String restoreUUID,
300+
Snapshot snapshot,
301+
Version version,
302+
IndexId indexId,
303+
boolean isSearchableSnapshot,
304+
boolean remoteStoreIndexShallowCopy,
305+
@Nullable String sourceRemoteStoreRepository,
306+
@Nullable String sourceRemoteTranslogRepository,
307+
long pinnedTimestamp
281308
) {
282309
this.restoreUUID = restoreUUID;
283310
this.snapshot = Objects.requireNonNull(snapshot);
@@ -286,6 +313,8 @@ public SnapshotRecoverySource(
286313
this.isSearchableSnapshot = isSearchableSnapshot;
287314
this.remoteStoreIndexShallowCopy = remoteStoreIndexShallowCopy;
288315
this.sourceRemoteStoreRepository = sourceRemoteStoreRepository;
316+
this.sourceRemoteTranslogRepository = sourceRemoteTranslogRepository;
317+
this.pinnedTimestamp = pinnedTimestamp;
289318
}
290319

291320
SnapshotRecoverySource(StreamInput in) throws IOException {
@@ -309,6 +338,13 @@ public SnapshotRecoverySource(
309338
remoteStoreIndexShallowCopy = false;
310339
sourceRemoteStoreRepository = null;
311340
}
341+
if (in.getVersion().onOrAfter(Version.V_2_17_0)) {
342+
sourceRemoteTranslogRepository = in.readOptionalString();
343+
pinnedTimestamp = in.readLong();
344+
} else {
345+
sourceRemoteTranslogRepository = null;
346+
pinnedTimestamp = 0L;
347+
}
312348
}
313349

314350
public String restoreUUID() {
@@ -341,10 +377,18 @@ public String sourceRemoteStoreRepository() {
341377
return sourceRemoteStoreRepository;
342378
}
343379

380+
public String sourceRemoteTranslogRepository() {
381+
return sourceRemoteTranslogRepository;
382+
}
383+
344384
public boolean remoteStoreIndexShallowCopy() {
345385
return remoteStoreIndexShallowCopy;
346386
}
347387

388+
public long pinnedTimestamp() {
389+
return pinnedTimestamp;
390+
}
391+
348392
@Override
349393
protected void writeAdditionalFields(StreamOutput out) throws IOException {
350394
out.writeString(restoreUUID);
@@ -362,6 +406,10 @@ protected void writeAdditionalFields(StreamOutput out) throws IOException {
362406
out.writeBoolean(remoteStoreIndexShallowCopy);
363407
out.writeOptionalString(sourceRemoteStoreRepository);
364408
}
409+
if (out.getVersion().onOrAfter(Version.V_2_17_0)) {
410+
out.writeOptionalString(sourceRemoteTranslogRepository);
411+
out.writeLong(pinnedTimestamp);
412+
}
365413
}
366414

367415
@Override
@@ -378,7 +426,8 @@ public void addAdditionalFields(XContentBuilder builder, ToXContent.Params param
378426
.field("restoreUUID", restoreUUID)
379427
.field("isSearchableSnapshot", isSearchableSnapshot)
380428
.field("remoteStoreIndexShallowCopy", remoteStoreIndexShallowCopy)
381-
.field("sourceRemoteStoreRepository", sourceRemoteStoreRepository);
429+
.field("sourceRemoteStoreRepository", sourceRemoteStoreRepository)
430+
.field("sourceRemoteTranslogRepository", sourceRemoteTranslogRepository);
382431
}
383432

384433
@Override
@@ -403,8 +452,11 @@ public boolean equals(Object o) {
403452
&& isSearchableSnapshot == that.isSearchableSnapshot
404453
&& remoteStoreIndexShallowCopy == that.remoteStoreIndexShallowCopy
405454
&& sourceRemoteStoreRepository != null
406-
? sourceRemoteStoreRepository.equals(that.sourceRemoteStoreRepository)
407-
: that.sourceRemoteStoreRepository == null;
455+
? sourceRemoteStoreRepository.equals(that.sourceRemoteStoreRepository)
456+
: that.sourceRemoteStoreRepository == null && sourceRemoteTranslogRepository != null
457+
? sourceRemoteTranslogRepository.equals(that.sourceRemoteTranslogRepository)
458+
: that.sourceRemoteTranslogRepository == null && pinnedTimestamp == that.pinnedTimestamp;
459+
408460
}
409461

410462
@Override
@@ -416,10 +468,11 @@ public int hashCode() {
416468
version,
417469
isSearchableSnapshot,
418470
remoteStoreIndexShallowCopy,
419-
sourceRemoteStoreRepository
471+
sourceRemoteStoreRepository,
472+
sourceRemoteTranslogRepository,
473+
pinnedTimestamp
420474
);
421475
}
422-
423476
}
424477

425478
/**

0 commit comments

Comments
 (0)