summaryrefslogtreecommitdiff
path: root/src/mongo/s/d_split.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/s/d_split.cpp')
-rw-r--r--src/mongo/s/d_split.cpp36
1 files changed, 29 insertions, 7 deletions
diff --git a/src/mongo/s/d_split.cpp b/src/mongo/s/d_split.cpp
index 048c8150c6b..da7e063d6f9 100644
--- a/src/mongo/s/d_split.cpp
+++ b/src/mongo/s/d_split.cpp
@@ -749,16 +749,38 @@ namespace mongo {
if (newChunks.size() == 2){
// If one of the chunks has only one object in it we should move it
- static const BSONObj fields = BSON("_id" << 1 );
- DBDirectClient conn;
for (int i=1; i >= 0 ; i--){ // high chunk more likely to have only one obj
- ChunkInfo chunk = newChunks[i];
- Query q = Query().minKey(chunk.min).maxKey(chunk.max);
- scoped_ptr<DBClientCursor> c (conn.query(ns, q, /*limit*/-2, 0, &fields));
- if (c && c->itcount() == 1) {
- result.append("shouldMigrate", BSON("min" << chunk.min << "max" << chunk.max));
+
+ Client::ReadContext ctx( ns );
+ NamespaceDetails *d = nsdetails( ns.c_str() );
+
+ const IndexDetails *idx = d->findIndexByPrefix( keyPattern ,
+ true ); /* exclude multikeys */
+ if ( idx == NULL ) {
break;
}
+
+ ChunkInfo chunk = newChunks[i];
+ BSONObj newmin = Helpers::modifiedRangeBound(chunk.min, idx->keyPattern(), -1);
+ BSONObj newmax = Helpers::modifiedRangeBound(chunk.max , idx->keyPattern(), -1);
+
+ scoped_ptr<BtreeCursor> bc( BtreeCursor::make( d ,
+ d->idxNo(*idx) ,
+ *idx ,
+ newmin , /* lower */
+ newmax , /* upper */
+ false , /* upper noninclusive */
+ 1 ) ); /* direction */
+
+ // check if exactly one document found
+ if ( bc->ok() ) {
+ bc->advance();
+ if ( bc->eof() ) {
+ result.append( "shouldMigrate",
+ BSON("min" << chunk.min << "max" << chunk.max) );
+ break;
+ }
+ }
}
}