summaryrefslogtreecommitdiff
path: root/src/mongo/db/background.cpp
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2013-06-25 19:42:11 -0400
committerEliot Horowitz <eliot@10gen.com>2013-06-26 22:36:37 -0400
commit692f1859a032a92e54f08b1a2a130fa99590b1d0 (patch)
treecb5704667f7ec4254b3a837e2f2668cfbaacafe5 /src/mongo/db/background.cpp
parentbd0713e9a67f67b19944841275007f6fc6ee1c69 (diff)
downloadmongo-692f1859a032a92e54f08b1a2a130fa99590b1d0.tar.gz
clean NamespaceString so that it can be the thing passed around
Diffstat (limited to 'src/mongo/db/background.cpp')
-rw-r--r--src/mongo/db/background.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/mongo/db/background.cpp b/src/mongo/db/background.cpp
new file mode 100644
index 00000000000..c57c3a5e919
--- /dev/null
+++ b/src/mongo/db/background.cpp
@@ -0,0 +1,78 @@
+// background.cpp
+
+/**
+* Copyright (C) 2010 10gen Inc.
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License, version 3,
+* as published by the Free Software Foundation.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "mongo/db/background.h"
+
+namespace mongo {
+
+ SimpleMutex BackgroundOperation::m("bg");
+ std::map<std::string, unsigned> BackgroundOperation::dbsInProg;
+ std::set<std::string> BackgroundOperation::nsInProg;
+
+ bool BackgroundOperation::inProgForDb(const StringData& db) {
+ SimpleMutex::scoped_lock lk(m);
+ return dbsInProg[db.toString()] > 0;
+ }
+
+ bool BackgroundOperation::inProgForNs(const StringData& ns) {
+ SimpleMutex::scoped_lock lk(m);
+ return nsInProg.count(ns.toString()) > 0;
+ }
+
+ void BackgroundOperation::assertNoBgOpInProgForDb(const StringData& db) {
+ uassert(12586,
+ "cannot perform operation: a background operation is currently running for this database",
+ !inProgForDb(db));
+ }
+
+ void BackgroundOperation::assertNoBgOpInProgForNs(const StringData& ns) {
+ uassert(12587,
+ "cannot perform operation: a background operation is currently running for this collection",
+ !inProgForNs(ns));
+ }
+
+ BackgroundOperation::BackgroundOperation(const StringData& ns) : _ns(ns) {
+ SimpleMutex::scoped_lock lk(m);
+ dbsInProg[_ns.db().toString()]++;
+ nsInProg.insert(_ns.ns());
+ }
+
+ BackgroundOperation::~BackgroundOperation() {
+ SimpleMutex::scoped_lock lk(m);
+ dbsInProg[_ns.db().toString()]--;
+ nsInProg.erase(_ns.ns());
+ }
+
+ void BackgroundOperation::dump(std::stringstream& ss) {
+ SimpleMutex::scoped_lock lk(m);
+ if( nsInProg.size() ) {
+ ss << "\n<b>Background Jobs in Progress</b>\n";
+ for( std::set<std::string>::iterator i = nsInProg.begin(); i != nsInProg.end(); i++ )
+ ss << " " << *i << '\n';
+ }
+ for( std::map<std::string,unsigned>::iterator i = dbsInProg.begin(); i != dbsInProg.end(); i++ ) {
+ if( i->second )
+ ss << "database " << i->first << ": " << i->second << '\n';
+ }
+ }
+
+
+
+
+} // namespace mongo
+