cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r1023919 - in /cassandra/trunk/src/java/org/apache/cassandra/io/sstable: SSTable.java SSTableReader.java SSTableWriter.java
Date Mon, 18 Oct 2010 17:40:51 GMT
Author: jbellis
Date: Mon Oct 18 17:40:51 2010
New Revision: 1023919

URL: http://svn.apache.org/viewvc?rev=1023919&view=rev
Log:
avoid null SSTable stat histograms
patch by jbellis; reviewed by brandonwilliams for CASSANDRA-1620

Modified:
    cassandra/trunk/src/java/org/apache/cassandra/io/sstable/SSTable.java
    cassandra/trunk/src/java/org/apache/cassandra/io/sstable/SSTableReader.java
    cassandra/trunk/src/java/org/apache/cassandra/io/sstable/SSTableWriter.java

Modified: cassandra/trunk/src/java/org/apache/cassandra/io/sstable/SSTable.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/io/sstable/SSTable.java?rev=1023919&r1=1023918&r2=1023919&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/io/sstable/SSTable.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/io/sstable/SSTable.java Mon Oct 18 17:40:51
2010
@@ -68,8 +68,8 @@ public abstract class SSTable
     public final CFMetaData metadata;
     public final IPartitioner partitioner;
 
-    protected EstimatedHistogram estimatedRowSize = new EstimatedHistogram(150);
-    protected EstimatedHistogram estimatedColumnCount = new EstimatedHistogram(114);
+    protected final EstimatedHistogram estimatedRowSize;
+    protected final EstimatedHistogram estimatedColumnCount;
 
     protected SSTable(Descriptor descriptor, CFMetaData metadata, IPartitioner partitioner)
     {
@@ -78,10 +78,27 @@ public abstract class SSTable
 
     protected SSTable(Descriptor descriptor, Set<Component> components, CFMetaData
metadata, IPartitioner partitioner)
     {
+        this(descriptor, components, metadata, partitioner, defaultRowHistogram(), defaultColumnHistogram());
+    }
+
+    static EstimatedHistogram defaultColumnHistogram()
+    {
+        return new EstimatedHistogram(114);
+    }
+
+    static EstimatedHistogram defaultRowHistogram()
+    {
+        return new EstimatedHistogram(150);
+    }
+
+    protected SSTable(Descriptor descriptor, Set<Component> components, CFMetaData
metadata, IPartitioner partitioner, EstimatedHistogram rowSizes, EstimatedHistogram columnCounts)
+    {
         this.descriptor = descriptor;
         this.components = components;
         this.metadata = metadata;
         this.partitioner = partitioner;
+        estimatedRowSize = rowSizes;
+        estimatedColumnCount = columnCounts;
     }
 
     public EstimatedHistogram getEstimatedRowSize()

Modified: cassandra/trunk/src/java/org/apache/cassandra/io/sstable/SSTableReader.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/io/sstable/SSTableReader.java?rev=1023919&r1=1023918&r2=1023919&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/io/sstable/SSTableReader.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/io/sstable/SSTableReader.java Mon Oct 18
17:40:51 2010
@@ -136,18 +136,6 @@ public class SSTableReader extends SSTab
         return count;
     }
 
-    private void loadStatistics(Descriptor desc) throws IOException
-    {
-        if (!new File(desc.filenameFor(SSTable.COMPONENT_STATS)).exists())
-            return;
-        if (logger.isDebugEnabled())
-            logger.debug("Load statistics for " + desc);
-        DataInputStream dis = new DataInputStream(new FileInputStream(desc.filenameFor(SSTable.COMPONENT_STATS)));
-        estimatedRowSize = EstimatedHistogram.serializer.deserialize(dis);
-        estimatedColumnCount = EstimatedHistogram.serializer.deserialize(dis);
-        dis.close();
-    }
-
     public static SSTableReader open(Descriptor desc) throws IOException
     {
         Set<Component> components = SSTable.componentsFor(desc);
@@ -166,7 +154,25 @@ public class SSTableReader extends SSTab
         long start = System.currentTimeMillis();
         logger.info("Sampling index for " + descriptor);
 
-        SSTableReader sstable = new SSTableReader(descriptor, components, metadata, partitioner,
null, null, null, null, System.currentTimeMillis(), null, null);
+        EstimatedHistogram rowSizes;
+        EstimatedHistogram columnCounts;
+        File statsFile = new File(descriptor.filenameFor(SSTable.COMPONENT_STATS));
+        if (statsFile.exists())
+        {
+            logger.debug("Load statistics for {}", descriptor);
+            DataInputStream dis = new DataInputStream(new FileInputStream(statsFile));
+            rowSizes = EstimatedHistogram.serializer.deserialize(dis);
+            columnCounts = EstimatedHistogram.serializer.deserialize(dis);
+            dis.close();
+        }
+        else
+        {
+            logger.debug("No statistics for {}", descriptor);
+            rowSizes = SSTable.defaultRowHistogram();
+            columnCounts = SSTable.defaultColumnHistogram();
+        }
+
+        SSTableReader sstable = new SSTableReader(descriptor, components, metadata, partitioner,
null, null, null, null, System.currentTimeMillis(), rowSizes, columnCounts);
         sstable.setTrackedBy(tracker);
 
         // versions before 'c' encoded keys as utf-16 before hashing to the filter
@@ -179,8 +185,6 @@ public class SSTableReader extends SSTab
             sstable.load(false, savedKeys);
             sstable.loadBloomFilter();
         }
-        sstable.loadStatistics(descriptor);
-
         if (logger.isDebugEnabled())
             logger.debug("INDEX LOAD TIME for " + descriptor + ": " + (System.currentTimeMillis()
- start) + " ms.");
 
@@ -209,19 +213,17 @@ public class SSTableReader extends SSTab
                           IndexSummary indexSummary,
                           BloomFilter bloomFilter,
                           long maxDataAge,
-                          EstimatedHistogram rowsize,
-                          EstimatedHistogram columncount)
+                          EstimatedHistogram rowSizes,
+                          EstimatedHistogram columnCounts)
     throws IOException
     {
-        super(desc, components, metadata, partitioner);
+        super(desc, components, metadata, partitioner, rowSizes, columnCounts);
         this.maxDataAge = maxDataAge;
 
         this.ifile = ifile;
         this.dfile = dfile;
         this.indexSummary = indexSummary;
         this.bf = bloomFilter;
-        estimatedRowSize = rowsize;
-        estimatedColumnCount = columncount;
     }
 
     public void setTrackedBy(SSTableTracker tracker)

Modified: cassandra/trunk/src/java/org/apache/cassandra/io/sstable/SSTableWriter.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/io/sstable/SSTableWriter.java?rev=1023919&r1=1023918&r2=1023919&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/io/sstable/SSTableWriter.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/io/sstable/SSTableWriter.java Mon Oct 18
17:40:51 2010
@@ -20,6 +20,7 @@
 package org.apache.cassandra.io.sstable;
 
 import java.io.*;
+import java.util.HashSet;
 import java.util.Set;
 
 import org.apache.cassandra.io.util.FileUtils;
@@ -55,7 +56,7 @@ public class SSTableWriter extends SSTab
 
     public SSTableWriter(String filename, long keyCount, CFMetaData metadata, IPartitioner
partitioner) throws IOException
     {
-        super(Descriptor.fromFilename(filename), metadata, partitioner);
+        super(Descriptor.fromFilename(filename), new HashSet<Component>(), metadata,
partitioner, SSTable.defaultRowHistogram(), SSTable.defaultColumnHistogram());
         iwriter = new IndexWriter(descriptor, partitioner, keyCount);
         dbuilder = SegmentedFile.getBuilder(DatabaseDescriptor.getDiskAccessMode());
         dataFile = new BufferedRandomAccessFile(getFilename(), "rw", DatabaseDescriptor.getInMemoryCompactionLimit());



Mime
View raw message