Skip to content

br: add keyspace-aware GC safepoint support for backup and restore #65482

Description

@RidRisR

Problem

When running BR (Backup & Restore) with keyspace enabled, the current GC safepoint management uses the deprecated global UpdateServiceGCSafePoint API which doesn't support keyspace isolation. This causes BR operations to fail or behave incorrectly in multi-tenant keyspace scenarios.

Root Cause

The existing BR code directly calls pd.Client.UpdateServiceGCSafePoint() which operates at the global cluster level, not per-keyspace. In keyspace mode, BR should use the new SetGCBarrier / DeleteGCBarrier APIs to set per-keyspace GC barriers.

Solution

Implement a GC manager abstraction layer that:

  1. Automatically detects whether keyspace mode is enabled (via --keyspace-name parameter)
  2. For non-keyspace mode: uses the existing global UpdateServiceGCSafePoint API (backward compatible)
  3. For keyspace mode: uses the new SetGCBarrier / DeleteGCBarrier APIs

Changes

  • Add gc_manager.go: Factory and wrapper functions
  • Add gc_manager_unified.go: Implementation for non-keyspace mode
  • Add gc_manager_keyspace.go: Implementation for keyspace mode
  • Add gc_manager_test.go: Unit tests with >85% coverage
  • Update backup.go, restore.go, stream.go, etc. to use new *WithStorage wrapper functions

Testing

  • Unit tests covering both keyspace and non-keyspace scenarios
  • Tests verify correct API selection based on keyspace configuration
  • Backward compatibility verified for existing non-keyspace deployments

Related

  • PD API: GCStatesClient.SetGCBarrier() / DeleteGCBarrier()

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    affects-9.0This bug affects the 9.0.x versions.component/brThis issue is related to BR of TiDB.severity/moderatetype/bugThe issue is confirmed as a bug.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions