Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Snapshot Interop] Add Changes in Restore Snapshot Flow for remote st…
Browse files Browse the repository at this point in the history
…ore Interoperability (opensearch-project#6788)

* [Snapshot Interop] Add Changes in Restore Snapshot Flow for remote store interoperability.
---------

Signed-off-by: Harish Bhakuni <[email protected]>
Co-authored-by: Harish Bhakuni <[email protected]>
Signed-off-by: Shivansh Arora <[email protected]>
2 people authored and shiv0408 committed Apr 25, 2024
1 parent 0c7b788 commit 01a3720
Showing 28 changed files with 1,303 additions and 87 deletions.
Original file line number Diff line number Diff line change
@@ -42,6 +42,10 @@
"type":"boolean",
"description":"Should this request wait until the operation has completed before returning",
"default":false
},
"source_remote_store_repository": {
"type":"string",
"description":"Remote Store Repository of Remote Store Indices"
}
},
"body":{

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -113,6 +113,8 @@ private static StorageType fromString(String string) {
private Settings indexSettings = EMPTY_SETTINGS;
private String[] ignoreIndexSettings = Strings.EMPTY_ARRAY;
private StorageType storageType = StorageType.LOCAL;
@Nullable
private String sourceRemoteStoreRepository = null;

@Nullable // if any snapshot UUID will do
private String snapshotUuid;
@@ -148,6 +150,9 @@ public RestoreSnapshotRequest(StreamInput in) throws IOException {
if (in.getVersion().onOrAfter(Version.V_2_7_0)) {
storageType = in.readEnum(StorageType.class);
}
if (in.getVersion().onOrAfter(Version.V_3_0_0)) {
sourceRemoteStoreRepository = in.readOptionalString();
}
}

@Override
@@ -169,6 +174,9 @@ public void writeTo(StreamOutput out) throws IOException {
if (out.getVersion().onOrAfter(Version.V_2_7_0)) {
out.writeEnum(storageType);
}
if (out.getVersion().onOrAfter(Version.V_3_0_0)) {
out.writeOptionalString(sourceRemoteStoreRepository);
}
}

@Override
@@ -521,6 +529,25 @@ public StorageType storageType() {
return storageType;
}

/**
* Sets Source Remote Store Repository for all the restored indices
*
* @param sourceRemoteStoreRepository name of the remote store repository that should be used for all restored indices.
*/
public RestoreSnapshotRequest setSourceRemoteStoreRepository(String sourceRemoteStoreRepository) {
this.sourceRemoteStoreRepository = sourceRemoteStoreRepository;
return this;
}

/**
* Returns Source Remote Store Repository for all the restored indices
*
* @return source Remote Store Repository
*/
public String getSourceRemoteStoreRepository() {
return sourceRemoteStoreRepository;
}

/**
* Parses restore definition
*
@@ -586,6 +613,12 @@ public RestoreSnapshotRequest source(Map<String, Object> source) {
throw new IllegalArgumentException("malformed storage_type");
}

} else if (name.equals("source_remote_store_repository")) {
if (entry.getValue() instanceof String) {
setSourceRemoteStoreRepository((String) entry.getValue());
} else {
throw new IllegalArgumentException("malformed source_remote_store_repository");
}
} else {
if (IndicesOptions.isIndicesOptions(name) == false) {
throw new IllegalArgumentException("Unknown parameter " + name);
@@ -631,6 +664,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
if (storageType != null) {
storageType.toXContent(builder);
}
if (sourceRemoteStoreRepository != null) {
builder.field("source_remote_store_repository", sourceRemoteStoreRepository);
}
builder.endObject();
return builder;
}
@@ -658,7 +694,8 @@ public boolean equals(Object o) {
&& Objects.equals(indexSettings, that.indexSettings)
&& Arrays.equals(ignoreIndexSettings, that.ignoreIndexSettings)
&& Objects.equals(snapshotUuid, that.snapshotUuid)
&& Objects.equals(storageType, that.storageType);
&& Objects.equals(storageType, that.storageType)
&& Objects.equals(sourceRemoteStoreRepository, that.sourceRemoteStoreRepository);
}

@Override
@@ -675,7 +712,8 @@ public int hashCode() {
includeAliases,
indexSettings,
snapshotUuid,
storageType
storageType,
sourceRemoteStoreRepository
);
result = 31 * result + Arrays.hashCode(indices);
result = 31 * result + Arrays.hashCode(ignoreIndexSettings);
Original file line number Diff line number Diff line change
@@ -256,4 +256,12 @@ public RestoreSnapshotRequestBuilder setStorageType(RestoreSnapshotRequest.Stora
request.storageType(storageType);
return this;
}

/**
* Sets the source remote store repository name
*/
public RestoreSnapshotRequestBuilder setSourceRemoteStoreRepository(String repositoryName) {
request.setSourceRemoteStoreRepository(repositoryName);
return this;
}
}
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@

import org.opensearch.Version;
import org.opensearch.cluster.metadata.IndexMetadata;
import org.opensearch.common.Nullable;
import org.opensearch.common.io.stream.StreamInput;
import org.opensearch.common.io.stream.StreamOutput;
import org.opensearch.common.io.stream.Writeable;
@@ -257,23 +258,29 @@ public static class SnapshotRecoverySource extends RecoverySource {
private final IndexId index;
private final Version version;
private final boolean isSearchableSnapshot;
private final boolean remoteStoreIndexShallowCopy;
private final String sourceRemoteStoreRepository;

public SnapshotRecoverySource(String restoreUUID, Snapshot snapshot, Version version, IndexId indexId) {
this(restoreUUID, snapshot, version, indexId, false);
this(restoreUUID, snapshot, version, indexId, false, false, null);
}

public SnapshotRecoverySource(
String restoreUUID,
Snapshot snapshot,
Version version,
IndexId indexId,
boolean isSearchableSnapshot
boolean isSearchableSnapshot,
boolean remoteStoreIndexShallowCopy,
@Nullable String sourceRemoteStoreRepository
) {
this.restoreUUID = restoreUUID;
this.snapshot = Objects.requireNonNull(snapshot);
this.version = Objects.requireNonNull(version);
this.index = Objects.requireNonNull(indexId);
this.isSearchableSnapshot = isSearchableSnapshot;
this.remoteStoreIndexShallowCopy = remoteStoreIndexShallowCopy;
this.sourceRemoteStoreRepository = sourceRemoteStoreRepository;
}

SnapshotRecoverySource(StreamInput in) throws IOException {
@@ -286,6 +293,13 @@ public SnapshotRecoverySource(
} else {
isSearchableSnapshot = false;
}
if (in.getVersion().onOrAfter(Version.V_3_0_0)) {
remoteStoreIndexShallowCopy = in.readBoolean();
sourceRemoteStoreRepository = in.readOptionalString();
} else {
remoteStoreIndexShallowCopy = false;
sourceRemoteStoreRepository = null;
}
}

public String restoreUUID() {
@@ -314,6 +328,14 @@ public boolean isSearchableSnapshot() {
return isSearchableSnapshot;
}

public String sourceRemoteStoreRepository() {
return sourceRemoteStoreRepository;
}

public boolean remoteStoreIndexShallowCopy() {
return remoteStoreIndexShallowCopy;
}

@Override
protected void writeAdditionalFields(StreamOutput out) throws IOException {
out.writeString(restoreUUID);
@@ -323,6 +345,10 @@ protected void writeAdditionalFields(StreamOutput out) throws IOException {
if (out.getVersion().onOrAfter(Version.V_2_7_0)) {
out.writeBoolean(isSearchableSnapshot);
}
if (out.getVersion().onOrAfter(Version.V_3_0_0)) {
out.writeBoolean(remoteStoreIndexShallowCopy);
out.writeOptionalString(sourceRemoteStoreRepository);
}
}

@Override
@@ -337,7 +363,9 @@ public void addAdditionalFields(XContentBuilder builder, ToXContent.Params param
.field("version", version.toString())
.field("index", index.getName())
.field("restoreUUID", restoreUUID)
.field("isSearchableSnapshot", isSearchableSnapshot);
.field("isSearchableSnapshot", isSearchableSnapshot)
.field("remoteStoreIndexShallowCopy", remoteStoreIndexShallowCopy)
.field("sourceRemoteStoreRepository", sourceRemoteStoreRepository);
}

@Override
@@ -359,12 +387,24 @@ public boolean equals(Object o) {
&& snapshot.equals(that.snapshot)
&& index.equals(that.index)
&& version.equals(that.version)
&& isSearchableSnapshot == that.isSearchableSnapshot;
&& isSearchableSnapshot == that.isSearchableSnapshot
&& remoteStoreIndexShallowCopy == that.remoteStoreIndexShallowCopy
&& sourceRemoteStoreRepository != null
? sourceRemoteStoreRepository.equals(that.sourceRemoteStoreRepository)
: that.sourceRemoteStoreRepository == null;
}

@Override
public int hashCode() {
return Objects.hash(restoreUUID, snapshot, index, version, isSearchableSnapshot);
return Objects.hash(
restoreUUID,
snapshot,
index,
version,
isSearchableSnapshot,
remoteStoreIndexShallowCopy,
sourceRemoteStoreRepository
);
}

}
Loading

0 comments on commit 01a3720

Please sign in to comment.