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 2010/06/14 19:59:26 UTC
svn commit: r954572 -
/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableNamesIterator.java
Author: jbellis
Date: Mon Jun 14 17:59:26 2010
New Revision: 954572
URL: http://svn.apache.org/viewvc?rev=954572&view=rev
Log:
close file in SSTableNamesIterator when opened locally. patch by mdennis; reviewed by jbellis for CASSANDRA-1188
Modified:
cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableNamesIterator.java
Modified: cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableNamesIterator.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableNamesIterator.java?rev=954572&r1=954571&r2=954572&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableNamesIterator.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableNamesIterator.java Mon Jun 14 17:59:26 2010
@@ -20,11 +20,14 @@ package org.apache.cassandra.db.filter;
*
*/
-
import java.io.IOError;
import java.io.IOException;
import java.util.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.db.ColumnFamily;
import org.apache.cassandra.db.DecoratedKey;
import org.apache.cassandra.db.IColumn;
@@ -32,13 +35,9 @@ import org.apache.cassandra.db.marshal.A
import org.apache.cassandra.io.sstable.IndexHelper;
import org.apache.cassandra.io.sstable.SSTableReader;
import org.apache.cassandra.io.util.FileDataInput;
-import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.utils.BloomFilter;
import org.apache.cassandra.utils.FBUtilities;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
public class SSTableNamesIterator extends SimpleAbstractColumnIterator implements IColumnIterator
{
private static Logger logger = LoggerFactory.getLogger(SSTableNamesIterator.class);
@@ -47,7 +46,7 @@ public class SSTableNamesIterator extend
private Iterator<IColumn> iter;
public final SortedSet<byte[]> columns;
public final DecoratedKey decoratedKey;
-
+
public SSTableNamesIterator(SSTableReader ssTable, DecoratedKey key, SortedSet<byte[]> columnNames)
{
this (ssTable, null, key, columnNames);
@@ -55,33 +54,28 @@ public class SSTableNamesIterator extend
public SSTableNamesIterator(SSTableReader ssTable, FileDataInput file, DecoratedKey key, SortedSet<byte[]> columnNames)
{
- assert columnNames != null;
+ boolean closeFileWhenDone = file == null;
+
+ try
+ {
+ assert columnNames != null;
- this.columns = columnNames;
- this.decoratedKey = key;
+ this.columns = columnNames;
+ this.decoratedKey = key;
- // open the sstable file, if we don't have one passed to use from range scan
- if (file == null)
- {
- try
+ // open the sstable file, if we don't have one passed to use from range scan
+ if (file == null)
{
file = ssTable.getFileDataInput(decoratedKey, DatabaseDescriptor.getIndexedReadBufferSizeInKB() * 1024);
if (file == null)
return;
DecoratedKey keyInDisk = ssTable.getPartitioner().convertFromDiskFormat(FBUtilities.readShortByteArray(file));
assert keyInDisk.equals(decoratedKey)
- : String.format("%s != %s in %s", keyInDisk, decoratedKey, file.getPath());
+ : String.format("%s != %s in %s", keyInDisk, decoratedKey, file.getPath());
file.readInt(); // data size
}
- catch (IOException e)
- {
- throw new IOError(e);
- }
- }
- // read the requested columns into `cf`
- try
- {
+ // read the requested columns into `cf`
/* Read the bloom filter summarizing the columns */
BloomFilter bf = IndexHelper.defreezeBloomFilter(file);
List<IndexHelper.IndexInfo> indexList = IndexHelper.deserializeIndex(file);
@@ -122,7 +116,7 @@ public class SSTableNamesIterator extend
for (IndexHelper.IndexInfo indexInfo : ranges)
{
file.reset();
- long curOffsert = file.skipBytes((int)indexInfo.offset);
+ long curOffsert = file.skipBytes((int) indexInfo.offset);
assert curOffsert == indexInfo.offset;
// TODO only completely deserialize columns we are interested in
while (file.bytesPastMark() < indexInfo.offset + indexInfo.width)
@@ -135,16 +129,30 @@ public class SSTableNamesIterator extend
}
}
}
+
+ // create an iterator view of the columns we read
+ iter = cf.getSortedColumns().iterator();
}
- catch (IOException e)
+ catch (IOException ioe)
{
- throw new IOError(e);
+ throw new IOError(ioe);
+ }
+ finally
+ {
+ if (closeFileWhenDone && file != null)
+ {
+ try
+ {
+ file.close();
+ }
+ catch (IOException ioe)
+ {
+ logger.warn("error closing " + file.getPath());
+ }
+ }
}
-
- // create an iterator view of the columns we read
- iter = cf.getSortedColumns().iterator();
}
-
+
public DecoratedKey getKey()
{
return decoratedKey;