Skip to content

Conversation

@boris-ilijic
Copy link
Member

@boris-ilijic boris-ilijic commented Dec 10, 2025

PBM-1561 Powered by Pull Request Badge

This is follow-up of #1129 which was about full logical restore.

This PR enables selective logical restore in the sharded cluster when targeted database/collection already exists:

  • During the cleanup phase PBM drops all the databases/collections that are listed with --ns option
  • In case of selective restore of collection (--ns "db.coll") PBM uses _shardsvrDropCollection command to cleanup specified collection.
  • In case of selective restore of database (--ns "db.*") PBM uses _shardsvrDropDatabase command to cleanup specified database.
  • The same logic is applied also for PITR (--time) restore.

PBM applyed cleanup cluster phase only for the full logical restore so
far.
The comand is used in the cleanup phase of the selective logical
restore. Before the restore procedure, it's necessary to do cluster-wide
cleanup of the particular namespace that is part of selective restore.
... to be able to share it between full and selective restore.
For the purpose of fetching config.databases document when performing
cleanup phase during logical restore.
It's used for the cleanup phase during selective logical restore.
... within logical restore
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enables selective logical restore for sharded MongoDB clusters by introducing database and collection cleanup operations specific to selective restores. The implementation adds support for cluster-wide dropping of databases and collections using MongoDB's internal _shardsvrDropDatabase and _shardsvrDropCollection commands.

Key Changes:

  • Added selective restore cleanup logic that drops specific databases/collections based on restore namespaces
  • Refactored full restore cleanup to use the same underlying database operation interface
  • Introduced mDB struct and mDBCl interface to encapsulate database operations for better testability

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 13 comments.

File Description
pbm/defs/defs.go Added ConfigDB constant for the "config" database name
pbm/restore/query.go Introduced mDB struct with methods for executing cluster-wide drop commands and fetching config database documents
pbm/restore/logical.go Refactored restore cleanup logic to support both full and selective restores with proper database/collection dropping
pbm/restore/logical_test.go Added comprehensive test coverage for selective restore cleanup scenarios including edge cases

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@boris-ilijic boris-ilijic force-pushed the PBM-1561-enable-sharded-sel-restore branch from d0e4954 to e925b65 Compare December 10, 2025 13:07
@boris-ilijic boris-ilijic marked this pull request as ready for review December 10, 2025 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants