summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Pasette <dan@10gen.com>2014-09-29 11:07:12 -0400
committerDan Pasette <dan@mongodb.com>2014-09-29 11:07:12 -0400
commite4a5649bb5bed607e0e907ce6f2d08e607dcde12 (patch)
tree78e4f27c9791a8b642bc003256a74e8f7a7338e3
parent66bfc5b6fbb64e03cfb80c1c830ac88b1d3ec5ba (diff)
downloadmongo-e4a5649bb5bed607e0e907ce6f2d08e607dcde12.tar.gz
SERVER-15369: Clean up partially created .ns files
(cherry picked from commit 243f11cd82d7925c77df0b04fad58b18f70cf031)
-rw-r--r--jstests/dur/diskfull.js16
-rw-r--r--src/mongo/db/namespace_details.cpp16
2 files changed, 28 insertions, 4 deletions
diff --git a/jstests/dur/diskfull.js b/jstests/dur/diskfull.js
index db03ad2fce5..79d64950e80 100644
--- a/jstests/dur/diskfull.js
+++ b/jstests/dur/diskfull.js
@@ -1,4 +1,13 @@
-/** Test running out of disk space with durability enabled */
+/** Test running out of disk space with durability enabled.
+To set up the test, it's required to set up a small partition something like the following:
+sudo umount /data/db/diskfulltest/
+rm -rf /data/db/diskfulltest
+mkdir -p /data/images
+dd bs=512 count=83968 if=/dev/zero of=/data/images/diskfulltest.img
+/sbin/mkfs.ext2 -m 0 -F /data/images/diskfulltest.img
+mkdir -p /data/db/diskfulltest
+mount -o loop /data/images/diskfulltest.img /data/db/diskfulltest
+*/
startPath = "/data/db/diskfulltest";
recoverPath = "/data/db/dur_diskfull";
@@ -52,7 +61,10 @@ function work() {
var d = conn.getDB("test");
big = new Array( 5000 ).toString();
- for( i = 0; i < 10000; ++i ) {
+ // This part of the test depends on the partition size used in the build env
+ // Currently, unused, but with larger partitions insert enough documents here
+ // to create a second db file
+ for( i = 0; i < 1; ++i ) {
d.foo.insert( { _id:i, b:big } );
}
diff --git a/src/mongo/db/namespace_details.cpp b/src/mongo/db/namespace_details.cpp
index c0a47d2e35c..360e3ddb89d 100644
--- a/src/mongo/db/namespace_details.cpp
+++ b/src/mongo/db/namespace_details.cpp
@@ -183,6 +183,7 @@ namespace mongo {
maybeMkdir();
unsigned long long l = lenForNewNsFiles;
+ log() << "allocating new ns file " << pathString << ", filling with zeroes..." << endl;
{
// Due to SERVER-15369 we need to explicitly write zero-bytes to the NS file.
@@ -193,10 +194,21 @@ namespace mongo {
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 ) {
+ for (fileofs ofs = 0; ofs < l && !file.bad(); ofs += kBlockSize ) {
file.write(ofs, &zeros[0], kBlockSize);
}
- file.fsync();
+ if (file.bad()) {
+ try {
+ boost::filesystem::remove(pathString);
+ } catch (const std::exception& e) {
+ StringBuilder ss;
+ ss << "error removing file: " << e.what();
+ massert(18909, ss.str(), 0);
+ }
+ }
+ else {
+ file.fsync();
+ }
massert(18826, str::stream() << "failure writing file " << pathString, !file.bad() );
}