I am using a MongoDB replSet. I went through the documentation which says the primary node writes data to oplog file and replica reads will happen from it asynchronously. I know that the oplog is a capped collection(specified size), data is being written to oplog at a very high velocity and synchronization to replica set is a bit slow. If the oplog reaches its max size, it overwrites the documents from the beginning of the file. During async process, if we get some other data and if the replication is still in-complete, there is a possibility of losing replication set since it will not be synchronized.
My question here is
1) Is there any way to overcome this?
2) If i give maximum oplog size for eg i give 500GB and oplog has 1gb of data will it occupy and reserve 500gb of size?
1) Is there any way to overcome this?
Hi Mujahid,
The size of the oplog determines how long a replica set member can be down for and still be able to catch up when it comes back online. The bigger the oplog size, the longer you can deal with a member being down for as the oplog can hold more operations. If it does fall too far behind, you must resynchronise the member by removing its data files and performing an initial sync. See Resync a member of a replica set.
The field timeDiffHours as returned by db.getReplicationInfo() reports how many hours worth of data the oplog currently has recorded. An example output of db.getReplicationInfo():
{
"logSizeMB": 100,
"usedMB": 90.68,
"timeDiff": 285195,
"timeDiffHours": 79.22,
"tFirst": "Fri Nov 20 2015 09:11:03 GMT+1100 (AEDT)",
"tLast": "Mon Nov 23 2015 16:24:18 GMT+1100 (AEDT)",
"now": "Tue Nov 24 2015 12:02:12 GMT+1100 (AEDT)"
}
It is recommended to monitor timeDiffHours value:
If you observe that it will never drop below N hours, then N is the maximum number of hours that you can tolerate a replica set member can be down for without having to perform a full resync. The member would then be able to automatically catch up to the primary after coming back online.
Be liberal in how much disk space you allocate for it, unless you have a compelling need for that space. Should you need a larger or smaller oplog in the future you can also change the size of the oplog.
2) If i give maximum oplog size for eg i give 500GB and oplog has 1gb of data will it occupy and reserve 500gb of size?
MongoDB pre-allocates the local.oplog.rs file to avoid filesystem fragmentation. The default value for oplog size is approximately 5% of disk space on 64 bit installation, but will always allocate at least 1GB and never more than 50GB.
Depending on your use case and workloads, you may require a larger oplog size. See Workloads that might require a larger oplog size.
Regards,
Wan.