summaryrefslogtreecommitdiff
path: root/s/strategy_shard.cpp
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2009-02-26 15:02:18 -0500
committerEliot Horowitz <eliot@10gen.com>2009-02-26 15:02:18 -0500
commit76304fd05772345e7c57bb855c9b8a24f5cb1614 (patch)
tree5c8db98fff65d1a0382c486d3643bf55d643c5ec /s/strategy_shard.cpp
parente910263ed246b5964d57e5b45119463ac9b3b67f (diff)
downloadmongo-76304fd05772345e7c57bb855c9b8a24f5cb1614.tar.gz
sharded update
Diffstat (limited to 's/strategy_shard.cpp')
-rw-r--r--s/strategy_shard.cpp50
1 files changed, 38 insertions, 12 deletions
diff --git a/s/strategy_shard.cpp b/s/strategy_shard.cpp
index 1b9cd5de046..d07fd1e4e4e 100644
--- a/s/strategy_shard.cpp
+++ b/s/strategy_shard.cpp
@@ -102,6 +102,42 @@ namespace mongo {
cursorCache.remove( id );
}
+ void receivedInsert( Request& r , DbMessage& d, ShardManager* manager ){
+ while ( d.moreJSObjs() ){
+ BSONObj o = d.nextJsObj();
+ if ( ! manager->hasShardKey( o ) ){
+ log() << "tried to insert object without shard key: " << r.getns() << " " << o << endl;
+ throw UserException( "tried to insert object without shard key" );
+ }
+
+ Shard& s = manager->findShard( o );
+ log(4) << " server:" << s.getServer() << " " << o << endl;
+ insert( s.getServer() , r.getns() , o );
+ }
+ }
+
+ void receivedUpdate( Request& r , DbMessage& d, ShardManager* manager ){
+ int flags = d.pullInt();
+
+ BSONObj query = d.nextJsObj();
+ uassert( "invalid update" , d.moreJSObjs() );
+ BSONObj toupdate = d.nextJsObj();
+
+
+ bool upsert = flags & 1;
+ if ( upsert && ! manager->hasShardKey( toupdate ) )
+ throw UserException( "can't upsert something without shard key" );
+
+ if ( ! manager->hasShardKey( query ) )
+ throw UserException( "can't do update with query that doesn't have the shard key" );
+
+ if ( manager->hasShardKey( toupdate ) && manager->getShardKey().compare( query , toupdate ) )
+ throw UserException( "change would move shards!" );
+
+ Shard& s = manager->findShard( toupdate );
+ doWrite( dbUpdate , r , s.getServer() );
+ }
+
virtual void writeOp( int op , Request& r ){
const char *ns = r.getns();
@@ -112,20 +148,10 @@ namespace mongo {
assert( info );
if ( op == dbInsert ){
- while ( d.moreJSObjs() ){
- BSONObj o = d.nextJsObj();
- if ( ! info->hasShardKey( o ) ){
- log() << "tried to insert object without shard key: " << ns << " " << o << endl;
- throw UserException( "tried to insert object without shard key" );
- }
-
- Shard& s = info->findShard( o );
- log(4) << " server:" << s.getServer() << " " << o << endl;
- insert( s.getServer() , ns , o );
- }
+ receivedInsert( r , d , info );
}
else if ( op == dbUpdate ){
- throw UserException( "can't do update yet on sharded collection" );
+ receivedUpdate( r , d , info );
}
else {
log() << "sharding can't do write op: " << op << endl;