From 16f30f16749fe4f75c94b17aa4a4b63df4ddb825 Mon Sep 17 00:00:00 2001 From: Avinash Lakshman Date: Thu, 19 Mar 2009 19:48:21 +0000 Subject: [PATCH] Fixed some bugs that resulted from moving sources over. git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@756155 13f79535-47bb-0310-9956-ffa450edef68 --- .../cassandra/io/AIORandomAccessFile.java | 44 ------------------- .../io/BufferedRandomAccessFile.java | 22 +++++----- .../io/ChecksumRandomAccessFile.java | 2 +- src/org/apache/cassandra/io/SSTable.java | 23 ++-------- src/org/apache/cassandra/io/SequenceFile.java | 2 +- 5 files changed, 17 insertions(+), 76 deletions(-) diff --git a/src/org/apache/cassandra/io/AIORandomAccessFile.java b/src/org/apache/cassandra/io/AIORandomAccessFile.java index 365c19f868..f115d32f2e 100644 --- a/src/org/apache/cassandra/io/AIORandomAccessFile.java +++ b/src/org/apache/cassandra/io/AIORandomAccessFile.java @@ -656,50 +656,6 @@ public final class AIORandomAccessFile extends RandomAccessFile this.curr_ += len; return len; } - - public static void main(String[] args) throws Throwable - { - /* - int i = 0; - try - { - RandomAccessFile aRaf2 = new AIORandomAccessFile( new File("/var/cassandra/test.dat"), 64*1024); - aRaf2.seek(0L); - while ( i < 10000 ) - { - aRaf2.writeInt(32); - aRaf2.writeUTF("Avinash Lakshman"); - ++i; - } - aRaf2.close(); - } - catch( IOException ex ) - { - ex.printStackTrace(); - } - */ - /* - int j = 0; - try - { - RandomAccessFile aRaf2 = new AIORandomAccessFile( new File("/var/cassandra/test.dat") ); - while ( j < 10 ) - { - System.out.println( aRaf2.readInt() ); - System.out.println( aRaf2.readUTF() ); - ++j; - } - aRaf2.close(); - } - catch( IOException ex ) - { - ex.printStackTrace(); - } - */ - - ExecutorService es = new ContinuationsExecutor(1, 1, Integer.MAX_VALUE, TimeUnit.SECONDS, new LinkedBlockingQueue() ); - es.execute(new ReadImpl()); - } } class ReadImpl implements Runnable diff --git a/src/org/apache/cassandra/io/BufferedRandomAccessFile.java b/src/org/apache/cassandra/io/BufferedRandomAccessFile.java index f9bf888429..e218b7d785 100644 --- a/src/org/apache/cassandra/io/BufferedRandomAccessFile.java +++ b/src/org/apache/cassandra/io/BufferedRandomAccessFile.java @@ -165,20 +165,20 @@ public final class BufferedRandomAccessFile extends RandomAccessFile * disk. If the file was created read-only, this method is a no-op. */ public void flush() throws IOException - { + { this.flushBuffer(); } /* Flush any dirty bytes in the buffer to disk. */ private void flushBuffer() throws IOException - { + { if (this.dirty_) { if (this.diskPos_ != this.lo_) super.seek(this.lo_); int len = (int) (this.curr_ - this.lo_); super.write(this.buff_, 0, len); - this.diskPos_ = this.curr_; + this.diskPos_ = this.curr_; this.dirty_ = false; } } @@ -222,7 +222,7 @@ public final class BufferedRandomAccessFile extends RandomAccessFile { if (pos >= this.hi_ || pos < this.lo_) { - // seeking outside of current buffer -- flush and read + // seeking outside of current buffer -- flush and read this.flushBuffer(); this.lo_ = pos & BuffMask_; // start at BuffSz boundary this.maxHi_ = this.lo_ + (long) this.buff_.length; @@ -332,14 +332,14 @@ public final class BufferedRandomAccessFile extends RandomAccessFile } public void write(byte[] b, int off, int len) throws IOException - { + { while (len > 0) - { + { int n = this.writeAtMost(b, off, len); off += n; len -= n; - } - this.dirty_ = true; + this.dirty_ = true; + } } /* @@ -347,7 +347,7 @@ public final class BufferedRandomAccessFile extends RandomAccessFile * the number of bytes written. */ private int writeAtMost(byte[] b, int off, int len) throws IOException - { + { if (this.curr_ >= this.hi_) { if (this.hitEOF_ && this.hi_ < this.maxHi_) @@ -356,8 +356,8 @@ public final class BufferedRandomAccessFile extends RandomAccessFile this.hi_ = this.maxHi_; } else - { - // slow path -- write current buffer; read next one + { + // slow path -- write current buffer; read next one this.seek(this.curr_); if (this.curr_ == this.hi_) { diff --git a/src/org/apache/cassandra/io/ChecksumRandomAccessFile.java b/src/org/apache/cassandra/io/ChecksumRandomAccessFile.java index c3f2ac2f59..7619e245f9 100644 --- a/src/org/apache/cassandra/io/ChecksumRandomAccessFile.java +++ b/src/org/apache/cassandra/io/ChecksumRandomAccessFile.java @@ -391,8 +391,8 @@ public final class ChecksumRandomAccessFile extends RandomAccessFile int n = this.writeAtMost(b, off, len); off += n; len -= n; + this.dirty_ = true; } - this.dirty_ = true; } /* diff --git a/src/org/apache/cassandra/io/SSTable.java b/src/org/apache/cassandra/io/SSTable.java index ad2e104118..e2d4cae595 100644 --- a/src/org/apache/cassandra/io/SSTable.java +++ b/src/org/apache/cassandra/io/SSTable.java @@ -432,7 +432,8 @@ public class SSTable */ public SSTable(String directory, String filename, PartitionerType pType) throws IOException { - dataFile_ = directory + System.getProperty("file.separator") + filename + "-Data.db"; + dataFile_ = directory + System.getProperty("file.separator") + filename + "-Data.db"; + // dataWriter_ = SequenceFile.writer(dataFile_); dataWriter_ = SequenceFile.bufferedWriter(dataFile_, 4*1024*1024); // dataWriter_ = SequenceFile.chksumWriter(dataFile_, 4*1024*1024); SSTable.positionAfterFirstBlockIndex_ = dataWriter_.getCurrentPosition(); @@ -747,22 +748,7 @@ public class SSTable SSTable.indexMetadataMap_.put(dataFile_, keyPositionInfos); } - keyPositionInfos.add(new KeyPositionInfo(blockIndex.firstKey(), position)); - /* - try - { - keyPositionInfos.add(new KeyPositionInfo(blockIndex.firstKey(), position)); - } - catch(Exception ex) - { - Set keysInBlock = blockIndex.keySet(); - for( String keyInBlock : keysInBlock ) - { - logger_.warn("BLOCK KEY: " + keyInBlock); - } - logger_.warn(LogUtil.throwableToString(ex)); - } - */ + keyPositionInfos.add(new KeyPositionInfo(blockIndex.firstKey(), position)); blockIndex.clear(); } @@ -1088,9 +1074,8 @@ public class SSTable /* reset the buffer and serialize the Bloom Filter. */ DataOutputBuffer bufOut = new DataOutputBuffer(); BloomFilter.serializer().serialize(bf, bufOut); - bufOut.close(); - close(bufOut.getData(), bufOut.getLength()); + bufOut.close(); // byte[] bytes = new byte[bufOut.getLength()]; // System.arraycopy(bufOut.getData(), 0, bytes, 0, bufOut.getLength()); // close(bytes, bytes.length); diff --git a/src/org/apache/cassandra/io/SequenceFile.java b/src/org/apache/cassandra/io/SequenceFile.java index 837079214f..19c9b14de9 100644 --- a/src/org/apache/cassandra/io/SequenceFile.java +++ b/src/org/apache/cassandra/io/SequenceFile.java @@ -974,7 +974,7 @@ public class SequenceFile Coordinate coordinate = columnRange.coordinate(); /* seek to the correct offset to the data, and calculate the data size */ - file_.skipBytes((int)coordinate.start_); + file_.skipBytes((int)coordinate.start_); dataSize = (int)(coordinate.end_ - coordinate.start_); /*