From e1adb14bb593e22203d82018f4ba78c77aa289b3 Mon Sep 17 00:00:00 2001 From: Kaloian Manassiev Date: Thu, 26 Feb 2015 15:42:15 -0500 Subject: SERVER-17388/SERVER-16776 If closing unopened file, do not check for journal writes (cherry picked from commit a9f240048fe27d925c0ad1798c1bf29ce59f0acc) --- src/mongo/db/storage/mmap_v1/data_file.cpp | 10 ++++++---- src/mongo/db/storage/mmap_v1/durable_mapped_file.cpp | 16 ++++++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/mongo/db/storage/mmap_v1/data_file.cpp b/src/mongo/db/storage/mmap_v1/data_file.cpp index 0144f71b74e..8b7fed7f106 100644 --- a/src/mongo/db/storage/mmap_v1/data_file.cpp +++ b/src/mongo/db/storage/mmap_v1/data_file.cpp @@ -173,12 +173,14 @@ namespace { } { - verify( _mb == 0 ); + invariant(_mb == 0); unsigned long long sz = size; - if( mmf.create(filename, sz, false) ) + if (mmf.create(filename, sz, false)) { _mb = mmf.getView(); - verify( sz <= 0x7fffffff ); - size = (int) sz; + } + + invariant(sz <= 0x7fffffff); + size = (int)sz; } data_file_check(_mb); diff --git a/src/mongo/db/storage/mmap_v1/durable_mapped_file.cpp b/src/mongo/db/storage/mmap_v1/durable_mapped_file.cpp index 0efb27c7800..3a2d2b2db9a 100644 --- a/src/mongo/db/storage/mmap_v1/durable_mapped_file.cpp +++ b/src/mongo/db/storage/mmap_v1/durable_mapped_file.cpp @@ -247,6 +247,8 @@ namespace mongo { bool DurableMappedFile::open(const std::string& fname, bool sequentialHint) { LOG(3) << "mmf open " << fname; + invariant(!_view_write); + setPath(fname); _view_write = mapWithOptions(fname.c_str(), sequentialHint ? SEQUENTIAL : 0); return finishOpening(); @@ -254,6 +256,8 @@ namespace mongo { bool DurableMappedFile::create(const std::string& fname, unsigned long long& len, bool sequentialHint) { LOG(3) << "mmf create " << fname; + invariant(!_view_write); + setPath(fname); _view_write = map(fname.c_str(), len, sequentialHint ? SEQUENTIAL : 0); return finishOpening(); @@ -284,15 +288,19 @@ namespace mongo { } DurableMappedFile::~DurableMappedFile() { - try { + try { LOG(3) << "mmf close " << filename(); - // Notify the durability system that we are closing a file. - getDur().closingFileNotification(); + // If _view_private was not set, this means file open failed + if (_view_private) { + // Notify the durability system that we are closing a file so it can ensure we + // will not have journaled operations with no corresponding file. + getDur().closingFileNotification(); + } LockMongoFilesExclusive lk; privateViews.remove(_view_private, length()); - _view_write = _view_private = 0; + MemoryMappedFile::close(); } catch (...) { -- cgit v1.2.1