use a context manager to apply --no-auto-shard option
...so that it gets unapplied at end of the run_* methods This is probably overkill, but does guard against unforeseen side-effects if the daemon run_* methods were ever called more than once with different kwargs. Change-Id: Iad6a3bcc99a26550048346dffec9aee432828f3a
This commit is contained in:
@@ -23,6 +23,7 @@ import os
|
||||
import six
|
||||
from six.moves.urllib.parse import quote
|
||||
from eventlet import Timeout
|
||||
from contextlib import contextmanager
|
||||
|
||||
from swift.common import internal_client
|
||||
from swift.common.constraints import check_drive, AUTO_CREATE_ACCOUNT_PREFIX
|
||||
@@ -1712,14 +1713,20 @@ class ContainerSharder(ContainerReplicator):
|
||||
|
||||
self._report_stats()
|
||||
|
||||
@contextmanager
|
||||
def _set_auto_shard_from_command_line(self, **kwargs):
|
||||
conf_auto_shard = self.auto_shard
|
||||
auto_shard = kwargs.get('auto_shard', None)
|
||||
if auto_shard is not None:
|
||||
self.auto_shard = config_true_value(auto_shard)
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
self.auto_shard = conf_auto_shard
|
||||
|
||||
def run_forever(self, *args, **kwargs):
|
||||
"""Run the container sharder until stopped."""
|
||||
self._set_auto_shard_from_command_line(**kwargs)
|
||||
with self._set_auto_shard_from_command_line(**kwargs):
|
||||
self.reported = time.time()
|
||||
time.sleep(random() * self.interval)
|
||||
while True:
|
||||
@@ -1742,7 +1749,7 @@ class ContainerSharder(ContainerReplicator):
|
||||
override_options = parse_override_options(once=True, **kwargs)
|
||||
devices_to_shard = override_options.devices or Everything()
|
||||
partitions_to_shard = override_options.partitions or Everything()
|
||||
self._set_auto_shard_from_command_line(**kwargs)
|
||||
with self._set_auto_shard_from_command_line(**kwargs):
|
||||
begin = self.reported = time.time()
|
||||
self._one_shard_cycle(devices_to_shard=devices_to_shard,
|
||||
partitions_to_shard=partitions_to_shard)
|
||||
|
Reference in New Issue
Block a user