|
5 | 5 | """
|
6 | 6 |
|
7 | 7 | import sys
|
8 |
| -from typing import List, Optional, cast |
| 8 | +from typing import Optional |
9 | 9 |
|
10 | 10 | import click
|
11 | 11 | from rich.console import Console
|
12 |
| -from rich.panel import Panel |
13 | 12 |
|
14 | 13 | from cratedb_toolkit.admin.xmover.analyze.report import ShardReporter
|
15 | 14 | from cratedb_toolkit.admin.xmover.analyze.shard import ShardAnalyzer
|
|
21 | 20 | )
|
22 | 21 | from cratedb_toolkit.admin.xmover.tune.recommend import Recommender
|
23 | 22 | from cratedb_toolkit.admin.xmover.tune.recover import RecoveryMonitor, RecoveryOptions
|
24 |
| - |
25 |
| -from .database import CrateDBClient |
| 23 | +from cratedb_toolkit.admin.xmover.util.database import CrateDBClient |
| 24 | +from cratedb_toolkit.admin.xmover.util.error import explain_cratedb_error |
26 | 25 |
|
27 | 26 | console = Console()
|
28 | 27 |
|
@@ -236,130 +235,7 @@ def explain_error(ctx, error_message: Optional[str]):
|
236 | 235 |
|
237 | 236 | Example: xmover explain-error "NO(a copy of this shard is already allocated to this node)"
|
238 | 237 | """
|
239 |
| - console.print(Panel.fit("[bold blue]CrateDB Error Message Decoder[/bold blue]")) |
240 |
| - console.print("[dim]Helps decode and troubleshoot CrateDB shard allocation errors[/dim]") |
241 |
| - console.print() |
242 |
| - |
243 |
| - if not error_message: |
244 |
| - console.print("Please paste the CrateDB error message (press Enter twice when done):") |
245 |
| - lines: List[str] = [] |
246 |
| - while True: |
247 |
| - try: |
248 |
| - line = input() |
249 |
| - if line.strip() == "" and lines: |
250 |
| - break |
251 |
| - lines.append(line) |
252 |
| - except (EOFError, KeyboardInterrupt): |
253 |
| - break |
254 |
| - error_message = "\n".join(lines) |
255 |
| - |
256 |
| - if not error_message.strip(): |
257 |
| - console.print("[yellow]No error message provided[/yellow]") |
258 |
| - return |
259 |
| - |
260 |
| - console.print("[dim]Analyzing error message...[/dim]") |
261 |
| - console.print() |
262 |
| - |
263 |
| - # Common CrateDB allocation error patterns and solutions |
264 |
| - error_patterns = [ |
265 |
| - { |
266 |
| - "pattern": "a copy of this shard is already allocated to this node", |
267 |
| - "title": "Node Already Has Shard Copy", |
268 |
| - "explanation": "The target node already contains a copy (primary or replica) of this shard.", |
269 |
| - "solutions": [ |
270 |
| - "Choose a different target node that doesn't have this shard", |
271 |
| - "Use 'xmover zone-analysis --show-shards' to see current distribution", |
272 |
| - "Verify the shard ID and table name are correct", |
273 |
| - ], |
274 |
| - "prevention": "Always check current shard locations before moving", |
275 |
| - }, |
276 |
| - { |
277 |
| - "pattern": "there are too many copies of the shard allocated to nodes with attribute", |
278 |
| - "title": "Zone Allocation Limit Exceeded", |
279 |
| - "explanation": "CrateDB's zone awareness prevents too many copies in the same zone.", |
280 |
| - "solutions": [ |
281 |
| - "Move the shard to a different availability zone", |
282 |
| - "Check zone balance with 'xmover check-balance'", |
283 |
| - "Ensure target zone doesn't already have copies of this shard", |
284 |
| - ], |
285 |
| - "prevention": "Use 'xmover recommend' which respects zone constraints", |
286 |
| - }, |
287 |
| - { |
288 |
| - "pattern": "not enough disk space", |
289 |
| - "title": "Insufficient Disk Space", |
290 |
| - "explanation": "The target node doesn't have enough free disk space for the shard.", |
291 |
| - "solutions": [ |
292 |
| - "Free up space on the target node", |
293 |
| - "Choose a node with more available capacity", |
294 |
| - "Check available space with 'xmover analyze'", |
295 |
| - ], |
296 |
| - "prevention": "Use '--min-free-space' parameter in recommendations", |
297 |
| - }, |
298 |
| - { |
299 |
| - "pattern": "shard recovery limit", |
300 |
| - "title": "Recovery Limit Exceeded", |
301 |
| - "explanation": "Too many shards are currently being moved/recovered simultaneously.", |
302 |
| - "solutions": [ |
303 |
| - "Wait for current recoveries to complete", |
304 |
| - "Check recovery status in CrateDB admin UI", |
305 |
| - "Reduce concurrent recoveries in cluster settings", |
306 |
| - ], |
307 |
| - "prevention": "Move shards gradually, monitor recovery progress", |
308 |
| - }, |
309 |
| - { |
310 |
| - "pattern": "allocation is disabled", |
311 |
| - "title": "Allocation Disabled", |
312 |
| - "explanation": "Shard allocation is temporarily disabled in the cluster.", |
313 |
| - "solutions": [ |
314 |
| - "Re-enable allocation: PUT /_cluster/settings " |
315 |
| - '{"persistent":{"cluster.routing.allocation.enable":"all"}}', |
316 |
| - "Check if allocation was disabled for maintenance", |
317 |
| - "Verify cluster health before re-enabling", |
318 |
| - ], |
319 |
| - "prevention": "Check allocation status before performing moves", |
320 |
| - }, |
321 |
| - ] |
322 |
| - |
323 |
| - # Find matching patterns |
324 |
| - matches = [] |
325 |
| - error_lower = error_message.lower() |
326 |
| - |
327 |
| - for pattern_info in error_patterns: |
328 |
| - if cast(str, pattern_info["pattern"]).lower() in error_lower: |
329 |
| - matches.append(pattern_info) |
330 |
| - |
331 |
| - if matches: |
332 |
| - for i, match in enumerate(matches): |
333 |
| - if i > 0: |
334 |
| - console.print("\n" + "─" * 60 + "\n") |
335 |
| - |
336 |
| - console.print(f"[bold red]🚨 {match['title']}[/bold red]") |
337 |
| - console.print(f"[yellow]📝 Explanation:[/yellow] {match['explanation']}") |
338 |
| - console.print() |
339 |
| - |
340 |
| - console.print("[green]💡 Solutions:[/green]") |
341 |
| - for j, solution in enumerate(match["solutions"], 1): |
342 |
| - console.print(f" {j}. {solution}") |
343 |
| - console.print() |
344 |
| - |
345 |
| - console.print(f"[blue]🛡️ Prevention:[/blue] {match['prevention']}") |
346 |
| - else: |
347 |
| - console.print("[yellow]⚠ No specific pattern match found[/yellow]") |
348 |
| - console.print() |
349 |
| - console.print("[bold]General Troubleshooting Steps:[/bold]") |
350 |
| - console.print("1. Check current shard distribution: [cyan]xmover analyze[/cyan]") |
351 |
| - console.print( |
352 |
| - "2. Validate the specific move: [cyan]xmover validate-move schema.table shard_id from_node to_node[/cyan]" |
353 |
| - ) |
354 |
| - console.print("3. Check zone conflicts: [cyan]xmover zone-analysis --show-shards[/cyan]") |
355 |
| - console.print("4. Verify node capacity: [cyan]xmover analyze[/cyan]") |
356 |
| - console.print("5. Review CrateDB documentation on shard allocation") |
357 |
| - |
358 |
| - console.print() |
359 |
| - console.print("[dim]💡 Tip: Use 'xmover validate-move' to check moves before execution[/dim]") |
360 |
| - console.print( |
361 |
| - "[dim]📚 For more help: https://crate.io/docs/crate/reference/en/latest/admin/system-information.html[/dim]" |
362 |
| - ) |
| 238 | + explain_cratedb_error(error_message) |
363 | 239 |
|
364 | 240 |
|
365 | 241 | @main.command()
|
|
0 commit comments