File tree Expand file tree Collapse file tree 3 files changed +23
-4
lines changed
ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented Expand file tree Collapse file tree 3 files changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -292,7 +292,11 @@ ReferenceCountedObject<LogEntryProto> load(TermIndex key) throws IOException {
292292 }
293293 });
294294 loadingTimes .incrementAndGet ();
295- return Objects .requireNonNull (toReturn .get (), () -> "toReturn == null for " + key );
295+ final ReferenceCountedObject <LogEntryProto > proto = toReturn .get ();
296+ if (proto == null ) {
297+ throw new RaftLogIOException ("Failed to load log entry " + key );
298+ }
299+ return proto ;
296300 }
297301 }
298302
@@ -502,8 +506,10 @@ synchronized ReferenceCountedObject<LogEntryProto> loadCache(TermIndex ti) throw
502506 }
503507 try {
504508 return cacheLoader .load (ti );
509+ } catch (RaftLogIOException e ) {
510+ throw e ;
505511 } catch (Exception e ) {
506- throw new RaftLogIOException (e );
512+ throw new RaftLogIOException ("Failed to loadCache for log entry " + ti , e );
507513 }
508514 }
509515
Original file line number Diff line number Diff line change 2121import java .io .EOFException ;
2222import java .io .File ;
2323import java .io .IOException ;
24+ import java .nio .channels .ClosedByInterruptException ;
2425import java .util .Optional ;
2526
2627import org .apache .ratis .proto .RaftProtos .LogEntryProto ;
@@ -104,7 +105,11 @@ public LogEntryProto nextEntry() throws IOException {
104105 try {
105106 init ();
106107 } catch (Exception e ) {
107- LOG .error ("caught exception initializing " + this , e );
108+ if (e .getCause () instanceof ClosedByInterruptException ) {
109+ LOG .warn ("Initialization is interrupted: {}" , this , e );
110+ } else {
111+ LOG .error ("Failed to initialize {}" , this , e );
112+ }
108113 throw IOUtils .asIOException (e );
109114 }
110115 }
Original file line number Diff line number Diff line change 4242import java .io .FilterInputStream ;
4343import java .io .IOException ;
4444import java .io .InputStream ;
45+ import java .nio .channels .ClosedByInterruptException ;
4546import java .util .Optional ;
4647import java .util .zip .Checksum ;
4748
@@ -169,7 +170,14 @@ public long skip(long amt) throws IOException {
169170 */
170171 boolean verifyHeader () throws IOException {
171172 final int headerLength = SegmentedRaftLogFormat .getHeaderLength ();
172- final int readLength = in .read (temp , 0 , headerLength );
173+ final int readLength ;
174+ try {
175+ readLength = in .read (temp , 0 , headerLength );
176+ } catch (ClosedByInterruptException e ) {
177+ Thread .currentThread ().interrupt ();
178+ throw new IOException ("Interrupted while reading the header of " + file , e );
179+ }
180+
173181 Preconditions .assertTrue (readLength <= headerLength );
174182 final int matchLength = SegmentedRaftLogFormat .matchHeader (temp , 0 , readLength );
175183 Preconditions .assertTrue (matchLength <= readLength );
You can’t perform that action at this time.
0 commit comments