summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Milkie <milkie@10gen.com>2015-03-19 15:00:12 -0400
committerEric Milkie <milkie@10gen.com>2015-03-26 08:25:06 -0400
commitfac3991b11a8c026aaf02175b2b5a43e31c8d103 (patch)
tree7d3b8b6ebc764edd67b69a0210359ccc8b183555
parentff7ae37d3f16a73e9ee956c31d6938f4768000dd (diff)
downloadmongo-fac3991b11a8c026aaf02175b2b5a43e31c8d103.tar.gz
SERVER-17652 open sockets before initializing storage engine
(cherry picked from commit b9b1c95520824c377b4c800e6193d9855be1e14d)
-rw-r--r--jstests/disk/too_many_fds.js22
-rw-r--r--src/mongo/db/db.cpp26
2 files changed, 35 insertions, 13 deletions
diff --git a/jstests/disk/too_many_fds.js b/jstests/disk/too_many_fds.js
new file mode 100644
index 00000000000..f714d495d7c
--- /dev/null
+++ b/jstests/disk/too_many_fds.js
@@ -0,0 +1,22 @@
+// Create more than 1024 files on certain storage engines, then restart the server and see that it
+// can still listen on fd's smaller than FD_SETSIZE.
+
+(function() {
+var baseName = "jstests_disk_too_many_fds";
+
+var m = MongoRunner.runMongod( { smallfiles: "" , nssize: 1 } );
+// Make 1026 collections, each in a separate database. On some storage engines, this may cause
+// 1026 files to be created.
+for (var i = 1; i < 1026; ++i) {
+ var db = m.getDB("db" + i);
+ var coll = db.getCollection("coll" + i);
+ assert.writeOK(coll.insert( {} ));
+}
+
+MongoRunner.stopMongod( m );
+
+// Ensure we can still start up with that many files.
+var m2 = MongoRunner.runMongod( { dbpath: m.dbpath, smallfiles: "" , nssize: 1,
+ restart: true, cleanData: false } );
+assert.eq(1, m2.getDB("db1025").getCollection("coll1025").count());
+}());
diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp
index 981c927b486..fc932974273 100644
--- a/src/mongo/db/db.cpp
+++ b/src/mongo/db/db.cpp
@@ -437,6 +437,19 @@ namespace mongo {
static void _initAndListen(int listenPort ) {
Client::initThread("initandlisten");
+ // Due to SERVER-15389, we must setupSockets first thing at startup in order to avoid
+ // obtaining too high a file descriptor for our calls to select().
+ MessageServer::Options options;
+ options.port = listenPort;
+ options.ipList = serverGlobalParams.bind_ip;
+
+ MessageServer* server = createServer(options, new MyMessageHandler());
+ server->setAsTimeTracker();
+
+ // This is what actually creates the sockets, but does not yet listen on them because we
+ // do not want connections to just hang if recovery takes a very long time.
+ server->setupSockets();
+
// Warn if we detect configurations for multiple registered storage engines in
// the same configuration file/environment.
if (serverGlobalParams.parsedOpts.hasField("storage")) {
@@ -507,19 +520,6 @@ namespace mongo {
boost::filesystem::exists(storageGlobalParams.repairpath));
}
- // Due to SERVER-15389, we must setupSockets first thing at startup in order to avoid
- // obtaining too high a file descriptor for our calls to select().
- MessageServer::Options options;
- options.port = listenPort;
- options.ipList = serverGlobalParams.bind_ip;
-
- MessageServer* server = createServer(options, new MyMessageHandler());
- server->setAsTimeTracker();
-
- // This is what actually creates the sockets, but does not yet listen on them because we
- // do not want connections to just hang if recovery takes a very long time.
- server->setupSockets();
-
// TODO: This should go into a MONGO_INITIALIZER once we have figured out the correct
// dependencies.
if (snmpInit) {