diff options
author | Eliot Horowitz <eliot@10gen.com> | 2012-04-19 12:31:47 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2012-04-19 12:31:47 -0400 |
commit | 4224195cd1fe4ce9a8e6f166f492948ba6e3b906 (patch) | |
tree | 6084cc2b6fa8a0f7e4a9a810e44e6a682290400b /src/mongo/db/dbcommands_admin.cpp | |
parent | d74e506c5d7e00cfefe097c4c9a82d70709d5bbd (diff) | |
download | mongo-4224195cd1fe4ce9a8e6f166f492948ba6e3b906.tar.gz |
move fsync comman to its own file
Diffstat (limited to 'src/mongo/db/dbcommands_admin.cpp')
-rw-r--r-- | src/mongo/db/dbcommands_admin.cpp | 94 |
1 files changed, 0 insertions, 94 deletions
diff --git a/src/mongo/db/dbcommands_admin.cpp b/src/mongo/db/dbcommands_admin.cpp index 68939e801a5..0c0dac15927 100644 --- a/src/mongo/db/dbcommands_admin.cpp +++ b/src/mongo/db/dbcommands_admin.cpp @@ -398,98 +398,4 @@ namespace mongo { } } validateCmd; - /* - class UnlockCommand : public Command { - public: - UnlockCommand() : Command( "unlock" ) { } - virtual bool readOnly() { return true; } - virtual bool slaveOk() const { return true; } - virtual bool adminOnly() const { return true; } - virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) { - if( lockedForWriting ) { - log() << "command: unlock requested" << endl; - errmsg = "unlock requested"; - unlockRequested = true; - } - else { - errmsg = "not locked, so cannot unlock"; - return 0; - } - return 1; - } - - } unlockCommand; - */ - - /* see unlockFsync() for unlocking: - db.$cmd.sys.unlock.findOne() - */ - class FSyncCommand : public Command { - static const char* url() { return "http://www.mongodb.org/display/DOCS/fsync+Command"; } - public: - bool locked; - SimpleMutex m; // protects locked var above - FSyncCommand() : Command( "fsync" ), m("lockfsync") { locked=false; } - virtual LockType locktype() const { return NONE; } - virtual bool slaveOk() const { return true; } - virtual bool adminOnly() const { return true; } - virtual void help(stringstream& h) const { h << url(); } - virtual bool run(const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { - bool sync = !cmdObj["async"].trueValue(); // async means do an fsync, but return immediately - bool lock = cmdObj["lock"].trueValue(); - log() << "CMD fsync: sync:" << sync << " lock:" << lock << endl; - if( lock ) { - Lock::ThreadSpanningOp::setWLockedNongreedy(); - verify( !locked ); // impossible to get here if locked is true - try { - //uassert(12034, "fsync: can't lock while an unlock is pending", !unlockRequested); - uassert(12032, "fsync: sync option must be true when using lock", sync); - getDur().syncDataAndTruncateJournal(); - } catch(...) { - Lock::ThreadSpanningOp::unsetW(); - throw; - } - SimpleMutex::scoped_lock lk(m); - Lock::ThreadSpanningOp::W_to_R(); - try { - MemoryMappedFile::flushAll(true); - } - catch(...) { - Lock::ThreadSpanningOp::unsetR(); - throw; - } - verify( !locked ); - locked = true; - log() << "db is now locked for snapshotting, no writes allowed. db.fsyncUnlock() to unlock" << endl; - log() << " For more info see " << FSyncCommand::url() << endl; - result.append("info", "now locked against writes, use db.fsyncUnlock() to unlock"); - result.append("seeAlso", url()); - Lock::ThreadSpanningOp::handoffR(); - } - else { - // the simple fsync command case - if (sync) { - Lock::GlobalWrite w; // can this be GlobalRead? and if it can, it should be nongreedy. - getDur().commitNow(); - } - // question : is it ok this is not in the dblock? i think so but this is a change from past behavior, - // please advise. - result.append( "numFiles" , MemoryMappedFile::flushAll( sync ) ); - } - return 1; - } - } fsyncCmd; - - bool lockedForWriting() { return fsyncCmd.locked; } - - // @return true if unlocked - bool _unlockFsync() { - SimpleMutex::scoped_lock lk(fsyncCmd.m); - if( !fsyncCmd.locked ) { - return false; - } - fsyncCmd.locked = false; - Lock::ThreadSpanningOp::unsetR(); - return true; - } } |