Skip to content

Commit 76480bb

Browse files
committed
review
1 parent dcd6bd8 commit 76480bb

File tree

2 files changed

+20
-56
lines changed

2 files changed

+20
-56
lines changed

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

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,35 +1551,22 @@ private static void ensureSearchableSnapshotsRestorable(
15511551
if (matchRepository(repositoryUuid, repositoryName, otherRepositoryUuid, otherRepositoryName) == false) {
15521552
continue; // other index is backed by a snapshot from a different repository, skip
15531553
}
1554-
if (otherSettings.getAsBoolean(SEARCHABLE_SNAPSHOTS_DELETE_SNAPSHOT_ON_INDEX_DELETION, false)) {
1554+
final boolean otherDeleteSnap = otherSettings.getAsBoolean(SEARCHABLE_SNAPSHOTS_DELETE_SNAPSHOT_ON_INDEX_DELETION, false);
1555+
if (deleteSnapshot != otherDeleteSnap) {
15551556
throw new SnapshotRestoreException(
15561557
repositoryName,
15571558
snapshotInfo.snapshotId().getName(),
15581559
String.format(
15591560
Locale.ROOT,
1560-
"cannot mount snapshot [%s/%s:%s] as index [%s]; another index %s uses the snapshot "
1561-
+ "with the deletion of snapshot on index removal enabled "
1562-
+ "[index.store.snapshot.delete_searchable_snapshot: true].",
1561+
"cannot mount snapshot [%s/%s:%s] as index [%s] with [index.store.snapshot.delete_searchable_snapshot: %b]; "
1562+
+ "another index %s is mounted with [index.store.snapshot.delete_searchable_snapshot: %b].",
15631563
repositoryName,
15641564
repositoryUuid,
15651565
snapshotInfo.snapshotId().getName(),
15661566
index.getName(),
1567-
other.getIndex()
1568-
)
1569-
);
1570-
} else if (deleteSnapshot) {
1571-
throw new SnapshotRestoreException(
1572-
repositoryName,
1573-
snapshotInfo.snapshotId().getName(),
1574-
String.format(
1575-
Locale.ROOT,
1576-
"cannot mount snapshot [%s/%s:%s] as index [%s] with the deletion of snapshot on index removal enabled "
1577-
+ "[index.store.snapshot.delete_searchable_snapshot: true]; another index %s uses the snapshot.",
1578-
repositoryName,
1579-
repositoryUuid,
1580-
snapshotInfo.snapshotId().getName(),
1581-
index.getName(),
1582-
other.getIndex()
1567+
deleteSnapshot,
1568+
other.getIndex(),
1569+
otherDeleteSnap
15831570
)
15841571
);
15851572
}

x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsRepositoryIntegTests.java

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public void testMountIndexWithDeletionOfSnapshotFailsIfNotSingleIndexSnapshot()
152152
);
153153
}
154154

155-
public void testMountIndexWithDeletionOfSnapshot() throws Exception {
155+
public void testMountIndexWithDifferentDeletionOfSnapshot() throws Exception {
156156
final String repository = "repository-" + getTestName().toLowerCase(Locale.ROOT);
157157
createRepository(repository, FsRepository.TYPE, randomRepositorySettings());
158158

@@ -165,53 +165,30 @@ public void testMountIndexWithDeletionOfSnapshot() throws Exception {
165165
createSnapshot(repository, snapshot, List.of(index));
166166
assertAcked(client().admin().indices().prepareDelete(index));
167167

168-
String mounted = "mounted-with-setting-enabled";
169-
mountSnapshot(repository, snapshot, index, mounted, deleteSnapshotIndexSettings(true), randomFrom(Storage.values()));
170-
assertIndexSetting(mounted, SEARCHABLE_SNAPSHOTS_DELETE_SNAPSHOT_ON_INDEX_DELETION, equalTo("true"));
168+
final boolean deleteSnapshot = randomBoolean();
169+
final String mounted = "mounted-with-setting-" + deleteSnapshot;
170+
mountSnapshot(repository, snapshot, index, mounted, deleteSnapshotIndexSettings(deleteSnapshot), randomFrom(Storage.values()));
171+
assertIndexSetting(mounted, SEARCHABLE_SNAPSHOTS_DELETE_SNAPSHOT_ON_INDEX_DELETION, equalTo(Boolean.toString(deleteSnapshot)));
171172
assertHitCount(client().prepareSearch(mounted).setTrackTotalHits(true).get(), totalHits.value);
172173

173-
// the snapshot is already mounted as an index with "index.store.snapshot.delete_searchable_snapshot: true",
174-
// any attempt to mount the snapshot again should fail
175174
final String mountedAgain = randomValueOtherThan(mounted, () -> randomAlphaOfLength(10).toLowerCase(Locale.ROOT));
176-
SnapshotRestoreException exception = expectThrows(
177-
SnapshotRestoreException.class,
178-
() -> mountSnapshot(repository, snapshot, index, mountedAgain, deleteSnapshotIndexSettings(randomBoolean()))
179-
);
180-
assertThat(
181-
exception.getMessage(),
182-
allOf(
183-
containsString("cannot mount snapshot [" + repository + '/'),
184-
containsString(':' + snapshot + "] as index [" + mountedAgain + "]; another index [" + mounted + '/'),
185-
containsString("] uses the snapshot with the deletion of snapshot on index removal enabled "),
186-
containsString("[index.store.snapshot.delete_searchable_snapshot: true].")
187-
)
188-
);
189-
190-
assertAcked(client().admin().indices().prepareDelete(mounted));
191-
mounted = "mounted-with-setting-disabled";
192-
mountSnapshot(repository, snapshot, index, mounted, deleteSnapshotIndexSettings(false), randomFrom(Storage.values()));
193-
assertIndexSetting(mounted, SEARCHABLE_SNAPSHOTS_DELETE_SNAPSHOT_ON_INDEX_DELETION, equalTo("false"));
194-
assertHitCount(client().prepareSearch(mounted).setTrackTotalHits(true).get(), totalHits.value);
195-
196-
// the snapshot is now mounted as an index with "index.store.snapshot.delete_searchable_snapshot: false",
197-
// any attempt to mount the snapshot again with "delete_searchable_snapshot: true" should fail
198-
exception = expectThrows(
175+
final SnapshotRestoreException exception = expectThrows(
199176
SnapshotRestoreException.class,
200-
() -> mountSnapshot(repository, snapshot, index, mountedAgain, deleteSnapshotIndexSettings(true))
177+
() -> mountSnapshot(repository, snapshot, index, mountedAgain, deleteSnapshotIndexSettings(deleteSnapshot == false))
201178
);
202179
assertThat(
203180
exception.getMessage(),
204181
allOf(
205182
containsString("cannot mount snapshot [" + repository + '/'),
206-
containsString(snapshot + "] as index [" + mountedAgain + "] with the deletion of snapshot on index removal enabled"),
207-
containsString("[index.store.snapshot.delete_searchable_snapshot: true]; another index [" + mounted + '/'),
208-
containsString("] uses the snapshot.")
183+
containsString(':' + snapshot + "] as index [" + mountedAgain + "] with "),
184+
containsString("[index.store.snapshot.delete_searchable_snapshot: " + (deleteSnapshot == false) + "]; another "),
185+
containsString("index [" + mounted + '/'),
186+
containsString("is mounted with [index.store.snapshot.delete_searchable_snapshot: " + deleteSnapshot + "].")
209187
)
210188
);
211189

212-
// but we can continue to mount the snapshot, as long as it does not require the cascade deletion of the snapshot
213-
mountSnapshot(repository, snapshot, index, mountedAgain, deleteSnapshotIndexSettings(false));
214-
assertIndexSetting(mountedAgain, SEARCHABLE_SNAPSHOTS_DELETE_SNAPSHOT_ON_INDEX_DELETION, equalTo("false"));
190+
mountSnapshot(repository, snapshot, index, mountedAgain, deleteSnapshotIndexSettings(deleteSnapshot));
191+
assertIndexSetting(mountedAgain, SEARCHABLE_SNAPSHOTS_DELETE_SNAPSHOT_ON_INDEX_DELETION, equalTo(Boolean.toString(deleteSnapshot)));
215192
assertHitCount(client().prepareSearch(mountedAgain).setTrackTotalHits(true).get(), totalHits.value);
216193

217194
assertAcked(client().admin().indices().prepareDelete(mountedAgain));

0 commit comments

Comments
 (0)