Don't use system.replset to check for replset

It requires an unnecessary level of permissions in Mongo 2.6.  Instead,
use the isMaster command plus parsing the URL.

Fixes #2121.
This commit is contained in:
David Glasser
2015-02-04 22:57:04 -08:00
parent 5936c0b3de
commit 2e4d3f2833
3 changed files with 21 additions and 7 deletions

View File

@@ -12,6 +12,9 @@
}
}
}
},
"mongodb-uri": {
"version": "0.9.7"
}
}
}

View File

@@ -1,7 +1,6 @@
var Future = Npm.require('fibers/future');
OPLOG_COLLECTION = 'oplog.rs';
var REPLSET_COLLECTION = 'system.replset';
// Like Perl's quotemeta: quotes all regexp metacharacters. See
// https://github.com/substack/quotemeta/blob/master/index.js
@@ -150,6 +149,13 @@ _.extend(OplogHandle.prototype, {
},
_startTailing: function () {
var self = this;
// First, make sure that we're talking to the local database.
var mongodbUri = Npm.require('mongodb-uri');
if (mongodbUri.parse(self._oplogUrl).database !== 'local') {
throw Error("$MONGO_OPLOG_URL must be set to the 'local' database of " +
"a Mongo replica set");
}
// We make two separate connections to Mongo. The Node Mongo driver
// implements a naive round-robin connection pool: each "connection" is a
// pool of several (5 by default) TCP connections, and each request is
@@ -169,13 +175,17 @@ _.extend(OplogHandle.prototype, {
self._oplogLastEntryConnection = new MongoConnection(
self._oplogUrl, {poolSize: 1});
// First, make sure that there actually is a repl set here. If not, oplog
// tailing won't ever find anything! (Blocks until the connection is ready.)
var replSetInfo = self._oplogLastEntryConnection.findOne(
REPLSET_COLLECTION, {});
if (!replSetInfo)
// Now, make sure that there actually is a repl set here. If not, oplog
// tailing won't ever find anything!
var f = new Future;
self._oplogLastEntryConnection.db.admin().command(
{ ismaster: 1 }, f.resolver());
var isMasterDoc = f.wait();
if (!(isMasterDoc && isMasterDoc.documents && isMasterDoc.documents[0] &&
isMasterDoc.documents[0].setName)) {
throw Error("$MONGO_OPLOG_URL must be set to the 'local' database of " +
"a Mongo replica set");
}
// Find the last oplog entry.
var lastOplogEntry = self._oplogLastEntryConnection.findOne(

View File

@@ -13,7 +13,8 @@ Package.describe({
});
Npm.depends({
mongodb: "https://github.com/meteor/node-mongodb-native/tarball/cbd6220ee17c3178d20672b4a1df80f82f97d4c1"
mongodb: "https://github.com/meteor/node-mongodb-native/tarball/cbd6220ee17c3178d20672b4a1df80f82f97d4c1",
"mongodb-uri": "0.9.7"
});
Npm.strip({