From 3931f7efcbc207d91b28cbf74c8cbd4e9cf4df9f Mon Sep 17 00:00:00 2001 From: Aaron Date: Tue, 10 Mar 2009 10:14:37 -0400 Subject: [PATCH] Revert "Use os file locking to lock dbpath" This reverts commit 56e81849a0c92bd9249dbd504a0978a94dd68aba. --- db/db.cpp | 18 +----------------- db/db.h | 2 +- db/instance.cpp | 11 ----------- db/instance.h | 4 +--- db/pdfile.cpp | 2 ++ 5 files changed, 5 insertions(+), 32 deletions(-) diff --git a/db/db.cpp b/db/db.cpp index 31aea804f28..45b64a18a5c 100644 --- a/db/db.cpp +++ b/db/db.cpp @@ -319,29 +319,13 @@ namespace mongo { Timer startupSrandTimer; - void acquirePathLock() { -#if !defined(_WIN32) - string name = lockFileName(); - - if ( boost::filesystem::exists( name ) ) { - int l = open( name.c_str(), O_RDONLY | O_EXLOCK | O_NONBLOCK ); - massert( "Could not acquire lock for dbpath: " + name, l > 0 ); - boost::filesystem::remove( name ); - close( l ); - } + void segvhandler(int x); - lockFile = open( name.c_str(), O_WRONLY | O_CREAT | O_EXCL | O_EXLOCK | O_TRUNC | O_NONBLOCK, S_IRWXU | S_IRWXG | S_IRWXO ); - massert( "Could not acquire lock for dbpath: " + name, lockFile > 0 ); -#endif - } - void _initAndListen(int listenPort, const char *appserverLoc = null) { stringstream ss; ss << "dbpath (" << dbpath << ") does not exist"; massert( ss.str().c_str(), boost::filesystem::exists( dbpath ) ); - acquirePathLock(); - clearTmpFiles(); clearTmpCollections(); diff --git a/db/db.h b/db/db.h index b44b4b89c90..a26945e22bd 100644 --- a/db/db.h +++ b/db/db.h @@ -209,7 +209,7 @@ namespace mongo { setClient(clientname.c_str(), clientpath.c_str()); } }; - + } // namespace mongo #include "dbinfo.h" diff --git a/db/instance.cpp b/db/instance.cpp index be2de65632e..024eb3d6be5 100644 --- a/db/instance.cpp +++ b/db/instance.cpp @@ -30,8 +30,6 @@ #include "reccache.h" namespace mongo { - - const char *dbpath = "/data/db/"; int nloggedsome = 0; #define LOGSOME if( ++nloggedsome < 1000 || nloggedsome % 100 == 0 ) @@ -630,17 +628,8 @@ namespace mongo { // should we be locked here? we aren't. might be ok as-is. recCacheCloseAll(); - // remove lock file - if ( lockFile > 0 ) { - string lockFile = lockFileName(); - boost::filesystem::remove( lockFile.c_str() ); - } - rawOut( "dbexit: really exiting now\n" ); ::exit(rc); } - string lockFileName() { return ( boost::filesystem::path( dbpath ) / "mongod.lock" ).native_file_string(); } - int lockFile = -1; - } // namespace mongo diff --git a/db/instance.h b/db/instance.h index 91bd7c190f1..925cdb49ac3 100644 --- a/db/instance.h +++ b/db/instance.h @@ -97,9 +97,7 @@ namespace mongo { void receivedQuery(DbResponse& dbresponse, /*AbstractMessagingPort& dbMsgPort, */Message& m, stringstream& ss, bool logit); void getDatabaseNames( vector< string > &names ); - string lockFileName(); - extern int lockFile; - + // --- local client --- class DBDirectClient : public DBClientBase { diff --git a/db/pdfile.cpp b/db/pdfile.cpp index 8258b3b4028..da909b8f6bb 100644 --- a/db/pdfile.cpp +++ b/db/pdfile.cpp @@ -43,6 +43,8 @@ namespace mongo { extern bool quota; extern int port; + const char *dbpath = "/data/db/"; + DataFileMgr theDataFileMgr; map databases; Database *database;