10
10
11
11
import java .io .IOException ;
12
12
13
+ import org .apache .logging .log4j .LogManager ;
14
+ import org .apache .logging .log4j .Logger ;
15
+ import org .apache .logging .log4j .message .ParameterizedMessage ;
13
16
import org .apache .lucene .codecs .CodecUtil ;
17
+ import org .apache .lucene .index .CorruptIndexException ;
14
18
import org .apache .lucene .store .ChecksumIndexInput ;
15
19
import org .apache .lucene .store .IndexInput ;
16
20
import org .apache .lucene .store .IndexOutput ;
22
26
* @opensearch.internal
23
27
*/
24
28
public class VersionedCodecStreamWrapper <T > {
29
+ private static final Logger logger = LogManager .getLogger (VersionedCodecStreamWrapper .class );
30
+
25
31
// TODO This can be updated to hold a streamReadWriteHandlerFactory and get relevant handler based on the stream versions
26
32
private final IndexIOStreamHandler <T > indexIOStreamHandler ;
27
33
private final int currentVersion ;
@@ -46,10 +52,21 @@ public VersionedCodecStreamWrapper(IndexIOStreamHandler<T> indexIOStreamHandler,
46
52
* @return stream content parsed into {@link T}
47
53
*/
48
54
public T readStream (IndexInput indexInput ) throws IOException {
49
- CodecUtil .checksumEntireFile (indexInput );
50
- int readStreamVersion = checkHeader (indexInput );
51
- T content = getHandlerForVersion (readStreamVersion ).readContent (indexInput );
52
- return content ;
55
+ logger .debug ("Reading input stream [{}] of length - [{}]" , indexInput .toString (), indexInput .length ());
56
+ try {
57
+ CodecUtil .checksumEntireFile (indexInput );
58
+ int readStreamVersion = checkHeader (indexInput );
59
+ return getHandlerForVersion (readStreamVersion ).readContent (indexInput );
60
+ } catch (CorruptIndexException cie ) {
61
+ logger .error (
62
+ () -> new ParameterizedMessage (
63
+ "Error while validating header/footer for [{}]. Total data length [{}]" ,
64
+ indexInput .toString (),
65
+ indexInput .length ()
66
+ )
67
+ );
68
+ throw cie ;
69
+ }
53
70
}
54
71
55
72
/**
0 commit comments