From cd79f03977bb136be76104464f539f0a209c3457 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Fri, 27 Apr 2012 18:47:25 +0300 Subject: [PATCH] Translog: Buffering translog does not write directly to the file channel but to RAF, which causes problems reading from the channel on windows, closes #1887. --- .../index/translog/fs/BufferingFsTranslogFile.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/elasticsearch/index/translog/fs/BufferingFsTranslogFile.java b/src/main/java/org/elasticsearch/index/translog/fs/BufferingFsTranslogFile.java index afa23dc5bdf..05485b50039 100644 --- a/src/main/java/org/elasticsearch/index/translog/fs/BufferingFsTranslogFile.java +++ b/src/main/java/org/elasticsearch/index/translog/fs/BufferingFsTranslogFile.java @@ -57,7 +57,9 @@ public class BufferingFsTranslogFile implements FsTranslogFile { long position = lastPosition; if (size >= buffer.length) { flushBuffer(); - raf.raf().write(data, from, size); + // we use the channel to write, since on windows, writing to the RAF might not be reflected + // when reading through the channel + raf.channel().write(ByteBuffer.wrap(data, from, size)); lastWrittenPosition += size; lastPosition += size; return new Translog.Location(id, position, size); @@ -76,7 +78,9 @@ public class BufferingFsTranslogFile implements FsTranslogFile { private void flushBuffer() throws IOException { if (bufferCount > 0) { - raf.raf().write(buffer, 0, bufferCount); + // we use the channel to write, since on windows, writing to the RAF might not be reflected + // when reading through the channel + raf.channel().write(ByteBuffer.wrap(buffer, 0, bufferCount)); lastWrittenPosition += bufferCount; bufferCount = 0; }