Skip to content

Commit c9ab2fc

Browse files
CR: comments
1 parent bf095d9 commit c9ab2fc

File tree

3 files changed

+22
-79
lines changed

3 files changed

+22
-79
lines changed

server/src/internalClusterTest/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,7 @@ public void testDeduplicateIndexMetadata() throws Exception {
11781178
final String repositoryName = "repo-" + indexName;
11791179
final String snapshot0 = "snapshot-0";
11801180
final String snapshot1 = "snapshot-1";
1181+
final String snapshot2 = "snapshot-2";
11811182

11821183
createIndex(indexName);
11831184

@@ -1186,12 +1187,8 @@ public void testDeduplicateIndexMetadata() throws Exception {
11861187
client().prepareIndex(indexName).setSource("test", "init").execute().actionGet();
11871188
}
11881189

1189-
logger.info("--> register a repository");
1190-
11911190
final Path repoPath = randomRepoPath();
1192-
assertAcked(client().admin().cluster().preparePutRepository(repositoryName)
1193-
.setType("fs")
1194-
.setSettings(Settings.builder().put("location", repoPath)));
1191+
createRepository(repositoryName, "fs", repoPath);
11951192

11961193
logger.info("--> create a snapshot");
11971194
client().admin().cluster().prepareCreateSnapshot(repositoryName, snapshot0)
@@ -1202,7 +1199,6 @@ public void testDeduplicateIndexMetadata() throws Exception {
12021199
final List<Path> snapshot0IndexMetaFiles = findRepoMetaBlobs(repoPath);
12031200
assertThat(snapshot0IndexMetaFiles, hasSize(1)); // snapshotting a single index
12041201

1205-
// add few docs - less than initially
12061202
docs = between(1, 5);
12071203
for (int i = 0; i < docs; i++) {
12081204
client().prepareIndex(indexName).setSource("test", "test" + i).execute().actionGet();
@@ -1213,17 +1209,27 @@ public void testDeduplicateIndexMetadata() throws Exception {
12131209
internalCluster().startDataOnlyNode();
12141210
ensureGreen(indexName);
12151211

1216-
// create another snapshot
1217-
// total size has to grow and has to be equal to files on fs
1218-
assertThat(client().admin().cluster()
1219-
.prepareCreateSnapshot(repositoryName, snapshot1)
1220-
.setWaitForCompletion(true).get().status(),
1221-
equalTo(RestStatus.OK));
1212+
assertThat(client().admin().cluster().prepareCreateSnapshot(repositoryName, snapshot1).setWaitForCompletion(true).get().status(),
1213+
equalTo(RestStatus.OK));
12221214

12231215
final List<Path> snapshot1IndexMetaFiles = findRepoMetaBlobs(repoPath);
12241216

12251217
// The IndexMetadata did not change between snapshots, verify that no new redundant IndexMetaData was written to the repository
12261218
assertThat(snapshot1IndexMetaFiles, is(snapshot0IndexMetaFiles));
1219+
1220+
// index to some other field to trigger a change in index metadata
1221+
for (int i = 0; i < docs; i++) {
1222+
client().prepareIndex(indexName).setSource("new_field", "test" + i).execute().actionGet();
1223+
}
1224+
assertThat(client().admin().cluster().prepareCreateSnapshot(repositoryName, snapshot2).setWaitForCompletion(true).get().status(),
1225+
equalTo(RestStatus.OK));
1226+
1227+
final List<Path> snapshot2IndexMetaFiles = findRepoMetaBlobs(repoPath);
1228+
assertThat(snapshot2IndexMetaFiles, hasSize(2)); // should have created one new metadata blob
1229+
1230+
assertAcked(client().admin().cluster().prepareDeleteSnapshot(repositoryName, snapshot0, snapshot1).get());
1231+
final List<Path> snapshot3IndexMetaFiles = findRepoMetaBlobs(repoPath);
1232+
assertThat(snapshot3IndexMetaFiles, hasSize(1)); // should have deleted the metadata blob referenced by the first two snapshots
12271233
}
12281234

12291235
public void testDataNodeRestartWithBusyMasterDuringSnapshot() throws Exception {

server/src/main/java/org/elasticsearch/repositories/IndexMetaDataGenerations.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@ public String toString() {
169169
* @return identifier string
170170
*/
171171
public static String buildUniqueIdentifier(IndexMetadata indexMetaData) {
172-
return indexMetaData.getIndexUUID() + "-" +
173-
indexMetaData.getSettings().get(IndexMetadata.SETTING_HISTORY_UUID, IndexMetadata.INDEX_UUID_NA_VALUE) +
174-
indexMetaData.getSettingsVersion() + "-" + indexMetaData.getMappingVersion() + "-" +
175-
indexMetaData.getAliasesVersion();
172+
return indexMetaData.getIndexUUID() +
173+
"-" + indexMetaData.getSettings().get(IndexMetadata.SETTING_HISTORY_UUID, IndexMetadata.INDEX_UUID_NA_VALUE) +
174+
"-" + indexMetaData.getSettingsVersion() + "-" + indexMetaData.getMappingVersion() +
175+
"-" + indexMetaData.getAliasesVersion();
176176
}
177177
}

server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
import org.elasticsearch.common.unit.TimeValue;
7373
import org.elasticsearch.index.Index;
7474
import org.elasticsearch.index.shard.ShardId;
75-
import org.elasticsearch.index.snapshots.IndexShardSnapshotStatus;
7675
import org.elasticsearch.repositories.IndexId;
7776
import org.elasticsearch.repositories.RepositoriesService;
7877
import org.elasticsearch.repositories.Repository;
@@ -105,7 +104,6 @@
105104

106105
import static java.util.Collections.emptySet;
107106
import static java.util.Collections.unmodifiableList;
108-
import static java.util.Collections.unmodifiableMap;
109107
import static org.elasticsearch.cluster.SnapshotsInProgress.completed;
110108

111109
/**
@@ -418,67 +416,6 @@ public static List<SnapshotsInProgress.Entry> currentSnapshots(@Nullable Snapsho
418416
return unmodifiableList(builder);
419417
}
420418

421-
/**
422-
* Returns status of shards currently finished snapshots
423-
* <p>
424-
* This method is executed on master node and it's complimentary to the
425-
* {@link SnapshotShardsService#currentSnapshotShards(Snapshot)} because it
426-
* returns similar information but for already finished snapshots.
427-
* </p>
428-
*
429-
* @param repositoryName repository name
430-
* @param snapshotInfo snapshot info
431-
* @return map of shard id to snapshot status
432-
*/
433-
public Map<ShardId, IndexShardSnapshotStatus> snapshotShards(final String repositoryName,
434-
final RepositoryData repositoryData,
435-
final SnapshotInfo snapshotInfo) throws IOException {
436-
final Repository repository = repositoriesService.repository(repositoryName);
437-
final Map<ShardId, IndexShardSnapshotStatus> shardStatus = new HashMap<>();
438-
for (String index : snapshotInfo.indices()) {
439-
IndexId indexId = repositoryData.resolveIndexId(index);
440-
IndexMetadata indexMetaData = repository.getSnapshotIndexMetaData(repositoryData, snapshotInfo.snapshotId(), indexId);
441-
if (indexMetaData != null) {
442-
int numberOfShards = indexMetaData.getNumberOfShards();
443-
for (int i = 0; i < numberOfShards; i++) {
444-
ShardId shardId = new ShardId(indexMetaData.getIndex(), i);
445-
SnapshotShardFailure shardFailure = findShardFailure(snapshotInfo.shardFailures(), shardId);
446-
if (shardFailure != null) {
447-
shardStatus.put(shardId, IndexShardSnapshotStatus.newFailed(shardFailure.reason()));
448-
} else {
449-
final IndexShardSnapshotStatus shardSnapshotStatus;
450-
if (snapshotInfo.state() == SnapshotState.FAILED) {
451-
// If the snapshot failed, but the shard's snapshot does
452-
// not have an exception, it means that partial snapshots
453-
// were disabled and in this case, the shard snapshot will
454-
// *not* have any metadata, so attempting to read the shard
455-
// snapshot status will throw an exception. Instead, we create
456-
// a status for the shard to indicate that the shard snapshot
457-
// could not be taken due to partial being set to false.
458-
shardSnapshotStatus = IndexShardSnapshotStatus.newFailed("skipped");
459-
} else {
460-
shardSnapshotStatus = repository.getShardSnapshotStatus(
461-
snapshotInfo.snapshotId(),
462-
indexId,
463-
shardId);
464-
}
465-
shardStatus.put(shardId, shardSnapshotStatus);
466-
}
467-
}
468-
}
469-
}
470-
return unmodifiableMap(shardStatus);
471-
}
472-
473-
private static SnapshotShardFailure findShardFailure(List<SnapshotShardFailure> shardFailures, ShardId shardId) {
474-
for (SnapshotShardFailure shardFailure : shardFailures) {
475-
if (shardId.getIndexName().equals(shardFailure.index()) && shardId.getId() == shardFailure.shardId()) {
476-
return shardFailure;
477-
}
478-
}
479-
return null;
480-
}
481-
482419
@Override
483420
public void applyClusterState(ClusterChangedEvent event) {
484421
try {

0 commit comments

Comments
 (0)