mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 10:25:15 +00:00
Snapshot info should contain version of elasticsearch that created the snapshot
This information was stored with the snapshot but wasn't available on the interface. Knowing the version of elasticsearch that created the snapshot can be useful to determine the minimal version of the cluster that is required in order to restore this snapshot. Closes #11980
This commit is contained in:
parent
ee30cf32ab
commit
f303a1d4eb
@ -21,6 +21,7 @@ package org.elasticsearch.snapshots;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.ShardOperationFailedException;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
@ -56,6 +57,8 @@ public class SnapshotInfo implements ToXContent, Streamable {
|
||||
|
||||
private int successfulShards;
|
||||
|
||||
private Version version;
|
||||
|
||||
private List<SnapshotShardFailure> shardFailures;
|
||||
|
||||
SnapshotInfo() {
|
||||
@ -77,6 +80,7 @@ public class SnapshotInfo implements ToXContent, Streamable {
|
||||
totalShards = snapshot.totalShard();
|
||||
successfulShards = snapshot.successfulShards();
|
||||
shardFailures = snapshot.shardFailures();
|
||||
version = snapshot.version();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -171,6 +175,15 @@ public class SnapshotInfo implements ToXContent, Streamable {
|
||||
return shardFailures;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the version of elasticsearch that the snapshot was created with
|
||||
*
|
||||
* @return version of elasticsearch that the snapshot was created with
|
||||
*/
|
||||
public Version version() {
|
||||
return version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns snapshot REST status
|
||||
*/
|
||||
@ -199,12 +212,16 @@ public class SnapshotInfo implements ToXContent, Streamable {
|
||||
static final XContentBuilderString TOTAL = new XContentBuilderString("total");
|
||||
static final XContentBuilderString FAILED = new XContentBuilderString("failed");
|
||||
static final XContentBuilderString SUCCESSFUL = new XContentBuilderString("successful");
|
||||
static final XContentBuilderString VERSION_ID = new XContentBuilderString("version_id");
|
||||
static final XContentBuilderString VERSION = new XContentBuilderString("version");
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject();
|
||||
builder.field("snapshot", name);
|
||||
builder.field(Fields.VERSION_ID, version.id);
|
||||
builder.field(Fields.VERSION, version.toString());
|
||||
builder.startArray(Fields.INDICES);
|
||||
for (String index : indices) {
|
||||
builder.value(index);
|
||||
@ -264,6 +281,7 @@ public class SnapshotInfo implements ToXContent, Streamable {
|
||||
} else {
|
||||
shardFailures = ImmutableList.of();
|
||||
}
|
||||
version = Version.readVersion(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -283,6 +301,7 @@ public class SnapshotInfo implements ToXContent, Streamable {
|
||||
for (SnapshotShardFailure failure : shardFailures) {
|
||||
failure.writeTo(out);
|
||||
}
|
||||
Version.writeVersion(version, out);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -20,6 +20,7 @@ package org.elasticsearch.bwcompat;
|
||||
|
||||
import org.apache.lucene.util.LuceneTestCase.Slow;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse;
|
||||
import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
@ -30,6 +31,7 @@ import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
import org.elasticsearch.snapshots.AbstractSnapshotTests;
|
||||
import org.elasticsearch.snapshots.RestoreInfo;
|
||||
import org.elasticsearch.snapshots.SnapshotInfo;
|
||||
import org.elasticsearch.snapshots.SnapshotRestoreException;
|
||||
import org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope;
|
||||
import org.elasticsearch.test.ElasticsearchIntegrationTest.Scope;
|
||||
@ -149,6 +151,12 @@ public class RestoreBackwardsCompatTests extends AbstractSnapshotTests {
|
||||
}
|
||||
|
||||
private void testOldSnapshot(String version, String repo, String snapshot) throws IOException {
|
||||
logger.info("--> get snapshot and check its version");
|
||||
GetSnapshotsResponse getSnapshotsResponse = client().admin().cluster().prepareGetSnapshots(repo).setSnapshots(snapshot).get();
|
||||
assertThat(getSnapshotsResponse.getSnapshots().size(), equalTo(1));
|
||||
SnapshotInfo snapshotInfo = getSnapshotsResponse.getSnapshots().get(0);
|
||||
assertThat(snapshotInfo.version().toString(), equalTo(version));
|
||||
|
||||
logger.info("--> restoring snapshot");
|
||||
RestoreSnapshotResponse response = client().admin().cluster().prepareRestoreSnapshot(repo, snapshot).setRestoreGlobalState(true).setWaitForCompletion(true).get();
|
||||
assertThat(response.status(), equalTo(RestStatus.OK));
|
||||
|
@ -25,6 +25,7 @@ import com.google.common.collect.ImmutableMap;
|
||||
import org.apache.lucene.util.IOUtils;
|
||||
import org.apache.lucene.util.LuceneTestCase.Slow;
|
||||
import org.elasticsearch.ExceptionsHelper;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.ListenableActionFuture;
|
||||
import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse;
|
||||
import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse;
|
||||
@ -125,7 +126,9 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests {
|
||||
assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0));
|
||||
assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse.getSnapshotInfo().totalShards()));
|
||||
|
||||
assertThat(client.admin().cluster().prepareGetSnapshots("test-repo").setSnapshots("test-snap").get().getSnapshots().get(0).state(), equalTo(SnapshotState.SUCCESS));
|
||||
SnapshotInfo snapshotInfo = client.admin().cluster().prepareGetSnapshots("test-repo").setSnapshots("test-snap").get().getSnapshots().get(0);
|
||||
assertThat(snapshotInfo.state(), equalTo(SnapshotState.SUCCESS));
|
||||
assertThat(snapshotInfo.version(), equalTo(Version.CURRENT));
|
||||
|
||||
logger.info("--> delete some data");
|
||||
for (int i = 0; i < 50; i++) {
|
||||
|
@ -34,6 +34,8 @@ setup:
|
||||
- match: { snapshot.state : SUCCESS }
|
||||
- match: { snapshot.shards.successful: 1 }
|
||||
- match: { snapshot.shards.failed : 0 }
|
||||
- is_true: snapshot.version
|
||||
- gt: { snapshot.version_id: 0}
|
||||
|
||||
- do:
|
||||
indices.close:
|
||||
|
Loading…
x
Reference in New Issue
Block a user