vstudio changes for replinfo commands

This commit is contained in:
Kristina Chodorow
2010-11-18 09:57:01 -05:00
parent 8e4acff269
commit a836da437b

View File

@@ -2045,22 +2045,35 @@ const StringData _jscode_raw_db =
"var db = this.getSisterDB(\"local\");\n"
"\n"
"var result = { };\n"
"var ol = db.system.namespaces.findOne({name:\"local.oplog.$main\"});\n"
"if( ol && ol.options ) {\n"
"result.logSizeMB = ol.options.size / ( 1024 * 1024 );\n"
"} else {\n"
"result.errmsg = \"local.oplog.$main, or its options, not found in system.namespaces collection (not --master?)\";\n"
"var oplog;\n"
"if (db.system.namespaces.findOne({name:\"local.oplog.rs\"}) != null) {\n"
"oplog = 'oplog.rs';\n"
"}\n"
"else if (db.system.namespaces.findOne({name:\"local.oplog.$main\"}) != null) {\n"
"oplog = 'oplog.$main';\n"
"}\n"
"else {\n"
"result.errmsg = \"neither master/slave nor replica set replication detected\";\n"
"return result;\n"
"}\n"
"\n"
"result.usedMB = db.oplog.$main.stats().size / ( 1024 * 1024 );\n"
"var ol_entry = db.system.namespaces.findOne({name:\"local.\"+oplog});\n"
"if( ol_entry && ol_entry.options ) {\n"
"result.logSizeMB = ol_entry.options.size / ( 1024 * 1024 );\n"
"} else {\n"
"result.errmsg = \"local.\"+oplog+\", or its options, not found in system.namespaces collection\";\n"
"return result;\n"
"}\n"
"ol = db.getCollection(oplog);\n"
"\n"
"result.usedMB = ol.stats().size / ( 1024 * 1024 );\n"
"result.usedMB = Math.ceil( result.usedMB * 100 ) / 100;\n"
"\n"
"var firstc = db.oplog.$main.find().sort({$natural:1}).limit(1);\n"
"var lastc = db.oplog.$main.find().sort({$natural:-1}).limit(1);\n"
"var firstc = ol.find().sort({$natural:1}).limit(1);\n"
"var lastc = ol.find().sort({$natural:-1}).limit(1);\n"
"if( !firstc.hasNext() || !lastc.hasNext() ) {\n"
"result.errmsg = \"objects not found in local.oplog.$main -- is this a new and empty db instance?\";\n"
"result.oplogMainRowCount = db.oplog.$main.count();\n"
"result.oplogMainRowCount = ol.count();\n"
"return result;\n"
"}\n"
"\n"
@@ -2085,7 +2098,8 @@ const StringData _jscode_raw_db =
"}\n"
"\n"
"return result;\n"
"}\n"
"};\n"
"\n"
"DB.prototype.printReplicationInfo = function() {\n"
"var result = this.getReplicationInfo();\n"
"if( result.errmsg ) {\n"
@@ -2100,27 +2114,53 @@ const StringData _jscode_raw_db =
"}\n"
"\n"
"DB.prototype.printSlaveReplicationInfo = function() {\n"
"function g(x) {\n"
"assert( x , \"how could this be null (printSlaveReplicationInfo gx)\" )\n"
"print(\"source: \" + x.host);\n"
"if ( x.syncedTo ){\n"
"var st = new Date( DB.tsToSeconds( x.syncedTo ) * 1000 );\n"
"function getReplLag(st) {\n"
"var now = new Date();\n"
"print(\"\\t syncedTo: \" + st.toString() );\n"
"var ago = (now-st)/1000;\n"
"var hrs = Math.round(ago/36)/100;\n"
"print(\"\\t\\t = \" + Math.round(ago) + \"secs ago (\" + hrs + \"hrs)\");\n"
"};\n"
"\n"
"function g(x) {\n"
"assert( x , \"how could this be null (printSlaveReplicationInfo gx)\" )\n"
"print(\"source: \" + x.host);\n"
"if ( x.syncedTo ){\n"
"var st = new Date( DB.tsToSeconds( x.syncedTo ) * 1000 );\n"
"getReplLag(st);\n"
"}\n"
"else {\n"
"print( \"\\t doing initial sync\" );\n"
"}\n"
"};\n"
"\n"
"function r(x) {\n"
"assert( x , \"how could this be null (printSlaveReplicationInfo rx)\" );\n"
"if ( x.state == 1 ) {\n"
"return;\n"
"}\n"
"\n"
"print(\"source: \" + x.name);\n"
"if ( x.optime ) {\n"
"getReplLag(x.optimeDate);\n"
"}\n"
"else {\n"
"print( \"\\t no replication info, yet. State: \" + x.stateStr );\n"
"}\n"
"};\n"
"\n"
"var L = this.getSisterDB(\"local\");\n"
"if( L.sources.count() == 0 ) {\n"
"if( L.sources.count() != 0 ) {\n"
"L.sources.find().forEach(g);\n"
"}\n"
"else if (L.system.replset.count() != 0) {\n"
"var status = this.adminCommand({'replSetGetStatus' : 1});\n"
"status.members.forEach(r);\n"
"}\n"
"else {\n"
"print(\"local.sources is empty; is this db a --slave?\");\n"
"return;\n"
"}\n"
"L.sources.find().forEach(g);\n"
"}\n"
"\n"
"DB.prototype.serverBuildInfo = function(){\n"