浏览代码

Do not propagate exception in case of index corruption (#89496)

When node performs listStoreMetadata it bubbles the corrupt index exception to
the caller. This is currently treated as retryable exception however it is not
likely that index is going to be fixed. Returning empty instead.
Ievgen Degtiarenko 3 年之前
父节点
当前提交
498a24b61f

+ 2 - 0
server/src/main/java/org/elasticsearch/index/store/Store.java

@@ -451,6 +451,8 @@ public class Store extends AbstractIndexShardComponent implements Closeable, Ref
             return MetadataSnapshot.loadFromIndexCommit(null, dir, logger);
             return MetadataSnapshot.loadFromIndexCommit(null, dir, logger);
         } catch (IndexNotFoundException ex) {
         } catch (IndexNotFoundException ex) {
             // that's fine - happens all the time no need to log
             // that's fine - happens all the time no need to log
+        } catch (CorruptIndexException ex) {
+            logger.info(() -> format("%s: corrupted", shardId), ex);
         } catch (FileNotFoundException | NoSuchFileException ex) {
         } catch (FileNotFoundException | NoSuchFileException ex) {
             logger.info("Failed to open / find files while reading metadata snapshot", ex);
             logger.info("Failed to open / find files while reading metadata snapshot", ex);
         } catch (ShardLockObtainFailedException ex) {
         } catch (ShardLockObtainFailedException ex) {

+ 11 - 0
server/src/test/java/org/elasticsearch/index/store/StoreTests.java

@@ -1187,4 +1187,15 @@ public class StoreTests extends ESTestCase {
             assertThat(segmentInfos.getUserData().get(Engine.ES_VERSION), is(equalTo(org.elasticsearch.Version.CURRENT.toString())));
             assertThat(segmentInfos.getUserData().get(Engine.ES_VERSION), is(equalTo(org.elasticsearch.Version.CURRENT.toString())));
         }
         }
     }
     }
+
+    public void testReadMetadataSnapshotReturnsEmptyWhenIndexIsCorrupted() throws IOException {
+        var shardId = new ShardId("index", "_na_", 1);
+        var dir = createTempDir();
+        try (Store store = new Store(shardId, INDEX_SETTINGS, new NIOFSDirectory(dir), new DummyShardLock(shardId))) {
+            store.createEmpty();
+            store.markStoreCorrupted(new IOException("test exception"));
+            var metadata = Store.readMetadataSnapshot(dir, shardId, (id, l, d) -> new DummyShardLock(id), logger);
+            assertThat(metadata, equalTo(Store.MetadataSnapshot.EMPTY));
+        }
+    }
 }
 }