cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dbros...@apache.org
Subject git commit: fix merge issues
Date Sun, 28 Apr 2013 16:24:18 GMT
Updated Branches:
  refs/heads/trunk 4439b4117 -> 385ce13f5


fix merge issues


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

Branch: refs/heads/trunk
Commit: 385ce13f5ac3be91e40caa4f2cb34ec0ce654719
Parents: 4439b41
Author: Dave Brosius <dbrosius@apache.org>
Authored: Sun Apr 28 12:23:10 2013 -0400
Committer: Dave Brosius <dbrosius@apache.org>
Committed: Sun Apr 28 12:23:10 2013 -0400

----------------------------------------------------------------------
 .../cassandra/io/sstable/IndexSummaryBuilder.java  |   76 +++++++++++++++
 .../apache/cassandra/io/sstable/SSTableReader.java |    4 +-
 .../apache/cassandra/io/sstable/SSTableWriter.java |    4 +-
 3 files changed, 80 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/385ce13f/src/java/org/apache/cassandra/io/sstable/IndexSummaryBuilder.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/sstable/IndexSummaryBuilder.java b/src/java/org/apache/cassandra/io/sstable/IndexSummaryBuilder.java
new file mode 100644
index 0000000..12be453
--- /dev/null
+++ b/src/java/org/apache/cassandra/io/sstable/IndexSummaryBuilder.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cassandra.io.sstable;
+
+import java.util.ArrayList;
+
+import com.google.common.primitives.Bytes;
+import com.google.common.primitives.Longs;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.db.DecoratedKey;
+import org.apache.cassandra.dht.IPartitioner;
+import org.apache.cassandra.utils.ByteBufferUtil;
+
+public class IndexSummaryBuilder
+{
+    private static final Logger logger = LoggerFactory.getLogger(IndexSummaryBuilder.class);
+
+    private final ArrayList<Long> positions;
+    private final ArrayList<byte[]> keys;
+    private long keysWritten = 0;
+
+    public IndexSummaryBuilder(long expectedKeys, int indexInterval)
+    {
+        long expectedEntries = expectedKeys / indexInterval;
+        if (expectedEntries > Integer.MAX_VALUE)
+        {
+            // that's a _lot_ of keys, and a very low interval
+            int effectiveInterval = (int) Math.ceil((double) Integer.MAX_VALUE / expectedKeys);
+            expectedEntries = expectedKeys / effectiveInterval;
+            assert expectedEntries <= Integer.MAX_VALUE : expectedEntries;
+            logger.warn("Index interval of {} is too low for {} expected keys; using interval
of {} instead",
+                    indexInterval, expectedKeys, effectiveInterval);
+        }
+        positions = new ArrayList<Long>((int)expectedEntries);
+        keys = new ArrayList<byte[]>((int)expectedEntries);
+    }
+
+    public IndexSummaryBuilder maybeAddEntry(DecoratedKey decoratedKey, int indexInterval,
long indexPosition)
+    {
+        if (keysWritten % indexInterval == 0)
+        {
+            keys.add(ByteBufferUtil.getArray(decoratedKey.key));
+            positions.add(indexPosition);
+        }
+        keysWritten++;
+
+        return this;
+    }
+
+    public IndexSummary build(IPartitioner partitioner, int indexInterval)
+    {
+        byte[][] keysArray = new byte[keys.size()][];
+        for (int i = 0; i < keys.size(); i++)
+            keysArray[i] = keys.get(i);
+
+        return new IndexSummary(partitioner, keysArray, Longs.toArray(positions), indexInterval);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cassandra/blob/385ce13f/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 2d6c1df..27589f5 100644
--- a/src/java/org/apache/cassandra/io/sstable/SSTableReader.java
+++ b/src/java/org/apache/cassandra/io/sstable/SSTableReader.java
@@ -400,14 +400,14 @@ public class SSTableReader extends SSTable
                 // if summary was already read from disk we don't want to re-populate it
using primary index
                 if (!summaryLoaded)
                 {
-                    summaryBuilder.maybeAddEntry(decoratedKey, indexPosition);
+                    summaryBuilder.maybeAddEntry(decoratedKey, metadata.getIndexInterval(),
indexPosition);
                     ibuilder.addPotentialBoundary(indexPosition);
                     dbuilder.addPotentialBoundary(indexEntry.position);
                 }
             }
 
             if (!summaryLoaded)
-                indexSummary = summaryBuilder.build(partitioner);
+                indexSummary = summaryBuilder.build(partitioner, metadata.getIndexInterval());
         }
         finally
         {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/385ce13f/src/java/org/apache/cassandra/io/sstable/SSTableWriter.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/sstable/SSTableWriter.java b/src/java/org/apache/cassandra/io/sstable/SSTableWriter.java
index 4b0b756..c67e868 100644
--- a/src/java/org/apache/cassandra/io/sstable/SSTableWriter.java
+++ b/src/java/org/apache/cassandra/io/sstable/SSTableWriter.java
@@ -339,7 +339,7 @@ public class SSTableWriter extends SSTable
                                                            partitioner,
                                                            ifile,
                                                            dfile,
-                                                           iwriter.summary.build(partitioner),
+                                                           iwriter.summary.build(partitioner,
metadata.getIndexInterval()),
                                                            iwriter.bf,
                                                            maxDataAge,
                                                            sstableMetadata);
@@ -434,7 +434,7 @@ public class SSTableWriter extends SSTable
             if (logger.isTraceEnabled())
                 logger.trace("wrote index entry: " + indexEntry + " at " + indexPosition);
 
-            summary.maybeAddEntry(key, indexPosition);
+            summary.maybeAddEntry(key, metadata.getIndexInterval(), indexPosition);
             builder.addPotentialBoundary(indexPosition);
         }
 


Mime
View raw message