本文整理汇总了C++中Shard类的典型用法代码示例。如果您正苦于以下问题:C++ Shard类的具体用法?C++ Shard怎么用?C++ Shard使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Shard类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: uassert
Shard * Shard::split( const BSONObj& m ){
uassert( "can't split as shard that doesn't have a manager" , _manager );
log(1) << " before split on: " << m << "\n"
<< "\t self : " << toString() << endl;
uassert( "locking namespace on server failed" , lockNamespaceOnServer( getServer() , _ns ) );
Shard * s = new Shard( _manager );
s->_ns = _ns;
s->_server = _server;
s->_min = m.getOwned();
s->_max = _max;
s->_markModified();
_markModified();
_manager->_shards.push_back( s );
_max = m.getOwned();
log(1) << " after split:\n"
<< "\t left : " << toString() << "\n"
<< "\t right: "<< s->toString() << endl;
_manager->save();
return s;
}
示例2: uassert
bool CmdAuthenticate::getUserObj(const string& dbname, const string& user, BSONObj& userObj, string& pwd) {
if (user == internalSecurity.user) {
uassert(15890, "key file must be used to log in with internal user",
!cmdLine.keyFile.empty());
pwd = internalSecurity.pwd;
}
else {
string systemUsers = dbname + ".system.users";
DBConfigPtr config = grid.getDBConfig( systemUsers );
Shard s = config->getShard( systemUsers );
static BSONObj userPattern = BSON("user" << 1);
scoped_ptr<ScopedDbConnection> conn(
ScopedDbConnection::getInternalScopedDbConnection( s.getConnString(), 30.0 ) );
OCCASIONALLY conn->get()->ensureIndex(systemUsers, userPattern, false, "user_1");
{
BSONObjBuilder b;
b << "user" << user;
BSONObj query = b.done();
userObj = conn->get()->findOne(systemUsers, query, 0, QueryOption_SlaveOk);
if( userObj.isEmpty() ) {
log() << "auth: couldn't find user " << user << ", " << systemUsers << endl;
conn->done(); // return to pool
return false;
}
}
pwd = userObj.getStringField("pwd");
conn->done(); // return to pool
}
return true;
}
示例3: dassert
Status DBClientShardResolver::chooseWriteHost( const string& shardName,
ConnectionString* shardHost ) const {
// Declare up here for parsing later
string errMsg;
// Special-case for config
if (shardName == "config") {
*shardHost = ConnectionString::parse( configServer.modelServer(), errMsg );
dassert( errMsg == "" );
return Status::OK();
}
//
// First get the information about the shard from the shard cache
//
// Internally uses our shard cache, does no reload
Shard shard = Shard::findIfExists( shardName );
if ( shard.getName() == "" ) {
return Status( ErrorCodes::ShardNotFound,
string("unknown shard name ") + shardName );
}
return findMaster(shard.getConnString().toString(), shardHost);
}
示例4: _config
ShardManager::ShardManager( DBConfig * config , string ns , ShardKeyPattern pattern ) : _config( config ) , _ns( ns ) , _key( pattern ){
Shard temp(0);
ScopedDbConnection conn( temp.modelServer() );
auto_ptr<DBClientCursor> cursor = conn->query( temp.getNS() , BSON( "ns" << ns ) );
while ( cursor->more() ){
Shard * s = new Shard( this );
BSONObj d = cursor->next();
s->unserialize( d );
_shards.push_back( s );
s->_id = d["_id"].wrap().getOwned();
}
conn.done();
if ( _shards.size() == 0 ){
Shard * s = new Shard( this );
s->_ns = ns;
s->_min = _key.globalMin();
s->_max = _key.globalMax();
s->_server = config->getPrimary();
s->_markModified();
_shards.push_back( s );
log() << "no shards for:" << ns << " so creating first: " << s->toString() << endl;
}
_sequenceNumber = ++NextSequenceNumber;
}
示例5: moveIfShould
bool Shard::moveIfShould( Shard * newShard ){
Shard * toMove = 0;
if ( newShard->countObjects() <= 1 ){
toMove = newShard;
}
else if ( this->countObjects() <= 1 ){
toMove = this;
}
else {
log(1) << "don't know how to decide if i should move inner shard" << endl;
}
if ( ! toMove )
return false;
string newLocation = grid.pickServerForNewDB();
if ( newLocation == getServer() ){
// if this is the best server, then we shouldn't do anything!
log(1) << "not moving shard: " << toString() << " b/c would move to same place " << newLocation << " -> " << getServer() << endl;
return 0;
}
log() << "moving shard (auto): " << toMove->toString() << " to: " << newLocation << " #objcets: " << toMove->countObjects() << endl;
string errmsg;
massert( (string)"moveAndCommit failed: " + errmsg ,
toMove->moveAndCommit( newLocation , errmsg ) );
return true;
}
示例6: _checkOIDs
bool Balancer::_checkOIDs() {
vector<Shard> all;
Shard::getAllShards( all );
map<int,Shard> oids;
for ( vector<Shard>::iterator i=all.begin(); i!=all.end(); ++i ) {
Shard s = *i;
BSONObj f = s.runCommand( "admin" , "features" , true );
if ( f["oidMachine"].isNumber() ) {
int x = f["oidMachine"].numberInt();
if ( oids.count(x) == 0 ) {
oids[x] = s;
}
else {
log() << "error: 2 machines have " << x << " as oid machine piece " << s.toString() << " and " << oids[x].toString() << endl;
s.runCommand( "admin" , BSON( "features" << 1 << "oidReset" << 1 ) , true );
oids[x].runCommand( "admin" , BSON( "features" << 1 << "oidReset" << 1 ) , true );
return false;
}
}
else {
log() << "warning: oidMachine not set on: " << s.toString() << endl;
}
}
return true;
}
示例7: _delete
void _delete( Request& r , DbMessage& d, ShardManager* manager ){
int flags = d.pullInt();
bool justOne = flags & 1;
uassert( "bad delete message" , d.moreJSObjs() );
BSONObj pattern = d.nextJsObj();
if ( manager->hasShardKey( pattern ) ){
Shard& s = manager->findShard( pattern );
doWrite( dbDelete , r , s.getServer() );
return;
}
if ( ! justOne && ! pattern.hasField( "_id" ) )
throw UserException( "can only delete with a non-shard key pattern if can delete as many as we find" );
vector<Shard*> shards;
manager->getShardsForQuery( shards , pattern );
set<string> seen;
for ( vector<Shard*>::iterator i=shards.begin(); i!=shards.end(); i++){
Shard * s = *i;
if ( seen.count( s->getServer() ) )
continue;
seen.insert( s->getServer() );
doWrite( dbDelete , r , s->getServer() );
}
}
示例8: setShardVersion
bool setShardVersion(DBClientBase& conn,
const string& ns,
const string& configServerPrimary,
ChunkVersion version,
ChunkManager* manager,
bool authoritative,
BSONObj& result) {
BSONObjBuilder cmdBuilder;
cmdBuilder.append("setShardVersion", ns);
cmdBuilder.append("configdb", configServerPrimary);
Shard s = Shard::make(conn.getServerAddress());
cmdBuilder.append("shard", s.getName());
cmdBuilder.append("shardHost", s.getConnString());
if (ns.size() > 0) {
version.addToBSON(cmdBuilder);
}
else {
cmdBuilder.append("init", true);
}
if (authoritative) {
cmdBuilder.appendBool("authoritative", 1);
}
BSONObj cmd = cmdBuilder.obj();
LOG(1) << " setShardVersion " << s.getName() << " " << conn.getServerAddress()
<< " " << ns << " " << cmd
<< (manager ? string(str::stream() << " " << manager->getSequenceNumber()) : "");
return conn.runCommand("admin", cmd, result, 0);
}
示例9: UserException
Shard& ShardManager::findShard( const BSONObj & obj ){
for ( vector<Shard*>::iterator i=_shards.begin(); i != _shards.end(); i++ ){
Shard * s = *i;
if ( s->contains( obj ) )
return *s;
}
throw UserException( "couldn't find a shard which should be impossible" );
}
示例10: isIdentical
bool Shard::isIdentical(Shard *other)
{
if (_type != other->_type) return false;
if (count() != other->count()) return false;
for (Shard *mine = _first, *yours = other->_first; mine;
mine = mine->_next, yours = yours->_next)
if (!mine->isIdentical(yours)) return false;
return true;
}
示例11: findShardOnServer
Shard* ShardManager::findShardOnServer( const string& server ) const {
for ( vector<Shard*>::const_iterator i=_shards.begin(); i!=_shards.end(); i++ ){
Shard* s = *i;
if ( s->getServer() == server )
return s;
}
return 0;
}
示例12: return
Token *Command::arg(int idx)
{
for(Shard *it = first(); it; it = it->next())
{
if(idx--) continue;
it = it->first();
if(!it || it->type() != BLOCK) break;
return (Token*) it->first();
}
return 0;
}
示例13: ensureIndex
void ShardManager::ensureIndex(){
set<string> seen;
for ( vector<Shard*>::const_iterator i=_shards.begin(); i!=_shards.end(); i++ ){
Shard* s = *i;
if ( seen.count( s->getServer() ) )
continue;
seen.insert( s->getServer() );
s->ensureIndex();
}
}
示例14: assert
// Deprecated, will move to the strategy itself
Shard Request::primaryShard() const {
assert( _didInit );
if ( _chunkManager ) {
if ( _chunkManager->numChunks() > 1 )
throw UserException( 8060 , "can't call primaryShard on a sharded collection" );
return _chunkManager->findChunk( _chunkManager->getShardKey().globalMin() )->getShard();
}
Shard s = _config->getShard( getns() );
uassert( 10194 , "can't call primaryShard on a sharded collection!" , s.ok() );
return s;
}
示例15: remove
void remove( const string& name ) {
scoped_lock lk( _mutex );
for ( map<string,Shard>::iterator i = _lookup.begin(); i!=_lookup.end(); ) {
Shard s = i->second;
if ( s.getName() == name ) {
_lookup.erase(i++);
}
else {
++i;
}
}
}