From: Mark Berger Date: Thu, 25 Jul 2013 15:48:32 +0000 (-0400) Subject: Uses LeaseDB for share count instead of BucketCounter X-Git-Url: https://git.rkrishnan.org/%3C?a=commitdiff_plain;h=006a04976eb42f56c118c34adf2ddb54c1605edb;p=tahoe-lafs%2Ftahoe-lafs.git Uses LeaseDB for share count instead of BucketCounter --- diff --git a/src/allmydata/storage/accountant.py b/src/allmydata/storage/accountant.py index c2aec865..e7a2b24b 100644 --- a/src/allmydata/storage/accountant.py +++ b/src/allmydata/storage/accountant.py @@ -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() diff --git a/src/allmydata/storage/leasedb.py b/src/allmydata/storage/leasedb.py index ad3bbfac..f397b056 100644 --- a/src/allmydata/storage/leasedb.py +++ b/src/allmydata/storage/leasedb.py @@ -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] diff --git a/src/allmydata/storage/server.py b/src/allmydata/storage/server.py index f74d67bf..c797947a 100644 --- a/src/allmydata/storage/server.py +++ b/src/allmydata/storage/server.py @@ -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):