Author: jbellis
Date: Thu Dec 31 21:31:01 2009
New Revision: 894943
URL: http://svn.apache.org/viewvc?rev=894943&view=rev
Log:
Implement FileDataInput with MappedFileDataInput, backed by a mmap'd ByteBuffer.
patch by jbellis; reviewed by Brandon Williams and goffinet for CASSANDRA-408
Added:
incubator/cassandra/trunk/src/java/org/apache/cassandra/io/util/MappedFileDataInput.java
(with props)
Modified:
incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Table.java
incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableNamesIterator.java
incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableSliceIterator.java
incubator/cassandra/trunk/src/java/org/apache/cassandra/io/IndexHelper.java
incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SSTableReader.java
incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SSTableScanner.java
incubator/cassandra/trunk/src/java/org/apache/cassandra/service/CassandraDaemon.java
Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Table.java
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Table.java?rev=894943&r1=894942&r2=894943&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Table.java
(original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Table.java Thu
Dec 31 21:31:01 2009
@@ -193,6 +193,7 @@
if (tableInstance == null)
{
tableInstance = new Table(table);
+ tableInstance.onStart();
instances.put(table, tableInstance);
}
}
Modified:
incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableNamesIterator.java
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableNamesIterator.java?rev=894943&r1=894942&r2=894943&view=diff
==============================================================================
---
incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableNamesIterator.java
(original)
+++
incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableNamesIterator.java
Thu Dec 31 21:31:01 2009
@@ -30,6 +30,7 @@
import org.apache.cassandra.db.marshal.AbstractType;
import org.apache.cassandra.io.*;
import org.apache.cassandra.io.util.BufferedRandomAccessFile;
+import org.apache.cassandra.io.util.FileDataInput;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.utils.BloomFilter;
@@ -49,7 +50,7 @@
if (position < 0)
return;
- BufferedRandomAccessFile file = new
BufferedRandomAccessFile(ssTable.getFilename(), "r",
DatabaseDescriptor.getIndexedReadBufferSizeInKB() * 1024);
+ FileDataInput file =
ssTable.getFileDataInput(DatabaseDescriptor.getIndexedReadBufferSizeInKB() *
1024);
try
{
file.seek(position);
Modified:
incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableSliceIterator.java
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableSliceIterator.java?rev=894943&r1=894942&r2=894943&view=diff
==============================================================================
---
incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableSliceIterator.java
(original)
+++
incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableSliceIterator.java
Thu Dec 31 21:31:01 2009
@@ -30,6 +30,7 @@
import org.apache.cassandra.db.marshal.AbstractType;
import org.apache.cassandra.io.*;
import org.apache.cassandra.io.util.BufferedRandomAccessFile;
+import org.apache.cassandra.io.util.FileDataInput;
import org.apache.cassandra.config.DatabaseDescriptor;
import com.google.common.collect.AbstractIterator;
@@ -114,14 +115,14 @@
private final List<IndexHelper.IndexInfo> indexes;
private final long columnStartPosition;
- private final BufferedRandomAccessFile file;
+ private final FileDataInput file;
private int curRangeIndex;
private Deque<IColumn> blockColumns = new ArrayDeque<IColumn>();
public ColumnGroupReader(SSTableReader ssTable, DecoratedKey key, long
position) throws IOException
{
- this.file = new BufferedRandomAccessFile(ssTable.getFilename(),
"r", DatabaseDescriptor.getSlicedReadBufferSizeInKB() * 1024);
+ this.file =
ssTable.getFileDataInput(DatabaseDescriptor.getSlicedReadBufferSizeInKB() *
1024);
file.seek(position);
DecoratedKey keyInDisk =
ssTable.getPartitioner().convertFromDiskFormat(file.readUTF());
Modified:
incubator/cassandra/trunk/src/java/org/apache/cassandra/io/IndexHelper.java
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/io/IndexHelper.java?rev=894943&r1=894942&r2=894943&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/io/IndexHelper.java
(original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/io/IndexHelper.java
Thu Dec 31 21:31:01 2009
@@ -21,10 +21,10 @@
import java.io.*;
import java.util.*;
-import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.db.ColumnSerializer;
import org.apache.cassandra.db.marshal.AbstractType;
import org.apache.cassandra.utils.BloomFilter;
+import org.apache.cassandra.io.util.FileDataInput;
/**
@@ -44,8 +44,9 @@
/* size of the bloom filter */
int size = in.readInt();
/* skip the serialized bloom filter */
- if (in.skipBytes(size) != size)
- throw new EOFException();
+ int skipped = in.skipBytes(size);
+ if (skipped != size)
+ throw new EOFException("attempted to skip " + size + " bytes but
only skipped " + skipped);
}
/**
@@ -66,7 +67,7 @@
* Deserialize the index into a structure and return it
* @throws IOException
*/
- public static ArrayList<IndexInfo> deserializeIndex(RandomAccessFile
in) throws IOException
+ public static ArrayList<IndexInfo> deserializeIndex(FileDataInput in)
throws IOException
{
ArrayList<IndexInfo> indexList = new ArrayList<IndexInfo>();
@@ -87,7 +88,7 @@
* @return bloom filter summarizing the column information
* @throws java.io.IOException
*/
- public static BloomFilter defreezeBloomFilter(RandomAccessFile file)
throws IOException
+ public static BloomFilter defreezeBloomFilter(FileDataInput file) throws
IOException
{
int size = file.readInt();
byte[] bytes = new byte[size];
@@ -149,7 +150,7 @@
return 2 + firstName.length + 2 + lastName.length + 8 + 8;
}
- public static IndexInfo deserialize(RandomAccessFile dis) throws
IOException
+ public static IndexInfo deserialize(FileDataInput dis) throws
IOException
{
return new IndexInfo(ColumnSerializer.readName(dis),
ColumnSerializer.readName(dis), dis.readLong(), dis.readLong());
}
Modified:
incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SSTableReader.java
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SSTableReader.java?rev=894943&r1=894942&r2=894943&view=diff
==============================================================================
---
incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SSTableReader.java
(original)
+++
incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SSTableReader.java
Thu Dec 31 21:31:01 2009
@@ -23,6 +23,8 @@
import java.lang.ref.ReferenceQueue;
import java.lang.ref.PhantomReference;
import java.lang.ref.Reference;
+import java.nio.channels.FileChannel;
+import java.nio.MappedByteBuffer;
import org.apache.log4j.Logger;
@@ -36,6 +38,8 @@
import org.apache.cassandra.db.*;
import org.apache.cassandra.db.marshal.AbstractType;
import org.apache.cassandra.io.util.BufferedRandomAccessFile;
+import org.apache.cassandra.io.util.FileDataInput;
+import org.apache.cassandra.io.util.MappedFileDataInput;
import org.cliffc.high_scale_lib.NonBlockingHashMap;
import com.google.common.base.Predicate;
@@ -180,6 +184,9 @@
}
FileDeletingReference phantomReference;
+ private final MappedByteBuffer indexBuffer;
+ private final MappedByteBuffer buffer;
+
public static ConcurrentLinkedHashMap<DecoratedKey, Long>
createKeyCache(int size)
{
@@ -191,6 +198,9 @@
SSTableReader(String filename, IPartitioner partitioner, List<KeyPosition>
indexPositions, BloomFilter bloomFilter, ConcurrentLinkedHashMap<DecoratedKey,
Long> keyCache)
{
super(filename, partitioner);
+ indexBuffer = mmap(indexFilename());
+ buffer = mmap(path); // TODO
System.getProperty("os.arch").contains("64") ? mmap(path) : null;
+
this.indexPositions = indexPositions;
this.bf = bloomFilter;
phantomReference = new FileDeletingReference(this, finalizerQueue);
@@ -199,6 +209,27 @@
this.keyCache = keyCache;
}
+ private static MappedByteBuffer mmap(String filename)
+ {
+ RandomAccessFile raf;
+ try
+ {
+ raf = new RandomAccessFile(filename, "r");
+ }
+ catch (FileNotFoundException e)
+ {
+ throw new IOError(e);
+ }
+ try
+ {
+ return raf.getChannel().map(FileChannel.MapMode.READ_ONLY, 0,
raf.length());
+ }
+ catch (IOException e)
+ {
+ throw new IOError(e);
+ }
+ }
+
private SSTableReader(String filename, IPartitioner partitioner)
{
this(filename, partitioner, null, null, null);
@@ -224,31 +255,24 @@
void loadIndexFile() throws IOException
{
- BufferedRandomAccessFile input = new
BufferedRandomAccessFile(indexFilename(), "r");
- try
- {
- indexPositions = new ArrayList<KeyPosition>();
+ indexPositions = new ArrayList<KeyPosition>();
- int i = 0;
- long indexSize = input.length();
- while (true)
+ FileDataInput input = new MappedFileDataInput(indexBuffer,
indexFilename());
+ int i = 0;
+ long indexSize = input.length();
+ while (true)
+ {
+ long indexPosition = input.getFilePointer();
+ if (indexPosition == indexSize)
{
- long indexPosition = input.getFilePointer();
- if (indexPosition == indexSize)
- {
- break;
- }
- DecoratedKey decoratedKey =
partitioner.convertFromDiskFormat(input.readUTF());
- input.readLong();
- if (i++ % INDEX_INTERVAL == 0)
- {
- indexPositions.add(new KeyPosition(decoratedKey,
indexPosition));
- }
+ break;
+ }
+ DecoratedKey decoratedKey =
partitioner.convertFromDiskFormat(input.readUTF());
+ input.readLong();
+ if (i++ % INDEX_INTERVAL == 0)
+ {
+ indexPositions.add(new KeyPosition(decoratedKey,
indexPosition));
}
- }
- finally
- {
- input.close();
}
}
@@ -293,39 +317,31 @@
return -1;
}
- // TODO mmap the index file?
- BufferedRandomAccessFile input = new
BufferedRandomAccessFile(indexFilename(path), "r");
+ FileDataInput input = new MappedFileDataInput(indexBuffer,
indexFilename());
input.seek(start);
int i = 0;
- try
+ do
{
- do
+ DecoratedKey indexDecoratedKey;
+ try
{
- DecoratedKey indexDecoratedKey;
- try
- {
- indexDecoratedKey =
partitioner.convertFromDiskFormat(input.readUTF());
- }
- catch (EOFException e)
- {
- return -1;
- }
- long position = input.readLong();
- int v = indexDecoratedKey.compareTo(decoratedKey);
- if (v == 0)
- {
- if (keyCache != null)
- keyCache.put(decoratedKey, position);
- return position;
- }
- if (v > 0)
- return -1;
- } while (++i < INDEX_INTERVAL);
- }
- finally
- {
- input.close();
- }
+ indexDecoratedKey =
partitioner.convertFromDiskFormat(input.readUTF());
+ }
+ catch (EOFException e)
+ {
+ return -1;
+ }
+ long position = input.readLong();
+ int v = indexDecoratedKey.compareTo(decoratedKey);
+ if (v == 0)
+ {
+ if (keyCache != null)
+ keyCache.put(decoratedKey, position);
+ return position;
+ }
+ if (v > 0)
+ return -1;
+ } while (++i < INDEX_INTERVAL);
return -1;
}
@@ -406,7 +422,20 @@
public SSTableScanner getScanner(int bufferSize) throws IOException
{
- return new SSTableScanner(this, bufferSize);
+ FileDataInput fdi = getFileDataInput(bufferSize);
+ return new SSTableScanner(this, fdi);
+ }
+
+ public FileDataInput getFileDataInput(int bufferSize)
+ {
+ try
+ {
+ return buffer == null ? new BufferedRandomAccessFile(path, "r",
bufferSize) : new MappedFileDataInput(buffer, path);
+ }
+ catch (FileNotFoundException e)
+ {
+ throw new AssertionError(e);
+ }
}
public AbstractType getColumnComparator()
Modified:
incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SSTableScanner.java
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SSTableScanner.java?rev=894943&r1=894942&r2=894943&view=diff
==============================================================================
---
incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SSTableScanner.java
(original)
+++
incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SSTableScanner.java
Thu Dec 31 21:31:01 2009
@@ -45,9 +45,9 @@
* @param sstable SSTable to scan.
* @param bufferSize Number of bytes to buffer the file while scanning.
*/
- SSTableScanner(SSTableReader sstable, int bufferSize) throws IOException
+ SSTableScanner(SSTableReader sstable, FileDataInput file) throws
IOException
{
- this.file = new BufferedRandomAccessFile(sstable.getFilename(), "r",
bufferSize);
+ this.file = file;
this.sstable = sstable;
}
Added:
incubator/cassandra/trunk/src/java/org/apache/cassandra/io/util/MappedFileDataInput.java
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/io/util/MappedFileDataInput.java?rev=894943&view=auto
==============================================================================
---
incubator/cassandra/trunk/src/java/org/apache/cassandra/io/util/MappedFileDataInput.java
(added)
+++
incubator/cassandra/trunk/src/java/org/apache/cassandra/io/util/MappedFileDataInput.java
Thu Dec 31 21:31:01 2009
@@ -0,0 +1,374 @@
+package org.apache.cassandra.io.util;
+
+import java.nio.MappedByteBuffer;
+import java.io.*;
+
+public class MappedFileDataInput extends InputStream implements FileDataInput
+{
+ private final MappedByteBuffer buffer;
+ private final String filename;
+ private final long length;
+ private int position;
+
+ public MappedFileDataInput(MappedByteBuffer buffer, String filename)
+ {
+ assert buffer != null;
+ this.buffer = buffer;
+ this.filename = filename;
+ length = new File(filename).length();
+ }
+
+ public void seek(long pos) throws IOException
+ {
+ assert pos <= Integer.MAX_VALUE; // TODO chunk file into 2GB buffers
+ position = (int) pos;
+ }
+
+ public long length() throws IOException
+ {
+ return length;
+ }
+
+ public long getFilePointer()
+ {
+ return position;
+ }
+
+ public String getPath()
+ {
+ return filename;
+ }
+
+ public int read() throws IOException
+ {
+ if (position == length)
+ return -1;
+ return buffer.get(position++) & 0xFF;
+ }
+
+ public int skipBytes(int n) throws IOException
+ {
+ if (n <= 0)
+ return 0;
+ long oldPosition = position;
+ position = (int) Math.min(length(), position + n); // TODO fix > 2GB
bug
+ return (int) (position - oldPosition);
+ }
+
+ /*
+ !! DataInput methods below are copied from the implementation in Apache
Harmony RandomAccessFile.
+ */
+
+ /**
+ * Reads a boolean from the current position in this file. Blocks until one
+ * byte has been read, the end of the file is reached or an exception is
+ * thrown.
+ *
+ * @return the next boolean value from this file.
+ * @throws EOFException
+ * if the end of this file is detected.
+ * @throws IOException
+ * if this file is closed or another I/O error occurs.
+ */
+ public final boolean readBoolean() throws IOException {
+ int temp = this.read();
+ if (temp < 0) {
+ throw new EOFException();
+ }
+ return temp != 0;
+ }
+
+ /**
+ * Reads an 8-bit byte from the current position in this file. Blocks until
+ * one byte has been read, the end of the file is reached or an exception
is
+ * thrown.
+ *
+ * @return the next signed 8-bit byte value from this file.
+ * @throws EOFException
+ * if the end of this file is detected.
+ * @throws IOException
+ * if this file is closed or another I/O error occurs.
+ */
+ public final byte readByte() throws IOException {
+ int temp = this.read();
+ if (temp < 0) {
+ throw new EOFException();
+ }
+ return (byte) temp;
+ }
+
+ /**
+ * Reads a 16-bit character from the current position in this file. Blocks
until
+ * two bytes have been read, the end of the file is reached or an
exception is
+ * thrown.
+ *
+ * @return the next char value from this file.
+ * @throws EOFException
+ * if the end of this file is detected.
+ * @throws IOException
+ * if this file is closed or another I/O error occurs.
+ */
+ public final char readChar() throws IOException {
+ byte[] buffer = new byte[2];
+ if (read(buffer, 0, buffer.length) != buffer.length) {
+ throw new EOFException();
+ }
+ return (char) (((buffer[0] & 0xff) << 8) + (buffer[1] & 0xff));
+ }
+
+ /**
+ * Reads a 64-bit double from the current position in this file. Blocks
+ * until eight bytes have been read, the end of the file is reached or an
+ * exception is thrown.
+ *
+ * @return the next double value from this file.
+ * @throws EOFException
+ * if the end of this file is detected.
+ * @throws IOException
+ * if this file is closed or another I/O error occurs.
+ */
+ public final double readDouble() throws IOException {
+ return Double.longBitsToDouble(readLong());
+ }
+
+ /**
+ * Reads a 32-bit float from the current position in this file. Blocks
+ * until four bytes have been read, the end of the file is reached or an
+ * exception is thrown.
+ *
+ * @return the next float value from this file.
+ * @throws EOFException
+ * if the end of this file is detected.
+ * @throws IOException
+ * if this file is closed or another I/O error occurs.
+ */
+ public final float readFloat() throws IOException {
+ return Float.intBitsToFloat(readInt());
+ }
+
+ /**
+ * Reads bytes from this file into {...@code buffer}. Blocks until
{...@code
+ * buffer.length} number of bytes have been read, the end of the file is
+ * reached or an exception is thrown.
+ *
+ * @param buffer
+ * the buffer to read bytes into.
+ * @throws EOFException
+ * if the end of this file is detected.
+ * @throws IOException
+ * if this file is closed or another I/O error occurs.
+ * @throws NullPointerException
+ * if {...@code buffer} is {...@code null}.
+ */
+ public final void readFully(byte[] buffer) throws IOException {
+ readFully(buffer, 0, buffer.length);
+ }
+
+ /**
+ * Read bytes from this file into {...@code buffer} starting at offset
{...@code
+ * offset}. This method blocks until {...@code count} number of bytes have
been
+ * read.
+ *
+ * @param buffer
+ * the buffer to read bytes into.
+ * @param offset
+ * the initial position in {...@code buffer} to store the bytes
read
+ * from this file.
+ * @param count
+ * the maximum number of bytes to store in {...@code buffer}.
+ * @throws EOFException
+ * if the end of this file is detected.
+ * @throws IndexOutOfBoundsException
+ * if {...@code offset < 0} or {...@code count < 0}, or if
{...@code
+ * offset + count} is greater than the length of {...@code
buffer}.
+ * @throws IOException
+ * if this file is closed or another I/O error occurs.
+ * @throws NullPointerException
+ * if {...@code buffer} is {...@code null}.
+ */
+ public final void readFully(byte[] buffer, int offset, int count)
+ throws IOException {
+ if (buffer == null) {
+ throw new NullPointerException();
+ }
+ // avoid int overflow
+ if (offset < 0 || offset > buffer.length || count < 0
+ || count > buffer.length - offset) {
+ throw new IndexOutOfBoundsException();
+ }
+ while (count > 0) {
+ int result = read(buffer, offset, count);
+ if (result < 0) {
+ throw new EOFException();
+ }
+ offset += result;
+ count -= result;
+ }
+ }
+
+ /**
+ * Reads a 32-bit integer from the current position in this file. Blocks
+ * until four bytes have been read, the end of the file is reached or an
+ * exception is thrown.
+ *
+ * @return the next int value from this file.
+ * @throws EOFException
+ * if the end of this file is detected.
+ * @throws IOException
+ * if this file is closed or another I/O error occurs.
+ */
+ public final int readInt() throws IOException {
+ byte[] buffer = new byte[4];
+ if (read(buffer, 0, buffer.length) != buffer.length) {
+ throw new EOFException();
+ }
+ return ((buffer[0] & 0xff) << 24) + ((buffer[1] & 0xff) << 16)
+ + ((buffer[2] & 0xff) << 8) + (buffer[3] & 0xff);
+ }
+
+ /**
+ * Reads a line of text form the current position in this file. A line is
+ * represented by zero or more characters followed by {...@code '\n'},
{...@code
+ * '\r'}, {...@code "\r\n"} or the end of file marker. The string does not
+ * include the line terminating sequence.
+ * <p>
+ * Blocks until a line terminating sequence has been read, the end of the
+ * file is reached or an exception is thrown.
+ *
+ * @return the contents of the line or {...@code null} if no characters
have
+ * been read before the end of the file has been reached.
+ * @throws IOException
+ * if this file is closed or another I/O error occurs.
+ */
+ public final String readLine() throws IOException {
+ StringBuilder line = new StringBuilder(80); // Typical line length
+ boolean foundTerminator = false;
+ long unreadPosition = 0;
+ while (true) {
+ int nextByte = read();
+ switch (nextByte) {
+ case -1:
+ return line.length() != 0 ? line.toString() : null;
+ case (byte) '\r':
+ if (foundTerminator) {
+ seek(unreadPosition);
+ return line.toString();
+ }
+ foundTerminator = true;
+ /* Have to be able to peek ahead one byte */
+ unreadPosition = getFilePointer();
+ break;
+ case (byte) '\n':
+ return line.toString();
+ default:
+ if (foundTerminator) {
+ seek(unreadPosition);
+ return line.toString();
+ }
+ line.append((char) nextByte);
+ }
+ }
+ }
+
+ /**
+ * Reads a 64-bit long from the current position in this file. Blocks until
+ * eight bytes have been read, the end of the file is reached or an
+ * exception is thrown.
+ *
+ * @return the next long value from this file.
+ * @throws EOFException
+ * if the end of this file is detected.
+ * @throws IOException
+ * if this file is closed or another I/O error occurs.
+ */
+ public final long readLong() throws IOException {
+ byte[] buffer = new byte[8];
+ int n = read(buffer, 0, buffer.length);
+ if (n != buffer.length) {
+ throw new EOFException("expected 8 bytes; read " + n + " at final
position " + position);
+ }
+ return ((long) (((buffer[0] & 0xff) << 24) + ((buffer[1] & 0xff) << 16)
+ + ((buffer[2] & 0xff) << 8) + (buffer[3] & 0xff)) << 32)
+ + ((long) (buffer[4] & 0xff) << 24)
+ + ((buffer[5] & 0xff) << 16)
+ + ((buffer[6] & 0xff) << 8)
+ + (buffer[7] & 0xff);
+ }
+
+ /**
+ * Reads a 16-bit short from the current position in this file. Blocks
until
+ * two bytes have been read, the end of the file is reached or an exception
+ * is thrown.
+ *
+ * @return the next short value from this file.
+ * @throws EOFException
+ * if the end of this file is detected.
+ * @throws IOException
+ * if this file is closed or another I/O error occurs.
+ */
+ public final short readShort() throws IOException {
+ byte[] buffer = new byte[2];
+ if (read(buffer, 0, buffer.length) != buffer.length) {
+ throw new EOFException();
+ }
+ return (short) (((buffer[0] & 0xff) << 8) + (buffer[1] & 0xff));
+ }
+
+ /**
+ * Reads an unsigned 8-bit byte from the current position in this file and
+ * returns it as an integer. Blocks until one byte has been read, the end
of
+ * the file is reached or an exception is thrown.
+ *
+ * @return the next unsigned byte value from this file as an int.
+ * @throws EOFException
+ * if the end of this file is detected.
+ * @throws IOException
+ * if this file is closed or another I/O error occurs.
+ */
+ public final int readUnsignedByte() throws IOException {
+ int temp = this.read();
+ if (temp < 0) {
+ throw new EOFException();
+ }
+ return temp;
+ }
+
+ /**
+ * Reads an unsigned 16-bit short from the current position in this file
and
+ * returns it as an integer. Blocks until two bytes have been read, the
end of
+ * the file is reached or an exception is thrown.
+ *
+ * @return the next unsigned short value from this file as an int.
+ * @throws EOFException
+ * if the end of this file is detected.
+ * @throws IOException
+ * if this file is closed or another I/O error occurs.
+ */
+ public final int readUnsignedShort() throws IOException {
+ byte[] buffer = new byte[2];
+ if (read(buffer, 0, buffer.length) != buffer.length) {
+ throw new EOFException();
+ }
+ return ((buffer[0] & 0xff) << 8) + (buffer[1] & 0xff);
+ }
+
+ /**
+ * Reads a string that is encoded in {...@link DataInput modified UTF-8}
from
+ * this file. The number of bytes that must be read for the complete string
+ * is determined by the first two bytes read from the file. Blocks until
all
+ * required bytes have been read, the end of the file is reached or an
+ * exception is thrown.
+ *
+ * @return the next string encoded in {...@link DataInput modified UTF-8}
from
+ * this file.
+ * @throws EOFException
+ * if the end of this file is detected.
+ * @throws IOException
+ * if this file is closed or another I/O error occurs.
+ * @throws UTFDataFormatException
+ * if the bytes read cannot be decoded into a character string.
+ */
+ public final String readUTF() throws IOException {
+ return DataInputStream.readUTF(this);
+ }
+}
Propchange:
incubator/cassandra/trunk/src/java/org/apache/cassandra/io/util/MappedFileDataInput.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
incubator/cassandra/trunk/src/java/org/apache/cassandra/service/CassandraDaemon.java
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/service/CassandraDaemon.java?rev=894943&r1=894942&r2=894943&view=diff
==============================================================================
---
incubator/cassandra/trunk/src/java/org/apache/cassandra/service/CassandraDaemon.java
(original)
+++
incubator/cassandra/trunk/src/java/org/apache/cassandra/service/CassandraDaemon.java
Thu Dec 31 21:31:01 2009
@@ -87,8 +87,7 @@
{
if (logger.isDebugEnabled())
logger.debug("opening keyspace " + table);
- Table tbl = Table.open(table);
- tbl.onStart();
+ Table.open(table);
}
// replay the log if necessary and check for compaction candidates