Skip to content

Commit

Permalink
CLI: check peer count before actually rebalancing meta1
Browse files Browse the repository at this point in the history
Also implement a new 'openio directory check' command, checking each
reference prefix is managed by the right number of meta1 services. This
complements 'openio-admin directory check' (which does not check this
number).

Jira: OS-470
  • Loading branch information
fvennetier committed Jan 17, 2020
1 parent 493b14e commit b7493c3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
36 changes: 31 additions & 5 deletions oio/cli/directory/directory.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2015-2019 OpenIO SAS, as part of OpenIO SDS
# Copyright (C) 2015-2020 OpenIO SAS, as part of OpenIO SDS
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
Expand All @@ -13,6 +13,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from __future__ import print_function


from oio.common.green import Queue, GreenPile, sleep

Expand Down Expand Up @@ -96,6 +98,26 @@ def _apply(self, mapping, moved=None,
raise


class DirectoryCheck(DirectoryCmd):
"""
Check that the service directory is ok.
Currently only checks that all meta1 prefixes have the right number
of replicas. More checks can be performed by running
'openio-admin directory check'.
"""

def take_action(self, parsed_args):
self.log.debug('take_action(%s)', parsed_args)
mapping = self.get_prefix_mapping(parsed_args)
mapping.load_meta0(read_timeout=parsed_args.meta0_timeout)
if mapping.check_replicas():
self.log.info("Everything is ok.")
else:
self.log.warn("Errors found.")
self.success = False


class DirectoryInit(DirectoryCmd):
"""
Initialize the service directory.
Expand Down Expand Up @@ -185,7 +207,7 @@ def take_action(self, parsed_args):
mapping = self.get_prefix_mapping(parsed_args)
mapping.load_meta0(connection_timeout=M0_CONN_TIMEOUT,
read_timeout=parsed_args.meta0_timeout)
print mapping.to_json()
print(mapping.to_json())


class DirectoryRebalance(DirectoryCmd):
Expand All @@ -196,9 +218,13 @@ def take_action(self, parsed_args):
mapping = self.get_prefix_mapping(parsed_args)
mapping.load_meta0(read_timeout=parsed_args.meta0_timeout)
moved = mapping.rebalance()
self._apply(mapping, moved=moved,
read_timeout=parsed_args.meta0_timeout)
self.log.info("Moved %s", moved)
if mapping.check_replicas():
self._apply(mapping, moved=moved,
read_timeout=parsed_args.meta0_timeout)
self.log.info("Moved %s", moved)
else:
self.log.warn("Nothing done due to errors")
self.success = False


class DirectoryRestore(DirectoryCmd):
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ openio.rdir =
rdir_assignments = oio.cli.rdir.rdir:RdirAssignments
openio.directory =
directory_bootstrap = oio.cli.directory.directory:DirectoryInit
directory_check = oio.cli.directory.directory:DirectoryCheck
directory_decommission = oio.cli.directory.directory:DirectoryDecommission
directory_dump = oio.cli.directory.directory:DirectoryList
directory_rebalance = oio.cli.directory.directory:DirectoryRebalance
Expand Down

0 comments on commit b7493c3

Please # to comment.