starrocks-br 0.3.0__py3-none-any.whl → 0.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- starrocks_br/cli.py +307 -217
- starrocks_br/concurrency.py +50 -50
- starrocks_br/config.py +31 -23
- starrocks_br/db.py +38 -38
- starrocks_br/error_handler.py +265 -0
- starrocks_br/exceptions.py +93 -0
- starrocks_br/executor.py +102 -73
- starrocks_br/health.py +1 -6
- starrocks_br/history.py +5 -8
- starrocks_br/labels.py +14 -10
- starrocks_br/logger.py +45 -15
- starrocks_br/planner.py +112 -111
- starrocks_br/repository.py +3 -5
- starrocks_br/restore.py +241 -191
- starrocks_br/schema.py +15 -14
- starrocks_br/timezone.py +29 -31
- starrocks_br/utils.py +86 -0
- starrocks_br-0.5.0.dist-info/METADATA +153 -0
- starrocks_br-0.5.0.dist-info/RECORD +23 -0
- starrocks_br-0.3.0.dist-info/METADATA +0 -456
- starrocks_br-0.3.0.dist-info/RECORD +0 -20
- {starrocks_br-0.3.0.dist-info → starrocks_br-0.5.0.dist-info}/WHEEL +0 -0
- {starrocks_br-0.3.0.dist-info → starrocks_br-0.5.0.dist-info}/entry_points.txt +0 -0
- {starrocks_br-0.3.0.dist-info → starrocks_br-0.5.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import click
|
|
2
|
+
|
|
3
|
+
from . import exceptions
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def display_structured_error(
|
|
7
|
+
title: str,
|
|
8
|
+
reason: str,
|
|
9
|
+
what_to_do: list[str],
|
|
10
|
+
inputs: dict = None,
|
|
11
|
+
help_links: list[str] = None,
|
|
12
|
+
) -> None:
|
|
13
|
+
click.echo()
|
|
14
|
+
click.echo(click.style(f"❌ {title}", fg="red", bold=True), err=True)
|
|
15
|
+
click.echo(reason, err=True)
|
|
16
|
+
click.echo()
|
|
17
|
+
|
|
18
|
+
click.echo(click.style("REASON", fg="yellow", bold=True), err=True)
|
|
19
|
+
click.echo(reason, err=True)
|
|
20
|
+
click.echo()
|
|
21
|
+
|
|
22
|
+
click.echo(click.style("WHAT YOU CAN DO", fg="cyan", bold=True), err=True)
|
|
23
|
+
for i, action in enumerate(what_to_do, 1):
|
|
24
|
+
click.echo(f"{i}) {action}", err=True)
|
|
25
|
+
click.echo()
|
|
26
|
+
|
|
27
|
+
if inputs:
|
|
28
|
+
click.echo(click.style("INPUT YOU PROVIDED", fg="magenta", bold=True), err=True)
|
|
29
|
+
for key, value in inputs.items():
|
|
30
|
+
if value is None:
|
|
31
|
+
click.echo(f" Missing: {key}", err=True)
|
|
32
|
+
else:
|
|
33
|
+
click.echo(f" {key}: {value}", err=True)
|
|
34
|
+
click.echo()
|
|
35
|
+
|
|
36
|
+
if help_links:
|
|
37
|
+
click.echo(click.style("NEED HELP?", fg="green", bold=True), err=True)
|
|
38
|
+
for link in help_links:
|
|
39
|
+
click.echo(f" → {link}", err=True)
|
|
40
|
+
click.echo()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def handle_missing_option_error(exc: exceptions.MissingOptionError, config: str = None) -> None:
|
|
44
|
+
display_structured_error(
|
|
45
|
+
title="OPERATION FAILED",
|
|
46
|
+
reason=f'The "{exc.missing_option}" option was not provided.\nThis parameter is required for the operation.',
|
|
47
|
+
what_to_do=[
|
|
48
|
+
f"Add the missing parameter: {exc.missing_option}",
|
|
49
|
+
"Run the command with --help to see all required options",
|
|
50
|
+
f"Example: starrocks-br <command> {exc.missing_option} <value>"
|
|
51
|
+
+ (f" --config {config}" if config else ""),
|
|
52
|
+
],
|
|
53
|
+
inputs={"--config": config, "Missing": exc.missing_option}
|
|
54
|
+
if config
|
|
55
|
+
else {"Missing": exc.missing_option},
|
|
56
|
+
help_links=["Run with --help for more information"],
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def handle_backup_label_not_found_error(
|
|
61
|
+
exc: exceptions.BackupLabelNotFoundError, config: str = None
|
|
62
|
+
) -> None:
|
|
63
|
+
display_structured_error(
|
|
64
|
+
title="RESTORE FAILED",
|
|
65
|
+
reason=f'The backup label "{exc.label}" does not exist in the repository'
|
|
66
|
+
+ (f' "{exc.repository}"' if exc.repository else "")
|
|
67
|
+
+ ",\nor the backup did not complete successfully.",
|
|
68
|
+
what_to_do=[
|
|
69
|
+
"List available backups by querying the backup history table:\n SELECT label, backup_type, status, finished_at FROM ops.backup_history ORDER BY finished_at DESC;",
|
|
70
|
+
"Check whether the backup completed successfully using StarRocks SQL:"
|
|
71
|
+
+ (
|
|
72
|
+
f"\n SHOW BACKUP FROM `{exc.repository}`;"
|
|
73
|
+
if exc.repository
|
|
74
|
+
else "\n SHOW BACKUP;"
|
|
75
|
+
),
|
|
76
|
+
"Verify that the backup label spelling is correct.",
|
|
77
|
+
],
|
|
78
|
+
inputs={"--config": config, "--target-label": exc.label, "Repository": exc.repository},
|
|
79
|
+
help_links=["starrocks-br restore --help"],
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def handle_no_successful_full_backup_found_error(
|
|
84
|
+
exc: exceptions.NoSuccessfulFullBackupFoundError, config: str = None
|
|
85
|
+
) -> None:
|
|
86
|
+
display_structured_error(
|
|
87
|
+
title="RESTORE FAILED",
|
|
88
|
+
reason=f'No successful full backup was found before the incremental backup "{exc.incremental_label}".\nIncremental backups require a base full backup to restore from.',
|
|
89
|
+
what_to_do=[
|
|
90
|
+
"Verify that a full backup was created before this incremental backup:\n SELECT label, backup_type, status, finished_at FROM ops.backup_history WHERE backup_type = 'full' AND status = 'FINISHED' ORDER BY finished_at DESC;",
|
|
91
|
+
"Run a full backup first:\n starrocks-br backup full --config "
|
|
92
|
+
+ (config if config else "<config.yaml>")
|
|
93
|
+
+ " --group <group_name>",
|
|
94
|
+
"Check that the full backup completed successfully before running the incremental backup",
|
|
95
|
+
],
|
|
96
|
+
inputs={"--target-label": exc.incremental_label, "--config": config},
|
|
97
|
+
help_links=["starrocks-br backup full --help"],
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def handle_table_not_found_in_backup_error(
|
|
102
|
+
exc: exceptions.TableNotFoundInBackupError, config: str = None
|
|
103
|
+
) -> None:
|
|
104
|
+
display_structured_error(
|
|
105
|
+
title="TABLE NOT FOUND",
|
|
106
|
+
reason=f'Table "{exc.table}" was not found in backup "{exc.label}" for database "{exc.database}".',
|
|
107
|
+
what_to_do=[
|
|
108
|
+
"List all tables in the backup:"
|
|
109
|
+
+ (
|
|
110
|
+
f"\n SELECT DISTINCT database_name, table_name FROM ops.backup_partitions WHERE label = '{exc.label}';"
|
|
111
|
+
if config
|
|
112
|
+
else ""
|
|
113
|
+
),
|
|
114
|
+
"Verify the table name spelling is correct",
|
|
115
|
+
f"Ensure the table was included in the backup {exc.label}",
|
|
116
|
+
],
|
|
117
|
+
inputs={
|
|
118
|
+
"--table": exc.table,
|
|
119
|
+
"--target-label": exc.label,
|
|
120
|
+
"Database": exc.database,
|
|
121
|
+
"--config": config,
|
|
122
|
+
},
|
|
123
|
+
help_links=["starrocks-br restore --help"],
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def handle_invalid_table_name_error(exc: exceptions.InvalidTableNameError) -> None:
|
|
128
|
+
display_structured_error(
|
|
129
|
+
title="INVALID TABLE NAME",
|
|
130
|
+
reason=f'The table name "{exc.table_name}" is invalid.\n{exc.reason}',
|
|
131
|
+
what_to_do=[
|
|
132
|
+
"Use only the table name without database prefix",
|
|
133
|
+
"Example: Use 'my_table' instead of 'database.my_table'",
|
|
134
|
+
"The database name should come from the config file",
|
|
135
|
+
],
|
|
136
|
+
inputs={"--table": exc.table_name},
|
|
137
|
+
help_links=["starrocks-br restore --help"],
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def handle_config_file_not_found_error(exc: exceptions.ConfigFileNotFoundError) -> None:
|
|
142
|
+
display_structured_error(
|
|
143
|
+
title="CONFIG FILE NOT FOUND",
|
|
144
|
+
reason=f'The configuration file "{exc.config_path}" could not be found.',
|
|
145
|
+
what_to_do=[
|
|
146
|
+
"Verify the config file path is correct",
|
|
147
|
+
"Ensure the file exists at the specified location",
|
|
148
|
+
"Create a config file with the required settings:\n host, port, user, database, repository",
|
|
149
|
+
],
|
|
150
|
+
inputs={"--config": exc.config_path},
|
|
151
|
+
help_links=["Check the documentation for config file format"],
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def handle_config_validation_error(
|
|
156
|
+
exc: exceptions.ConfigValidationError, config: str = None
|
|
157
|
+
) -> None:
|
|
158
|
+
display_structured_error(
|
|
159
|
+
title="CONFIGURATION ERROR",
|
|
160
|
+
reason=str(exc),
|
|
161
|
+
what_to_do=[
|
|
162
|
+
"Review your configuration file for missing or invalid settings",
|
|
163
|
+
"Ensure all required fields are present: host, port, user, database, repository",
|
|
164
|
+
"Check that values are in the correct format",
|
|
165
|
+
],
|
|
166
|
+
inputs={"--config": config},
|
|
167
|
+
help_links=["Check the documentation for config file requirements"],
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def handle_cluster_health_check_failed_error(
|
|
172
|
+
exc: exceptions.ClusterHealthCheckFailedError, config: str = None
|
|
173
|
+
) -> None:
|
|
174
|
+
display_structured_error(
|
|
175
|
+
title="CLUSTER HEALTH CHECK FAILED",
|
|
176
|
+
reason=f"The StarRocks cluster health check failed: {exc.health_message}",
|
|
177
|
+
what_to_do=[
|
|
178
|
+
"Check that the StarRocks cluster is running",
|
|
179
|
+
"Verify database connectivity settings in your config file",
|
|
180
|
+
"Check cluster status with: SHOW PROC '/frontends'; SHOW PROC '/backends';",
|
|
181
|
+
],
|
|
182
|
+
inputs={"--config": config},
|
|
183
|
+
help_links=["Check StarRocks documentation for troubleshooting cluster issues"],
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def handle_snapshot_not_found_error(
|
|
188
|
+
exc: exceptions.SnapshotNotFoundError, config: str = None
|
|
189
|
+
) -> None:
|
|
190
|
+
display_structured_error(
|
|
191
|
+
title="SNAPSHOT NOT FOUND",
|
|
192
|
+
reason=f'Snapshot "{exc.snapshot_name}" was not found in repository "{exc.repository}".',
|
|
193
|
+
what_to_do=[
|
|
194
|
+
f"List available snapshots:\n SHOW SNAPSHOT ON {exc.repository};",
|
|
195
|
+
"Verify the snapshot name spelling is correct",
|
|
196
|
+
"Ensure the backup completed successfully:\n SELECT * FROM ops.backup_history WHERE label = '"
|
|
197
|
+
+ exc.snapshot_name
|
|
198
|
+
+ "';",
|
|
199
|
+
],
|
|
200
|
+
inputs={"Snapshot": exc.snapshot_name, "Repository": exc.repository, "--config": config},
|
|
201
|
+
help_links=["starrocks-br restore --help"],
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def handle_no_partitions_found_error(
|
|
206
|
+
exc: exceptions.NoPartitionsFoundError, config: str = None, group: str = None
|
|
207
|
+
) -> None:
|
|
208
|
+
display_structured_error(
|
|
209
|
+
title="NO PARTITIONS FOUND",
|
|
210
|
+
reason="No partitions were found to backup"
|
|
211
|
+
+ (f" for group '{exc.group_name}'" if exc.group_name else "")
|
|
212
|
+
+ ".",
|
|
213
|
+
what_to_do=[
|
|
214
|
+
"Verify that the inventory group exists in ops.table_inventory:\n SELECT * FROM ops.table_inventory WHERE inventory_group = "
|
|
215
|
+
+ (f"'{exc.group_name}';" if exc.group_name else "'<your_group>';"),
|
|
216
|
+
"Check that the tables in the group have partitions",
|
|
217
|
+
"Ensure the baseline backup date is correct",
|
|
218
|
+
],
|
|
219
|
+
inputs={"--group": exc.group_name or group, "--config": config},
|
|
220
|
+
help_links=["starrocks-br backup incremental --help"],
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def handle_no_tables_found_error(
|
|
225
|
+
exc: exceptions.NoTablesFoundError, config: str = None, target_label: str = None
|
|
226
|
+
) -> None:
|
|
227
|
+
display_structured_error(
|
|
228
|
+
title="NO TABLES FOUND",
|
|
229
|
+
reason="No tables were found"
|
|
230
|
+
+ (
|
|
231
|
+
f" in backup '{exc.label}' for group '{exc.group}'"
|
|
232
|
+
if exc.group and exc.label
|
|
233
|
+
else f" in backup '{exc.label}'"
|
|
234
|
+
if exc.label
|
|
235
|
+
else ""
|
|
236
|
+
)
|
|
237
|
+
+ ".",
|
|
238
|
+
what_to_do=[
|
|
239
|
+
"Verify that tables exist in the backup manifest:\n SELECT DISTINCT database_name, table_name FROM ops.backup_partitions WHERE label = "
|
|
240
|
+
+ (f"'{exc.label}';" if exc.label else "'<label>';"),
|
|
241
|
+
"Check that the group name is correct in ops.table_inventory"
|
|
242
|
+
if exc.group
|
|
243
|
+
else "Verify the backup completed successfully",
|
|
244
|
+
"List available backups:\n SELECT label, backup_type, status, finished_at FROM ops.backup_history ORDER BY finished_at DESC;",
|
|
245
|
+
],
|
|
246
|
+
inputs={
|
|
247
|
+
"--target-label": exc.label or target_label,
|
|
248
|
+
"--group": exc.group,
|
|
249
|
+
"--config": config,
|
|
250
|
+
},
|
|
251
|
+
help_links=["starrocks-br restore --help"],
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
def handle_restore_operation_cancelled_error() -> None:
|
|
256
|
+
display_structured_error(
|
|
257
|
+
title="OPERATION CANCELLED",
|
|
258
|
+
reason="The restore operation was cancelled by the user.",
|
|
259
|
+
what_to_do=[
|
|
260
|
+
"Review the restore plan carefully",
|
|
261
|
+
"Run again and confirm with 'Y' to proceed",
|
|
262
|
+
"Use the --yes flag to skip the confirmation prompt:\n starrocks-br restore --yes ...",
|
|
263
|
+
],
|
|
264
|
+
help_links=["starrocks-br restore --help"],
|
|
265
|
+
)
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
class StarRocksBRError(Exception):
|
|
2
|
+
pass
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class MissingOptionError(StarRocksBRError):
|
|
6
|
+
def __init__(self, missing_option: str):
|
|
7
|
+
self.missing_option = missing_option
|
|
8
|
+
super().__init__(f"Missing required option: {missing_option}")
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class BackupLabelNotFoundError(StarRocksBRError):
|
|
12
|
+
def __init__(self, label: str, repository: str = None):
|
|
13
|
+
self.label = label
|
|
14
|
+
self.repository = repository
|
|
15
|
+
if repository:
|
|
16
|
+
super().__init__(f"Backup label '{label}' not found in repository '{repository}'")
|
|
17
|
+
else:
|
|
18
|
+
super().__init__(f"Backup label '{label}' not found")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class NoSuccessfulFullBackupFoundError(StarRocksBRError):
|
|
22
|
+
def __init__(self, incremental_label: str):
|
|
23
|
+
self.incremental_label = incremental_label
|
|
24
|
+
super().__init__(
|
|
25
|
+
f"No successful full backup found before incremental '{incremental_label}'"
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class TableNotFoundInBackupError(StarRocksBRError):
|
|
30
|
+
def __init__(self, table: str, label: str, database: str):
|
|
31
|
+
self.table = table
|
|
32
|
+
self.label = label
|
|
33
|
+
self.database = database
|
|
34
|
+
super().__init__(f"Table '{table}' not found in backup '{label}' for database '{database}'")
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class InvalidTableNameError(StarRocksBRError):
|
|
38
|
+
def __init__(self, table_name: str, reason: str):
|
|
39
|
+
self.table_name = table_name
|
|
40
|
+
self.reason = reason
|
|
41
|
+
super().__init__(f"Invalid table name '{table_name}': {reason}")
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class ConfigFileNotFoundError(StarRocksBRError):
|
|
45
|
+
def __init__(self, config_path: str):
|
|
46
|
+
self.config_path = config_path
|
|
47
|
+
super().__init__(f"Config file not found: {config_path}")
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class ConfigValidationError(StarRocksBRError):
|
|
51
|
+
def __init__(self, message: str):
|
|
52
|
+
super().__init__(f"Configuration error: {message}")
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class ClusterHealthCheckFailedError(StarRocksBRError):
|
|
56
|
+
def __init__(self, message: str):
|
|
57
|
+
self.health_message = message
|
|
58
|
+
super().__init__(f"Cluster health check failed: {message}")
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class SnapshotNotFoundError(StarRocksBRError):
|
|
62
|
+
def __init__(self, snapshot_name: str, repository: str):
|
|
63
|
+
self.snapshot_name = snapshot_name
|
|
64
|
+
self.repository = repository
|
|
65
|
+
super().__init__(f"Snapshot '{snapshot_name}' not found in repository '{repository}'")
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class NoPartitionsFoundError(StarRocksBRError):
|
|
69
|
+
def __init__(self, group_name: str = None):
|
|
70
|
+
self.group_name = group_name
|
|
71
|
+
if group_name:
|
|
72
|
+
super().__init__(f"No partitions found to backup for group '{group_name}'")
|
|
73
|
+
else:
|
|
74
|
+
super().__init__("No partitions found to backup")
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class NoTablesFoundError(StarRocksBRError):
|
|
78
|
+
def __init__(self, group: str = None, label: str = None):
|
|
79
|
+
self.group = group
|
|
80
|
+
self.label = label
|
|
81
|
+
if group and label:
|
|
82
|
+
super().__init__(f"No tables found in backup '{label}' for group '{group}'")
|
|
83
|
+
elif group:
|
|
84
|
+
super().__init__(f"No tables found for group '{group}'")
|
|
85
|
+
elif label:
|
|
86
|
+
super().__init__(f"No tables found in backup '{label}'")
|
|
87
|
+
else:
|
|
88
|
+
super().__init__("No tables found")
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
class RestoreOperationCancelledError(StarRocksBRError):
|
|
92
|
+
def __init__(self):
|
|
93
|
+
super().__init__("Restore operation cancelled by user")
|