Public bug reported:

[Impact]

When an operator of Juju attempts to restore a backup, it fails with a
mongorestore related error[0]. Under the hood, Juju uses the supplied
mongo related command line interfaces (mongodump, mongorestore etc),
using these in conjunction with the oplog related flags for the former
CLIs, the mongorestore fails with the following error:

 > Failed: restore error: error applying oplog: applyOps: applyOps had
one or more errors applying ops

The only work around for Juju at the moment is to update mongod, so that
it carries the following commit[1]. MongoDB have an identical issue,
under a different name, which fixes this[2], but there is unfortunately
no work around without upgrading mongod so it caries the former commit.

The original investigation around Juju failing to restore a previous
dump can be seen here[3]

I've verified with the 3.6.11 and the same restore, worked fine.

[Test Case]

The following test case doesn't require Juju, and can be replicated
quite easily inside a lxc container. It may require 2 or 3 goes,
depending on timings of the creation of the index and the mongodump, but
I've been getting this consistently.

You can also find instructions in one pastebin[4]

// Launch a container
lxc launch ubuntu:18.04 mongo
lxc exec mongo bash

// Install a version of mongo that Juju is using.
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 
58712A2291FA4AD5
sudo bash -c 'echo "deb http://repo.mongodb.org/apt/ubuntu 
xenial/mongodb-org/3.6 multiverse" > 
/etc/apt/sources.list.d/mongodb-org-3.6.list'
sudo apt update
sudo apt-get install -y mongodb-org=3.6.3 mongodb-org-server=3.6.3 
mongodb-org-shell=3.6.3 mongodb-org-mongos=3.6.3 mongodb-org-tools=3.6.3

// Apply the patch to /etc/mongod.conf to enable the replication - this is 
required.
--- /etc/mongod.conf    2019-03-22 17:17:10.530432761 +0000
+++ /etc/mongod.conf    2019-03-22 17:16:51.602528908 +0000
@@ -32,8 +32,7 @@
 
 #operationProfiling:
 
-replication:
-  replSetName: "rs0"
+#replication:
 
 #sharding:
 
// Start the mongod service
systemctl enable mongod.service
systemctl start mongod.service

// not required, but helps diagnose bsondump
snap install jq

// launch the mongo CLI, running each command
mongo --eval "rs.initiate()"
mongo --eval "rs.status()"
mongo --eval "db.foo.insert({'foo':'bar'})"
mongo --eval "db.foo.createIndex({'bar':1})"

// Get the dump
mongodump --oplog

// check if it's going to fail
// if the output contains a createIndex, but doesn't contain an oid then it'll 
fail.
bsondump dump/oplog.bson | jq

// Drop the foo collection, so we don't get any duplication errors
mongo --eval "db.foo.drop()"

// Now restore the dump

mongorestore --oplogReplay dump/

// It should fail with
2019-03-22T17:26:28.034+0000    preparing collections to restore from
2019-03-22T17:26:28.035+0000    reading metadata for test.foo from 
dump/test/foo.metadata.json
2019-03-22T17:26:28.053+0000    restoring test.foo from dump/test/foo.bson
2019-03-22T17:26:28.056+0000    restoring indexes for collection test.foo from 
metadata
2019-03-22T17:26:28.062+0000    finished restoring test.foo (1 document)
2019-03-22T17:26:28.062+0000    replaying oplog
2019-03-22T17:26:28.064+0000    Failed: restore error: error applying oplog: 
applyOps: applyOps had one or more errors applying ops


[Other Info]

 0. https://paste.ubuntu.com/p/9r9pYc9g9D/
 1. 
https://github.com/mongodb/mongo/commit/0d0ba866052fd2b9ceaaa66c2b725a02822b102d
 2. https://jira.mongodb.org/browse/SERVER-36951
 3. https://bugs.launchpad.net/juju/+bug/1818831
 4. https://paste.ubuntu.com/p/HJsDf5yNkS/

** Affects: mongodb (Ubuntu)
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1821391

Title:
  mongorestore fails with createIndexes command in oplog

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/mongodb/+bug/1821391/+subscriptions

-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to