@@ -138,12 +138,9 @@ public class Store extends AbstractIndexShardComponent implements Closeable, Ref
138138 public static final Setting <Boolean > FORCE_RAM_TERM_DICT = Setting .boolSetting ("index.force_memory_term_dictionary" , false ,
139139 Property .IndexScope , Property .Deprecated );
140140 static final String CODEC = "store" ;
141- static final int VERSION_WRITE_THROWABLE = 2 ; // we write throwable since 2.0
142- static final int VERSION_STACK_TRACE = 1 ; // we write the stack trace too since 1.4.0
143- static final int VERSION_START = 0 ;
144- static final int VERSION = VERSION_WRITE_THROWABLE ;
141+ static final int CORRUPTED_MARKER_CODEC_VERSION = 2 ;
145142 // public is for test purposes
146- public static final String CORRUPTED = "corrupted_" ;
143+ public static final String CORRUPTED_MARKER_NAME_PREFIX = "corrupted_" ;
147144 public static final Setting <TimeValue > INDEX_STORE_STATS_REFRESH_INTERVAL_SETTING =
148145 Setting .timeSetting ("index.store.stats_refresh_interval" , TimeValue .timeValueSeconds (10 ), Property .IndexScope );
149146
@@ -448,7 +445,7 @@ public static MetadataSnapshot readMetadataSnapshot(Path indexLocation, ShardId
448445 Logger logger ) throws IOException {
449446 try (ShardLock lock = shardLocker .lock (shardId , "read metadata snapshot" , TimeUnit .SECONDS .toMillis (5 ));
450447 Directory dir = new SimpleFSDirectory (indexLocation )) {
451- failIfCorrupted (dir , shardId );
448+ failIfCorrupted (dir );
452449 return new MetadataSnapshot (null , dir , logger );
453450 } catch (IndexNotFoundException ex ) {
454451 // that's fine - happens all the time no need to log
@@ -469,7 +466,7 @@ public static void tryOpenIndex(Path indexLocation, ShardId shardId, NodeEnviron
469466 Logger logger ) throws IOException , ShardLockObtainFailedException {
470467 try (ShardLock lock = shardLocker .lock (shardId , "open index" , TimeUnit .SECONDS .toMillis (5 ));
471468 Directory dir = new SimpleFSDirectory (indexLocation )) {
472- failIfCorrupted (dir , shardId );
469+ failIfCorrupted (dir );
473470 SegmentInfos segInfo = Lucene .readSegmentInfos (dir );
474471 logger .trace ("{} loaded segment info [{}]" , shardId , segInfo );
475472 }
@@ -550,7 +547,7 @@ public boolean isMarkedCorrupted() throws IOException {
550547 */
551548 final String [] files = directory ().listAll ();
552549 for (String file : files ) {
553- if (file .startsWith (CORRUPTED )) {
550+ if (file .startsWith (CORRUPTED_MARKER_NAME_PREFIX )) {
554551 return true ;
555552 }
556553 }
@@ -566,7 +563,7 @@ public void removeCorruptionMarker() throws IOException {
566563 IOException firstException = null ;
567564 final String [] files = directory .listAll ();
568565 for (String file : files ) {
569- if (file .startsWith (CORRUPTED )) {
566+ if (file .startsWith (CORRUPTED_MARKER_NAME_PREFIX )) {
570567 try {
571568 directory .deleteFile (file );
572569 } catch (IOException ex ) {
@@ -585,40 +582,25 @@ public void removeCorruptionMarker() throws IOException {
585582
586583 public void failIfCorrupted () throws IOException {
587584 ensureOpen ();
588- failIfCorrupted (directory , shardId );
585+ failIfCorrupted (directory );
589586 }
590587
591- private static void failIfCorrupted (Directory directory , ShardId shardId ) throws IOException {
588+ private static void failIfCorrupted (Directory directory ) throws IOException {
592589 final String [] files = directory .listAll ();
593590 List <CorruptIndexException > ex = new ArrayList <>();
594591 for (String file : files ) {
595- if (file .startsWith (CORRUPTED )) {
592+ if (file .startsWith (CORRUPTED_MARKER_NAME_PREFIX )) {
596593 try (ChecksumIndexInput input = directory .openChecksumInput (file , IOContext .READONCE )) {
597- int version = CodecUtil .checkHeader (input , CODEC , VERSION_START , VERSION );
598-
599- if (version == VERSION_WRITE_THROWABLE ) {
600- final int size = input .readVInt ();
601- final byte [] buffer = new byte [size ];
602- input .readBytes (buffer , 0 , buffer .length );
603- StreamInput in = StreamInput .wrap (buffer );
604- Exception t = in .readException ();
605- if (t instanceof CorruptIndexException ) {
606- ex .add ((CorruptIndexException ) t );
607- } else {
608- ex .add (new CorruptIndexException (t .getMessage (), "preexisting_corruption" , t ));
609- }
594+ CodecUtil .checkHeader (input , CODEC , CORRUPTED_MARKER_CODEC_VERSION , CORRUPTED_MARKER_CODEC_VERSION );
595+ final int size = input .readVInt ();
596+ final byte [] buffer = new byte [size ];
597+ input .readBytes (buffer , 0 , buffer .length );
598+ StreamInput in = StreamInput .wrap (buffer );
599+ Exception t = in .readException ();
600+ if (t instanceof CorruptIndexException ) {
601+ ex .add ((CorruptIndexException ) t );
610602 } else {
611- assert version == VERSION_START || version == VERSION_STACK_TRACE ;
612- String msg = input .readString ();
613- StringBuilder builder = new StringBuilder (shardId .toString ());
614- builder .append (" Preexisting corrupted index [" );
615- builder .append (file ).append ("] caused by: " );
616- builder .append (msg );
617- if (version == VERSION_STACK_TRACE ) {
618- builder .append (System .lineSeparator ());
619- builder .append (input .readString ());
620- }
621- ex .add (new CorruptIndexException (builder .toString (), "preexisting_corruption" ));
603+ ex .add (new CorruptIndexException (t .getMessage (), "preexisting_corruption" , t ));
622604 }
623605 CodecUtil .checkFooter (input );
624606 }
@@ -654,7 +636,7 @@ public void cleanupAndVerify(String reason, MetadataSnapshot sourceMetaData) thr
654636 } catch (IOException ex ) {
655637 if (existingFile .startsWith (IndexFileNames .SEGMENTS )
656638 || existingFile .equals (IndexFileNames .OLD_SEGMENTS_GEN )
657- || existingFile .startsWith (CORRUPTED )) {
639+ || existingFile .startsWith (CORRUPTED_MARKER_NAME_PREFIX )) {
658640 // TODO do we need to also fail this if we can't delete the pending commit file?
659641 // if one of those files can't be deleted we better fail the cleanup otherwise we might leave an old commit
660642 // point around?
@@ -1386,9 +1368,9 @@ public void deleteQuiet(String... files) {
13861368 public void markStoreCorrupted (IOException exception ) throws IOException {
13871369 ensureOpen ();
13881370 if (!isMarkedCorrupted ()) {
1389- String uuid = CORRUPTED + UUIDs .randomBase64UUID ();
1390- try (IndexOutput output = this .directory ().createOutput (uuid , IOContext .DEFAULT )) {
1391- CodecUtil .writeHeader (output , CODEC , VERSION );
1371+ final String corruptionMarkerName = CORRUPTED_MARKER_NAME_PREFIX + UUIDs .randomBase64UUID ();
1372+ try (IndexOutput output = this .directory ().createOutput (corruptionMarkerName , IOContext .DEFAULT )) {
1373+ CodecUtil .writeHeader (output , CODEC , CORRUPTED_MARKER_CODEC_VERSION );
13921374 BytesStreamOutput out = new BytesStreamOutput ();
13931375 out .writeException (exception );
13941376 BytesReference bytes = out .bytes ();
@@ -1399,7 +1381,7 @@ public void markStoreCorrupted(IOException exception) throws IOException {
13991381 } catch (IOException ex ) {
14001382 logger .warn ("Can't mark store as corrupted" , ex );
14011383 }
1402- directory ().sync (Collections .singleton (uuid ));
1384+ directory ().sync (Collections .singleton (corruptionMarkerName ));
14031385 }
14041386 }
14051387
0 commit comments