mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
shard versioning checkpoint
This commit is contained in:
parent
265436b22d
commit
26ad67b9c7
@ -48,6 +48,8 @@ namespace mongo {
|
||||
}
|
||||
|
||||
ScopedDbConnection conn( server );
|
||||
checkShardVersion( conn.conn() , _ns );
|
||||
|
||||
log(5) << "ShardedCursor::query server:" << server << " ns:" << _ns << " query:" << q << " num:" << num << " _fields:" << _fields << " options: " << _options << endl;
|
||||
auto_ptr<DBClientCursor> cursor = conn->query( _ns.c_str() , q , num , 0 , ( _fields.isEmpty() ? 0 : &_fields ) , _options );
|
||||
conn.done();
|
||||
|
20
s/shard.cpp
20
s/shard.cpp
@ -190,7 +190,7 @@ namespace mongo {
|
||||
}
|
||||
return added;
|
||||
}
|
||||
|
||||
|
||||
void ShardManager::save(){
|
||||
for ( vector<Shard*>::const_iterator i=_shards.begin(); i!=_shards.end(); i++ ){
|
||||
Shard* s = *i;
|
||||
@ -200,6 +200,24 @@ namespace mongo {
|
||||
}
|
||||
}
|
||||
|
||||
ServerShardVersion ShardManager::getVersion( const string& server ) const{
|
||||
// TODO: cache or something?
|
||||
|
||||
ServerShardVersion max = 0;
|
||||
cout << "getVersion for: " << server << endl;
|
||||
for ( vector<Shard*>::const_iterator i=_shards.begin(); i!=_shards.end(); i++ ){
|
||||
Shard* s = *i;
|
||||
cout << "\t" << s->getServer() << endl;
|
||||
if ( s->getServer() != server )
|
||||
continue;
|
||||
|
||||
if ( s->_lastmod > max )
|
||||
max = s->_lastmod;
|
||||
}
|
||||
|
||||
return max;
|
||||
}
|
||||
|
||||
string ShardManager::toString() const {
|
||||
stringstream ss;
|
||||
ss << "ShardManager: " << _ns << " key:" << _key.toString() << "\n";
|
||||
|
@ -35,6 +35,8 @@ namespace mongo {
|
||||
class ShardManager;
|
||||
class ShardObjUnitTest;
|
||||
|
||||
typedef unsigned long long ServerShardVersion;
|
||||
|
||||
/**
|
||||
config.shard
|
||||
{ ns : "alleyinsider.fs.chunks" , min : {} , max : {} , server : "localhost:30001" }
|
||||
@ -88,7 +90,7 @@ namespace mongo {
|
||||
BSONObj _min;
|
||||
BSONObj _max;
|
||||
string _server;
|
||||
unsigned long long _lastmod;
|
||||
ServerShardVersion _lastmod;
|
||||
|
||||
bool _modified;
|
||||
|
||||
@ -129,7 +131,8 @@ namespace mongo {
|
||||
|
||||
string toString() const;
|
||||
operator string() const { return toString(); }
|
||||
|
||||
|
||||
ServerShardVersion getVersion( const string& server ) const;
|
||||
private:
|
||||
DBConfig * _config;
|
||||
string _ns;
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "request.h"
|
||||
#include "../client/connpool.h"
|
||||
#include "../db/commands.h"
|
||||
#include "shard.h"
|
||||
|
||||
namespace mongo {
|
||||
|
||||
@ -25,6 +26,8 @@ namespace mongo {
|
||||
ScopedDbConnection dbcon( server );
|
||||
DBClientBase &_c = dbcon.conn();
|
||||
|
||||
checkShardVersion( _c , r.getns() );
|
||||
|
||||
// TODO: This will not work with Paired connections. Fix.
|
||||
DBClientConnection&c = dynamic_cast<DBClientConnection&>(_c);
|
||||
Message response;
|
||||
@ -47,4 +50,22 @@ namespace mongo {
|
||||
dbcon.done();
|
||||
}
|
||||
|
||||
void checkShardVersion( DBClientBase& conn , const string& ns ){
|
||||
// TODO: cache, optimize, etc...
|
||||
|
||||
DBConfig * conf = grid.getDBConfig( ns );
|
||||
if ( ! conf )
|
||||
return;
|
||||
|
||||
if ( ! conf->sharded( ns ) )
|
||||
return;
|
||||
|
||||
ServerShardVersion version = conf->getShardManager( ns )->getVersion( conn.getServerAddress() );
|
||||
cout << "got version: " << version << " for : " << ns << endl;
|
||||
|
||||
|
||||
// grid->getVersion( conn.server() , ns );
|
||||
// check
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,6 +19,8 @@ namespace mongo {
|
||||
void insert( string server , const char * ns , const BSONObj& obj );
|
||||
|
||||
};
|
||||
|
||||
void checkShardVersion( DBClientBase & conn , const string& ns );
|
||||
|
||||
extern Strategy * SINGLE;
|
||||
extern Strategy * SHARDED;
|
||||
|
Loading…
Reference in New Issue
Block a user