]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Uses LeaseDB for share count instead of BucketCounter
authorMark Berger <mark.berger.j@gmail.com>
Thu, 25 Jul 2013 15:48:32 +0000 (11:48 -0400)
committerDaira Hopwood <daira@jacaranda.org>
Mon, 5 May 2014 18:29:43 +0000 (19:29 +0100)
src/allmydata/storage/accountant.py
src/allmydata/storage/leasedb.py
src/allmydata/storage/server.py

index c2aec865e14f7003a7abf82186131f384abb6af6..e7a2b24b9dd1c45ce645854bd1fc8bb6ffe23d03 100644 (file)
@@ -57,3 +57,9 @@ class Accountant(service.MultiService):
             else:
                 yield Account(ownerid, pubkey_vs,
                               self.storage_server, self._leasedb)
+
+    def get_total_leased_sharecount_and_used_space(self):
+        return self._leasedb.get_total_leased_sharecount_and_used_space()
+
+    def get_number_of_sharesets(self):
+        return self._leasedb.get_number_of_sharesets()
index ad3bbfac9df0cdc834ab423750788c914ecbbcfe..f397b056c2ad143acaa4220e438e6fae2898748a 100644 (file)
@@ -374,3 +374,18 @@ class LeaseDB(service.Service):
         self._cursor.execute("SELECT `id`,`pubkey_vs`"
                              " FROM `accounts` ORDER BY `id` ASC")
         return self._cursor.fetchall()
+
+    def get_total_leased_sharecount_and_used_space(self):
+        self._cursor.execute("SELECT COUNT(*), SUM(`used_space`)"
+                             " FROM (SELECT `used_space`"
+                                " FROM `shares` s JOIN `leases` l"
+                                " ON (s.`storage_index` = l.`storage_index` AND s.`shnum` = l.`shnum`)"
+                                " GROUP BY s.`storage_index`, s.`shnum`)")
+        share_count, used_space = self._cursor.fetchall()[0]
+        if share_count == 0 and used_space is None:
+            used_space = 0
+        return share_count, used_space
+
+    def get_number_of_sharesets(self):
+        self._cursor.execute("SELECT COUNT(DISTINCT `storage_index`) AS si_num FROM `shares`")
+        return self._cursor.fetchall()[0][0]
index f74d67bfa4d3d182845022b4dc8058c81e6d1613..c797947a345bcf1d1f8c05c8182a0184257f2a4c 100644 (file)
@@ -167,11 +167,11 @@ class StorageServer(service.MultiService):
 
         self.backend.fill_in_space_stats(stats)
 
-        if self.bucket_counter:
-            s = self.bucket_counter.get_state()
-            bucket_count = s.get("last-complete-bucket-count")
-            if bucket_count:
-                stats['storage_server.total_bucket_count'] = bucket_count
+        sharecount = self.accountant.get_number_of_sharesets()
+        leased_share_count, leased_used_space = self.accountant.get_total_leased_sharecount_and_used_space()
+        stats['storage_server.total_bucket_count'] = sharecount
+        stats["storage_server.total_leased_sharecount"] = leased_share_count
+        stats["storage_server.total_leased_used_space"] = leased_used_space
         return stats
 
     def get_available_space(self):