Skip to content

Commit 6d394c4

Browse files
committed
PBM-1398: check applyOps to exclude namespace
1 parent 5e8e2db commit 6d394c4

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

pbm/oplog/restore.go

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,27 @@ func (o *OplogRestore) isOpSelected(oe *Record) bool {
310310
return false
311311
}
312312

313+
func (o *OplogRestore) isOpExcluded(oe *Record) bool {
314+
if o.excludeNS == nil {
315+
return false
316+
}
317+
db, coll, _ := strings.Cut(oe.Namespace, ".")
318+
if coll != "$cmd" {
319+
return o.excludeNS.Has(oe.Namespace)
320+
}
321+
322+
cmd := oe.Object[0].Key
323+
if cmd == "applyOps" {
324+
return false // internal ops of applyOps are checked one by one later
325+
}
326+
if _, ok := selectedNSSupportedCommands[cmd]; ok {
327+
coll, _ = oe.Object[0].Value.(string)
328+
return o.excludeNS.Has(db + "." + coll)
329+
}
330+
331+
return false
332+
}
333+
313334
func (o *OplogRestore) LastOpTS() uint32 {
314335
return atomic.LoadUint32(&o.lastOpT)
315336
}
@@ -325,11 +346,7 @@ func (o *OplogRestore) handleOp(oe db.Oplog) error {
325346
return nil
326347
}
327348

328-
if o.excludeNS.Has(oe.Namespace) {
329-
return nil
330-
}
331-
332-
if !isOpAllowed(&oe) || !o.isOpSelected(&oe) {
349+
if o.isOpExcluded(&oe) || !isOpAllowed(&oe) || !o.isOpSelected(&oe) {
333350
return nil
334351
}
335352

@@ -648,11 +665,7 @@ func (o *OplogRestore) HandleUncommittedTxn(
648665
func (o *OplogRestore) handleNonTxnOp(op db.Oplog) error {
649666
// have to handle it here one more time because before the op gets thru
650667
// txnBuffer its namespace is `collection.$cmd` instead of the real one
651-
if o.excludeNS.Has(op.Namespace) {
652-
return nil
653-
}
654-
655-
if !isOpAllowed(&op) || !o.isOpSelected(&op) {
668+
if o.isOpExcluded(&op) || !isOpAllowed(&op) || !o.isOpSelected(&op) {
656669
return nil
657670
}
658671

0 commit comments

Comments
 (0)