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

118 lines
2.7 KiB
C++

// shard.h
/*
A "shard" is a database (replica pair typically) which represents
one partition of the overall database.
*/
/**
* Copyright (C) 2008 10gen Inc.
*
* 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.
*
* 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.
*
* 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/>.
*/
#pragma once
#include "../client/dbclient.h"
#include "../client/model.h"
#include "shardkey.h"
namespace mongo {
class DBConfig;
class ShardInfo;
class Shard : public Stringable {
public:
BSONObj& getMin(){
return _min;
}
BSONObj& getMax(){
return _max;
}
string getServer(){
return _data.getStringField( "server" );
}
bool contains( const BSONObj& obj );
void split();
virtual string toString() const;
bool operator==(const Shard& s);
bool operator!=(const Shard& s){
return ! ( *this == s );
}
Shard( const Shard& s );
private:
Shard( ShardInfo * info , BSONObj data );
ShardInfo * _info;
BSONObj _data;
BSONObj _min;
BSONObj _max;
void _split( BSONObj& middle );
friend class ShardInfo;
};
/* config.sharding
{ ns: 'alleyinsider.fs.chunks' ,
key: { ts : 1 } ,
shards: [ { min: 1, max: 100, server: a } , { min: 101, max: 200 , server : b } ]
}
*/
class ShardInfo : public Model , public Stringable {
public:
ShardInfo( DBConfig * config );
virtual ~ShardInfo();
string getns(){
return _ns;
}
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();
virtual string toString() const;
private:
DBConfig * _config;
string _ns;
ShardKey _key;
vector<Shard*> _shards;
friend class Shard;
};
} // namespace mongo