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

140 lines
3.5 KiB
C
Raw Normal View History

2009-02-17 20:41:31 +01:00
// shard.h
2008-12-29 02:28:49 +01:00
2009-02-17 20:41:31 +01:00
/*
2008-11-09 23:49:37 +01:00
A "shard" is a database (replica pair typically) which represents
one partition of the overall database.
*/
2008-09-15 15:14:42 +02:00
/**
* Copyright (C) 2008 10gen Inc.
2008-12-29 02:28:49 +01:00
*
2008-09-15 15:14:42 +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-09-15 15:14:42 +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-09-15 15:14:42 +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/>.
*/
2008-11-09 23:49:37 +01:00
#pragma once
2009-02-19 23:32:19 +01:00
#include "../stdafx.h"
2008-11-09 23:49:37 +01:00
#include "../client/dbclient.h"
#include "../client/model.h"
2009-02-17 20:41:31 +01:00
#include "shardkey.h"
2009-02-19 23:32:19 +01:00
#include <boost/utility.hpp>
2008-09-15 15:14:42 +02:00
2009-01-14 23:09:51 +01:00
namespace mongo {
class DBConfig;
class ShardManager;
class ShardObjUnitTest;
/**
config.shard
{ ns : "alleyinsider.fs.chunks" , min : {} , max : {} , server : "localhost:30001" }
*/
class Shard : public Model , boost::noncopyable {
2009-02-17 20:41:31 +01:00
public:
BSONObj& getMin(){
return _min;
2009-02-17 20:41:31 +01:00
}
BSONObj& getMax(){
return _max;
2009-02-17 20:41:31 +01:00
}
2009-02-20 19:46:57 +01:00
2009-02-17 20:41:31 +01:00
string getServer(){
2009-02-20 19:46:57 +01:00
return _server;
2009-02-17 20:41:31 +01:00
}
2009-02-20 19:46:57 +01:00
void setServer( string server );
bool contains( const BSONObj& obj );
string toString() const;
2009-02-20 16:48:32 +01:00
operator string() const { return toString(); }
bool operator==(const Shard& s);
bool operator!=(const Shard& s){
return ! ( *this == s );
}
2009-02-20 19:46:57 +01:00
void getFilter( BSONObjBuilder& b );
Shard * split();
Shard * split( const BSONObj& middle );
virtual const char * getNS(){ return "config.shard"; }
virtual void serialize(BSONObjBuilder& to);
virtual void unserialize(BSONObj& from);
virtual string modelServer();
protected:
Shard( ShardManager * info );
2009-02-20 19:46:57 +01:00
private:
ShardManager * _manager;
2009-02-20 19:46:57 +01:00
string _ns;
BSONObj _min;
BSONObj _max;
2009-02-20 19:46:57 +01:00
string _server;
bool _modified;
2009-02-17 21:34:52 +01:00
void _split( BSONObj& middle );
2009-02-20 19:46:57 +01:00
friend class ShardManager;
friend class ShardObjUnitTest;
2009-02-17 20:41:31 +01:00
};
/* config.sharding
{ ns: 'alleyinsider.fs.chunks' ,
2009-02-17 21:34:52 +01:00
key: { ts : 1 } ,
2009-02-17 20:41:31 +01:00
shards: [ { min: 1, max: 100, server: a } , { min: 101, max: 200 , server : b } ]
}
*/
class ShardManager {
public:
2009-02-17 20:41:31 +01:00
ShardManager( DBConfig * config , string ns ,ShardKeyPattern pattern );
virtual ~ShardManager();
2009-02-17 20:41:31 +01:00
string getns(){
return _ns;
}
int numShards(){ return _shards.size(); }
2009-02-20 16:46:42 +01:00
bool hasShardKey( const BSONObj& obj );
Shard& findShard( const BSONObj& obj );
ShardKeyPattern& getShardKey(){ return _key; }
/**
* @return number of shards added to the vector
*/
int getShardsForQuery( vector<Shard*>& shards , const BSONObj& query );
void save();
2009-02-19 18:55:01 +01:00
string toString() const;
2009-02-20 16:48:32 +01:00
operator string() const { return toString(); }
2009-02-17 20:41:31 +01:00
private:
DBConfig * _config;
2009-02-17 20:41:31 +01:00
string _ns;
ShardKeyPattern _key;
vector<Shard*> _shards;
friend class Shard;
};
2009-01-14 23:09:51 +01:00
} // namespace mongo