cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r893603 - in /incubator/cassandra/trunk/src/java/org/apache/cassandra: db/ColumnFamilyStore.java db/ColumnFamilyStoreMBean.java io/SSTable.java service/StorageService.java tools/NodeProbe.java
Date Wed, 23 Dec 2009 19:19:15 GMT
Author: jbellis
Date: Wed Dec 23 19:19:15 2009
New Revision: 893603

URL: http://svn.apache.org/viewvc?rev=893603&view=rev
Log:
expose cf count, disk space to JMX.  patch by jbellis; reviewed by eevans for CASSANDRA-599

Modified:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStoreMBean.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SSTable.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/tools/NodeProbe.java

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java?rev=893603&r1=893602&r2=893603&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java Wed
Dec 23 19:19:15 2009
@@ -170,6 +170,22 @@
         return cfs;
     }
 
+    private Set<File> files()
+    {
+        Set<File> fileSet = new HashSet<File>(3 * ssTables_.size() + 6); // 6
is fudge factor so we don't have to double if there's a couple uncompacted ones around
+        for (String directory : DatabaseDescriptor.getAllDataFileLocationsForTable(table_))
+        {
+            File[] files = new File(directory).listFiles();
+            for (File file : files)
+            {
+                String cfName = getColumnFamilyFromFileName(file.getName());
+                if (cfName.equals(columnFamily_))
+                    fileSet.add(file);
+            }
+        }
+        return fileSet;
+    }
+
     void onStart() throws IOException
     {
         if (logger_.isDebugEnabled())
@@ -177,43 +193,32 @@
         // scan for data files corresponding to this CF
         List<File> sstableFiles = new ArrayList<File>();
         Pattern auxFilePattern = Pattern.compile("(.*)(-Filter\\.db$|-Index\\.db$)");
-        String[] dataFileDirectories = DatabaseDescriptor.getAllDataFileLocationsForTable(table_);
-        for (String directory : dataFileDirectories)
+        for (File file : files())
         {
-            File fileDir = new File(directory);
-            File[] files = fileDir.listFiles();
-            for (File file : files)
-            {
-                String filename = file.getName();
-                String cfName = getColumnFamilyFromFileName(filename);
+            String filename = file.getName();
 
-                // skip files that are not from this column family
-                if (!cfName.equals(columnFamily_))
-                    continue;
-
-                /* look for and remove orphans. An orphan is a -Filter.db or -Index.db with
no corresponding -Data.db. */
-                Matcher matcher = auxFilePattern.matcher(file.getAbsolutePath());
-                if (matcher.matches())
-                {
-                    String basePath = matcher.group(1);
-                    if (!new File(basePath + "-Data.db").exists())
-                    {
-                        logger_.info(String.format("Removing orphan %s", file.getAbsolutePath()));
-                        FileUtils.deleteWithConfirm(file);
-                        continue;
-                    }
-                }
-
-                if (((file.length() == 0 && !filename.endsWith("-Compacted")) ||
(filename.contains("-" + SSTable.TEMPFILE_MARKER))))
+            /* look for and remove orphans. An orphan is a -Filter.db or -Index.db with no
corresponding -Data.db. */
+            Matcher matcher = auxFilePattern.matcher(file.getAbsolutePath());
+            if (matcher.matches())
+            {
+                String basePath = matcher.group(1);
+                if (!new File(basePath + "-Data.db").exists())
                 {
+                    logger_.info(String.format("Removing orphan %s", file.getAbsolutePath()));
                     FileUtils.deleteWithConfirm(file);
                     continue;
                 }
+            }
 
-                if (filename.contains("-Data.db"))
-                {
-                    sstableFiles.add(file.getAbsoluteFile());
-                }
+            if (((file.length() == 0 && !filename.endsWith("-Compacted")) || (filename.contains("-"
+ SSTable.TEMPFILE_MARKER))))
+            {
+                FileUtils.deleteWithConfirm(file);
+                continue;
+            }
+
+            if (filename.contains("-Data.db"))
+            {
+                sstableFiles.add(file.getAbsoluteFile());
             }
         }
         Collections.sort(sstableFiles, new FileUtils.FileComparator());
@@ -1211,6 +1216,31 @@
         }
     }
 
+    public long getTotalDiskSpaceUsed()
+    {
+        long n = 0;
+        for (File file : files())
+        {
+            n += file.length();
+        }
+        return n;
+    }
+
+    public long getLiveDiskSpaceUsed()
+    {
+        long n = 0;
+        for (SSTableReader sstable : ssTables_)
+        {
+            n += sstable.bytesOnDisk();
+        }
+        return n;
+    }
+
+    public int getLiveSSTableCount()
+    {
+        return ssTables_.size();
+    }
+
     /**
      * for testing.  no effort is made to clear historical memtables.
      */

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStoreMBean.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStoreMBean.java?rev=893603&r1=893602&r2=893603&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStoreMBean.java
(original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStoreMBean.java
Wed Dec 23 19:19:15 2009
@@ -80,9 +80,22 @@
     public double getWriteLatency();
     
     /**
-     * 
      * @return the estimated number of tasks pending for this column family
      */
     public int getPendingTasks();
-    
+
+    /**
+     * @return the number of SSTables on disk for this CF
+     */
+    public int getLiveSSTableCount();
+
+    /**
+     * @return disk space used by SSTables belonging to this CF
+     */
+    public long getLiveDiskSpaceUsed();
+
+    /**
+     * @return total disk space used by SSTables belonging to this CF, including obsolete
ones waiting to be GC'd
+     */
+    public long getTotalDiskSpaceUsed();
 }

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SSTable.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SSTable.java?rev=893603&r1=893602&r2=893603&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SSTable.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SSTable.java Wed Dec 23 19:19:15
2009
@@ -198,6 +198,11 @@
         }
     }
 
+    public long dataBytesOnDisk()
+    {
+        return new File(path).length();
+    }
+
     public long bytesOnDisk()
     {
         long bytes = 0;

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java?rev=893603&r1=893602&r2=893603&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java Wed
Dec 23 19:19:15 2009
@@ -781,10 +781,7 @@
             for (String cfName : table.getColumnFamilies())
             {
                 ColumnFamilyStore cfs = table.getColumnFamilyStore(cfName);
-                for (SSTableReader sstable : cfs.getSSTables())
-                {
-                    bytes += sstable.bytesOnDisk();
-                }
+                bytes += cfs.getLiveDiskSpaceUsed();
             }
         }
         return bytes;

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/tools/NodeProbe.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/tools/NodeProbe.java?rev=893603&r1=893602&r2=893603&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/tools/NodeProbe.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/tools/NodeProbe.java Wed Dec 23
19:19:15 2009
@@ -322,10 +322,14 @@
                 outs.println("\tWrite Count: " + tableWriteCount);
                 outs.println("\tWrite Latency: " + String.format("%01.3f", tableWriteLatency)
+ " ms.");
                 outs.println("\tPending Tasks: " + tablePendingTasks);
-                // print out column family statistic for this table
+
+                // print out column family statistics for this table
                 for (ColumnFamilyStoreMBean cfstore : columnFamilies)
                 {
                     outs.println("\t\tColumn Family: " + cfstore.getColumnFamilyName());
+                    outs.println("\t\tSSTable count: " + cfstore.getLiveSSTableCount());
+                    outs.println("\t\tSpace used (live): " + cfstore.getLiveDiskSpaceUsed());
+                    outs.println("\t\tSpace used (total): " + cfstore.getTotalDiskSpaceUsed());
                     outs.println("\t\tMemtable Columns Count: " + cfstore.getMemtableColumnsCount());
                     outs.println("\t\tMemtable Data Size: " + cfstore.getMemtableDataSize());
                     outs.println("\t\tMemtable Switch Count: " + cfstore.getMemtableSwitchCount());



Mime
View raw message