summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--db/curop.h141
-rw-r--r--db/db.cpp2
-rw-r--r--db/dbwebserver.cpp4
-rw-r--r--db/instance.cpp29
-rw-r--r--db/instance.h4
-rw-r--r--db/query.cpp2
6 files changed, 83 insertions, 99 deletions
diff --git a/db/curop.h b/db/curop.h
index 2d0c86300f5..52853d119b8 100644
--- a/db/curop.h
+++ b/db/curop.h
@@ -1,72 +1,69 @@
-// curop.h
-
-#pragma once
-
-#include "namespace.h"
-#include "security.h"
-
-namespace mongo {
-
- struct CurOp {
- void reset(time_t now) {
- active = true;
- opNum++;
- startTime = now;
- ns[0] = '?'; // just in case not set later
- *query = 0;
- killCurrentOp = 0;
- }
-
- bool active;
- unsigned opNum;
- time_t startTime;
- int op;
- char ns[Namespace::MaxNsLen+1];
- char query[128];
- char zero;
-
- CurOp() {
- opNum = 0;
- ns[sizeof(ns)-1] = 0;
- query[sizeof(query)-1] = 0;
- }
-
- BSONObj info() {
- AuthenticationInfo *ai = authInfo.get();
- if( ai == 0 || !ai->isAuthorized("admin") ) {
- BSONObjBuilder b;
- b.append("err", "unauthorized");
- return b.obj();
- }
- return infoNoauth();
- }
-
- BSONObj infoNoauth() const {
- BSONObjBuilder b;
- b.append("opid", opNum);
- b.append("active", active);
- if( active )
- b.append("secs_running", (int) (time(0)-startTime));
- if( op == 2004 )
- b.append("op", "query");
- else if( op == 2005 )
- b.append("op", "getMore");
- else if( op == 2001 )
- b.append("op", "update");
- else if( op == 2002 )
- b.append("op", "insert");
- else if( op == 2006 )
- b.append("op", "delete");
- else
- b.append("op", op);
- b.append("ns", ns);
- b.append("query", query);
- b.append("inLock", dbMutexInfo.isLocked());
- return b.obj();
- }
- };
-
- CurOp &currentOp();
- void pushCurrentOp();
- void popCurrentOp();
-}
+// curop.h
+
+#pragma once
+
+#include "namespace.h"
+#include "security.h"
+
+namespace mongo {
+
+ extern struct CurOp {
+ void reset(time_t now) {
+ active = true;
+ opNum++;
+ startTime = now;
+ ns[0] = '?'; // just in case not set later
+ *query = 0;
+ killCurrentOp = 0;
+ }
+
+ bool active;
+ unsigned opNum;
+ time_t startTime;
+ int op;
+ char ns[Namespace::MaxNsLen+1];
+ char query[128];
+ char zero;
+
+ CurOp() {
+ opNum = 0;
+ ns[sizeof(ns)-1] = 0;
+ query[sizeof(query)-1] = 0;
+ }
+
+ BSONObj info() {
+ AuthenticationInfo *ai = authInfo.get();
+ if( ai == 0 || !ai->isAuthorized("admin") ) {
+ BSONObjBuilder b;
+ b.append("err", "unauthorized");
+ return b.obj();
+ }
+ return infoNoauth();
+ }
+
+ BSONObj infoNoauth() {
+ BSONObjBuilder b;
+ b.append("opid", opNum);
+ b.append("active", active);
+ if( active )
+ b.append("secs_running", (int) (time(0)-startTime));
+ if( op == 2004 )
+ b.append("op", "query");
+ else if( op == 2005 )
+ b.append("op", "getMore");
+ else if( op == 2001 )
+ b.append("op", "update");
+ else if( op == 2002 )
+ b.append("op", "insert");
+ else if( op == 2006 )
+ b.append("op", "delete");
+ else
+ b.append("op", op);
+ b.append("ns", ns);
+ b.append("query", query);
+ b.append("inLock", dbMutexInfo.isLocked());
+ return b.obj();
+ }
+ } currentOp;
+
+}
diff --git a/db/db.cpp b/db/db.cpp
index 6b79dd5c68a..05c8a06cac5 100644
--- a/db/db.cpp
+++ b/db/db.cpp
@@ -669,7 +669,7 @@ namespace mongo {
rawOut( ossSig.str() );
ostringstream ossOp;
- ossOp << "Last op: " << currentOp().infoNoauth() << endl;
+ ossOp << "Last op: " << currentOp.infoNoauth() << endl;
rawOut( ossOp.str() );
ostringstream oss;
diff --git a/db/dbwebserver.cpp b/db/dbwebserver.cpp
index 5f3b743e051..a78d252ab5f 100644
--- a/db/dbwebserver.cpp
+++ b/db/dbwebserver.cpp
@@ -113,9 +113,7 @@ namespace mongo {
public:
// caller locks
void doLockedStuff(stringstream& ss) {
- ss << "current ops: \n";
- for( vector< CurOp >::const_iterator i = currentOpsBegin(); i != currentOpsEnd(); ++i )
- ss << "\t" << i->infoNoauth() << "\n";
+ ss << "currentOp: " << currentOp.infoNoauth() << "\n";
ss << "# databases: " << databases.size() << '\n';
if ( database ) {
ss << "curclient: " << database->name;
diff --git a/db/instance.cpp b/db/instance.cpp
index dd6f1e67fad..83930749bec 100644
--- a/db/instance.cpp
+++ b/db/instance.cpp
@@ -90,16 +90,10 @@ namespace mongo {
int lockFile = 0;
- vector< CurOp > currentOps;
- CurOp &currentOp() { return currentOps.back(); }
- bool haveCurrentOp() { return !currentOps.empty(); }
- void pushCurrentOp() { currentOps.push_back( CurOp() ); }
- void popCurrentOp() { currentOps.pop_back(); }
- vector< CurOp >::const_iterator currentOpsBegin() { return currentOps.begin(); }
- vector< CurOp >::const_iterator currentOpsEnd() { return currentOps.end(); }
+ CurOp currentOp;
void inProgCmd( Message &m, DbResponse &dbresponse ) {
- BSONObj obj = currentOp().info();
+ BSONObj obj = currentOp.info();
replyToQuery(0, m, dbresponse, obj);
}
@@ -146,11 +140,8 @@ namespace mongo {
stringstream ss;
char buf[64];
- while ( haveCurrentOp() && !currentOp().active )
- popCurrentOp();
- pushCurrentOp();
time_t now = time(0);
- currentOp().reset(now);
+ currentOp.reset(now);
time_t_to_String(now, buf);
buf[20] = 0; // don't want the year
@@ -161,7 +152,7 @@ namespace mongo {
int ms;
bool log = false;
- currentOp().op = curOp = m.data->operation();
+ currentOp.op = curOp = m.data->operation();
#if 0
/* use this if you only want to process operations for a particular namespace.
@@ -208,7 +199,7 @@ namespace mongo {
const char *ns = m.data->_data + 4;
char cl[256];
nsToClient(ns, cl);
- strncpy(currentOp().ns, ns, Namespace::MaxNsLen);
+ strncpy(currentOp.ns, ns, Namespace::MaxNsLen);
AuthenticationInfo *ai = authInfo.get();
if( !ai->isAuthorized(cl) ) {
uassert_nothrow("unauthorized");
@@ -260,7 +251,7 @@ namespace mongo {
}
else {
out() << " operation isn't supported: " << m.data->operation() << endl;
- currentOp().active = false;
+ currentOp.active = false;
assert(false);
}
}
@@ -278,7 +269,7 @@ namespace mongo {
}
}
- currentOp().active = false;
+ currentOp.active = false;
return true;
}
@@ -339,7 +330,7 @@ namespace mongo {
{
string s = query.toString();
ss << " query: " << s;
- strncpy(currentOp().query, s.c_str(), sizeof(currentOp().query)-1);
+ strncpy(currentOp.query, s.c_str(), sizeof(currentOp.query)-1);
}
bool updatedExisting = updateObjects(ns, toupdate, query, flags & 1, ss);
recordUpdate( updatedExisting, ( upsert || updatedExisting ) ? 1 : 0 );
@@ -358,7 +349,7 @@ namespace mongo {
{
string s = pattern.toString();
ss << " query: " << s;
- strncpy(currentOp().query, s.c_str(), sizeof(currentOp().query)-1);
+ strncpy(currentOp.query, s.c_str(), sizeof(currentOp.query)-1);
}
int n = deleteObjects(ns, pattern, justOne, true);
recordDelete( n );
@@ -387,7 +378,7 @@ namespace mongo {
uassert( "not master", isMasterNs( q.ns ) || (q.queryOptions & Option_SlaveOk) || strstr( q.ns, ".$cmd" ) );
setClient( q.ns );
- strncpy(currentOp().ns, q.ns, Namespace::MaxNsLen);
+ strncpy(currentOp.ns, q.ns, Namespace::MaxNsLen);
msgdata = runQuery(m, ss ).release();
}
catch ( AssertionException& e ) {
diff --git a/db/instance.h b/db/instance.h
index 9dcb1cb3833..b8920011f6a 100644
--- a/db/instance.h
+++ b/db/instance.h
@@ -25,9 +25,7 @@
namespace mongo {
- CurOp& currentOp();
- vector< CurOp >::const_iterator currentOpsBegin();
- vector< CurOp >::const_iterator currentOpsEnd();
+ extern CurOp currentOp;
// turn on or off the oplog.* files which the db can generate.
// these files are for diagnostic purposes and are unrelated to
diff --git a/db/query.cpp b/db/query.cpp
index 8e63f86d29b..9de6447b611 100644
--- a/db/query.cpp
+++ b/db/query.cpp
@@ -1186,7 +1186,7 @@ namespace mongo {
ss << "query " << ns << " ntoreturn:" << ntoreturn;
{
string s = jsobj.toString();
- strncpy(currentOp().query, s.c_str(), sizeof(currentOp().query)-1);
+ strncpy(currentOp.query, s.c_str(), sizeof(currentOp.query)-1);
}
BufBuilder bb;