Search code examples
mongodbmongodb-queryreplicationmaster-slavedatabase

Database on mongodb slave not identical with master


My problem - setting up simple master-slave replication mongodb, but size of databases on slave and master - not identical.

Start replication on slave (with resync = true). Waiting 6 hours (large database). Volume /var/lib/mongodb on slave = 20GB Volume /var/lib/mongodb on master = 100GB

Nothing change after 24 hours - 20GB on slave. It's normal? Check the some collections on slave - count of items in collections equally with master.

Some part of mongodb.log:

/usr/bin/mongod(_ZN5mongo10ReplSource14applyOperationERKNS_7BSONObjE+0x32) [0xb951f2]
/usr/bin/mongod(_ZN5mongo10ReplSource29sync_pullOpLog_applyOperationERNS_7BSONObjEb+0x11ad) [0xba5bed]
 /usr/bin/mongod(_ZN5mongo10ReplSource14sync_pullOpLogERi+0x207d) [0xba802d]
/usr/bin/mongod(_ZN5mongo10ReplSource4syncERi+0x2d3) [0xbaad43]
/usr/bin/mongod(_ZN5mongo9_replMainERSt6vectorIN5boost10shared_ptrINS_10ReplSourceEEESaIS4_EERi+0xea) [0xbad81a]
/usr/bin/mongod(_ZN5mongo8replMainEv+0xc1) [0xbadf21]
/usr/bin/mongod(_ZN5mongo15replSlaveThreadEv+0x4c) [0xbae3ac]
/usr/bin/mongod() [0xe318b9]
/lib64/libpthread.so.0(+0x79d1) [0x7ffff7bc79d1]
/lib64/libc.so.6(clone+0x6d) [0x7ffff6f6c9dd]
Sun Dec  7 20:23:47.987 [replslave] sync: caught db exception 12583 unexpected index insertion failure on capped collection while applying op: { ts: Timestamp 1417973112000|19, op: "i", ns: "test.customdata", o: { _id: ObjectId('54848d781eff6701f2b577e4'), key: "uservariables", value: { autoexpandfeed: "no" }, vuid: "5483fb42b4182e0e448b4595" } }
Sun Dec  7 20:23:48.332 [replslave] replication update of non-mod failed: { ts: Timestamp 1417973112000|26, op: "u", ns: "test.customdata", o2: { _id: ObjectId('548489da1eff6701f2b54a69') }, o: { $set: { value: { autoexpandfeed: "no" } } } }
Sun Dec  7 20:23:48.332 [replslave] replication info adding missing object
Sun Dec  7 20:23:48.332 [replslave] replication missing doc, but this is okay for a capped collection (test.customdata)
Sun Dec  7 20:23:48.332 [replslave] replication missing object not found on source. presumably deleted later in oplog
Sun Dec  7 20:23:48.332 [replslave] replication o2: { _id: ObjectId('548489da1eff6701f2b54a69') }
Sun Dec  7 20:23:48.332 [replslave] replication o firstfield: $set
Sun Dec  7 20:23:54.059 [replslave] Saving repl source: { host: "192.168.205.1", source: "main", syncedTo: Timestamp 1417973118000|13 }
Sun Dec  7 20:23:54.059 [replslave] repl:   checkpoint applied 1125 operations
Sun Dec  7 20:23:54.059 [replslave] repl:   syncedTo: Dec  7 20:25:18 54848d7e:d
Sun Dec  7 20:24:10.485 [DataFileSync] flushing mmaps took 279ms  for 16 files
Sun Dec  7 20:24:10.768 [journal] lsn set 113299808
Sun Dec  7 20:24:13.401 [TTLMonitor] query test.system.indexes query: { expireAfterSeconds: { $exists: true } } ntoreturn:0 ntoskip:0 nscanned:128 keyUpdates:0 locks(micros) r:212 nreturned:0 reslen:20 0ms
Sun Dec  7 20:24:13.402 [TTLMonitor] query local.system.indexes query: { expireAfterSeconds: { $exists: true } } ntoreturn:0 ntoskip:0 nscanned:2 keyUpdates:0 locks(micros) r:69 nreturned:0 reslen:20 0ms

PS> centos 6.5, oplog = 2GB, mongodb ver. 2.4.10 PS> sorry for the language


Solution

  • It is possible that the master database is highly fragmented, causing it to be much larger than the secondary. http://docs.mongodb.org/manual/reference/command/compact/

    See this answer about a similar EC2 related question: https://stackoverflow.com/a/23922416/68567