summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Pasette <dan@10gen.com>2014-09-27 20:14:09 -0400
committerDan Pasette <dan@mongodb.com>2014-09-29 10:25:56 -0400
commit689c0faf75e0cc3f1663b962c3db55360e0ef3b5 (patch)
tree0a5a374c7704d056c16d6ba0bbf620eb3af70f46
parent52948ec0597a4726021049c9dae6635c5a41d1a4 (diff)
downloadmongo-689c0faf75e0cc3f1663b962c3db55360e0ef3b5.tar.gz
SERVER-15369: Clean up partially created .ns files
-rw-r--r--jstests/dur/diskfull.js16
-rw-r--r--src/mongo/db/storage/mmap_v1/catalog/namespace_index.cpp16
2 files changed, 28 insertions, 4 deletions
diff --git a/jstests/dur/diskfull.js b/jstests/dur/diskfull.js
index a604439424d..6fb38a15d1b 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 = MongoRunner.dataDir + "/diskfulltest";
recoverPath = MongoRunner.dataDir + "/dur_diskfull";
@@ -52,7 +61,10 @@ function work() {
var d = conn.getDB("test");
var big = new Array( 5000 ).toString();
var bulk = d.foo.initializeUnorderedBulkOp();
- 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 ) {
bulk.insert({ _id: i, b: big });
}
assert.writeOK(bulk.execute());
diff --git a/src/mongo/db/storage/mmap_v1/catalog/namespace_index.cpp b/src/mongo/db/storage/mmap_v1/catalog/namespace_index.cpp
index 5dd65c214aa..ac091b167f7 100644
--- a/src/mongo/db/storage/mmap_v1/catalog/namespace_index.cpp
+++ b/src/mongo/db/storage/mmap_v1/catalog/namespace_index.cpp
@@ -169,6 +169,7 @@ namespace mongo {
storageGlobalParams.lenForNewNsFiles >= 1024*1024);
maybeMkdir();
unsigned long long l = storageGlobalParams.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.
@@ -179,10 +180,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() );
}