summaryrefslogtreecommitdiff
path: root/src/mongo/s/request.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/s/request.cpp')
-rw-r--r--src/mongo/s/request.cpp177
1 files changed, 80 insertions, 97 deletions
diff --git a/src/mongo/s/request.cpp b/src/mongo/s/request.cpp
index 6ece1659e93..89fd65e079c 100644
--- a/src/mongo/s/request.cpp
+++ b/src/mongo/s/request.cpp
@@ -48,115 +48,98 @@
namespace mongo {
- using std::endl;
- using std::string;
-
- Request::Request(Message& m, AbstractMessagingPort* p)
- : _clientInfo(&cc()),
- _m(m),
- _d(m),
- _p(p),
- _id(_m.header().getId()),
- _didInit(false) {
-
- ClusterLastErrorInfo::get(_clientInfo).newRequest();
- }
-
- void Request::init() {
- if (_didInit) {
- return;
- }
+using std::endl;
+using std::string;
- _m.header().setId(_id);
- LastError::get(_clientInfo).startRequest();
- ClusterLastErrorInfo::get(_clientInfo).clearRequestInfo();
+Request::Request(Message& m, AbstractMessagingPort* p)
+ : _clientInfo(&cc()), _m(m), _d(m), _p(p), _id(_m.header().getId()), _didInit(false) {
+ ClusterLastErrorInfo::get(_clientInfo).newRequest();
+}
- if (_d.messageShouldHaveNs()) {
- const NamespaceString nss(getns());
-
- uassert(ErrorCodes::IllegalOperation,
- "can't use 'local' database through mongos",
- nss.db() != "local");
-
- uassert(ErrorCodes::InvalidNamespace,
- str::stream() << "Invalid ns [" << nss.ns() << "]",
- nss.isValid());
- }
-
- AuthorizationSession::get(_clientInfo)->startRequest(NULL);
- _didInit = true;
+void Request::init() {
+ if (_didInit) {
+ return;
}
- void Request::process( int attempt ) {
- init();
- int op = _m.operation();
- verify( op > dbMsg );
+ _m.header().setId(_id);
+ LastError::get(_clientInfo).startRequest();
+ ClusterLastErrorInfo::get(_clientInfo).clearRequestInfo();
- const MSGID msgId = _m.header().getId();
+ if (_d.messageShouldHaveNs()) {
+ const NamespaceString nss(getns());
- Timer t;
- LOG(3) << "Request::process begin ns: " << getns()
- << " msg id: " << msgId
- << " op: " << op
- << " attempt: " << attempt
- << endl;
+ uassert(ErrorCodes::IllegalOperation,
+ "can't use 'local' database through mongos",
+ nss.db() != "local");
- _d.markSet();
+ uassert(ErrorCodes::InvalidNamespace,
+ str::stream() << "Invalid ns [" << nss.ns() << "]",
+ nss.isValid());
+ }
- bool iscmd = false;
- if ( op == dbKillCursors ) {
- cursorCache.gotKillCursors( _m );
- globalOpCounters.gotOp( op , iscmd );
- }
- else if ( op == dbQuery ) {
- NamespaceString nss(getns());
- iscmd = nss.isCommand() || nss.isSpecialCommand();
-
- if (iscmd) {
- int n = _d.getQueryNToReturn();
- uassert( 16978, str::stream() << "bad numberToReturn (" << n
- << ") for $cmd type ns - can only be 1 or -1",
- n == 1 || n == -1 );
-
- Strategy::clientCommandOp(*this);
- }
- else {
- Strategy::queryOp( *this );
- }
-
- globalOpCounters.gotOp( op , iscmd );
- }
- else if ( op == dbGetMore ) {
- Strategy::getMore( *this );
- globalOpCounters.gotOp( op , iscmd );
- }
- else {
- Strategy::writeOp( op, *this );
- // globalOpCounters are handled by write commands.
+ AuthorizationSession::get(_clientInfo)->startRequest(NULL);
+ _didInit = true;
+}
+
+void Request::process(int attempt) {
+ init();
+ int op = _m.operation();
+ verify(op > dbMsg);
+
+ const MSGID msgId = _m.header().getId();
+
+ Timer t;
+ LOG(3) << "Request::process begin ns: " << getns() << " msg id: " << msgId << " op: " << op
+ << " attempt: " << attempt << endl;
+
+ _d.markSet();
+
+ bool iscmd = false;
+ if (op == dbKillCursors) {
+ cursorCache.gotKillCursors(_m);
+ globalOpCounters.gotOp(op, iscmd);
+ } else if (op == dbQuery) {
+ NamespaceString nss(getns());
+ iscmd = nss.isCommand() || nss.isSpecialCommand();
+
+ if (iscmd) {
+ int n = _d.getQueryNToReturn();
+ uassert(16978,
+ str::stream() << "bad numberToReturn (" << n
+ << ") for $cmd type ns - can only be 1 or -1",
+ n == 1 || n == -1);
+
+ Strategy::clientCommandOp(*this);
+ } else {
+ Strategy::queryOp(*this);
}
- LOG(3) << "Request::process end ns: " << getns()
- << " msg id: " << msgId
- << " op: " << op
- << " attempt: " << attempt
- << " " << t.millis() << "ms"
- << endl;
+ globalOpCounters.gotOp(op, iscmd);
+ } else if (op == dbGetMore) {
+ Strategy::getMore(*this);
+ globalOpCounters.gotOp(op, iscmd);
+ } else {
+ Strategy::writeOp(op, *this);
+ // globalOpCounters are handled by write commands.
}
- void Request::reply( Message & response , const string& fromServer ) {
- verify( _didInit );
- long long cursor = response.header().getCursor();
- if ( cursor ) {
- if ( fromServer.size() ) {
- cursorCache.storeRef(fromServer, cursor, getns());
- }
- else {
- // probably a getMore
- // make sure we have a ref for this
- verify( cursorCache.getRef( cursor ).size() );
- }
+ LOG(3) << "Request::process end ns: " << getns() << " msg id: " << msgId << " op: " << op
+ << " attempt: " << attempt << " " << t.millis() << "ms" << endl;
+}
+
+void Request::reply(Message& response, const string& fromServer) {
+ verify(_didInit);
+ long long cursor = response.header().getCursor();
+ if (cursor) {
+ if (fromServer.size()) {
+ cursorCache.storeRef(fromServer, cursor, getns());
+ } else {
+ // probably a getMore
+ // make sure we have a ref for this
+ verify(cursorCache.getRef(cursor).size());
}
- _p->reply( _m , response , _id );
}
+ _p->reply(_m, response, _id);
+}
-} // namespace mongo
+} // namespace mongo