summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Pasette <dan@10mongodb.com>2014-09-25 18:16:07 -0400
committerDan Pasette <dan@mongodb.com>2014-09-25 18:16:07 -0400
commit66bfc5b6fbb64e03cfb80c1c830ac88b1d3ec5ba (patch)
tree3592b7ff14c8b2f1b3702c50e75f7a678998ea8c
parent59dc05c0b60be7097723020dd59c370f06041c1d (diff)
downloadmongo-66bfc5b6fbb64e03cfb80c1c830ac88b1d3ec5ba.tar.gz
SERVER-15369 Explicitly write zeros when creating ns files
Backported from commit b39f5ccc3e5c74918c8f2cd46d33c5b6316f4b06
-rw-r--r--src/mongo/db/namespace_details.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/mongo/db/namespace_details.cpp b/src/mongo/db/namespace_details.cpp
index 8573aff9961..c0a47d2e35c 100644
--- a/src/mongo/db/namespace_details.cpp
+++ b/src/mongo/db/namespace_details.cpp
@@ -31,6 +31,7 @@
#include "mongo/db/ops/update.h"
#include "mongo/db/pdfile.h"
#include "mongo/scripting/engine.h"
+#include "mongo/util/file.h"
#include "mongo/util/hashtab.h"
namespace mongo {
@@ -179,8 +180,26 @@ namespace mongo {
else {
// use lenForNewNsFiles, we are making a new database
massert( 10343, "bad lenForNewNsFiles", lenForNewNsFiles >= 1024*1024 );
+
maybeMkdir();
unsigned long long l = lenForNewNsFiles;
+
+ {
+ // Due to SERVER-15369 we need to explicitly write zero-bytes to the NS file.
+ const unsigned long long kBlockSize = 1024*1024;
+ verify(l % kBlockSize == 0); // ns files can only be multiples of 1MB
+ const std::vector<char> zeros(kBlockSize, 0);
+
+ File file;
+ file.open(pathString.c_str());
+ massert(18825, str::stream() << "couldn't create file " << pathString, file.is_open());
+ for (fileofs ofs = 0; ofs < l; ofs += kBlockSize ) {
+ file.write(ofs, &zeros[0], kBlockSize);
+ }
+ file.fsync();
+ massert(18826, str::stream() << "failure writing file " << pathString, !file.bad() );
+ }
+
if( f.create(pathString, l, true) ) {
getDur().createdFile(pathString, l); // always a new file
len = l;