trivial: reorder AccountBroker.path methods

To me, this structure makes the call order more obvious.  There was some
uneccessary defensiveness on the structure of the dict returned from the
SELECT query.

Drive-by: cleanup docstrings, there was some extra info about failures
and ContainerBrokers that was confusing me.

Related-Change: Ic7c2aa878caf039b29abb900b4f491130be3d8a8
Change-Id: I13e91abb09b2102dc52429df22fe47c73c6346aa
Signed-off-by: Clay Gerrard <clay.gerrard@gmail.com>
This commit is contained in:
Clay Gerrard
2025-09-29 10:21:48 -05:00
committed by Alistair Coles
parent 3c6e967a58
commit 97e00e208f

View File

@@ -224,18 +224,6 @@ class AccountBroker(DatabaseBroker):
record['bytes_used'], record['deleted'],
record['storage_policy_index'])
@property
def path(self):
"""
Logical namespace path used for logging.
For ContainerBroker this is "<account>/<container>";
for AccountBroker we return just "<account>".
"""
if self.account is None:
self._populate_instance_cache()
return self.account or ''
def put_container(self, name, put_timestamp, delete_timestamp,
object_count, bytes_used, storage_policy_index):
"""
@@ -348,7 +336,7 @@ class AccountBroker(DatabaseBroker):
def get_info(self):
"""
Return a dict with account name for this broker.
Get global data for the account.
:returns: dict with keys: account, created_at, put_timestamp,
delete_timestamp, status_changed_at, container_count,
@@ -362,9 +350,28 @@ class AccountBroker(DatabaseBroker):
bytes_used, hash, id
FROM account_stat
''').fetchone())
self.account = data.get('account')
self.account = data['account']
return data
def _populate_instance_cache(self):
"""
Lazily hydrate instance attributes used for logging and other
read-mostly flows. Use `self.account is None` as the only
indicator that we haven't populated yet.
"""
if self.account is None:
self.get_info()
@property
def path(self):
"""
Logical namespace path used for logging.
For AccountBroker we return just "<account>".
"""
self._populate_instance_cache()
return self.account
def list_containers_iter(self, limit, marker, end_marker, prefix,
delimiter, reverse=False, allow_reserved=False):
"""
@@ -653,15 +660,3 @@ class AccountBroker(DatabaseBroker):
ALTER TABLE container
ADD COLUMN storage_policy_index INTEGER DEFAULT 0;
''' + POLICY_STAT_TRIGGER_SCRIPT)
def _populate_instance_cache(self):
"""
Lazily hydrate instance attributes used for logging and other
read-mostly flows. Use `self.account is None` as the only
indicator that we haven't populated yet.
On failure, we leave `self.account` as-is (likely None) so that
a future caller can try again.
"""
if self.account is None:
self.get_info()