Skip to content

Commit

Permalink
Add NoValidRatesOfChangeException and don't emit ALTER errors for it (#…
Browse files Browse the repository at this point in the history
…87)

* Add NoValidRatesOfChangeException and don't emit ALTER errors for it

Fixes #86

* Add exception name to warning log
  • Loading branch information
jcjones authored Mar 14, 2024
1 parent 0cb3786 commit 67ec019
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
7 changes: 5 additions & 2 deletions partitionmanager/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,11 @@ def do_partition(conf):
except partitionmanager.types.DatabaseCommandException as e:
log.warning("Failed to automatically handle %s: %s", table, e)
metrics.add("alter_errors", table.name, 1)
except partitionmanager.types.TableEmptyException:
log.warning("Table %s appears to be empty. Skipping.", table)
except (
partitionmanager.types.TableEmptyException,
partitionmanager.types.NoValidRatesOfChangeException,
) as e:
log.warning("Table %s appears to be empty (%s). Skipping.", table, e)
except (ValueError, Exception) as e:
log.warning("Failed to handle %s: %s", table, e)
metrics.add("alter_errors", table.name, 1)
Expand Down
2 changes: 1 addition & 1 deletion partitionmanager/table_append_partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def _get_weighted_position_increase_per_day_for_partitions(partitions):
log.error(
"No rates of change were valid for the partition list: %s", partitions
)
raise ValueError("No valid rates of change")
raise partitionmanager.types.NoValidRatesOfChangeException

# Initialize a list with a zero for each position
weighted_sums = [0] * partitions[0].num_columns
Expand Down
7 changes: 7 additions & 0 deletions partitionmanager/table_append_partition_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
DuplicatePartitionException,
NewPlannedPartition,
NoEmptyPartitionsAvailableException,
NoValidRatesOfChangeException,
InstantPartition,
SqlInput,
SqlQuery,
Expand Down Expand Up @@ -444,6 +445,12 @@ def test_get_weighted_position_increase_per_day_for_partitions(self):
),
[548.3636363636364],
)
with self.assertRaises(NoValidRatesOfChangeException):
_get_weighted_position_increase_per_day_for_partitions(
[
mkPPart("p_736563646E64", 1200000),
]
)

def test_predict_forward_position(self):
with self.assertRaises(ValueError):
Expand Down
4 changes: 4 additions & 0 deletions partitionmanager/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,3 +625,7 @@ class DatabaseCommandException(Exception):

class NoExactTimeException(Exception):
"""Raised if there's no exact time available for this partition."""


class NoValidRatesOfChangeException(Exception):
"""Raised if the table's rate of change cannot be calculated."""
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "mariadb-sequential-partition-manager"
maintainers = [
{name = "J.C. Jones", email = "[email protected]"},
]
version = "0.4.0"
version = "0.4.1"
description = "Manage DB partitions based on sequential IDs"
license = {file = "LICENSE.txt"}
classifiers = [
Expand Down

0 comments on commit 67ec019

Please sign in to comment.