0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

locking cleaning

This commit is contained in:
Eliot Horowitz 2010-02-16 00:56:22 -05:00
parent 0dcc8b9262
commit 6dbd99b3db
2 changed files with 18 additions and 41 deletions

View File

@ -1427,23 +1427,6 @@ namespace mongo {
} }
} cmdFindAndModify; } cmdFindAndModify;
bool commandIsReadOnly(BSONObj& _cmdobj) {
BSONObj jsobj;
{
BSONElement e = _cmdobj.firstElement();
if ( e.type() == Object && string("query") == e.fieldName() ) {
jsobj = e.embeddedObject();
}
else {
jsobj = _cmdobj;
}
}
BSONElement e = jsobj.firstElement();
if ( ! e.type() )
return false;
return Command::readOnly( e.fieldName() );
}
/** /**
* this handles * this handles
- auth - auth

View File

@ -212,13 +212,9 @@ namespace mongo {
return ok; return ok;
} }
bool commandIsReadOnly(BSONObj& _cmdobj);
// Returns false when request includes 'end' // Returns false when request includes 'end'
bool assembleResponse( Message &m, DbResponse &dbresponse, const sockaddr_in &client ) { bool assembleResponse( Message &m, DbResponse &dbresponse, const sockaddr_in &client ) {
bool writeLock = true;
// before we lock... // before we lock...
int op = m.data->operation(); int op = m.data->operation();
bool isCommand = false; bool isCommand = false;
@ -226,6 +222,7 @@ namespace mongo {
if ( op == dbQuery ) { if ( op == dbQuery ) {
if( strstr(ns, ".$cmd") ) { if( strstr(ns, ".$cmd") ) {
isCommand = true; isCommand = true;
OPWRITE;
if( strstr(ns, ".$cmd.sys.") ) { if( strstr(ns, ".$cmd.sys.") ) {
if( strstr(ns, "$cmd.sys.inprog") ) { if( strstr(ns, "$cmd.sys.inprog") ) {
inProgCmd(m, dbresponse); inProgCmd(m, dbresponse);
@ -240,17 +237,19 @@ namespace mongo {
return true; return true;
} }
} }
DbMessage d( m );
QueryMessage q( d ); }
writeLock = !commandIsReadOnly(q.query); else {
OPREAD;
} }
else
writeLock = false;
} }
else if( op == dbGetMore ) { else if( op == dbGetMore ) {
writeLock = false; OPREAD;
} }
else {
OPWRITE;
}
globalOpCounters.gotOp( op , isCommand ); globalOpCounters.gotOp( op , isCommand );
if ( handlePossibleShardedMessage( m , dbresponse ) ){ if ( handlePossibleShardedMessage( m , dbresponse ) ){
@ -260,13 +259,6 @@ namespace mongo {
return true; return true;
} }
if ( writeLock ){
OPWRITE;
}
else {
OPREAD;
}
Client& c = cc(); Client& c = cc();
auto_ptr<CurOp> nestedOp; auto_ptr<CurOp> nestedOp;
@ -295,7 +287,7 @@ namespace mongo {
log = true; log = true;
} }
else if ( op == dbMsg ) { else if ( op == dbMsg ) {
mongolock lk(writeLock); writelock lk("");
/* deprecated / rarely used. intended for connection diagnostics. */ /* deprecated / rarely used. intended for connection diagnostics. */
char *p = m.data->_data; char *p = m.data->_data;
int len = strlen(p); int len = strlen(p);
@ -322,14 +314,12 @@ namespace mongo {
else { else {
try { try {
if ( op == dbInsert ) { if ( op == dbInsert ) {
mongolock lk(writeLock);
receivedInsert(m, currentOp); receivedInsert(m, currentOp);
} }
else if ( op == dbUpdate ) { else if ( op == dbUpdate ) {
receivedUpdate(m, currentOp); receivedUpdate(m, currentOp);
} }
else if ( op == dbDelete ) { else if ( op == dbDelete ) {
mongolock lk(writeLock);
receivedDelete(m, currentOp); receivedDelete(m, currentOp);
} }
else if ( op == dbKillCursors ) { else if ( op == dbKillCursors ) {
@ -462,7 +452,6 @@ namespace mongo {
const char *ns = d.getns(); const char *ns = d.getns();
assert(*ns); assert(*ns);
uassert( 10056 , "not master", isMasterNs( ns ) ); uassert( 10056 , "not master", isMasterNs( ns ) );
Client::Context ctx(ns);
int flags = d.pullInt(); int flags = d.pullInt();
bool justOne = flags & 1; bool justOne = flags & 1;
assert( d.moreJSObjs() ); assert( d.moreJSObjs() );
@ -472,6 +461,10 @@ namespace mongo {
op.debug().str << " query: " << s; op.debug().str << " query: " << s;
op.setQuery(pattern); op.setQuery(pattern);
} }
writelock lk(ns);
Client::Context ctx(ns);
long long n = deleteObjects(ns, pattern, justOne, true); long long n = deleteObjects(ns, pattern, justOne, true);
recordDelete( (int) n ); recordDelete( (int) n );
} }
@ -516,9 +509,10 @@ namespace mongo {
const char *ns = d.getns(); const char *ns = d.getns();
assert(*ns); assert(*ns);
uassert( 10058 , "not master", isMasterNs( ns ) ); uassert( 10058 , "not master", isMasterNs( ns ) );
Client::Context ctx(ns);
op.debug().str << ns; op.debug().str << ns;
writelock lk(ns);
Client::Context ctx(ns);
while ( d.moreJSObjs() ) { while ( d.moreJSObjs() ) {
BSONObj js = d.nextJsObj(); BSONObj js = d.nextJsObj();
uassert( 10059 , "object to insert too large", js.objsize() <= MaxBSONObjectSize); uassert( 10059 , "object to insert too large", js.objsize() <= MaxBSONObjectSize);