Esempio n. 1
0
    Status ChunkType::validate() const {

        if (!_name.is_initialized() || _name->empty()) {
            return Status(ErrorCodes::NoSuchKey,
                          str::stream() << "missing " << name.name() << " field");
        }

        if (!_ns.is_initialized() || _ns->empty()) {
            return Status(ErrorCodes::NoSuchKey,
                          str::stream() << "missing " << ns.name() << " field");
        }

        if (!_min.is_initialized() || _min->isEmpty()) {
            return Status(ErrorCodes::NoSuchKey,
                          str::stream() << "missing " << min.name() << " field");
        }

        if (!_max.is_initialized() || _max->isEmpty()) {
            return Status(ErrorCodes::NoSuchKey,
                          str::stream() << "missing " << max.name() << " field");
        }

        if (!_version.is_initialized() || !_version->isSet()) {
            return Status(ErrorCodes::NoSuchKey,
                          str::stream() << "missing " << version.name() << " field");
        }

        if (!_shard.is_initialized() || _shard->empty()) {
            return Status(ErrorCodes::NoSuchKey,
                          str::stream() << "missing " << shard.name() << " field");
        }

        // NOTE: all the following semantic checks should eventually become the caller's
        // responsibility, and should be moved out of this class completely

        // 'min' and 'max' must share the same fields.
        if (_min->nFields() != _max->nFields()) {
            return Status(ErrorCodes::FailedToParse,
                          str::stream() << "min and max have a different number of keys");
        }
        BSONObjIterator minIt(getMin());
        BSONObjIterator maxIt(getMax());
        while (minIt.more() && maxIt.more()) {
            BSONElement minElem = minIt.next();
            BSONElement maxElem = maxIt.next();
            if (strcmp(minElem.fieldName(), maxElem.fieldName())) {
                return Status(ErrorCodes::FailedToParse,
                              str::stream() << "min and max must have the same set of keys");
            }
        }

        // 'max' should be greater than 'min'.
        if (_min->woCompare(getMax()) >= 0) {
            return Status(ErrorCodes::FailedToParse,
                          str::stream() << "max key must be greater than min key");
        }

        return Status::OK();
    }
Esempio n. 2
0
    Status ChunkType::validate() const {

        if (!_name.is_initialized() || _name->empty()) {
            return Status(ErrorCodes::NoSuchKey,
                          str::stream() << "missing " << name.name() << " field");
        }

        if (!_ns.is_initialized() || _ns->empty()) {
            return Status(ErrorCodes::NoSuchKey,
                          str::stream() << "missing " << ns.name() << " field");
        }

        if (!_min.is_initialized() || _min->isEmpty()) {
            return Status(ErrorCodes::NoSuchKey,
                          str::stream() << "missing " << min.name() << " field");
        }

        if (!_max.is_initialized() || _max->isEmpty()) {
            return Status(ErrorCodes::NoSuchKey,
                          str::stream() << "missing " << max.name() << " field");
        }

        if (!_version.is_initialized() || !_version->isSet()) {
            return Status(ErrorCodes::NoSuchKey,
                          str::stream() << "missing " << version.name() << " field");
        }

        if (!_shard.is_initialized() || _shard->empty()) {
            return Status(ErrorCodes::NoSuchKey,
                          str::stream() << "missing " << shard.name() << " field");
        }

        // 'min' and 'max' must share the same fields.
        if (_min->nFields() != _max->nFields()) {
            return Status(ErrorCodes::BadValue,
                          str::stream() << "min and max have a different number of keys");
        }

        BSONObjIterator minIt(getMin());
        BSONObjIterator maxIt(getMax());
        while (minIt.more() && maxIt.more()) {
            BSONElement minElem = minIt.next();
            BSONElement maxElem = maxIt.next();
            if (strcmp(minElem.fieldName(), maxElem.fieldName())) {
                return Status(ErrorCodes::BadValue,
                              str::stream() << "min and max must have the same set of keys");
            }
        }

        // 'max' should be greater than 'min'.
        if (_min->woCompare(getMax()) >= 0) {
            return Status(ErrorCodes::BadValue,
                          str::stream() << "max key must be greater than min key");
        }

        return Status::OK();
    }
Esempio n. 3
0
Status ChunkType::validate() const {
    if (!_min.is_initialized() || _min->isEmpty()) {
        return Status(ErrorCodes::NoSuchKey, str::stream() << "missing " << min.name() << " field");
    }

    if (!_max.is_initialized() || _max->isEmpty()) {
        return Status(ErrorCodes::NoSuchKey, str::stream() << "missing " << max.name() << " field");
    }

    if (!_version.is_initialized() || !_version->isSet()) {
        return Status(ErrorCodes::NoSuchKey, str::stream() << "missing version field");
    }

    if (!_shard.is_initialized() || !_shard->isValid()) {
        return Status(ErrorCodes::NoSuchKey,
                      str::stream() << "missing " << shard.name() << " field");
    }

    // 'min' and 'max' must share the same fields.
    if (_min->nFields() != _max->nFields()) {
        return {ErrorCodes::BadValue,
                str::stream() << "min and max don't have the same number of keys: " << *_min << ", "
                              << *_max};
    }

    BSONObjIterator minIt(getMin());
    BSONObjIterator maxIt(getMax());
    while (minIt.more() && maxIt.more()) {
        BSONElement minElem = minIt.next();
        BSONElement maxElem = maxIt.next();
        if (strcmp(minElem.fieldName(), maxElem.fieldName())) {
            return {ErrorCodes::BadValue,
                    str::stream() << "min and max don't have matching keys: " << *_min << ", "
                                  << *_max};
        }
    }

    // 'max' should be greater than 'min'.
    if (_min->woCompare(getMax()) >= 0) {
        return {ErrorCodes::BadValue,
                str::stream() << "max is not greater than min: " << *_min << ", " << *_max};
    }

    return Status::OK();
}