What does the oplogReplay parameter for the tail cursor add to mongodb? Why did he fix my timeout problem?

I tried to drive oplog into mongo and got a timeout error. The oplog collection contains over 7 million documents. However, as a last effort, I added a parameter oplogReplay: trueto the cursor parameters, and the timeout error went away, and I read the oplog stream.

nodejs mongo docs are pretty cryptic as to what this option really does, only that it suits tail cursors, so I watched it

oplogReplay {Boolean}, sets the internal flag, applicable only for the tail cursor.

I assume that it either skips the initial scan of the entire dictionary and goes right to the end, or scans it from the other end of the oplog.

My code looks something like this:

const tstamp = new MongoDB.Timestamp(0, Math.floor(new Date().getTime() / 1000));
const filters = {
  ts: { $gt: tstamp }
};
const curOpts = {
    tailable: true,
    timeout: false,
    oplogReplay: true,  //<- What does this actually do?
    awaitData: true,
    numberOfRetries: 60 * 60 * 24,
    tailableRetryInterval: 1000
};

mongodb.connect(url).then(db => {
    const cur = db.collection('oplog.rs').find(filters, curOpts);
    const stream = cur.stream();
    stream
      .on('data', log => {
        console.log('Data!')
        console.log(log)
      })
      .on('close', () => {
        console.log('Stream closed....')
        db.close()
      })
      .on('error', err => {
        console.log('Stream error....')
        console.error(err)
        db.close()
      });
}));

Related Search

I also found this question and the answer that is related. I found that after I solved my original question, though.

And when I studied the problem, I found that the oplog scan time expires after 30 seconds, and this causes / causes problems with some of them.

Another question and answer related to my timeout problem. It seems that creating an index in the ts field for oplog is a very bad idea and impossible for newer versions of mongo.

+4
source share

Source: https://habr.com/ru/post/1656855/


All Articles