Skip to content

Commit c449afe

Browse files
authored
Don't stop because a single table is incompatible (#54)
Fixes #47 We shouldn't abort early if the config isn't perfect, we should operate on what we can.
1 parent a96b8bb commit c449afe

File tree

2 files changed

+6
-74
lines changed

2 files changed

+6
-74
lines changed

partitionmanager/cli.py

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -162,23 +162,6 @@ def config_from_args(args):
162162
return conf
163163

164164

165-
def all_configured_tables_are_compatible(conf):
166-
"""Pre-flight test that all tables are compatible; returns True/False.
167-
168-
Returns True only if all are compatible, otherwise logs errors and returns
169-
False.
170-
"""
171-
log = logging.getLogger("all_configured_tables_are_compatible")
172-
173-
problems = dict()
174-
for table in conf.tables:
175-
table_problems = pm_tap.get_table_compatibility_problems(conf.dbcmd, table)
176-
if table_problems:
177-
problems[table.name] = table_problems
178-
log.error(f"Cannot proceed: {table} {table_problems}")
179-
return len(problems) == 0
180-
181-
182165
def is_read_only(conf):
183166
"""Pre-flight test whether the database is read-only; returns True/False."""
184167
rows = conf.dbcmd.run("SELECT @@READ_ONLY;")
@@ -304,9 +287,6 @@ def do_partition(conf):
304287
do_stats(conf)
305288
return dict()
306289

307-
if not all_configured_tables_are_compatible(conf):
308-
return dict()
309-
310290
if conf.noop:
311291
log.info("Running in noop mode, no changes will be made")
312292

@@ -320,6 +300,11 @@ def do_partition(conf):
320300
all_results = dict()
321301
for table in conf.tables:
322302
try:
303+
table_problems = pm_tap.get_table_compatibility_problems(conf.dbcmd, table)
304+
if table_problems:
305+
log.error(f"Cannot proceed: {table} {table_problems}")
306+
continue
307+
323308
map_data = pm_tap.get_partition_map(conf.dbcmd, table)
324309

325310
duration = conf.partition_period

partitionmanager/cli_test.py

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from datetime import datetime, timezone
66
from pathlib import Path
77
from .cli import (
8-
all_configured_tables_are_compatible,
98
migrate_cmd,
109
config_from_args,
1110
do_partition,
@@ -139,7 +138,7 @@ def test_partition_unpartitioned_table(self):
139138
mariadb: {str(fake_exec)}
140139
"""
141140
)
142-
self.assertSequenceEqual(list(o), [])
141+
self.assertSequenceEqual(list(o), ["test"])
143142

144143
def test_partition_cmd_invalid_yaml(self):
145144
with self.assertRaises(TypeError):
@@ -327,58 +326,6 @@ def test_stats_yaml(self):
327326
self.assert_stats_prometheus_outfile(stats_outfile.read())
328327

329328

330-
class TestHelpers(unittest.TestCase):
331-
def test_all_configured_tables_are_compatible_one(self):
332-
args = PARSER.parse_args(
333-
[
334-
"--mariadb",
335-
str(fake_exec),
336-
"maintain",
337-
"--table",
338-
"partitioned_yesterday",
339-
]
340-
)
341-
config = config_from_args(args)
342-
self.assertTrue(all_configured_tables_are_compatible(config))
343-
344-
def test_all_configured_tables_are_compatible_three(self):
345-
args = PARSER.parse_args(
346-
[
347-
"--mariadb",
348-
str(fake_exec),
349-
"maintain",
350-
"--table",
351-
"partitioned_last_week",
352-
"partitioned_yesterday",
353-
"othertable",
354-
]
355-
)
356-
config = config_from_args(args)
357-
self.assertTrue(all_configured_tables_are_compatible(config))
358-
359-
def test_all_configured_tables_are_compatible_three_one_unpartitioned(self):
360-
args = PARSER.parse_args(
361-
[
362-
"--mariadb",
363-
str(fake_exec),
364-
"maintain",
365-
"--table",
366-
"partitioned_last_week",
367-
"unpartitioned",
368-
"othertable",
369-
]
370-
)
371-
config = config_from_args(args)
372-
self.assertFalse(all_configured_tables_are_compatible(config))
373-
374-
def test_all_configured_tables_are_compatible_unpartitioned(self):
375-
args = PARSER.parse_args(
376-
["--mariadb", str(fake_exec), "maintain", "--table", "unpartitioned"]
377-
)
378-
config = config_from_args(args)
379-
self.assertFalse(all_configured_tables_are_compatible(config))
380-
381-
382329
class TestConfig(unittest.TestCase):
383330
def test_cli_tables_override_yaml(self):
384331
args = PARSER.parse_args(

0 commit comments

Comments
 (0)