Skip to content

Commit 46a25fd

Browse files
committed
SERVER-14395 Clean up StorageEngine initialization and shutdown
* Added StorageEngine::cleanShutdown() and commented that the destructor will never be called. * MMapV1StorageEngine specific operations were pulled into its constructor and cleanShutdown implementation. * StorageEngines are now constructed at a point where it is safe to spawn threads.
1 parent 4939ccc commit 46a25fd

File tree

13 files changed

+359
-331
lines changed

13 files changed

+359
-331
lines changed

src/mongo/base/error_codes.err

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ error_code("NotYetInitialized", 94)
9797
error_code("NotSecondary", 95)
9898
error_code("OperationFailed", 96)
9999
error_code("NoProjectionFound", 97)
100+
error_code("DBPathInUse", 98)
100101

101102
# Non-sequential error codes (for compatibility only)
102103
error_code("NotMaster", 10107) #this comes from assert_util.h

src/mongo/db/db.cpp

Lines changed: 4 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080
#include "mongo/db/startup_warnings.h"
8181
#include "mongo/db/stats/counters.h"
8282
#include "mongo/db/stats/snapshots.h"
83-
#include "mongo/db/storage/mmap_v1/dur.h"
8483
#include "mongo/db/storage/storage_engine.h"
8584
#include "mongo/db/storage_options.h"
8685
#include "mongo/db/ttl.h"
@@ -93,7 +92,6 @@
9392
#include "mongo/util/concurrency/thread_name.h"
9493
#include "mongo/util/exception_filter_win32.h"
9594
#include "mongo/util/exit.h"
96-
#include "mongo/util/file_allocator.h"
9795
#include "mongo/util/log.h"
9896
#include "mongo/util/net/message_server.h"
9997
#include "mongo/util/net/ssl_manager.h"
@@ -118,7 +116,6 @@ namespace mongo {
118116
void (*snmpInit)() = NULL;
119117

120118
extern int diagLogging;
121-
extern int lockFile;
122119

123120
#ifdef _WIN32
124121
ntservice::NtServiceDefaultStrings defaultServiceStrings = {
@@ -350,7 +347,7 @@ namespace mongo {
350347
if (shouldClearNonLocalTmpCollections || dbName == "local")
351348
ctx.db()->clearTmpCollections(&txn);
352349

353-
if ( mongodGlobalParams.repair ) {
350+
if ( storageGlobalParams.repair ) {
354351
fassert(18506, globalStorageEngine->repairDatabase(&txn, dbName));
355352
}
356353
else if (!ctx.db()->getDatabaseCatalogEntry()->currentFilesCompatible(&txn)) {
@@ -406,17 +403,6 @@ namespace mongo {
406403
LOG(1) << "done repairDatabases" << endl;
407404
}
408405

409-
void clearTmpFiles() {
410-
boost::filesystem::path path(storageGlobalParams.dbpath);
411-
for ( boost::filesystem::directory_iterator i( path );
412-
i != boost::filesystem::directory_iterator(); ++i ) {
413-
string fileName = boost::filesystem::path(*i).leaf().string();
414-
if ( boost::filesystem::is_directory( *i ) &&
415-
fileName.length() && fileName[ 0 ] == '$' )
416-
boost::filesystem::remove_all( *i );
417-
}
418-
}
419-
420406
/**
421407
* Checks if this server was started without --replset but has a config in local.system.replset
422408
* (meaning that this is probably a replica set member started in stand-alone mode).
@@ -548,53 +534,6 @@ namespace mongo {
548534
}
549535
#endif
550536

551-
/// warn if readahead > 256KB (gridfs chunk size)
552-
static void checkReadAhead(const string& dir) {
553-
#ifdef __linux__
554-
try {
555-
const dev_t dev = getPartition(dir);
556-
557-
// This path handles the case where the filesystem uses the whole device (including LVM)
558-
string path = str::stream() <<
559-
"/sys/dev/block/" << major(dev) << ':' << minor(dev) << "/queue/read_ahead_kb";
560-
561-
if (!boost::filesystem::exists(path)){
562-
// This path handles the case where the filesystem is on a partition.
563-
path = str::stream()
564-
<< "/sys/dev/block/" << major(dev) << ':' << minor(dev) // this is a symlink
565-
<< "/.." // parent directory of a partition is for the whole device
566-
<< "/queue/read_ahead_kb";
567-
}
568-
569-
if (boost::filesystem::exists(path)) {
570-
ifstream file (path.c_str());
571-
if (file.is_open()) {
572-
int kb;
573-
file >> kb;
574-
if (kb > 256) {
575-
log() << startupWarningsLog;
576-
577-
log() << "** WARNING: Readahead for " << dir << " is set to " << kb << "KB"
578-
<< startupWarningsLog;
579-
580-
log() << "** We suggest setting it to 256KB (512 sectors) or less"
581-
<< startupWarningsLog;
582-
583-
log() << "** http://dochub.mongodb.org/core/readahead"
584-
<< startupWarningsLog;
585-
}
586-
}
587-
}
588-
}
589-
catch (const std::exception& e) {
590-
log() << "unable to validate readahead settings due to error: " << e.what()
591-
<< startupWarningsLog;
592-
log() << "for more information, see http://dochub.mongodb.org/core/readahead"
593-
<< startupWarningsLog;
594-
}
595-
#endif // __linux__
596-
}
597-
598537
static void _initAndListen(int listenPort ) {
599538
Client::initThread("initandlisten");
600539

@@ -635,23 +574,15 @@ namespace mongo {
635574
boost::filesystem::exists(storageGlobalParams.repairpath));
636575
}
637576

638-
// TODO check non-journal subdirs if using directory-per-db
639-
checkReadAhead(storageGlobalParams.dbpath);
640-
641-
acquirePathLock(mongodGlobalParams.repair);
642-
boost::filesystem::remove_all(storageGlobalParams.dbpath + "/_tmp/");
643-
644-
FileAllocator::get()->start();
645-
646577
// TODO: This should go into a MONGO_INITIALIZER once we have figured out the correct
647578
// dependencies.
648579
if (snmpInit) {
649580
snmpInit();
650581
}
651582

652-
MONGO_ASSERT_ON_EXCEPTION_WITH_MSG( clearTmpFiles(), "clear tmp files" );
583+
initGlobalStorageEngine();
653584

654-
dur::startup();
585+
boost::filesystem::remove_all(storageGlobalParams.dbpath + "/_tmp/");
655586

656587
if (storageGlobalParams.durOptions & StorageGlobalParams::DurRecoverOnly)
657588
return;
@@ -684,7 +615,7 @@ namespace mongo {
684615
|| replSettings.slave == repl::SimpleSlave);
685616
repairDatabasesAndCheckVersion(shouldClearNonLocalTmpCollections);
686617

687-
if (mongodGlobalParams.upgrade) {
618+
if (storageGlobalParams.upgrade) {
688619
log() << "finished checking dbs" << endl;
689620
cc().shutdown();
690621
exitCleanly(EXIT_CLEAN);

0 commit comments

Comments
 (0)