static bool checkIndexConstraints(OperationContext* txn, ShardingState* shardingState, const BatchedCommandRequest& request, WriteOpResult* result) { const NamespaceString nss( request.getTargetingNS() ); txn->lockState()->assertWriteLocked( nss.ns() ); if ( !request.isUniqueIndexRequest() ) return true; if ( shardingState->enabled() ) { CollectionMetadataPtr metadata = shardingState->getCollectionMetadata( nss.ns() ); if ( metadata ) { if ( !isUniqueIndexCompatible( metadata->getKeyPattern(), request.getIndexKeyPattern() ) ) { result->setError(new WriteErrorDetail); buildUniqueIndexError(metadata->getKeyPattern(), request.getIndexKeyPattern(), result->getError()); return false; } } } return true; }
static bool checkIndexConstraints( ShardingState* shardingState, const BatchedCommandRequest& request, WriteErrorDetail** error ) { const NamespaceString nss( request.getTargetingNS() ); Lock::assertWriteLocked( nss.ns() ); if ( !request.isUniqueIndexRequest() ) return true; if ( shardingState->enabled() ) { CollectionMetadataPtr metadata = shardingState->getCollectionMetadata( nss.ns() ); if ( metadata ) { if ( !isUniqueIndexCompatible( metadata->getKeyPattern(), request.getIndexKeyPattern() ) ) { *error = new WriteErrorDetail; buildUniqueIndexError( metadata->getKeyPattern(), request.getIndexKeyPattern(), *error ); return false; } } } return true; }
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(); }