summaryrefslogtreecommitdiff
path: root/s
diff options
context:
space:
mode:
authorDwight <dmerriman@gmail.com>2009-09-01 16:39:01 -0400
committerDwight <dmerriman@gmail.com>2009-09-01 16:39:01 -0400
commite5fb018121c7a939328648f9b02756499078512c (patch)
treed263cd1a15398e52e13484aebe20dd3e723f67a0 /s
parent7172529835487de9dec84e03c5eea4c2d065a621 (diff)
parent562564d8f4daa24fdcc859662355c226fe92c0a3 (diff)
downloadmongo-e5fb018121c7a939328648f9b02756499078512c.tar.gz
Merge branch 'master' of git@github.com:mongodb/mongo
Diffstat (limited to 's')
-rw-r--r--s/chunk.h1
-rw-r--r--s/commands_admin.cpp6
-rw-r--r--s/request.cpp17
-rw-r--r--s/request.h7
-rw-r--r--s/strategy_single.cpp43
5 files changed, 63 insertions, 11 deletions
diff --git a/s/chunk.h b/s/chunk.h
index e5dae17b719..f5f28728b62 100644
--- a/s/chunk.h
+++ b/s/chunk.h
@@ -162,6 +162,7 @@ namespace mongo {
}
int numChunks(){ return _chunks.size(); }
+ Chunk* getChunk( int i ){ return _chunks[i]; }
bool hasShardKey( const BSONObj& obj );
Chunk& findChunk( const BSONObj& obj );
diff --git a/s/commands_admin.cpp b/s/commands_admin.cpp
index ef64624b000..8812e63b8f2 100644
--- a/s/commands_admin.cpp
+++ b/s/commands_admin.cpp
@@ -258,9 +258,15 @@ namespace mongo {
return false;
}
+ if ( ns.find( ".system." ) != string::npos ){
+ errmsg = "can't shard system namespaces";
+ return false;
+ }
+
config->shardCollection( ns , key );
config->save( true );
+ result << "collectionsharded" << ns;
result << "ok" << 1;
return true;
}
diff --git a/s/request.cpp b/s/request.cpp
index ade683abb63..83a42b3f990 100644
--- a/s/request.cpp
+++ b/s/request.cpp
@@ -42,11 +42,11 @@ namespace mongo {
_config = grid.getDBConfig( getns() );
if ( _config->isSharded( getns() ) ){
- _shardInfo = _config->getChunkManager( getns() , reload );
- uassert( (string)"no shard info for: " + getns() , _shardInfo );
+ _chunkManager = _config->getChunkManager( getns() , reload );
+ uassert( (string)"no shard info for: " + getns() , _chunkManager );
}
else {
- _shardInfo = 0;
+ _chunkManager = 0;
}
_m.data->id = _id;
@@ -54,10 +54,10 @@ namespace mongo {
}
string Request::singleServerName(){
- if ( _shardInfo ){
- if ( _shardInfo->numChunks() > 1 )
+ if ( _chunkManager ){
+ if ( _chunkManager->numChunks() > 1 )
throw UserException( "can't call singleServerName on a sharded collection" );
- return _shardInfo->findChunk( _shardInfo->getShardKey().globalMin() ).getShard();
+ return _chunkManager->findChunk( _chunkManager->getShardKey().globalMin() ).getShard();
}
string s = _config->getShard( getns() );
uassert( "can't call singleServerName on a sharded collection!" , s.size() > 0 );
@@ -98,9 +98,8 @@ namespace mongo {
_d.markReset();
}
- if ( _shardInfo ){
- //if ( _shardInfo->numShards() > 1 )
- s = SHARDED;
+ if ( _chunkManager ){
+ s = SHARDED;
}
if ( op == dbQuery ) {
diff --git a/s/request.h b/s/request.h
index 58b8dca7980..6be88afee3c 100644
--- a/s/request.h
+++ b/s/request.h
@@ -33,9 +33,12 @@ namespace mongo {
DBConfig * getConfig(){
return _config;
}
+ bool isShardingEnabled(){
+ return _config->isShardingEnabled();
+ }
ChunkManager * getChunkManager(){
- return _shardInfo;
+ return _chunkManager;
}
// ---- remote location info -----
@@ -69,7 +72,7 @@ namespace mongo {
MSGID _id;
DBConfig * _config;
- ChunkManager * _shardInfo;
+ ChunkManager * _chunkManager;
};
class StaleConfigException : public std::exception {
diff --git a/s/strategy_single.cpp b/s/strategy_single.cpp
index b45af4c57c2..2408b48055e 100644
--- a/s/strategy_single.cpp
+++ b/s/strategy_single.cpp
@@ -64,8 +64,51 @@ namespace mongo {
}
+ void handleIndexWrite( int op , Request& r ){
+
+ DbMessage& d = r.d();
+
+ if ( op == dbInsert ){
+ while( d.moreJSObjs() ){
+ BSONObj o = d.nextJsObj();
+ const char * ns = o["ns"].valuestr();
+ if ( r.getConfig()->isSharded( ns ) ){
+ uassert( "can't use unique indexes with sharding" , ! o["unique"].trueValue() );
+ ChunkManager * cm = r.getConfig()->getChunkManager( ns );
+ assert( cm );
+ for ( int i=0; i<cm->numChunks();i++)
+ doWrite( op , r , cm->getChunk(i)->getShard() );
+ }
+ else {
+ doWrite( op , r , r.singleServerName() );
+ }
+ }
+ }
+ else if ( op == dbUpdate ){
+ throw UserException( "can't update system.indexes" );
+ }
+ else if ( op == dbDelete ){
+ // TODO
+ throw UserException( "can't delete indexes on sharded collection yet" );
+ }
+ else {
+ log() << "handleIndexWrite invalid write op: " << op << endl;
+ throw UserException( "handleIndexWrite invalid write op" );
+ }
+
+ }
+
virtual void writeOp( int op , Request& r ){
const char *ns = r.getns();
+
+ if ( r.isShardingEnabled() &&
+ strstr( ns , ".system.indexes" ) == strstr( ns , "." ) &&
+ strstr( ns , "." ) ){
+ log(1) << " .system.indexes write for: " << ns << endl;
+ handleIndexWrite( op , r );
+ return;
+ }
+
log(3) << "single write: " << ns << endl;
doWrite( op , r , r.singleServerName() );
}