Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Option BYPASS_OPLOG_VALIDATION not working #17143

Merged
merged 1 commit into from
Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -27,7 +27,7 @@ function fallbackMongoInfo() {
console.error('==================================');
}

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

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

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