mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-30 17:10:48 +01:00
add client ip / port to current op, add unlocked version of current op to http interface
This commit is contained in:
parent
5f4cb7b25c
commit
0532b35568
12
db/curop.h
12
db/curop.h
@ -8,25 +8,30 @@
|
||||
namespace mongo {
|
||||
|
||||
extern struct CurOp {
|
||||
void reset(time_t now) {
|
||||
void reset(time_t now, const sockaddr_in &_client) {
|
||||
active = true;
|
||||
opNum++;
|
||||
startTime = now;
|
||||
ns[0] = '?'; // just in case not set later
|
||||
*query = 0;
|
||||
killCurrentOp = 0;
|
||||
client = _client;
|
||||
}
|
||||
|
||||
bool active;
|
||||
unsigned opNum;
|
||||
time_t startTime;
|
||||
int op;
|
||||
char ns[Namespace::MaxNsLen+1];
|
||||
char ns[Namespace::MaxNsLen+2];
|
||||
char query[128];
|
||||
char zero;
|
||||
struct sockaddr_in client;
|
||||
|
||||
CurOp() {
|
||||
opNum = 0;
|
||||
// These addresses should never be written to again. The zeroes are
|
||||
// placed here as a precaution because currentOp may be accessed
|
||||
// without the db mutex.
|
||||
ns[sizeof(ns)-1] = 0;
|
||||
query[sizeof(query)-1] = 0;
|
||||
}
|
||||
@ -62,6 +67,9 @@ namespace mongo {
|
||||
b.append("ns", ns);
|
||||
b.append("query", query);
|
||||
b.append("inLock", dbMutexInfo.isLocked());
|
||||
stringstream clientStr;
|
||||
clientStr << inet_ntoa( client.sin_addr ) << ":" << ntohs( client.sin_port );
|
||||
b.append("client", clientStr.str());
|
||||
return b.obj();
|
||||
}
|
||||
} currentOp;
|
||||
|
@ -201,7 +201,7 @@ namespace mongo {
|
||||
le->nPrev++;
|
||||
|
||||
DbResponse dbresponse;
|
||||
if ( !assembleResponse( m, dbresponse ) ) {
|
||||
if ( !assembleResponse( m, dbresponse, dbMsgPort.farEnd.sa ) ) {
|
||||
out() << curTimeMillis() % 10000 << " end msg " << dbMsgPort.farEnd.toString() << endl;
|
||||
/* todo: we may not wish to allow this, even on localhost: very low priv accounts could stop us. */
|
||||
if ( dbMsgPort.farEnd.isLocalHost() ) {
|
||||
|
@ -173,6 +173,7 @@ namespace mongo {
|
||||
}
|
||||
|
||||
ss << "\nreplInfo: " << replInfo << '\n';
|
||||
ss << "currentOp (unlocked): " << currentOp.infoNoauth() << "\n";
|
||||
}
|
||||
|
||||
bool allowed( const char * rq , vector<string>& headers, const SockAddr &from ){
|
||||
|
@ -113,7 +113,7 @@ namespace mongo {
|
||||
}
|
||||
|
||||
// Returns false when request includes 'end'
|
||||
bool assembleResponse( Message &m, DbResponse &dbresponse ) {
|
||||
bool assembleResponse( Message &m, DbResponse &dbresponse, const sockaddr_in &client ) {
|
||||
// before we lock...
|
||||
if ( m.data->operation() == dbQuery ) {
|
||||
const char *ns = m.data->_data + 4;
|
||||
@ -141,7 +141,7 @@ namespace mongo {
|
||||
stringstream ss;
|
||||
char buf[64];
|
||||
time_t now = time(0);
|
||||
currentOp.reset(now);
|
||||
currentOp.reset(now, client);
|
||||
|
||||
time_t_to_String(now, buf);
|
||||
buf[20] = 0; // don't want the year
|
||||
@ -331,7 +331,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)-2);
|
||||
}
|
||||
bool updatedExisting = updateObjects(ns, toupdate, query, flags & 1, ss);
|
||||
recordUpdate( updatedExisting, ( upsert || updatedExisting ) ? 1 : 0 );
|
||||
@ -351,7 +351,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)-2);
|
||||
}
|
||||
int n = deleteObjects(ns, pattern, justOne, true);
|
||||
recordDelete( n );
|
||||
|
@ -87,7 +87,9 @@ namespace mongo {
|
||||
}
|
||||
};
|
||||
|
||||
bool assembleResponse( Message &m, DbResponse &dbresponse );
|
||||
static SockAddr unknownAddress( "0.0.0.0", 0 );
|
||||
|
||||
bool assembleResponse( Message &m, DbResponse &dbresponse, const sockaddr_in &client = unknownAddress.sa );
|
||||
|
||||
void receivedKillCursors(Message& m);
|
||||
void receivedUpdate(Message& m, stringstream& ss);
|
||||
|
@ -1192,7 +1192,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)-2);
|
||||
}
|
||||
|
||||
BufBuilder bb;
|
||||
|
Loading…
Reference in New Issue
Block a user