mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
sharded delete
This commit is contained in:
parent
347c6a862f
commit
d8661d9b08
@ -136,4 +136,17 @@ db.foo.update( { num : 3 } , person );
|
||||
person = db.foo.findOne( { num : 3 } );
|
||||
assert.eq( "bob is gone" , person.name );
|
||||
|
||||
// remove
|
||||
assert( db.foo.findOne( { num : 3 } ) != null );
|
||||
db.foo.remove( { num : 3 } );
|
||||
assert( db.foo.findOne( { num : 3 } ) == null );
|
||||
|
||||
db.foo.save( { num : 3 , name : "eliot2" } );
|
||||
person = db.foo.findOne( { num : 3 } );
|
||||
assert( person );
|
||||
assert( person.name == "eliot2" );
|
||||
|
||||
db.foo.remove( { _id : person._id } );
|
||||
assert( db.foo.findOne( { num : 3 } ) == null );
|
||||
|
||||
s.stop();
|
||||
|
@ -137,7 +137,37 @@ namespace mongo {
|
||||
Shard& s = manager->findShard( toupdate );
|
||||
doWrite( dbUpdate , r , s.getServer() );
|
||||
}
|
||||
|
||||
void receivedDelete( 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() );
|
||||
}
|
||||
}
|
||||
|
||||
virtual void writeOp( int op , Request& r ){
|
||||
|
||||
const char *ns = r.getns();
|
||||
@ -153,6 +183,9 @@ namespace mongo {
|
||||
else if ( op == dbUpdate ){
|
||||
receivedUpdate( r , d , info );
|
||||
}
|
||||
else if ( op == dbDelete ){
|
||||
receivedDelete( r , d , info );
|
||||
}
|
||||
else {
|
||||
log() << "sharding can't do write op: " << op << endl;
|
||||
throw UserException( "can't do this write op on sharded collection" );
|
||||
|
Loading…
Reference in New Issue
Block a user