From 83a58aa700ad04d428240328e893f7c5d26cb893 Mon Sep 17 00:00:00 2001 From: dwight Date: Sun, 28 Nov 2010 10:13:01 -0500 Subject: [PATCH] dur add a cmd lien setting --- db/cmdline.h | 8 ++++++-- db/db.cpp | 11 ++++++++++- db/db.vcxproj | 1 + db/db.vcxproj.filters | 3 +++ db/dur.cpp | 5 +++-- db/dur_recover.cpp | 2 +- db/durop.h | 3 ++- db/instance.cpp | 4 ++-- db/mongommf.cpp | 9 +++++---- jstests/dur/dur1.js | 23 +++++++++++++++++++++++ jstests/replsets/slaveDelay2.js | 4 ++-- pch.h | 2 -- shell/mongo_vstudio.cpp | 1 + 13 files changed, 59 insertions(+), 17 deletions(-) create mode 100644 jstests/dur/dur1.js diff --git a/db/cmdline.h b/db/cmdline.h index 39f14141f52..101e9024bb9 100644 --- a/db/cmdline.h +++ b/db/cmdline.h @@ -28,7 +28,10 @@ namespace mongo { port(DefaultDBPort), rest(false), jsonp(false), quiet(false), noTableScan(false), prealloc(true), smallfiles(false), quota(false), quotaFiles(8), cpu(false), durTrace(0), oplogSize(0), defaultProfile(0), slowMS(100), pretouch(0), moveParanoia( true ), syncdelay(60) - { } + { + // default may change for this later. + dur = false; + } string binaryName; // mongod or mongos @@ -67,6 +70,7 @@ namespace mongo { int quotaFiles; // --quotaFiles bool cpu; // --cpu show cpu time periodically + bool dur; // --dur durability enum { DurDumpJournal = 1, // dump diagnostics on the journal during recovery DurScanOnly = 2, // don't do any real work, just scan and dump if dump specified @@ -100,6 +104,6 @@ namespace mongo { }; extern CmdLine cmdLine; - + void setupCoreSignals(); } diff --git a/db/db.cpp b/db/db.cpp index ed91c95799e..41ef935fdb6 100644 --- a/db/db.cpp +++ b/db/db.cpp @@ -697,7 +697,6 @@ int main(int argc, char* argv[], char *envp[] ) ("sysinfo", "print some diagnostic system information") ("upgrade", "upgrade db if needed") ("repair", "run repair on all dbs") - ("durTrace", po::value(), "durability diagnostic options") ("notablescan", "do not allow table scans") ("syncdelay",po::value(&cmdLine.syncdelay)->default_value(60), "seconds between disk syncs (0=never, but not recommended)") ("profile",po::value(), "0=off 1=slow, 2=all") @@ -744,6 +743,9 @@ int main(int argc, char* argv[], char *envp[] ) ("pretouch", po::value(), "n pretouch threads for applying replicationed operations") ("command", po::value< vector >(), "command") ("cacheSize", po::value(), "cache size (in MB) for rec store") + // these move to unhidden later: + ("dur", "enable journaling") + ("durTrace", po::value(), "durability diagnostic options") ; @@ -826,6 +828,13 @@ int main(int argc, char* argv[], char *envp[] ) cmdLine.quota = true; cmdLine.quotaFiles = params["quotaFiles"].as() - 1; } + if( params.count("dur") ) { + cmdLine.dur = true; +#if !defined(_DURABLE) + log() << "--dur not yet available" << endl; + assert( false ); +#endif + } if (params.count("durTrace")) { cmdLine.durTrace = params["durTrace"].as(); #if !defined(_DURABLE) diff --git a/db/db.vcxproj b/db/db.vcxproj index 394a5f77515..9a8b9b84af4 100644 --- a/db/db.vcxproj +++ b/db/db.vcxproj @@ -585,6 +585,7 @@ + diff --git a/db/db.vcxproj.filters b/db/db.vcxproj.filters index c0c045603ab..017ba32a3f6 100755 --- a/db/db.vcxproj.filters +++ b/db/db.vcxproj.filters @@ -958,6 +958,9 @@ replSets\testing + + db\storage engine + diff --git a/db/dur.cpp b/db/dur.cpp index c2635b13ac0..79e8dd42e48 100644 --- a/db/dur.cpp +++ b/db/dur.cpp @@ -42,6 +42,7 @@ #if defined(_DURABLE) +#include "cmdline.h" #include "client.h" #include "dur.h" #include "dur_journal.h" @@ -106,7 +107,7 @@ namespace mongo { */ void debugCheckLastDeclaredWrite() { #if 0 - assert(debug && durable); + assert(debug && cmdLine.dur); vector& w = cj.writes(); if( w.size() == 0 ) return; @@ -363,7 +364,7 @@ namespace mongo { void recover(); void startup() { - if( !durable ) + if( !cmdLine.dur ) return; if( testIntent ) return; diff --git a/db/dur_recover.cpp b/db/dur_recover.cpp index 0893323f3db..d27a773ade1 100644 --- a/db/dur_recover.cpp +++ b/db/dur_recover.cpp @@ -344,7 +344,7 @@ namespace mongo { throws on error */ void /*dur::*/recover() { - assert( durable ); + assert( cmdLine.dur ); filesystem::path p = getJournalDir(); if( !exists(p) ) { diff --git a/db/durop.h b/db/durop.h index 17084621c69..7c31f6de8a2 100644 --- a/db/durop.h +++ b/db/durop.h @@ -73,7 +73,8 @@ namespace mongo { class FileCreatedOp : public DurOp { public: FileCreatedOp(BufReader& log); - FileCreatedOp(string f, unsigned long long l) : _filename(f), _len(l), DurOp(JEntry::OpCode_FileCreated) { } + FileCreatedOp(string f, unsigned long long l) : + DurOp(JEntry::OpCode_FileCreated), _filename(f), _len(l) { } virtual void replay(); diff --git a/db/instance.cpp b/db/instance.cpp index e8d5847dd61..761ea268c4a 100644 --- a/db/instance.cpp +++ b/db/instance.cpp @@ -710,7 +710,7 @@ namespace mongo { theFileAllocator().waitUntilFinished(); log() << "shutdown: closing all files..." << endl; - if( durable ) { + if( cmdLine.dur ) { /* is this useful? needed? helpful? perhaps even without _DURABLE. ifdef'd for now just to avoid behavior change short term */ MemoryMappedFile::flushAll(true); } @@ -719,7 +719,7 @@ namespace mongo { rawOut( ss3.str() ); #if defined(_DURABLE) - if( durable ) { + if( cmdLine.dur ) { log() << "shutdown: journalCleanup..." << endl; dur::journalCleanup(); } diff --git a/db/mongommf.cpp b/db/mongommf.cpp index 579aadc6f96..1ef9e5a2b8b 100644 --- a/db/mongommf.cpp +++ b/db/mongommf.cpp @@ -21,6 +21,7 @@ */ #include "pch.h" +#include "cmdline.h" #include "mongommf.h" #include "dur.h" #include "../util/mongoutils/str.h" @@ -31,7 +32,7 @@ namespace mongo { void MongoMMF::remapThePrivateView() { - assert( durable && !testIntent ); + assert( cmdLine.dur && !testIntent ); privateViews.remove(_view_private); _view_private = remapPrivateView(_view_private); privateViews.add(_view_private, this); @@ -108,7 +109,7 @@ namespace mongo { static PointerToMMF ourReadViews; /// _TESTINTENT (testIntent) build use only (other than existance) /*static*/ void* MongoMMF::switchToPrivateView(void *readonly_ptr) { - assert( durable ); + assert( cmdLine.dur ); assert( testIntent ); void *p = readonly_ptr; @@ -167,7 +168,7 @@ namespace mongo { bool MongoMMF::create(string fname, unsigned long long& len, bool sequentialHint) { setPath(fname); _view_write = map(fname.c_str(), len, sequentialHint ? SEQUENTIAL : 0); - if( durable && !testIntent && _view_write ) { + if( cmdLine.dur && !testIntent && _view_write ) { dur::createdFile(fname, len); } return finishOpening(); @@ -175,7 +176,7 @@ namespace mongo { bool MongoMMF::finishOpening() { if( _view_write ) { - if( durable ) { + if( cmdLine.dur ) { if( testIntent ) { _view_private = _view_write; _view_readonly = MemoryMappedFile::createReadOnlyMap(); diff --git a/jstests/dur/dur1.js b/jstests/dur/dur1.js new file mode 100644 index 00000000000..86d2d0089de --- /dev/null +++ b/jstests/dur/dur1.js @@ -0,0 +1,23 @@ +// dur1.js + +print("dur1.js"); + +var name = "dur1"; + +print(1); + +var n = startMongodTest(31001, name + "-nodur", 0, {}); + +print(2); + +var d = startMongodTest(31002, name + "-dur", 0, { dur: true }); + +print(3); + +//assert(n.foo.count() == 0); + +print(4); + +//assert(d.foo.count() == 0); + +print("SUCCESS dur1.js"); diff --git a/jstests/replsets/slaveDelay2.js b/jstests/replsets/slaveDelay2.js index b60aa7b3ef2..52151474c8e 100644 --- a/jstests/replsets/slaveDelay2.js +++ b/jstests/replsets/slaveDelay2.js @@ -56,8 +56,8 @@ doTest = function( signal ) { * start a slave with a long delay (1 hour) and do some writes while it is * initializing. Make sure it syncs all of these writes before going into * syncDelay. - */ - var conn = startMongodTest( 31008 , name+"-sd" , 0 , {useHostname : true, replSet : name} ); + */ + var conn = startMongodTest(31008, name + "-sd", 0, { useHostname: true, replSet: name }); conn.setSlaveOk(); config = master.getSisterDB("local").system.replset.findOne(); diff --git a/pch.h b/pch.h index a6e8a523a6e..22376fd4380 100644 --- a/pch.h +++ b/pch.h @@ -94,7 +94,6 @@ namespace mongo { /** _DURABLE define - this likely goes away later. to facilitate testing for a while without impacting other things. */ #if defined(_DURABLE) - const bool durable = true; # if defined(_TESTINTENT) /** Use _TESTINTENT to test write intent declarations by using a read only view for non-declared operations. We don't do journalling when _TESTINTENT is enabled. @@ -111,7 +110,6 @@ namespace mongo { # error _TESTINTENT requires _DURABLE # endif const bool testIntent = false; - const bool durable = false; #endif using namespace std; diff --git a/shell/mongo_vstudio.cpp b/shell/mongo_vstudio.cpp index 3491e799e31..707034bf14d 100644 --- a/shell/mongo_vstudio.cpp +++ b/shell/mongo_vstudio.cpp @@ -1430,6 +1430,7 @@ const StringData _jscode_raw_utils = "print(\"\\t or you can specify the port as the first arg\");\n" "print(\"\\t dir is /data/db// if not specified as the 2nd arg\");\n" "print(\"\\t returns a connection to the new server\");\n" +"print(\"\\tresetDbpath(dirpathstr) deletes everything under the dir specified including subdirs\");\n" "return;\n" "}\n" "else if (x == \"\") {\n"