0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-30 00:56:44 +01:00
mongodb/s/config.h

148 lines
4.1 KiB
C
Raw Normal View History

2009-02-13 03:03:46 +01:00
// config.h
2008-10-13 23:58:51 +02:00
/**
* Copyright (C) 2008 10gen Inc.
2008-12-29 02:28:49 +01:00
*
2008-10-13 23:58:51 +02:00
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
2008-12-29 02:28:49 +01:00
*
2008-10-13 23:58:51 +02:00
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
2008-12-29 02:28:49 +01:00
*
2008-10-13 23:58:51 +02:00
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* This file is things related to the "grid configuration":
- what machines make up the db component of our cloud
- where various ranges of things live
*/
#pragma once
2009-02-06 21:44:21 +01:00
#include "../db/namespace.h"
2008-10-20 00:46:53 +02:00
#include "../client/dbclient.h"
#include "../client/model.h"
2009-02-26 16:14:50 +01:00
#include "shardkey.h"
2008-10-13 23:58:51 +02:00
2009-01-14 23:09:51 +01:00
namespace mongo {
2009-02-08 23:55:33 +01:00
class Grid;
2009-02-13 03:09:06 +01:00
class ConfigServer;
2009-02-08 23:55:33 +01:00
2009-02-13 03:09:06 +01:00
extern ConfigServer configServer;
extern Grid grid;
2009-02-19 18:55:01 +01:00
class ShardManager;
2009-02-06 21:44:21 +01:00
/**
top level grid configuration for an entire database
*/
class DBConfig : public Model {
public:
DBConfig( string name = "" ) : _name( name ) , _primary("") , _partitioned(false){ }
string getName(){ return _name; };
2009-02-17 17:41:34 +01:00
/**
* @return if anything in this db is partitioned or not
*/
bool isPartitioned(){
return _partitioned;
}
2009-02-19 18:55:01 +01:00
void turnOnPartitioning();
ShardManager* turnOnSharding( const string& ns , ShardKeyPattern fieldsAndOrder );
2009-02-06 21:44:21 +01:00
/**
* @return whether or not this partition is partitioned
*/
2009-02-19 18:55:01 +01:00
bool sharded( const string& ns );
2009-02-06 21:44:21 +01:00
ShardManager* getShardManager( const string& ns );
2009-02-06 21:44:21 +01:00
/**
2009-02-17 17:41:34 +01:00
* @return the correct for machine for the ns
* if the namespace is partitioned, will return an empty string
2009-02-06 21:44:21 +01:00
*/
2009-02-19 18:55:01 +01:00
string getServer( const string& ns );
2009-02-06 21:44:21 +01:00
string getPrimary(){
if ( _primary.size() == 0 )
throw UserException( (string)"no primary server configured for db: " + _name );
2009-02-06 21:44:21 +01:00
return _primary;
}
2009-02-13 22:18:14 +01:00
void setPrimary( string s ){
_primary = s;
}
2009-02-18 19:54:22 +01:00
virtual void save( bool check=true);
virtual string modelServer();
2009-02-18 19:54:22 +01:00
2009-02-06 21:44:21 +01:00
// model stuff
2009-02-08 23:55:33 +01:00
virtual const char * getNS(){ return "config.databases"; }
2009-02-06 21:44:21 +01:00
virtual void serialize(BSONObjBuilder& to);
2009-02-27 16:37:13 +01:00
virtual void unserialize(const BSONObj& from);
2009-02-06 21:44:21 +01:00
bool loadByName(const char *nm);
2009-02-18 19:54:22 +01:00
2009-02-06 21:44:21 +01:00
protected:
string _name; // e.g. "alleyinsider"
string _primary; // e.g. localhost , mongo.foo.com:9999
2009-02-06 21:44:21 +01:00
bool _partitioned;
2009-02-19 18:55:01 +01:00
2009-02-26 16:14:50 +01:00
map<string,ShardKeyPattern> _sharded; // { "alleyinsider.blog.posts" : { ts : 1 } , ... ] - all ns that are sharded
map<string,ShardManager*> _shards; // this will only have entries for things that have been looked at
2009-02-08 23:55:33 +01:00
friend class Grid;
};
class Grid {
public:
2009-02-05 22:45:58 +01:00
/**
gets the config the db.
will return an empty DBConfig if not in db already
*/
DBConfig * getDBConfig( string ns , bool create=true);
2009-02-08 23:55:33 +01:00
string pickServerForNewDB();
bool knowAboutServer( string name ) const;
2009-02-05 22:45:58 +01:00
private:
map<string,DBConfig*> _databases;
};
2009-02-13 03:09:06 +01:00
class ConfigServer : public DBConfig {
public:
enum { Port = 27016 }; /* standard port # for a grid db */
ConfigServer();
~ConfigServer();
bool ok(){
// TODO: check can connect
return _primary.size() > 0;
}
virtual string modelServer(){
uassert( "ConfigServer not setup" , _primary.size() );
return _primary;
}
/**
call at startup, this will initiate connection to the grid db
*/
bool init( vector<string> configHosts , bool infer );
2009-01-14 23:09:51 +01:00
private:
string getHost( string name , bool withPort );
};
2009-01-14 23:09:51 +01:00
} // namespace mongo