ipop911
ipop911

Reputation: 31

Data too stale, halting replication

I have an error in MongoDB replication: Data too stale, halting replication. I tried to delete all collections from my databases, but it doesn't work. How can I delete oplog to work my replication? I just need the replication to work.

Thanks.

Upvotes: 2

Views: 7124

Answers (3)

Jerry
Jerry

Reputation: 8111

Stale occurs when MongoDB doesn't have enough oplog to carry away the process.So i suggest two methods:

  • Start secondary with new data-dir by stopping the application writes, this reduces the oplog growth hence it helps for better initial sync.
  • If you dont want to stop application writes you have to increase the oplog size that the current size. Oplog size can be calculated on the basis of replication window.

Increasing oplog:

Shutdown the primary server

use admin

db.shutdownServer()

Start primary as standalone & run on different port say 37017

Login to mongo in port 37017

mongo --port 37017

Remove the old contents in local database

For safety have backop of old oplog before dropping

mongodump --db local --collection 'oplog.rs' --port 37017

Drop the old contents in local database

use local

db.oplog.rs.drop()

db.me.drop()

db.replset.election.drop()

db.replset.minvalid.drop()

db.startup_log.drop()

Replset collection cannot be dropped so remove it with required id :

db.system.replset.remove({ "_id" : "your_replsetname"})

Create a new oplog of required size say 50 GB

db.runCommand( { create: "oplog.rs", capped: true, size: (50 * 1024 * 1024 * 1024) } )

Also you can specify the oplog size in MB in mongod.conf file,say for 50 GB its 429496 MB

replication:
   oplogSizeMB: 429496

Hope this Helps !!!

Upvotes: 1

zamnuts
zamnuts

Reputation: 9592

Read the manual: http://docs.mongodb.org/manual/tutorial/resync-replica-set-member removing the collections is not enough, you need to complete clear all data and then perform an initial sync.

There are two high-level options (quoted from the manual):

Restart the mongod with an empty data directory and let MongoDB’s normal initial syncing feature restore the data. This is the more simple option but may take longer to replace the data.

or

Restart the machine with a copy of a recent data directory from another member in the replica set. This procedure can replace the data more quickly but requires more manual steps.

Upvotes: 4

Wesley
Wesley

Reputation: 238

You do NOT want to delete your oplog. You simply stop your mongod process on a secondary, delete the data database files within your secondary's data directory, and then start your mongod on the secondary. You then do this on all affected secondaries.

As user Zamnuts pointed out, you should read the MongoDB documented titled "Resync a Member of a Replica Set"

Upvotes: 4

Related Questions