-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add configuration for lease maintenance behavior #255
Merged
Merged
Changes from 12 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
7ead7a3
test for lease maint config read from config file, and related refact…
exarkun 7a6eb5e
fix isodate parse_datetime incompatibility
exarkun fc066a5
read some lease maintenance schedule config from config file
exarkun 11482da
add min lease renewal time to the config object as well
exarkun e354f35
docs for the new config items
exarkun 22f6cf9
module docstring
exarkun dc21970
black and isort
exarkun de981cc
some comment improvements
exarkun 78f43b3
use integer number of seconds to represent duration
exarkun 63c88d4
trivial simplification
exarkun 5ed4228
fix wacko timedelta strategies
exarkun a5618bb
Fix mistake in example for crawl interval range
exarkun 96b752a
Merge remote-tracking branch 'origin/main' into 169.lease-maint-from-…
exarkun 96aedab
Merge remote-tracking branch 'origin/main' into 169.lease-maint-from-…
exarkun fe3e5dd
pyflakes
exarkun 0f66705
black
exarkun 5396725
isort
exarkun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# Copyright 2019 PrivateStorage.io, LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
""" | ||
Helpers for reading values from the Tahoe-LAFS configuration. | ||
""" | ||
|
||
from datetime import timedelta | ||
|
||
from .lease_maintenance import LeaseMaintenanceConfig | ||
|
||
|
||
class _EmptyConfig(object): | ||
""" | ||
Weakly pretend to be a Tahoe-LAFS configuration object with no | ||
configuration. | ||
""" | ||
|
||
def get_config(self, section, option, default=object(), boolean=False): | ||
return default | ||
|
||
|
||
empty_config = _EmptyConfig() | ||
|
||
|
||
def lease_maintenance_from_tahoe_config(node_config): | ||
# type: (_Config) -> LeaseMaintenanceConfig | ||
""" | ||
Return a ``LeaseMaintenanceConfig`` representing the values from the given | ||
configuration object. | ||
""" | ||
return LeaseMaintenanceConfig( | ||
crawl_interval_mean=_read_duration( | ||
node_config, | ||
u"lease.crawl-interval.mean", | ||
timedelta(days=26), | ||
), | ||
crawl_interval_range=_read_duration( | ||
node_config, | ||
u"lease.crawl-interval.range", | ||
timedelta(days=4), | ||
), | ||
# The greater the min lease remaining time, the more of each lease | ||
# period is "wasted" by renewing the lease before it has expired. The | ||
# premise of ZKAPAuthorizer's use of leases is that if they expire, | ||
# the storage server is free to reclaim the storage by forgetting | ||
# about the share. However, since we do not know of any | ||
# ZKAPAuthorizer-enabled storage grids which will garbage collect | ||
# shares when leases expire, we have no reason not to use a zero | ||
# duration here - for now. | ||
# | ||
# In the long run, storage servers must run with garbage collection | ||
# enabled. Ideally, before that happens, we will have a system that | ||
# doesn't involve trading of wasted lease time against reliability of | ||
# leases being renewed before the shares are garbage collected. | ||
# | ||
# Also, since this is configuration, you can set it to something else | ||
# if you want. | ||
min_lease_remaining=_read_duration( | ||
node_config, | ||
u"lease.min-time-remaining", | ||
timedelta(days=0), | ||
), | ||
) | ||
|
||
|
||
def _read_duration(cfg, option, default): | ||
""" | ||
Read an integer number of seconds from the ZKAPAuthorizer section of a | ||
Tahoe-LAFS config. | ||
|
||
:param cfg: The Tahoe-LAFS config object to consult. | ||
:param option: The name of the option to read. | ||
|
||
:return: ``None`` if the option is missing, otherwise the parsed duration | ||
as a ``timedelta``. | ||
""" | ||
# type: (_Config, str) -> Optional[timedelta] | ||
section_name = u"storageclient.plugins.privatestorageio-zkapauthz-v1" | ||
exarkun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
value_str = cfg.get_config( | ||
section=section_name, | ||
option=option, | ||
default=None, | ||
) | ||
if value_str is None: | ||
return default | ||
return timedelta(seconds=int(value_str)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we want to have separate modules for client and server config. Other than
empty_config
(which I guess is a test fixture), all the stuff here is client specific.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be, yea. Since this project started it has become clear that two different plugins may have made more sense than a single plugin with such a tightly coupled implementation. We could probably try to keep the pieces as separate as possible until a more definitive decoupling happens. I'll keep it in mind for future development.