cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bened...@apache.org
Subject [2/3] cassandra git commit: ninja add testing for index summary scan position after downsampling
Date Wed, 18 Mar 2015 19:27:25 GMT
ninja add testing for index summary scan position after downsampling


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/b0621801
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/b0621801
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/b0621801

Branch: refs/heads/trunk
Commit: b06218011ecb7db15e765f0185c5ec000ba2233c
Parents: accbfa7
Author: Benedict Elliott Smith <benedict@apache.org>
Authored: Wed Mar 18 19:26:28 2015 +0000
Committer: Benedict Elliott Smith <benedict@apache.org>
Committed: Wed Mar 18 19:26:28 2015 +0000

----------------------------------------------------------------------
 .../cassandra/io/sstable/SSTableReader.java     |  3 +-
 .../org/apache/cassandra/io/util/Memory.java    |  2 +
 .../cassandra/io/sstable/IndexSummaryTest.java  | 39 +++++++++++++++-----
 3 files changed, 33 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/b0621801/src/java/org/apache/cassandra/io/sstable/SSTableReader.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/sstable/SSTableReader.java b/src/java/org/apache/cassandra/io/sstable/SSTableReader.java
index f42bfc7..e4a6e85 100644
--- a/src/java/org/apache/cassandra/io/sstable/SSTableReader.java
+++ b/src/java/org/apache/cassandra/io/sstable/SSTableReader.java
@@ -1074,7 +1074,8 @@ public class SSTableReader extends SSTable implements SelfRefCounted<SSTableRead
         return getIndexScanPositionFromBinarySearchResult(indexSummary.binarySearch(key),
indexSummary);
     }
 
-    private static long getIndexScanPositionFromBinarySearchResult(int binarySearchResult,
IndexSummary referencedIndexSummary)
+    @VisibleForTesting
+    public static long getIndexScanPositionFromBinarySearchResult(int binarySearchResult,
IndexSummary referencedIndexSummary)
     {
         if (binarySearchResult == -1)
             return 0;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b0621801/src/java/org/apache/cassandra/io/util/Memory.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/util/Memory.java b/src/java/org/apache/cassandra/io/util/Memory.java
index dcb9de6..bbe6049 100644
--- a/src/java/org/apache/cassandra/io/util/Memory.java
+++ b/src/java/org/apache/cassandra/io/util/Memory.java
@@ -330,6 +330,8 @@ public class Memory implements AutoCloseable
 
     public void put(long trgOffset, Memory memory, long srcOffset, long size)
     {
+        checkBounds(trgOffset, trgOffset + size);
+        memory.checkBounds(srcOffset, srcOffset + size);
         unsafe.copyMemory(memory.peer + srcOffset, peer + trgOffset, size);
     }
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b0621801/test/unit/org/apache/cassandra/io/sstable/IndexSummaryTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/io/sstable/IndexSummaryTest.java b/test/unit/org/apache/cassandra/io/sstable/IndexSummaryTest.java
index 9c709a3..95183d4 100644
--- a/test/unit/org/apache/cassandra/io/sstable/IndexSummaryTest.java
+++ b/test/unit/org/apache/cassandra/io/sstable/IndexSummaryTest.java
@@ -173,20 +173,24 @@ public class IndexSummaryTest
         int downsamplingRound = 1;
         for (int samplingLevel = BASE_SAMPLING_LEVEL - 1; samplingLevel >= 1; samplingLevel--)
         {
-            IndexSummary downsampled = downsample(original, samplingLevel, 128, DatabaseDescriptor.getPartitioner());
-            assertEquals(entriesAtSamplingLevel(samplingLevel, original.getMaxNumberOfEntries()),
downsampled.size());
-
-            int sampledCount = 0;
-            List<Integer> skipStartPoints = samplePattern.subList(0, downsamplingRound);
-            for (int i = 0; i < ORIGINAL_NUM_ENTRIES; i++)
+            try (IndexSummary downsampled = downsample(original, samplingLevel, 128, DatabaseDescriptor.getPartitioner());)
             {
-                if (!shouldSkip(i, skipStartPoints))
+                assertEquals(entriesAtSamplingLevel(samplingLevel, original.getMaxNumberOfEntries()),
downsampled.size());
+
+                int sampledCount = 0;
+                List<Integer> skipStartPoints = samplePattern.subList(0, downsamplingRound);
+                for (int i = 0; i < ORIGINAL_NUM_ENTRIES; i++)
                 {
-                    assertEquals(keys.get(i * INDEX_INTERVAL).getKey(), ByteBuffer.wrap(downsampled.getKey(sampledCount)));
-                    sampledCount++;
+                    if (!shouldSkip(i, skipStartPoints))
+                    {
+                        assertEquals(keys.get(i * INDEX_INTERVAL).getKey(), ByteBuffer.wrap(downsampled.getKey(sampledCount)));
+                        sampledCount++;
+                    }
                 }
+
+                testPosition(original, downsampled, keys);
+                downsamplingRound++;
             }
-            downsamplingRound++;
         }
 
         // downsample one level each time
@@ -195,6 +199,8 @@ public class IndexSummaryTest
         for (int downsampleLevel = BASE_SAMPLING_LEVEL - 1; downsampleLevel >= 1; downsampleLevel--)
         {
             IndexSummary downsampled = downsample(previous, downsampleLevel, 128, DatabaseDescriptor.getPartitioner());
+            if (previous != original)
+                previous.close();
             assertEquals(entriesAtSamplingLevel(downsampleLevel, original.getMaxNumberOfEntries()),
downsampled.size());
 
             int sampledCount = 0;
@@ -208,9 +214,22 @@ public class IndexSummaryTest
                 }
             }
 
+            testPosition(original, downsampled, keys);
             previous = downsampled;
             downsamplingRound++;
         }
+        previous.close();
+        original.close();
+    }
+
+    private void testPosition(IndexSummary original, IndexSummary downsampled, Iterable<DecoratedKey>
keys)
+    {
+        for (DecoratedKey key : keys)
+        {
+            long orig = SSTableReader.getIndexScanPositionFromBinarySearchResult(original.binarySearch(key),
original);
+            long down = SSTableReader.getIndexScanPositionFromBinarySearchResult(downsampled.binarySearch(key),
downsampled);
+            assert down <= orig;
+        }
     }
 
     @Test


Mime
View raw message