mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
handle databases with different cases in mongos SERVER-1443
This commit is contained in:
parent
aa586edf7e
commit
380cdd5bf2
@ -55,7 +55,7 @@ namespace mongo {
|
||||
|
||||
stringstream ss;
|
||||
ss << "db already exists with different case other: [" << others[i] << "] me [" << nm << "]";
|
||||
uasserted( 13297 , ss.str() );
|
||||
uasserted( DatabaseDifferCaseCode , ss.str() );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,6 @@
|
||||
|
||||
namespace mongo {
|
||||
|
||||
|
||||
/**
|
||||
* Database represents a database database
|
||||
* Each database database has its own set of files -- dbname.ns, dbname.0, dbname.1, ...
|
||||
|
@ -6,10 +6,12 @@ a.dropDatabase();
|
||||
b.dropDatabase();
|
||||
|
||||
a.foo.save( { x : 1 } )
|
||||
assert.eq( 0 , db.getLastErrorObj().code || 0 , "A" )
|
||||
z = db.getLastErrorObj();
|
||||
assert.eq( 0 , z.code || 0 , "A : " + tojson(z) )
|
||||
|
||||
b.foo.save( { x : 1 } )
|
||||
assert.eq( 13297 , db.getLastErrorObj().code || 0 , "A" )
|
||||
z = db.getLastErrorObj();
|
||||
assert.eq( 13297 , z.code || 0 , "B : " + tojson(z) )
|
||||
|
||||
a.dropDatabase();
|
||||
b.dropDatabase();
|
||||
|
@ -128,8 +128,8 @@ namespace mongo {
|
||||
log() << "DROP DATABASE: " << dbName << endl;
|
||||
|
||||
if ( ! conf ){
|
||||
log(1) << " passing though drop database for: " << dbName << endl;
|
||||
return passthrough( conf , cmdObj , result );
|
||||
result.append( "info" , "database didn't exist" );
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( ! conf->dropDatabase( errmsg ) )
|
||||
|
20
s/config.cpp
20
s/config.cpp
@ -397,6 +397,24 @@ namespace mongo {
|
||||
// note here that cc->primary == 0.
|
||||
log() << "couldn't find database [" << database << "] in config db" << endl;
|
||||
|
||||
{ // lets check case
|
||||
ScopedDbConnection conn( configServer.modelServer() );
|
||||
BSONObjBuilder b;
|
||||
b.appendRegex( "_id" , (string)"^" + database + "$" , "i" );
|
||||
BSONObj d = conn->findOne( ShardNS::database , b.obj() );
|
||||
conn.done();
|
||||
|
||||
if ( ! d.isEmpty() ){
|
||||
cc.reset();
|
||||
stringstream ss;
|
||||
ss << "can't have 2 databases that just differ on case "
|
||||
<< " have: " << d["_id"].String()
|
||||
<< " want to add: " << database;
|
||||
|
||||
uasserted( DatabaseDifferCaseCode ,ss.str() );
|
||||
}
|
||||
}
|
||||
|
||||
if ( database == "admin" )
|
||||
cc->_primary = configServer.getPrimary();
|
||||
else
|
||||
@ -409,7 +427,7 @@ namespace mongo {
|
||||
else {
|
||||
cc.reset();
|
||||
log() << "\t can't find a shard to put new db on" << endl;
|
||||
uassert( 10185 , "can't find a shard to put new db on" , 0 );
|
||||
uasserted( 10185 , "can't find a shard to put new db on" );
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -37,7 +37,7 @@
|
||||
namespace mongo {
|
||||
|
||||
Request::Request( Message& m, AbstractMessagingPort* p ) :
|
||||
_m(m) , _d( m ) , _p(p){
|
||||
_m(m) , _d( m ) , _p(p) , _didInit(false){
|
||||
|
||||
assert( _d.getns() );
|
||||
_id = _m.header()->id;
|
||||
@ -46,9 +46,15 @@ namespace mongo {
|
||||
_clientInfo = ClientInfo::get( _clientId );
|
||||
_clientInfo->newRequest( p );
|
||||
|
||||
}
|
||||
|
||||
void Request::init(){
|
||||
if ( _didInit )
|
||||
return;
|
||||
_didInit = true;
|
||||
reset();
|
||||
}
|
||||
|
||||
|
||||
void Request::reset( bool reload ){
|
||||
if ( _m.operation() == dbKillCursors ){
|
||||
return;
|
||||
@ -71,6 +77,8 @@ namespace mongo {
|
||||
}
|
||||
|
||||
Shard Request::primaryShard() const {
|
||||
assert( _didInit );
|
||||
|
||||
if ( _chunkManager ){
|
||||
if ( _chunkManager->numChunks() > 1 )
|
||||
throw UserException( 8060 , "can't call primaryShard on a sharded collection" );
|
||||
@ -82,7 +90,7 @@ namespace mongo {
|
||||
}
|
||||
|
||||
void Request::process( int attempt ){
|
||||
|
||||
init();
|
||||
int op = _m.operation();
|
||||
assert( op > dbMsg );
|
||||
|
||||
@ -143,6 +151,7 @@ namespace mongo {
|
||||
}
|
||||
|
||||
void Request::reply( Message & response , const string& fromServer ){
|
||||
assert( _didInit );
|
||||
long long cursor =response.header()->getCursor();
|
||||
if ( cursor ){
|
||||
cursorCache.storeRef( fromServer , cursor );
|
||||
|
10
s/request.h
10
s/request.h
@ -35,7 +35,7 @@ namespace mongo {
|
||||
Request( Message& m, AbstractMessagingPort* p );
|
||||
|
||||
// ---- message info -----
|
||||
|
||||
|
||||
|
||||
const char * getns() const {
|
||||
return _d.getns();
|
||||
@ -53,13 +53,16 @@ namespace mongo {
|
||||
}
|
||||
|
||||
DBConfigPtr getConfig() const {
|
||||
assert( _didInit );
|
||||
return _config;
|
||||
}
|
||||
bool isShardingEnabled() const {
|
||||
assert( _didInit );
|
||||
return _config->isShardingEnabled();
|
||||
}
|
||||
|
||||
ChunkManagerPtr getChunkManager() const {
|
||||
assert( _didInit );
|
||||
return _chunkManager;
|
||||
}
|
||||
|
||||
@ -87,10 +90,11 @@ namespace mongo {
|
||||
|
||||
void gotInsert();
|
||||
|
||||
void init();
|
||||
|
||||
void reset( bool reload=false );
|
||||
|
||||
private:
|
||||
|
||||
Message& _m;
|
||||
DbMessage _d;
|
||||
AbstractMessagingPort* _p;
|
||||
@ -103,6 +107,8 @@ namespace mongo {
|
||||
ClientInfo * _clientInfo;
|
||||
|
||||
OpCounters* _counter;
|
||||
|
||||
bool _didInit;
|
||||
};
|
||||
|
||||
typedef map<int,ClientInfo*> ClientCache;
|
||||
|
@ -82,6 +82,7 @@ namespace mongo {
|
||||
log(5) << "client id: " << hex << r.getClientId() << "\t" << r.getns() << "\t" << dec << r.op() << endl;
|
||||
}
|
||||
try {
|
||||
r.init();
|
||||
setClientId( r.getClientId() );
|
||||
r.process();
|
||||
}
|
||||
|
@ -223,6 +223,4 @@ namespace mongo {
|
||||
_writeLock = 0; // TODO
|
||||
}
|
||||
|
||||
|
||||
const int StaleConfigInContextCode = 13388;
|
||||
}
|
||||
|
@ -137,6 +137,7 @@ namespace mongo {
|
||||
}
|
||||
|
||||
Request r( m , 0 );
|
||||
r.init();
|
||||
r.process();
|
||||
}
|
||||
else {
|
||||
|
2
s/util.h
2
s/util.h
@ -28,8 +28,6 @@
|
||||
|
||||
namespace mongo {
|
||||
|
||||
extern const int StaleConfigInContextCode;
|
||||
|
||||
struct ShardChunkVersion {
|
||||
union {
|
||||
struct {
|
||||
|
@ -22,6 +22,11 @@
|
||||
|
||||
namespace mongo {
|
||||
|
||||
enum CommonErrorCodes {
|
||||
DatabaseDifferCaseCode = 13297 ,
|
||||
StaleConfigInContextCode = 13388
|
||||
};
|
||||
|
||||
/* these are manipulated outside of mutexes, so be careful */
|
||||
struct Assertion {
|
||||
Assertion() {
|
||||
|
Loading…
Reference in New Issue
Block a user