Skip to content

Commit bcdc3e9

Browse files
committed
Update README, bugfix that --table and --in/--out were all mutually exclusive
1 parent 03a9cc8 commit bcdc3e9

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

README.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
This tool partitions and manages MariaDB tables by sequential IDs.
55

6-
Note that reorganizing partitions is not a fast operation on ext4 filesystems; it is fast on xfs and zfs, but only when the partition being edited contains no rows. Adding partitions in the first place with InnoDB requires a full table copy.
6+
This is primarily a mechanism for dropping large numbers of rows of data without using `DELETE` statements.
7+
8+
Adding partitions in the first place with InnoDB requires a full table copy. Otherwise, the `REORGANIZE PARTITION` command is fast only if operating on a partition that is empty, e.g., has no rows.
79

810
Similar tools:
911
* https://github.com/davidburger/gomypartition, intended for tables with date-based partitions
@@ -48,9 +50,26 @@ partitionmanager:
4850
days: 14
4951
```
5052
53+
For tables which are either partitioned but not yet using this tool's schema, or which have no empty partitions, the `bootstrap` command can be useful for proposing alterations to run manually. Note that `bootstrap` proposes commands that are likely to require partial copies of each table, so likely they will require a maintenance period.
54+
55+
```sh
56+
partition-manager --mariadb ~/bin/rootsql-dev-primary bootstrap --out /tmp/bootstrap.yml --table orders
57+
INFO:write_state_info:Writing current state information
58+
INFO:write_state_info:(Table("orders"): {'id': 9236}),
59+
60+
# wait some time
61+
partition-manager --mariadb ~/bin/rootsql-dev-primary bootstrap --in /tmp/bootstrap.yml --table orders
62+
INFO:calculate_sql_alters:Reading prior state information
63+
INFO:calculate_sql_alters:Table orders, 24.0 hours, [9236] - [29236], [20000] pos_change, [832.706363653845]/hour
64+
orders:
65+
- ALTER TABLE `orders` REORGANIZE PARTITION `p_20210405` INTO (PARTITION `p_20210416` VALUES LESS THAN (30901), PARTITION `p_20210516` VALUES LESS THAN (630449), PARTITION `p_20210615` VALUES LESS THAN MAXVALUE);
66+
67+
```
5168

5269
# Algorithm
5370

71+
The core algorithm is implemented in a method `plan_partition_changes` in `table_append_partition.py`. That algorithm is:
72+
5473
For a given table and that table's intended partition period, desired end-state is to have:
5574
- All the existing partitions containing data,
5675
- A configurable number of trailing partitions which contain no data, and
@@ -79,16 +98,16 @@ Procedure:
7998
- Create a new list of intended empty partitions.
8099
- For each empty partition:
81100
- Predict the start-of-fill date using the partition's position relative to the current active partition, the current active partition's date, the partition period, and the future partition fill rate.
82-
- Predict the end-of-fill value using the start-of-fill date and the future partition fill rate.
83101
- If the start-of-fill date is different than the partition's name, rename the partition.
84-
- If the end-of-fill value is different than the partition's current value, change that value.
85102
- Append the changed partition to the intended empty partition list.
86103
- While the number of empty partitions is less than the intended number of trailing partitions to keep:
87104
- Predict the start-of-fill date for a new partition using the previous partition's date and the partition period.
88-
- Predict the end-of-fill value using the start-of-fill date and the future partition fill rate.
89105
- Append the new partition to the intended empty partition list.
90106
- Return the lists of non-empty partitions, the current empty partitions, and the post-algorithm intended empty partitions.
91107

92108
# TODOs
93109

94-
Lots. A drop mechanism, for one. Yet more tests, particularly live integration tests with a test DB, for another.
110+
Lots:
111+
[X] Support for tables with partitions across multiple columns.
112+
[ ] A drop mechanism, for one. Initially it should take a retention period and log proposed `DROP` statements, not perform them.
113+
[ ] Yet more tests, particularly live integration tests with a test DB.

partitionmanager/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def bootstrap_cmd(args):
239239
BOOTSTRAP_GROUP.add_argument(
240240
"--out", "-o", dest="outfile", type=argparse.FileType("w"), help="output YAML"
241241
)
242-
BOOTSTRAP_GROUP.add_argument(
242+
BOOTSTRAP_PARSER.add_argument(
243243
"--table", "-t", type=SqlInput, nargs="+", help="table names, overwriting config"
244244
)
245245
BOOTSTRAP_PARSER.set_defaults(func=bootstrap_cmd)

0 commit comments

Comments
 (0)