Skip to content

Commit 037a9be

Browse files
authored
Revert workarounds for tryOpenIndex change (#53615)
In #50239 we introduced a temporary workaround in Store#tryOpenIndex to allow searchable snapshots shards to be allocated anywhere. #52527 reverts this workaround but did not revert the associated test changes. This commit reverts the associated test changes.
1 parent d35c156 commit 037a9be

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

server/src/test/java/org/elasticsearch/gateway/RecoveryFromGatewayIT.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import org.elasticsearch.cluster.routing.UnassignedInfo;
3636
import org.elasticsearch.cluster.service.ClusterService;
3737
import org.elasticsearch.common.Strings;
38-
import org.elasticsearch.common.UUIDs;
3938
import org.elasticsearch.common.settings.Settings;
4039
import org.elasticsearch.common.xcontent.XContentFactory;
4140
import org.elasticsearch.env.NodeEnvironment;
@@ -47,7 +46,6 @@
4746
import org.elasticsearch.index.query.QueryBuilders;
4847
import org.elasticsearch.index.shard.ShardId;
4948
import org.elasticsearch.index.shard.ShardPath;
50-
import org.elasticsearch.index.store.Store;
5149
import org.elasticsearch.indices.IndicesService;
5250
import org.elasticsearch.indices.recovery.RecoveryState;
5351
import org.elasticsearch.plugins.Plugin;
@@ -58,9 +56,9 @@
5856
import org.elasticsearch.test.InternalTestCluster.RestartCallback;
5957
import org.elasticsearch.test.store.MockFSIndexStore;
6058

59+
import java.nio.file.DirectoryStream;
6160
import java.nio.file.Files;
6261
import java.nio.file.Path;
63-
import java.nio.file.StandardOpenOption;
6462
import java.util.Arrays;
6563
import java.util.Collection;
6664
import java.util.Collections;
@@ -560,14 +558,19 @@ public Settings onNodeStopped(String nodeName) throws Exception {
560558
});
561559

562560
if (corrupt) {
563-
// TODO NORELEASE revert this change when Store#tryOpenIndex is fixed
564561
for (Path path : internalCluster().getInstance(NodeEnvironment.class, nodeName).availableShardPaths(shardId)) {
565562
final Path indexPath = path.resolve(ShardPath.INDEX_FOLDER_NAME);
566563
if (Files.exists(indexPath)) { // multi data path might only have one path in use
567-
final Path markerPath = indexPath.resolve(Store.CORRUPTED_MARKER_NAME_PREFIX + UUIDs.randomBase64UUID(random()));
568-
logger.info("writing corruption marker at [{}]", markerPath);
569-
Files.write(markerPath, new byte[0], StandardOpenOption.CREATE_NEW);
564+
try (DirectoryStream<Path> stream = Files.newDirectoryStream(indexPath)) {
565+
for (Path item : stream) {
566+
if (item.getFileName().toString().startsWith("segments_")) {
567+
logger.debug("--> deleting [{}]", item);
568+
Files.delete(item);
569+
}
570+
}
571+
}
570572
}
573+
571574
}
572575
}
573576

server/src/test/java/org/elasticsearch/index/store/StoreTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ public void testCanOpenIndex() throws IOException {
932932
IndexWriterConfig iwc = newIndexWriterConfig();
933933
Path tempDir = createTempDir();
934934
final BaseDirectoryWrapper dir = newFSDirectory(tempDir);
935-
// assertFalse(StoreUtils.canOpenIndex(logger, tempDir, shardId, (id, l, d) -> new DummyShardLock(id))); TODO NORELEASE
935+
assertFalse(StoreUtils.canOpenIndex(logger, tempDir, shardId, (id, l, d) -> new DummyShardLock(id)));
936936
IndexWriter writer = new IndexWriter(dir, iwc);
937937
Document doc = new Document();
938938
doc.add(new StringField("id", "1", random().nextBoolean() ? Field.Store.YES : Field.Store.NO));

0 commit comments

Comments
 (0)