Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Z
ZKAPAuthorizer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Administrator
ZKAPAuthorizer
Commits
b1ecb2f7
Commit
b1ecb2f7
authored
5 years ago
by
Jean-Paul Calderone
Browse files
Options
Downloads
Patches
Plain Diff
docstrings
parent
a8447cc2
No related branches found
No related tags found
1 merge request
!68
Add stat_shares interface
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/_zkapauthorizer/_storage_server.py
+27
-0
27 additions, 0 deletions
src/_zkapauthorizer/_storage_server.py
with
27 additions
and
0 deletions
src/_zkapauthorizer/_storage_server.py
+
27
−
0
View file @
b1ecb2f7
...
...
@@ -514,12 +514,24 @@ def get_storage_index_share_size(sharepath):
def
get_lease_expiration
(
get_leases
,
storage_index_or_slot
):
"""
Get the lease expiration time for the shares in a bucket or slot, or None
if there is no lease on them.
:param get_leases: A one-argument callable which returns the leases.
:param storage_index_or_slot: Either a storage index or a slot identifying
the shares the leases of which to inspect.
"""
for
lease
in
get_leases
(
storage_index_or_slot
):
return
lease
.
get_expiration_time
()
return
None
def
stat_bucket
(
storage_server
,
storage_index
,
sharepath
):
"""
Get a ``ShareStat`` for the shares in a bucket.
"""
return
ShareStat
(
size
=
get_storage_index_share_size
(
sharepath
),
lease_expiration
=
get_lease_expiration
(
storage_server
.
get_leases
,
storage_index
),
...
...
@@ -527,6 +539,9 @@ def stat_bucket(storage_server, storage_index, sharepath):
def
stat_slot
(
storage_server
,
slot
,
sharepath
):
"""
Get a ``ShareStat`` for the shares in a slot.
"""
return
ShareStat
(
size
=
get_slot_share_size
(
sharepath
),
lease_expiration
=
get_lease_expiration
(
storage_server
.
get_slot_leases
,
slot
),
...
...
@@ -548,6 +563,12 @@ def get_slot_share_size(sharepath):
def
stat_share
(
storage_server
,
storage_index_or_slot
):
"""
Get a ``ShareStat`` for each share in a bucket or a slot.
:return: An iterator of two-tuples of share number and corresponding
``ShareStat``.
"""
stat
=
None
for
sharenum
,
sharepath
in
get_all_share_paths
(
storage_server
,
storage_index_or_slot
):
if
stat
is
None
:
...
...
@@ -556,6 +577,12 @@ def stat_share(storage_server, storage_index_or_slot):
def
get_stat
(
sharepath
):
"""
Get a function that can retrieve the metadata from the share at the given
path.
This is necessary to differentiate between buckets and slots.
"""
# Figure out if it is a storage index or a slot.
with
open
(
sharepath
)
as
share_file
:
magic
=
share_file
.
read
(
32
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment