Skip to content

Commit

Permalink
PBM-951: drop pbm*.old collections (percona#819)
Browse files Browse the repository at this point in the history
Preserving of pbmBackups and pbmPITRChunks during resync is redundant.
As storage is the source of trues anyway. And these preserved data had
been never used or requested. But copying pbmPITRChunks slows resync
down ALOT if there is a quite amount of chunks.
  • Loading branch information
dAdAbird authored Apr 6, 2023
1 parent 085329d commit 5cdc4cb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 35 deletions.
4 changes: 0 additions & 4 deletions pbm/pbm.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,12 @@ const (
LockOpCollection = "pbmLockOp"
// BcpCollection is a collection for backups metadata
BcpCollection = "pbmBackups"
// BcpOldCollection contains a backup of backups metadata
BcpOldCollection = "pbmBackups.old"
// RestoresCollection is a collection for restores metadata
RestoresCollection = "pbmRestores"
// CmdStreamCollection is the name of the mongo collection that contains backup/restore commands stream
CmdStreamCollection = "pbmCmd"
// PITRChunksCollection contains index metadata of PITR chunks
PITRChunksCollection = "pbmPITRChunks"
// PITRChunksOldCollection contains archived index metadata of PITR chunks
PITRChunksOldCollection = "pbmPITRChunks.old"
// PBMOpLogCollection contains log of acquired locks (hence run ops)
PBMOpLogCollection = "pbmOpLog"
// AgentsStatusCollection is an agents registry with its status/health checks
Expand Down
34 changes: 5 additions & 29 deletions pbm/rsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,14 @@ func (p *PBM) ResyncStorage(l *log.Event) error {
}
l.Debug("got backups list: %v", len(bcps))

err = p.moveCollection(BcpCollection, BcpOldCollection)
_, err = p.Conn.Database(DB).Collection(BcpCollection).DeleteMany(p.ctx, bson.M{})
if err != nil {
return errors.Wrapf(err, "copy current backups meta from %s to %s", BcpCollection, BcpOldCollection)
return errors.Wrapf(err, "clean up %s", BcpCollection)
}
err = p.moveCollection(PITRChunksCollection, PITRChunksOldCollection)

_, err = p.Conn.Database(DB).Collection(PITRChunksCollection).DeleteMany(p.ctx, bson.M{})
if err != nil {
return errors.Wrapf(err, "copy current pitr meta from %s to %s", PITRChunksCollection, PITRChunksOldCollection)
return errors.Wrapf(err, "clean up %s", PITRChunksCollection)
}

var ins []interface{}
Expand Down Expand Up @@ -213,31 +214,6 @@ func checkFile(stg storage.Storage, filename string) error {
return nil
}

func (p *PBM) moveCollection(coll, as string) error {
err := p.Conn.Database(DB).Collection(as).Drop(p.ctx)
if err != nil {
return errors.Wrap(err, "failed to remove old archive from backups metadata")
}

cur, err := p.Conn.Database(DB).Collection(coll).Find(p.ctx, bson.M{})
if err != nil {
return errors.Wrap(err, "get current data")
}
for cur.Next(p.ctx) {
_, err = p.Conn.Database(DB).Collection(as).InsertOne(p.ctx, cur.Current)
if err != nil {
return errors.Wrapf(err, "insert")
}
}

if cur.Err() != nil {
return cur.Err()
}

_, err = p.Conn.Database(DB).Collection(coll).DeleteMany(p.ctx, bson.M{})
return errors.Wrap(err, "remove current data")
}

func GetPhysRestoreMeta(restore string, stg storage.Storage, l *log.Event) (rmeta *RestoreMeta, err error) {
mjson := filepath.Join(PhysRestoresDir, restore) + ".json"
_, err = stg.FileStat(mjson)
Expand Down
6 changes: 4 additions & 2 deletions pbm/snapshot/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ var ExcludeFromRestore = []string{
pbm.DB + "." + pbm.LogCollection,
pbm.DB + "." + pbm.ConfigCollection,
pbm.DB + "." + pbm.BcpCollection,
pbm.DB + "." + pbm.BcpOldCollection,
pbm.DB + "." + pbm.RestoresCollection,
pbm.DB + "." + pbm.LockCollection,
pbm.DB + "." + pbm.LockOpCollection,
pbm.DB + "." + pbm.PITRChunksCollection,
pbm.DB + "." + pbm.PITRChunksOldCollection,
pbm.DB + "." + pbm.AgentsStatusCollection,
pbm.DB + "." + pbm.PBMOpLogCollection,
"config.version",
Expand All @@ -42,6 +40,10 @@ var ExcludeFromRestore = []string{
"config.transaction_coordinators",
"admin.system.version",
"config.system.indexBuilds",

// deprecated PBM collections, keep it here not to bring back from old backups
pbm.DB + ".pbmBackups.old",
pbm.DB + ".pbmPITRChunks.old",
}

type restorer struct{ *mongorestore.MongoRestore }
Expand Down

0 comments on commit 5cdc4cb

Please sign in to comment.