You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by jb...@apache.org on 2011/02/22 19:03:31 UTC
svn commit: r1073438 - in /cassandra/branches/cassandra-0.7: CHANGES.txt
src/java/org/apache/cassandra/io/util/BufferedRandomAccessFile.java
test/unit/org/apache/cassandra/io/util/BufferedRandomAccessFileTest.java
Author: jbellis
Date: Tue Feb 22 18:03:31 2011
New Revision: 1073438
URL: http://svn.apache.org/viewvc?rev=1073438&view=rev
Log:
avoid EOFing on requests for the last bytes in a file
patch by Leo Jay; reviewed by jbellis for CASSANDRA-2213
Modified:
cassandra/branches/cassandra-0.7/CHANGES.txt
cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/util/BufferedRandomAccessFile.java
cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/io/util/BufferedRandomAccessFileTest.java
Modified: cassandra/branches/cassandra-0.7/CHANGES.txt
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/CHANGES.txt?rev=1073438&r1=1073437&r2=1073438&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/CHANGES.txt (original)
+++ cassandra/branches/cassandra-0.7/CHANGES.txt Tue Feb 22 18:03:31 2011
@@ -16,6 +16,7 @@
* fix for compaction and cleanup writing old-format data into new-version
sstable (CASSANDRA-2211, -2216)
* fix sstable2json large-row pagination (CASSANDRA-2188)
+ * fix EOFing on requests for the last bytes in a file (CASSANDRA-2213)
0.7.2
Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/util/BufferedRandomAccessFile.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/util/BufferedRandomAccessFile.java?rev=1073438&r1=1073437&r2=1073438&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/util/BufferedRandomAccessFile.java (original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/util/BufferedRandomAccessFile.java Tue Feb 22 18:03:31 2011
@@ -55,7 +55,7 @@ public class BufferedRandomAccessFile ex
// `current` as current position in file
// `bufferOffset` is the offset of the beginning of the buffer
- // `bufferEnd` is `bufferOffset` + count of bytes read from file
+ // `bufferEnd` is `bufferOffset` + count of bytes read from file, i.e. the lowest position we can't read from the buffer
private long bufferOffset, bufferEnd, current = 0;
// max buffer size is set according to (int size) parameter in the
@@ -259,9 +259,8 @@ public class BufferedRandomAccessFile ex
}
@Override
- // -1 will be returned if EOF is reached, RandomAccessFile is responsible
- // for
- // throwing EOFException
+ // -1 will be returned if EOF is reached; higher-level methods like readInt
+ // or readFully (from RandomAccessFile) will throw EOFException but this should not
public int read(byte[] buff, int offset, int length) throws IOException
{
int bytesCount = 0;
@@ -282,7 +281,7 @@ public class BufferedRandomAccessFile ex
private int readAtMost(byte[] buff, int offset, int length) throws IOException
{
- if (length >= bufferEnd && hitEOF)
+ if (length > bufferEnd && hitEOF)
return -1;
final int left = (int) maxBufferSize - buffer.position();
Modified: cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/io/util/BufferedRandomAccessFileTest.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/io/util/BufferedRandomAccessFileTest.java?rev=1073438&r1=1073437&r2=1073438&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/io/util/BufferedRandomAccessFileTest.java (original)
+++ cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/io/util/BufferedRandomAccessFileTest.java Tue Feb 22 18:03:31 2011
@@ -163,4 +163,27 @@ public class BufferedRandomAccessFileTes
// Expect this call to fail -- the distance from mark to current file pointer > 2gb.
bpm = rw.bytesPastMark(mark);
}
+
+ @Test
+ public void testRead() throws IOException
+ {
+ File tmpFile = File.createTempFile("readtest", "bin");
+ tmpFile.deleteOnExit();
+
+ BufferedRandomAccessFile rw = new BufferedRandomAccessFile(tmpFile.getPath(), "rw");
+ rw.write(new byte[]{ 1 });
+
+ rw.seek(0);
+ // test read of buffered-but-not-yet-written data
+ byte[] buffer = new byte[1];
+ assert rw.read(buffer) == 1;
+ assert buffer[0] == 1;
+ rw.close();
+
+ // test read of not-yet-buffered data
+ rw = new BufferedRandomAccessFile(tmpFile.getPath(), "rw");
+ assert rw.read(buffer) == 1;
+ assert buffer[0] == 1;
+ }
+
}