Skip to content

Commit d556a6d

Browse files
committed
PBM-1297: allow to create config.databases during oplog replay
1 parent 4e46784 commit d556a6d

File tree

2 files changed

+37
-28
lines changed

2 files changed

+37
-28
lines changed

pbm/oplog/restore.go

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"fmt"
1515
"io"
1616
"reflect"
17+
"slices"
1718
"strings"
1819
"sync/atomic"
1920

@@ -77,8 +78,6 @@ var selectedNSSupportedCommands = map[string]struct{}{
7778
"dropIndex": {},
7879
"dropIndexes": {},
7980
"collMod": {},
80-
"startIndexBuild": {},
81-
"abortIndexBuild": {},
8281
"commitIndexBuild": {},
8382
}
8483

@@ -258,6 +257,32 @@ func (o *OplogRestore) SetIncludeNS(nss []string) {
258257
o.includeNS = dbs
259258
}
260259

260+
func isOpAllowed(oe *Record) bool {
261+
coll, ok := strings.CutPrefix(oe.Namespace, "config.")
262+
if !ok {
263+
return true // OK: not a "config" database. allow any ops
264+
}
265+
266+
if slices.Contains(dumprestore.ConfigCollectionsToKeep, coll) {
267+
return true // OK: create/update/delete a doc
268+
}
269+
270+
if coll != "$cmd" || len(oe.Object) == 0 {
271+
return false // other collection is not allowed
272+
}
273+
274+
op := oe.Object[0].Key
275+
if op == "applyOps" {
276+
return true // internal ops of applyOps are checked one by one later
277+
}
278+
if _, ok := selectedNSSupportedCommands[op]; ok {
279+
s, _ := oe.Object[0].Value.(string)
280+
return slices.Contains(dumprestore.ConfigCollectionsToKeep, s)
281+
}
282+
283+
return false
284+
}
285+
261286
func (o *OplogRestore) isOpSelected(oe *Record) bool {
262287
if o.includeNS == nil || o.includeNS[""] != nil {
263288
return true
@@ -273,11 +298,13 @@ func (o *OplogRestore) isOpSelected(oe *Record) bool {
273298
return false
274299
}
275300

276-
for _, el := range oe.Object {
277-
if _, ok := selectedNSSupportedCommands[el.Key]; ok {
278-
s, _ := el.Value.(string)
279-
return colls[s]
280-
}
301+
cmd := oe.Object[0].Key
302+
if cmd == "applyOps" {
303+
return true // internal ops of applyOps are checked one by one later
304+
}
305+
if _, ok := selectedNSSupportedCommands[cmd]; ok {
306+
s, _ := oe.Object[0].Value.(string)
307+
return colls[s]
281308
}
282309

283310
return false
@@ -302,13 +329,7 @@ func (o *OplogRestore) handleOp(oe db.Oplog) error {
302329
return nil
303330
}
304331

305-
if db, coll, _ := strings.Cut(oe.Namespace, "."); db == "config" {
306-
if !sliceContains(dumprestore.ConfigCollectionsToKeep, coll) {
307-
return nil
308-
}
309-
}
310-
311-
if !o.isOpSelected(&oe) {
332+
if !isOpAllowed(&oe) || !o.isOpSelected(&oe) {
312333
return nil
313334
}
314335

@@ -631,10 +652,8 @@ func (o *OplogRestore) handleNonTxnOp(op db.Oplog) error {
631652
return nil
632653
}
633654

634-
if db, coll, _ := strings.Cut(op.Namespace, "."); db == "config" {
635-
if !sliceContains(dumprestore.ConfigCollectionsToKeep, coll) {
636-
return nil
637-
}
655+
if !isOpAllowed(&op) || !o.isOpSelected(&op) {
656+
return nil
638657
}
639658

640659
op, err := o.filterUUIDs(op)

pbm/oplog/util.go

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)