summaryrefslogtreecommitdiff
path: root/src/mongo/shell
diff options
context:
space:
mode:
authorGreg Studer <greg@10gen.com>2012-01-06 16:14:34 -0500
committerGreg Studer <greg@10gen.com>2012-02-16 15:09:30 -0500
commit218fea2e18f4f22104ad531e6cabcd34c3304245 (patch)
treed0384c688336e5c5d3035a30e347ad8c1015bf90 /src/mongo/shell
parentaa853edd99a59dd317751dbc4fc79365690a150e (diff)
downloadmongo-218fea2e18f4f22104ad531e6cabcd34c3304245.tar.gz
SERVER-4621 noBalance flag for sharded collections
Diffstat (limited to 'src/mongo/shell')
-rw-r--r--src/mongo/shell/utils_sh.js60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/mongo/shell/utils_sh.js b/src/mongo/shell/utils_sh.js
index 7d34fa3b52c..3b0d975c0c1 100644
--- a/src/mongo/shell/utils_sh.js
+++ b/src/mongo/shell/utils_sh.js
@@ -257,3 +257,63 @@ sh.waitForBalancer = function( onOrNot, timeout, interval ){
}
+sh.disableBalancing = function( coll ){
+ var dbase = db
+ if( coll instanceof DBCollection ) dbase = coll.getDB()
+ dbase.getSisterDB( "config" ).collections.update({ _id : coll + "" }, { $set : { "noBalance" : true } })
+}
+
+sh.enableBalancing = function( coll ){
+ var dbase = db
+ if( coll instanceof DBCollection ) dbase = coll.getDB()
+ dbase.getSisterDB( "config" ).collections.update({ _id : coll + "" }, { $set : { "noBalance" : false } })
+}
+
+/*
+ * Can call _lastMigration( coll ), _lastMigration( db ), _lastMigration( st ), _lastMigration( mongos )
+ */
+sh._lastMigration = function( ns ){
+
+ var coll = null
+ var dbase = null
+ var config = null
+
+ if( ! ns ){
+ config = db.getSisterDB( "config" )
+ }
+ else if( ns instanceof DBCollection ){
+ coll = ns
+ config = coll.getDB().getSisterDB( "config" )
+ }
+ else if( ns instanceof DB ){
+ dbase = ns
+ config = dbase.getSisterDB( "config" )
+ }
+ else if( ns instanceof ShardingTest ){
+ config = ns.s.getDB( "config" )
+ }
+ else if( ns instanceof Mongo ){
+ config = ns.getDB( "config" )
+ }
+ else {
+ // String namespace
+ ns = ns + ""
+ if( ns.indexOf( "." ) > 0 ){
+ config = db.getSisterDB( "config" )
+ coll = db.getMongo().getCollection( ns )
+ }
+ else{
+ config = db.getSisterDB( "config" )
+ dbase = db.getSisterDB( ns )
+ }
+ }
+
+ var searchDoc = { what : /^moveChunk/ }
+ if( coll ) searchDoc.ns = coll + ""
+ if( dbase ) searchDoc.ns = new RegExp( "^" + dbase + "\\." )
+
+ var cursor = config.changelog.find( searchDoc ).sort({ time : -1 }).limit( 1 )
+ if( cursor.hasNext() ) return cursor.next()
+ else return null
+}
+