Skip to content

XMover: Fix system-schema filter in active-shards command: 'gc' schema not properly excluded #542

@coderabbitai

Description

@coderabbitai

Problem

The system-schema filter in the active-shards command has a bug that prevents proper exclusion of system tables under the gc schema.

Current Code (Line ~319-330 in cratedb_toolkit/admin/xmover/cli.py)

if exclude_system:
    snapshots = [
        s
        for s in snapshots
        if not (
            s.schema_name.startswith("gc.")  # ❌ This won't match "gc" schema
            or s.schema_name == "information_schema"
            or s.schema_name == "sys"
            or s.table_name.endswith("_events")
            or s.table_name.endswith("_log")
        )
    ]

Issue

s.schema_name.startswith("gc.") looks for schemas starting with "gc." (with dot), but the actual schema name is "gc" (without dot). This means:

  • "gc".startswith("gc.") returns False
  • System tables under the gc schema won't be excluded as intended

Evidence

From test file tests/admin/test_active_shard_monitor.py:

self.create_test_snapshot("gc", "scheduled_jobs_log", 0, "data-hot-8", True, 15876, 100.0)

The help text also suggests this intent:

@click.option("--exclude-system", is_flag=True, help="Exclude system tables (gc.*, information_schema.*)")

Suggested Fix

if exclude_system:
    system_schemas = {"gc", "information_schema", "sys"}
    snapshots = [
        s for s in snapshots
        if s.schema_name not in system_schemas
        and not (s.table_name.endswith("_events") or s.table_name.endswith("_log"))
    ]

Or if there are indeed sub-schemas under gc:

if exclude_system:
    snapshots = [
        s for s in snapshots
        if not (
            (s.schema_name == "gc" or s.schema_name.startswith("gc."))
            or s.schema_name == "information_schema"
            or s.schema_name == "sys"
            or s.table_name.endswith("_events")
            or s.table_name.endswith("_log")
        )
    ]

Backlinks

Please review and confirm the expected behavior for system schema filtering.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions