Skip to content

Don't stop because a single table is incompatible #54

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

Merged
merged 1 commit into from
May 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 5 additions & 20 deletions partitionmanager/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,23 +162,6 @@ def config_from_args(args):
return conf


def all_configured_tables_are_compatible(conf):
"""Pre-flight test that all tables are compatible; returns True/False.

Returns True only if all are compatible, otherwise logs errors and returns
False.
"""
log = logging.getLogger("all_configured_tables_are_compatible")

problems = dict()
for table in conf.tables:
table_problems = pm_tap.get_table_compatibility_problems(conf.dbcmd, table)
if table_problems:
problems[table.name] = table_problems
log.error(f"Cannot proceed: {table} {table_problems}")
return len(problems) == 0


def is_read_only(conf):
"""Pre-flight test whether the database is read-only; returns True/False."""
rows = conf.dbcmd.run("SELECT @@READ_ONLY;")
Expand Down Expand Up @@ -304,9 +287,6 @@ def do_partition(conf):
do_stats(conf)
return dict()

if not all_configured_tables_are_compatible(conf):
return dict()

if conf.noop:
log.info("Running in noop mode, no changes will be made")

Expand All @@ -320,6 +300,11 @@ def do_partition(conf):
all_results = dict()
for table in conf.tables:
try:
table_problems = pm_tap.get_table_compatibility_problems(conf.dbcmd, table)
if table_problems:
log.error(f"Cannot proceed: {table} {table_problems}")
continue

map_data = pm_tap.get_partition_map(conf.dbcmd, table)

duration = conf.partition_period
Expand Down
55 changes: 1 addition & 54 deletions partitionmanager/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from datetime import datetime, timezone
from pathlib import Path
from .cli import (
all_configured_tables_are_compatible,
migrate_cmd,
config_from_args,
do_partition,
Expand Down Expand Up @@ -139,7 +138,7 @@ def test_partition_unpartitioned_table(self):
mariadb: {str(fake_exec)}
"""
)
self.assertSequenceEqual(list(o), [])
self.assertSequenceEqual(list(o), ["test"])

def test_partition_cmd_invalid_yaml(self):
with self.assertRaises(TypeError):
Expand Down Expand Up @@ -327,58 +326,6 @@ def test_stats_yaml(self):
self.assert_stats_prometheus_outfile(stats_outfile.read())


class TestHelpers(unittest.TestCase):
def test_all_configured_tables_are_compatible_one(self):
args = PARSER.parse_args(
[
"--mariadb",
str(fake_exec),
"maintain",
"--table",
"partitioned_yesterday",
]
)
config = config_from_args(args)
self.assertTrue(all_configured_tables_are_compatible(config))

def test_all_configured_tables_are_compatible_three(self):
args = PARSER.parse_args(
[
"--mariadb",
str(fake_exec),
"maintain",
"--table",
"partitioned_last_week",
"partitioned_yesterday",
"othertable",
]
)
config = config_from_args(args)
self.assertTrue(all_configured_tables_are_compatible(config))

def test_all_configured_tables_are_compatible_three_one_unpartitioned(self):
args = PARSER.parse_args(
[
"--mariadb",
str(fake_exec),
"maintain",
"--table",
"partitioned_last_week",
"unpartitioned",
"othertable",
]
)
config = config_from_args(args)
self.assertFalse(all_configured_tables_are_compatible(config))

def test_all_configured_tables_are_compatible_unpartitioned(self):
args = PARSER.parse_args(
["--mariadb", str(fake_exec), "maintain", "--table", "unpartitioned"]
)
config = config_from_args(args)
self.assertFalse(all_configured_tables_are_compatible(config))


class TestConfig(unittest.TestCase):
def test_cli_tables_override_yaml(self):
args = PARSER.parse_args(
Expand Down