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

121 lines
3.0 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;
2009-02-17 20:41:31 +01:00
class ShardInfo;
2009-02-19 23:32:19 +01:00
class Shard : 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
}
string getServer(){
return _data.getStringField( "server" );
}
bool contains( const BSONObj& obj );
void split();
2009-02-19 23:32:19 +01:00
void split( const BSONObj& middle );
string toString() const;
static string toString( void *o ) {
return ( (Shard*) o )->toString();
}
bool operator==(const Shard& s);
bool operator!=(const Shard& s){
return ! ( *this == s );
}
2009-02-17 20:41:31 +01:00
private:
Shard( ShardInfo * info , BSONObj data );
ShardInfo * _info;
2009-02-17 21:34:52 +01:00
BSONObj _data;
2009-02-17 20:41:31 +01:00
BSONObj _min;
BSONObj _max;
2009-02-17 21:34:52 +01:00
void _split( BSONObj& middle );
2009-02-17 20:41:31 +01:00
friend class ShardInfo;
};
/* 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 ShardInfo : public Model {
public:
2009-02-17 20:41:31 +01:00
ShardInfo( DBConfig * config );
virtual ~ShardInfo();
2009-02-17 20:41:31 +01:00
string getns(){
return _ns;
}
int numShards(){ return _shards.size(); }
Shard& findShard( const BSONObj & obj );
ShardKey& getShardKey(){ return _key; }
virtual const char * getNS(){ return "config.sharding"; }
virtual void serialize(BSONObjBuilder& to);
virtual void unserialize(BSONObj& from);
virtual string modelServer();
2009-02-19 18:55:01 +01:00
bool loadByName( const string& ns );
string toString() const;
static string toString( void *o ) {
return ( (ShardInfo*) o )->toString();
}
2009-02-17 20:41:31 +01:00
private:
DBConfig * _config;
2009-02-17 20:41:31 +01:00
string _ns;
ShardKey _key;
vector<Shard*> _shards;
friend class Shard;
};
2009-01-14 23:09:51 +01:00
} // namespace mongo