void run() { ShardKeyPattern shardKeyPattern(shardKey()); ChunkManager chunkManager("", shardKeyPattern, false); chunkManager.setSingleChunkForShards( splitPointsVector() ); set<Shard> shards; chunkManager.getShardsForQuery( shards, query() ); BSONArrayBuilder b; for( set<Shard>::const_iterator i = shards.begin(); i != shards.end(); ++i ) { b << i->getName(); } ASSERT_EQUALS( expectedShardNames(), b.arr() ); }
static Status checkUniqueIndexConstraints(const StringData& ns, const BSONObj& newIdxKey) { Lock::assertWriteLocked( ns ); if ( shardingState.enabled() ) { CollectionMetadataPtr metadata( shardingState.getCollectionMetadata( ns.toString() )); if ( metadata ) { BSONObj shardKey(metadata->getKeyPattern()); if ( !isUniqueIndexCompatible( shardKey, newIdxKey )) { return Status(ErrorCodes::CannotCreateIndex, str::stream() << "cannot create unique index over " << newIdxKey << " with shard key pattern " << shardKey); } } } return Status::OK(); }