cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r886006 - in /incubator/cassandra/trunk: ./ src/java/org/apache/cassandra/db/ src/java/org/apache/cassandra/io/ src/java/org/apache/cassandra/service/ src/java/org/apache/cassandra/utils/
Date Tue, 01 Dec 2009 23:31:48 GMT
Author: jbellis
Date: Tue Dec  1 23:31:47 2009
New Revision: 886006

URL: http://svn.apache.org/viewvc?rev=886006&view=rev
Log:
use size of sstables as load, instead of naively counting everything in the data directories
patch by jbellis; reviewed by Stu Hood for CASSANDRA-554

Modified:
    incubator/cassandra/trunk/CHANGES.txt
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Table.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SSTable.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/service/CassandraDaemon.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/utils/FileUtils.java

Modified: incubator/cassandra/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/CHANGES.txt?rev=886006&r1=886005&r2=886006&view=diff
==============================================================================
--- incubator/cassandra/trunk/CHANGES.txt (original)
+++ incubator/cassandra/trunk/CHANGES.txt Tue Dec  1 23:31:47 2009
@@ -5,6 +5,7 @@
  * fix NPE in get_range_slice when no data is found (CASSANDRA-578)
  * fix potential NPE in hinted handoff (CASSANDRA-585)
  * fix cleanup of local "system" keyspace (CASSANDRA-576)
+ * improve computation of cluster load balance (CASSANDRA-554)
 
 
 0.5.0 beta

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Table.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Table.java?rev=886006&r1=886005&r2=886006&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Table.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Table.java Tue Dec  1 23:31:47
2009
@@ -504,4 +504,9 @@
     {
         return dataDirPath + File.separator + tableName + File.separator + SNAPSHOT_SUBDIR_NAME
+ File.separator + snapshotName;
     }
+
+    public static Set<String> getAllTableNames()
+    {
+        return DatabaseDescriptor.getTableToColumnFamilyMap().keySet();
+    }
 }

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=886006&r1=886005&r2=886006&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 Tue Dec  1 23:31:47
2009
@@ -183,6 +183,16 @@
         }
     }
 
+    public long bytesOnDisk()
+    {
+        long bytes = 0;
+        for (String fname : getAllFilenames())
+        {
+            bytes += new File(fname).length();
+        }
+        return bytes;
+    }
+
     @Override
     public String toString()
     {

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/service/CassandraDaemon.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/service/CassandraDaemon.java?rev=886006&r1=886005&r2=886006&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/service/CassandraDaemon.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/service/CassandraDaemon.java Tue
Dec  1 23:31:47 2009
@@ -77,7 +77,7 @@
         });
 
         // initialize stuff
-        for (String table : DatabaseDescriptor.getTableToColumnFamilyMap().keySet())
+        for (String table : Table.getAllTableNames())
         {
             if (logger.isDebugEnabled())
                 logger.debug("opening keyspace " + table);

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=886006&r1=886005&r2=886006&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 Tue
Dec  1 23:31:47 2009
@@ -507,12 +507,33 @@
     /** raw load value */
     public double getLoad()
     {
-        return FileUtils.getUsedDiskSpace();
+        double bytes = 0;
+        for (String tableName : Table.getAllTableNames())
+        {
+            Table table;
+            try
+            {
+                table = Table.open(tableName);
+            }
+            catch (IOException e)
+            {
+                throw new IOError(e);
+            }
+            for (String cfName : table.getColumnFamilies())
+            {
+                ColumnFamilyStore cfs = table.getColumnFamilyStore(cfName);
+                for (SSTableReader sstable : cfs.getSSTables())
+                {
+                    bytes += sstable.bytesOnDisk();
+                }
+            }
+        }
+        return bytes;
     }
 
     public String getLoadString()
     {
-        return FileUtils.stringifyFileSize(FileUtils.getUsedDiskSpace());
+        return FileUtils.stringifyFileSize(getLoad());
     }
 
     public Map<String, String> getLoadMap()

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/utils/FileUtils.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/utils/FileUtils.java?rev=886006&r1=886005&r2=886006&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/utils/FileUtils.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/utils/FileUtils.java Tue Dec 
1 23:31:47 2009
@@ -201,20 +201,7 @@
         }
         return diskSpace;
     }
-    
-    public static long getUsedDiskSpace()
-    {
-        long diskSpace = 0L;
-        String[] directories = DatabaseDescriptor.getAllDataFileLocations();        
-        for ( String directory : directories )
-        {
-            diskSpace += getUsedDiskSpaceForPath(directory);
-        }
 
-        String value = df_.format(diskSpace);
-        return Long.parseLong(value);
-    }    
-    
     /**
      * Deletes all files and subdirectories under "dir".
      * @param dir Directory to be deleted



Mime
View raw message