diff options
-rw-r--r-- | src/mongo/db/commands/fsync.cpp | 5 | ||||
-rw-r--r-- | src/mongo/db/commands/fsync.h | 22 | ||||
-rw-r--r-- | src/mongo/db/dur.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/instance.cpp | 3 | ||||
-rw-r--r-- | src/mongo/db/repl.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/repl/bgsync.cpp | 13 | ||||
-rw-r--r-- | src/mongo/db/repl/rs_sync.cpp | 10 | ||||
-rw-r--r-- | src/mongo/db/ttl.cpp | 6 |
8 files changed, 44 insertions, 21 deletions
diff --git a/src/mongo/db/commands/fsync.cpp b/src/mongo/db/commands/fsync.cpp index 567d8485a3f..d3debc7565c 100644 --- a/src/mongo/db/commands/fsync.cpp +++ b/src/mongo/db/commands/fsync.cpp @@ -1,6 +1,9 @@ // fsync.cpp -#include "pch.h" +#include "mongo/pch.h" + +#include "mongo/db/commands/fsync.h" + #include "mongo/db/d_concurrency.h" #include "mongo/db/commands.h" #include "mongo/db/dur.h" diff --git a/src/mongo/db/commands/fsync.h b/src/mongo/db/commands/fsync.h new file mode 100644 index 00000000000..2e57cbda403 --- /dev/null +++ b/src/mongo/db/commands/fsync.h @@ -0,0 +1,22 @@ +/** + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#pragma once + +namespace mongo { + // Use this for blocking during an fsync-and-lock + extern SimpleMutex filesLockedFsync; + bool lockedForWriting(); +} diff --git a/src/mongo/db/dur.cpp b/src/mongo/db/dur.cpp index c3da06c482d..978c4bea9eb 100644 --- a/src/mongo/db/dur.cpp +++ b/src/mongo/db/dur.cpp @@ -72,14 +72,12 @@ #include "../util/timer.h" #include "mongo/util/stacktrace.h" #include "../server.h" +#include "mongo/db/commands/fsync.h" using namespace mongoutils; namespace mongo { - bool lockedForWriting(); - extern SimpleMutex filesLockedFsync; - namespace dur { void assertNothingSpooled(); diff --git a/src/mongo/db/instance.cpp b/src/mongo/db/instance.cpp index 19751236026..b514cb62cf0 100644 --- a/src/mongo/db/instance.cpp +++ b/src/mongo/db/instance.cpp @@ -51,6 +51,7 @@ #include <fstream> #include <boost/filesystem/operations.hpp> #include "dur_commitjob.h" +#include "mongo/db/commands/fsync.h" namespace mongo { @@ -78,8 +79,6 @@ namespace mongo { HANDLE lockFileHandle; #endif - // see FSyncCommand: - extern bool lockedForWriting(); /*static*/ OpTime OpTime::_now() { OpTime result; diff --git a/src/mongo/db/repl.cpp b/src/mongo/db/repl.cpp index 6893d024b64..06fc4db02a4 100644 --- a/src/mongo/db/repl.cpp +++ b/src/mongo/db/repl.cpp @@ -1093,7 +1093,7 @@ namespace mongo { BSONObj me; { - Lock::GlobalWrite l; + Lock::DBWrite l("local"); // local.me is an identifier for a server for getLastError w:2+ if ( ! Helpers::getSingleton( "local.me" , me ) || ! me.hasField("host") || diff --git a/src/mongo/db/repl/bgsync.cpp b/src/mongo/db/repl/bgsync.cpp index cacd64b46ae..e2c61fe1570 100644 --- a/src/mongo/db/repl/bgsync.cpp +++ b/src/mongo/db/repl/bgsync.cpp @@ -15,9 +15,11 @@ */ #include "mongo/pch.h" -#include "mongo/db/repl/rs_sync.h" -#include "mongo/db/repl/bgsync.h" + #include "mongo/db/client.h" +#include "mongo/db/commands/fsync.h" +#include "mongo/db/repl/bgsync.h" +#include "mongo/db/repl/rs_sync.h" namespace mongo { namespace replset { @@ -140,9 +142,12 @@ namespace replset { bool BackgroundSync::hasCursor() { { - // we don't need the global write lock yet, but it's needed by OplogReader::connect + // prevent writers from blocking readers during fsync + SimpleMutex::scoped_lock fsynclk(filesLockedFsync); + // we don't need the local write lock yet, but it's needed by OplogReader::connect // so we take it preemptively to avoid deadlocking. - Lock::GlobalWrite gwl; + Lock::DBWrite lk("local"); + boost::unique_lock<boost::mutex> lock(_mutex); if (!_oplogMarkerTarget || _currentSyncTarget != _oplogMarkerTarget) { diff --git a/src/mongo/db/repl/rs_sync.cpp b/src/mongo/db/repl/rs_sync.cpp index 1224d46e13f..152adcc5015 100644 --- a/src/mongo/db/repl/rs_sync.cpp +++ b/src/mongo/db/repl/rs_sync.cpp @@ -14,12 +14,14 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "pch.h" +#include "mongo/pch.h" + #include "mongo/db/client.h" -#include "rs.h" +#include "mongo/db/commands/fsync.h" #include "mongo/db/repl.h" -#include "mongo/db/repl/rs_sync.h" #include "mongo/db/repl/bgsync.h" +#include "mongo/db/repl/rs.h" +#include "mongo/db/repl/rs_sync.h" namespace mongo { @@ -208,8 +210,6 @@ namespace mongo { return golive; } - extern SimpleMutex filesLockedFsync; - class DontLockOnEverySingleOperation : boost::noncopyable { scoped_ptr<Lock::ScopedLock> lk; scoped_ptr<SimpleMutex::scoped_lock> fsync; diff --git a/src/mongo/db/ttl.cpp b/src/mongo/db/ttl.cpp index 3501a65448a..39d904e08ea 100644 --- a/src/mongo/db/ttl.cpp +++ b/src/mongo/db/ttl.cpp @@ -18,6 +18,7 @@ #include "pch.h" +#include "mongo/db/commands/fsync.h" #include "mongo/db/ttl.h" #include "mongo/db/databaseholder.h" #include "mongo/db/instance.h" @@ -27,11 +28,6 @@ namespace mongo { - // this is defined in fsync.cpp - // need to figure out where to put for real - bool lockedForWriting(); - - class TTLMonitor : public BackgroundJob { public: TTLMonitor(){} |