FileWriteAheadLogManager cannot start with zero-length WAL segment - Fixes
@@ -1169,10 +1169,12 @@ public class FileWriteAheadLogManager extends GridCacheSharedManagerAdapter impl
private FileDescriptor readFileDescriptor(File file, FileIOFactory ioFactory) {
FileDescriptor ds = new FileDescriptor(file);
- try (
- SegmentIO fileIO = ds.toIO(ioFactory);
- ByteBufferExpander buf = new ByteBufferExpander(HEADER_RECORD_SIZE, ByteOrder.nativeOrder())
- ) {
+ try (SegmentIO fileIO = ds.toIO(ioFactory)) {
+ // File may be empty when LOG_ONLY mode is enabled and mmap is disabled
+ if (fileIO.size() == 0)
+ return null;
+
+ try (ByteBufferExpander buf = new ByteBufferExpander(HEADER_RECORD_SIZE, ByteOrder.nativeOrder())) {
final DataInput in = segmentFileInputFactory.createFileInput(fileIO, buf);
// Header record must be agnostic to the serializer version.
@@ -1189,6 +1191,7 @@ public class FileWriteAheadLogManager extends GridCacheSharedManagerAdapter impl
return new FileDescriptor(file, ptr.index());
}
+ }
catch (IOException e) {
U.warn(log, "Failed to read file header [" + file + "]. Skipping this file", e);
