Esempio n. 1
0
    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;
    }
Esempio n. 2
0
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;
}
Esempio n. 3
0
        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();
        }