summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTad Marshall <tad@10gen.com>2012-10-17 05:11:52 -0400
committerEric Milkie <milkie@10gen.com>2012-11-06 15:45:20 -0500
commitf43972dd586475132045bb11a96baac168f5b8cd (patch)
treeb7b7aead2681e3a5b92a9452137ba14ff99e86d4
parent4a8a7627d91d1cff7547d4ee11ce9f487898d3d0 (diff)
downloadmongo-f43972dd586475132045bb11a96baac168f5b8cd.tar.gz
SERVER-7378 Prevent WRITETODATAFILES and FlushViewOfFile from running at the same time
Prevent errors on Azure Storage drives that occur when a memory-mapped data file is modified in memory while it is being flushed to disk with FlushViewOfFile. Use a SimpleMutex (Critical Section on Windows) to prevent these two routines from running at the same time.
-rw-r--r--src/mongo/db/dur_writetodatafiles.cpp16
-rw-r--r--src/mongo/util/mmap_win.cpp4
2 files changed, 16 insertions, 4 deletions
diff --git a/src/mongo/db/dur_writetodatafiles.cpp b/src/mongo/db/dur_writetodatafiles.cpp
index d77b0482c20..b50d1ae66d6 100644
--- a/src/mongo/db/dur_writetodatafiles.cpp
+++ b/src/mongo/db/dur_writetodatafiles.cpp
@@ -17,12 +17,17 @@
*/
#include "pch.h"
-#include "dur_commitjob.h"
-#include "dur_stats.h"
-#include "dur_recover.h"
-#include "../util/timer.h"
+
+#include "mongo/db/dur_commitjob.h"
+#include "mongo/db/dur_recover.h"
+#include "mongo/db/dur_stats.h"
+#include "mongo/util/concurrency/mutex.h"
+#include "mongo/util/timer.h"
namespace mongo {
+#ifdef _WIN32
+ extern SimpleMutex globalFlushMutex; // defined in mongo/util/mmap_win.cpp
+#endif
namespace dur {
void debugValidateAllMapsMatch();
@@ -83,6 +88,9 @@ namespace mongo {
*/
void WRITETODATAFILES(const JSectHeader& h, AlignedBuilder& uncompressed) {
+#ifdef _WIN32
+ SimpleMutex::scoped_lock _globalFlushMutex(globalFlushMutex);
+#endif
Timer t;
WRITETODATAFILES_Impl1(h, uncompressed);
unsigned long long m = t.micros();
diff --git a/src/mongo/util/mmap_win.cpp b/src/mongo/util/mmap_win.cpp
index 55cdc1ddeb8..599882f3c16 100644
--- a/src/mongo/util/mmap_win.cpp
+++ b/src/mongo/util/mmap_win.cpp
@@ -326,6 +326,9 @@ namespace mongo {
return newPrivateView;
}
+ // prevent WRITETODATAFILES() from running at the same time as FlushViewOfFile()
+ SimpleMutex globalFlushMutex("globalFlushMutex");
+
class WindowsFlushable : public MemoryMappedFile::Flushable {
public:
WindowsFlushable( void * view , HANDLE fd , string filename , boost::shared_ptr<mutex> flushMutex )
@@ -336,6 +339,7 @@ namespace mongo {
if (!_view || !_fd)
return;
+ SimpleMutex::scoped_lock _globalFlushMutex(globalFlushMutex);
scoped_lock lk(*_flushMutex);
int loopCount = 0;