Skip to content

Commit

Permalink
[FIX] Option BYPASS_OPLOG_VALIDATION not working (#17143)
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigok authored and sampaiodiego committed Apr 3, 2020
1 parent 1dae091 commit 13b4114
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
17 changes: 12 additions & 5 deletions app/models/server/models/_BaseDb.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { EventEmitter } from 'events';

import { Match } from 'meteor/check';
import { Mongo, MongoInternals } from 'meteor/mongo';
import { Mongo } from 'meteor/mongo';
import _ from 'underscore';

import { getMongoInfo } from '../../../utils/server/functions/getMongoInfo';

const baseName = 'rocketchat_';

const trash = new Mongo.Collection(`${ baseName }_trash`);
Expand Down Expand Up @@ -35,6 +37,8 @@ export class BaseDb extends EventEmitter {

this.wrapModel();

const { oplogEnabled, mongo } = getMongoInfo();

// When someone start listening for changes we start oplog if available
const handleListener = (event /* , listener*/) => {
if (event !== 'change') {
Expand All @@ -47,26 +51,29 @@ export class BaseDb extends EventEmitter {
collection: this.collectionName,
};

if (!MongoInternals.defaultRemoteCollectionDriver().mongo._oplogHandle) {
if (!mongo._oplogHandle) {
throw new Error(`Error: Unable to find Mongodb Oplog. You must run the server with oplog enabled. Try the following:\n
1. Start your mongodb in a replicaset mode: mongod --smallfiles --oplogSize 128 --replSet rs0\n
2. Start the replicaset via mongodb shell: mongo mongo/meteor --eval "rs.initiate({ _id: ''rs0'', members: [ { _id: 0, host: ''localhost:27017'' } ]})"\n
3. Start your instance with OPLOG configuration: export MONGO_OPLOG_URL=mongodb://localhost:27017/local MONGO_URL=mongodb://localhost:27017/meteor node main.js
`);
}

MongoInternals.defaultRemoteCollectionDriver().mongo._oplogHandle.onOplogEntry(
mongo._oplogHandle.onOplogEntry(
query,
this.processOplogRecord.bind(this),
);
// Meteor will handle if we have a value https://github.com/meteor/meteor/blob/5dcd0b2eb9c8bf881ffbee98bc4cb7631772c4da/packages/mongo/oplog_tailing.js#L5
if (process.env.METEOR_OPLOG_TOO_FAR_BEHIND == null) {
MongoInternals.defaultRemoteCollectionDriver().mongo._oplogHandle._defineTooFarBehind(
mongo._oplogHandle._defineTooFarBehind(
Number.MAX_SAFE_INTEGER,
);
}
};
this.on('newListener', handleListener);

if (oplogEnabled) {
this.on('newListener', handleListener);
}

this.tryEnsureIndex({ _updatedAt: 1 }, options._updatedAtIndexOptions);
}
Expand Down
4 changes: 2 additions & 2 deletions app/utils/server/functions/getMongoInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function fallbackMongoInfo() {
console.error('==================================');
}

return { oplogEnabled, mongoVersion, mongoStorageEngine };
return { oplogEnabled, mongoVersion, mongoStorageEngine, mongo };
}

export function getMongoInfo() {
Expand All @@ -51,5 +51,5 @@ export function getMongoInfo() {
return fallbackMongoInfo();
}

return { oplogEnabled, mongoVersion, mongoStorageEngine };
return { oplogEnabled, mongoVersion, mongoStorageEngine, mongo };
}

0 comments on commit 13b4114

Please sign in to comment.