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 2009/05/01 04:24:11 UTC
svn commit: r770517 - in /incubator/cassandra/trunk:
src/java/org/apache/cassandra/io/SequenceFile.java
test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
Author: jbellis
Date: Fri May 1 02:24:10 2009
New Revision: 770517
URL: http://svn.apache.org/viewvc?rev=770517&view=rev
Log:
avoid raising an exception in SequenceFile.next when a key does not exist (e.g. when bloom filter gives a false positive). patch by Jun Rao; reviewed by jbellis for CASSANDRA-126
Modified:
incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SequenceFile.java
incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SequenceFile.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SequenceFile.java?rev=770517&r1=770516&r2=770517&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SequenceFile.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SequenceFile.java Fri May 1 02:24:10 2009
@@ -705,14 +705,13 @@
* @param section indicates the location of the block index.
* @throws IOException
*/
- protected void seekTo(String key, Coordinate section) throws IOException
+ private long seekTo(String key, Coordinate section) throws IOException
{
- /* Goto the Block Index */
seek(section.end_);
long position = getPositionFromBlockIndex(key);
- if (position == -1)
- throw new IOException("This key " + key + " does not exist in this file.");
- seek(position);
+ if (position >= 0)
+ seek(position);
+ return position;
}
/**
@@ -809,9 +808,8 @@
assert timeRange == null || columnNames == null; // at most one may be non-null
long bytesRead = -1L;
- if (isEOF())
+ if (isEOF() || seekTo(key, section) < 0)
return bytesRead;
- seekTo(key, section);
/* note the position where the key starts */
long startPosition = file_.getFilePointer();
String keyInDisk = file_.readUTF();
@@ -1065,10 +1063,8 @@
public long next(String key, DataOutputBuffer bufOut, Coordinate section) throws IOException
{
long bytesRead = -1L;
- if (isEOF())
+ if (isEOF() || seekTo(key, section) < 0)
return bytesRead;
-
- seekTo(key, section);
/* note the position where the key starts */
long startPosition = file_.getFilePointer();
String keyInDisk = file_.readUTF();
Modified: incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java?rev=770517&r1=770516&r2=770517&view=diff
==============================================================================
--- incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java (original)
+++ incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java Fri May 1 02:24:10 2009
@@ -18,6 +18,9 @@
import org.apache.commons.lang.StringUtils;
import org.apache.cassandra.ServerTest;
+import org.apache.cassandra.io.DataInputBuffer;
+import org.apache.cassandra.io.SSTable;
+import org.apache.cassandra.service.StorageService;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;
@@ -407,4 +410,26 @@
Future ft = MinorCompactionManager.instance().submit(store);
ft.get();
}
+
+ @Test
+ public void testGetColumnWithWrongBF() throws IOException, ExecutionException, InterruptedException
+ {
+ Table table = Table.open("Table1");
+ ColumnFamilyStore store = table.getColumnFamilyStore("Standard1");
+ RowMutation rm;
+
+ // add data
+ rm = new RowMutation("Table1", "key1");
+ rm.add("Standard1:Column1", "asdf".getBytes(), 0);
+ rm.add("Standard1:Column2", "asdf".getBytes(), 0);
+ rm.apply();
+ store.forceBlockingFlush();
+
+ List<String> ssTables = table.getAllSSTablesOnDisk();
+ /* the following call can happen if BF is wrong. Should return an empty buffer. */
+ IFilter filter = new IdentityFilter();
+ SSTable ssTable = new SSTable(ssTables.get(0), StorageService.getPartitioner());
+ DataInputBuffer bufIn = filter.next("key2", "Standard1:Column1", ssTable);
+ assertEquals(bufIn.getLength(), 0);
+ }
}