00001 // grid.h 00002 00019 #pragma once 00020 00021 #include <boost/date_time/posix_time/posix_time.hpp> 00022 00023 #include "../util/time_support.h" 00024 #include "../util/concurrency/mutex.h" 00025 00026 #include "config.h" // DBConfigPtr 00027 00028 namespace mongo { 00029 00034 class Grid { 00035 public: 00036 Grid() : _lock( "Grid" ) , _allowLocalShard( true ) { } 00037 00042 DBConfigPtr getDBConfig( string ns , bool create=true , const string& shardNameHint="" ); 00043 00048 void removeDB( string db ); 00049 00053 bool allowLocalHost() const; 00054 00058 void setAllowLocalHost( bool allow ); 00059 00073 bool addShard( string* name , const ConnectionString& servers , long long maxSize , string& errMsg ); 00074 00078 bool knowAboutShard( const string& name ) const; 00079 00083 bool shouldBalance() const; 00084 00085 unsigned long long getNextOpTime() const; 00086 00087 // exposed methods below are for testing only 00088 00094 static bool _inBalancingWindow( const BSONObj& balancerDoc , const boost::posix_time::ptime& now ); 00095 00096 private: 00097 mongo::mutex _lock; // protects _databases; TODO: change to r/w lock ?? 00098 map<string, DBConfigPtr > _databases; // maps ns to DBConfig's 00099 bool _allowLocalShard; // can 'localhost' be used in shard addresses? 00100 00106 bool _getNewShardName( string* name ) const; 00107 00111 static bool _isSpecialLocalDB( const string& dbName ); 00112 00118 static bool _balancerStopped( const BSONObj& balancerDoc ); 00119 00120 }; 00121 00122 extern Grid grid; 00123 00124 } // namespace mongo