Skip to content

Commit 9a10d47

Browse files
committed
Stop applying balancer related entries during PITR
1 parent da3bd6c commit 9a10d47

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

pbm/oplog/restore.go

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,24 @@ var dontPreserveUUID = []string{
100100
"*.system.views", // timeseries
101101
}
102102

103+
// ConfigCollToKeep defines a list of collections in the `config`
104+
// database that PBM will apply oplog events.
105+
var configCollToKeep = []string{
106+
"chunks",
107+
"collections",
108+
"databases",
109+
"shards",
110+
"tags",
111+
"version",
112+
}
113+
114+
const settingsColl = "settings"
115+
116+
var settingsToSkip = []string{
117+
"balancer",
118+
"automerge",
119+
}
120+
103121
var ErrNoCloningNamespace = errors.New("cloning namespace desn't exist")
104122

105123
// cloneNS has all data related to cloning namespace within oplog
@@ -322,10 +340,14 @@ func isOpAllowed(oe *Record) bool {
322340
return true // OK: not a "config" database. allow any ops
323341
}
324342

325-
if slices.Contains(dumprestore.ConfigCollectionsToKeep, coll) {
343+
if slices.Contains(configCollToKeep, coll) {
326344
return true // OK: create/update/delete a doc
327345
}
328346

347+
if coll == settingsColl {
348+
return isConfigSettingAllowed(oe)
349+
}
350+
329351
if coll != "$cmd" || len(oe.Object) == 0 {
330352
return false // other collection is not allowed
331353
}
@@ -342,6 +364,20 @@ func isOpAllowed(oe *Record) bool {
342364
return false
343365
}
344366

367+
// isConfigSettingAllowed filter out entries from config.settings collection
368+
func isConfigSettingAllowed(oe *Record) bool {
369+
for _, e := range oe.Query {
370+
if e.Key != "_id" {
371+
continue
372+
}
373+
setting, _ := e.Value.(string)
374+
if slices.Contains(settingsToSkip, setting) {
375+
return false
376+
}
377+
}
378+
return true // allow setting from config.settings
379+
}
380+
345381
func (o *OplogRestore) isOpSelected(oe *Record) bool {
346382
if o.includeNS == nil || o.includeNS[""] != nil {
347383
return true
@@ -412,6 +448,8 @@ func (o *OplogRestore) isOpForCloning(oe *db.Oplog) bool {
412448
return false
413449
}
414450

451+
// isOpExcluded check if collection is excluded.
452+
// Mostly refers PBM's control collections, but also some config and admin ones.
415453
func (o *OplogRestore) isOpExcluded(oe *Record) bool {
416454
if o.excludeNS == nil {
417455
return false

0 commit comments

Comments
 (0)