From c9756fd528cc009cfd83c5bcfe9e309344f5e781 Mon Sep 17 00:00:00 2001 From: mike o'brien Date: Mon, 9 Feb 2015 16:43:27 -0500 Subject: SERVER-17216 2.6 mongostat should not crash if connected to a 3.0 mongod, and warn if detected Closes #922 Signed-off-by: Ramon Fernandez --- src/mongo/tools/stat.cpp | 11 +++++++++++ src/mongo/tools/stat_util.cpp | 8 +++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/mongo/tools/stat.cpp b/src/mongo/tools/stat.cpp index 30bb78252e1..002d8a4a5f0 100644 --- a/src/mongo/tools/stat.cpp +++ b/src/mongo/tools/stat.cpp @@ -151,6 +151,7 @@ namespace mongo { return -1; int maxLockedDbWidth = 0; + bool warned = false; while (mongoStatGlobalParams.rowCount == 0 || rowNum < mongoStatGlobalParams.rowCount) { @@ -169,6 +170,11 @@ namespace mongo { try { + if ( !warned && now["storageEngine"].type() ) { + toolError() << "warning: detected a 3.0 mongod, some columns not applicable" << endl; + warned = true; + } + BSONObj out = _statUtil.doRow( prev , now ); // adjust width up as longer 'locked db' values appear @@ -230,6 +236,7 @@ namespace mongo { static void serverThread( shared_ptr state , int sleepTime) { try { + bool warned = false; DBClientConnection conn( true ); conn._logLevel = logger::LogSeverity::Debug(1); string errmsg; @@ -260,6 +267,10 @@ namespace mongo { state->error = errorStream; state->lastUpdate = time(0); } + if ( !warned && out["storageEngine"].type() ) { + toolError() << "warning: detected a 3.0 mongod, some columns not applicable" << endl; + warned = true; + } if ( out["shardCursorType"].type() == Object || out["process"].str() == "mongos" ) { diff --git a/src/mongo/tools/stat_util.cpp b/src/mongo/tools/stat_util.cpp index 7117d7ce511..d8d7c51e74b 100644 --- a/src/mongo/tools/stat_util.cpp +++ b/src/mongo/tools/stat_util.cpp @@ -331,9 +331,11 @@ namespace mongo { NamespaceInfo& s = stats[e.fieldName()]; s.ns = e.fieldName(); - BSONObj temp = e.Obj()["timeLockedMicros"].Obj(); - s.read = ( temp["r"].numberLong() + temp["R"].numberLong() ) / 1000; - s.write = ( temp["w"].numberLong() + temp["W"].numberLong() ) / 1000; + if ( e.Obj()["timeLockedMicros"].isABSONObj() ){ + BSONObj temp = e.Obj()["timeLockedMicros"].Obj(); + s.read = ( temp["r"].numberLong() + temp["R"].numberLong() ) / 1000; + s.write = ( temp["w"].numberLong() + temp["W"].numberLong() ) / 1000; + } } return stats; -- cgit v1.2.1